@livelayer/react 0.5.24-debug.3 → 0.5.24-debug.4

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,4 +1,4 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),n=require("react"),Dn=require("@livelayer/sdk"),ht=require("livekit-client");class Qt extends n.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,o){var i,s;(s=(i=this.props).onError)==null||s.call(i,r,o)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[t.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),t.jsx("p",{className:"ll-error-boundary__message",children:((r=this.state.error)==null?void 0:r.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function Zt(e){const[r,o]=n.useState("idle"),[i,s]=n.useState("idle"),[a,d]=n.useState([]),[f,h]=n.useState(null),[b,w]=n.useState(null),[c,l]=n.useState(null),[S,E]=n.useState(!1),[L,x]=n.useState(null),_=n.useRef(null),T=n.useRef(e.onDataMessage);T.current=e.onDataMessage,n.useEffect(()=>{const R={onConnectionStateChange:I=>{o(I),I==="connected"&&x(null)},onAgentStateChange:s,onTranscript:I=>d([...I]),onAgentConfig:h,onAudioTrack:I=>l(I),onVideoTrack:I=>w(I),onVideoTrackRemoved:()=>w(null),onError:I=>x(I),onDataMessage:I=>{var A;(A=T.current)==null||A.call(T,I)},onResumabilityChange:E},z=new Dn.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody,manageMic:!1},R);return _.current=z,o("idle"),s("idle"),d([]),h(null),w(null),l(null),E(!1),x(null),()=>{var I;(I=z.destroy)==null||I.call(z),_.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const M=n.useCallback(async()=>{const R=_.current;if(R)try{await R.connect()}catch(z){throw x(z instanceof Error?z.message:String(z)),z}},[]),P=n.useCallback(()=>{const R=_.current;R&&R.disconnect()},[]),g=n.useCallback(()=>{var R;return((R=_.current)==null?void 0:R.getRoom())??null},[]);return{connectionState:r,agentState:i,transcript:a,agentConfig:f,videoElement:b,audioElement:c,canResume:S,error:L,connect:M,disconnect:P,getRoom:g,session:_.current}}function en(){const e=n.useRef(null),r=n.useRef(null),o=n.useRef(null),i=n.useRef(null),s=n.useRef(new Set),a=n.useRef(null),d=n.useCallback(()=>{const c=r.current;if(!c){i.current=null;return}(!a.current||a.current.length!==c.frequencyBinCount)&&(a.current=new Uint8Array(new ArrayBuffer(c.frequencyBinCount)));const l=a.current;c.getByteFrequencyData(l);let S=0;for(let L=0;L<l.length;L++)S+=l[L];const E=S/l.length/255;for(const L of s.current)try{L(E)}catch(x){console.error("[useAudioLevel] subscriber threw:",x)}i.current=requestAnimationFrame(d)},[]),f=n.useCallback(()=>{if(e.current||typeof window>"u"||typeof AudioContext>"u")return;const c=new AudioContext,l=c.createAnalyser();l.fftSize=64,l.connect(c.destination),e.current=c,r.current=l},[]),h=n.useCallback(c=>{if(f(),!(!e.current||!r.current)){if(o.current){try{o.current.disconnect()}catch{}o.current=null}try{const l=e.current.createMediaElementSource(c);l.connect(r.current),o.current=l}catch(l){console.warn("[useAudioLevel] createMediaElementSource failed:",l);return}i.current===null&&(i.current=requestAnimationFrame(d))}},[f,d]),b=n.useCallback(()=>{if(i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),o.current){try{o.current.disconnect()}catch{}o.current=null}},[]),w=n.useCallback(c=>(s.current.add(c),()=>{s.current.delete(c)}),[]);return n.useEffect(()=>()=>{if(b(),r.current){try{r.current.disconnect()}catch{}r.current=null}if(e.current){try{e.current.close()}catch{}e.current=null}s.current.clear(),a.current=null},[b]),{attach:h,detach:b,subscribe:w}}function tn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),s=n.useRef(null),a=n.useRef(null),d=n.useCallback(async(c,l)=>{if(s.current&&a.current){try{await a.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}a.current=c,i(null);try{const S=await ht.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await c.localParticipant.publishTrack(S),s.current=S,l!=null&&l.startMuted&&await S.mute(),r(S.isMuted)}catch(S){const E=S instanceof Error&&S.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw i(E),S}},[]),f=n.useCallback(()=>{const c=s.current;c&&(c.isMuted?(c.unmute(),r(!1)):(c.mute(),r(!0)))},[]),h=n.useCallback(c=>{const l=s.current;l&&(c&&!l.isMuted?(l.mute(),r(!0)):!c&&l.isMuted&&(l.unmute(),r(!1)))},[]),b=n.useCallback(()=>{const c=s.current,l=a.current;if(c&&l){try{l.localParticipant.unpublishTrack(c)}catch{}c.stop()}s.current=null,a.current=null,r(!1)},[]),w=n.useCallback(()=>i(null),[]);return{isMuted:e,micError:o,toggleMute:f,setMuted:h,setupMic:d,teardownMic:b,clearError:w}}const In={resolution:{width:640,height:480,frameRate:24}};function nn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),[d,f]=n.useState(""),h=n.useRef(null),b=n.useRef(null),w=n.useCallback(_=>{h.current=_},[]),c=n.useCallback(()=>{const _=h.current,T=b.current;if(T&&_){const M=_.localParticipant.getTrackPublication(ht.Track.Source.Camera);if(M!=null&&M.track){try{_.localParticipant.unpublishTrack(M.track)}catch{}M.track.stop()}else T.stop()}b.current=null,a(null),r(!1)},[]),l=n.useCallback(async _=>{const T=h.current;if(T){i(null);try{const M={...In};_&&(M.deviceId=_);const P=await ht.createLocalVideoTrack(M);await T.localParticipant.publishTrack(P),b.current=P;const g=P.attach();a(g),r(!0),_&&f(_);try{T.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(M){const P=M instanceof Error&&M.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";i(P)}}},[]),S=n.useCallback(async()=>{e?c():await l(d||void 0)},[e,d,c,l]),E=n.useCallback(async _=>{c(),await l(_)},[c,l]),L=n.useCallback(()=>{c(),h.current=null,i(null),f("")},[c]),x=n.useCallback(()=>i(null),[]);return n.useEffect(()=>()=>{b.current&&b.current.stop()},[]),{isEnabled:e,error:o,previewEl:s,activeDeviceId:d,toggle:S,switchDevice:E,attachRoom:w,teardown:L,clearError:x}}function rn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),d=n.useRef(null),f=n.useCallback(l=>{d.current=l},[]),h=n.useCallback(()=>a(null),[]),b=n.useCallback(async()=>{const l=d.current;if(l){if(e){try{await l.localParticipant.setScreenShareEnabled(!1)}catch{}h(),r(!1);return}i(null);try{await l.localParticipant.setScreenShareEnabled(!0);let S=0;const E=()=>{const L=l.localParticipant.getTrackPublication(ht.Track.Source.ScreenShare);if(L!=null&&L.track){const x=L.track.attach();a(x),r(!0);try{l.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}S++<10?setTimeout(E,100):r(!0)};E()}catch(S){const E=S instanceof Error?S.name:"";E!=="NotAllowedError"&&E!=="AbortError"&&i("Screen share unavailable. Try again."),r(!1)}}},[e,h]),w=n.useCallback(()=>{const l=d.current;if(l&&e)try{l.localParticipant.setScreenShareEnabled(!1)}catch{}h(),r(!1),i(null),d.current=null},[e,h]),c=n.useCallback(()=>i(null),[]);return{isEnabled:e,error:o,previewEl:s,toggle:b,attachRoom:f,teardown:w,clearError:c}}function on(){const[e,r]=n.useState([]),[o,i]=n.useState([]),s=n.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const a=await navigator.mediaDevices.enumerateDevices();r(a.filter(d=>d.kind==="audioinput")),i(a.filter(d=>d.kind==="videoinput"))}catch{}},[]);return n.useEffect(()=>{if(s(),typeof navigator>"u"||!navigator.mediaDevices)return;const a=()=>void s();return navigator.mediaDevices.addEventListener("devicechange",a),()=>navigator.mediaDevices.removeEventListener("devicechange",a)},[s]),{mics:e,cameras:o,refresh:s}}function sn(e,r,o=!1){const[i,s]=n.useState(null),[a,d]=n.useState(null),[f,h]=n.useState(!o&&!!e);return n.useEffect(()=>{if(o||!e){h(!1);return}const b=new AbortController,w=r||"https://app.livelayer.studio";return h(!0),d(null),fetch(`${w}/api/widget/agent/${encodeURIComponent(e)}`,{signal:b.signal}).then(async c=>{if(!c.ok){const l=await c.json().catch(()=>({}));throw new Error(l.error||`HTTP ${c.status}`)}return c.json()}).then(c=>{b.signal.aborted||(s(c),h(!1))}).catch(c=>{b.signal.aborted||(d(c instanceof Error?c.message:"Agent lookup failed"),h(!1))}),()=>b.abort()},[e,r,o]),{info:i,error:a,loading:f}}function Tn(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Pn(e,r){if(!(typeof window>"u"))try{window.localStorage.setItem(e,r)}catch{}}function an({value:e,defaultValue:r="expanded",onChange:o}={}){const i=e!==void 0,[s,a]=n.useState(r),d=i?e:s,f=n.useCallback(h=>{h!==d&&(i||a(h),o==null||o(h))},[d,i,o]);return[d,f]}const $n=["hidden","minimized","expanded"];function Bn(e){return e&&$n.includes(e)?e:null}function ln({value:e,defaultValue:r="expanded",onChange:o,persistKey:i="ll-widget",disablePersistence:s=!1}={}){const a=`${i}:display-mode`,d=n.useRef(!1),[f,h]=an({value:e,defaultValue:r,onChange:b=>{e===void 0&&!s&&Pn(a,b),o==null||o(b)}});return n.useEffect(()=>{if(d.current||(d.current=!0,s||e!==void 0))return;const b=Bn(Tn(a));b&&b!==f&&h(b)},[]),[f,h]}const zn=640;function cn(e=zn){const[r,o]=n.useState(!1);return n.useEffect(()=>{if(e===!1){o(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const i=`(max-width: ${e-1}px)`,s=window.matchMedia(i),a=()=>o(s.matches);return a(),typeof s.addEventListener=="function"?(s.addEventListener("change",a),()=>s.removeEventListener("change",a)):(s.addListener(a),()=>{s.removeListener(a)})},[e]),r}const Pt="__llHistoryPatched",mt="ll:pathname";function qn(){if(typeof window>"u"||window.history[Pt])return;const e=window.history.pushState,r=window.history.replaceState;window.history.pushState=function(...o){const i=e.apply(this,o);return window.dispatchEvent(new Event(mt)),i},window.history.replaceState=function(...o){const i=r.apply(this,o);return window.dispatchEvent(new Event(mt)),i},window.history[Pt]=!0}function $t(){return typeof window>"u"?"/":window.location.pathname||"/"}function un(e){const[r,o]=n.useState(()=>e??$t());return n.useEffect(()=>{if(e!==void 0)return;qn();const i=()=>o($t());return i(),window.addEventListener("popstate",i),window.addEventListener(mt,i),()=>{window.removeEventListener("popstate",i),window.removeEventListener(mt,i)}},[e]),e??r}const Bt=new Map,Hn=/[\\^$+?.()|{}[\]]/g;function On(e){return e.replace(Hn,"\\$&")}function Un(e){const r=Bt.get(e);if(r)return r;const o=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,i="",s="",a=o.replace(/\*\*/g,i).replace(/\*/g,s),f=On(a).replace(new RegExp(`\\/${i}`,"g"),"(?:\\/.*)?").replace(new RegExp(i,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),h=new RegExp(`^${f}\\/?$`);return Bt.set(e,h),h}function Wn(e,r){const o=r.length>1&&r.endsWith("/")?r.slice(0,-1):r;return Un(e).test(o)}function dn(e,r){return typeof e=="function"?e(r):e instanceof RegExp?e.test(r):Wn(e,r)}function zt(e,r){if(!e||e.length===0)return!1;for(const o of e)if(dn(o,r))return!0;return!1}function fn(e,r,o){return e===void 0?!0:zt(o,e)?!1:r&&r.length>0?zt(r,e):!0}function pn(e,r,o){return n.useMemo(()=>fn(e,r,o),[e,r,o])}const qt=({muted:e=!1,className:r})=>e?t.jsxs("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"})}),Ht=({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"})}),Vn=({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"})}),Fn={left:180,right:0,up:-90,down:90},Ot=({direction:e="right",className:r})=>t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${Fn[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function Gn(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const hn="ll-hidden-tab-center-y",Yn=5,Ut=16;function Jn(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(hn);if(!e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null}catch{return null}}function Wt(e){if(!(typeof window>"u"))try{window.localStorage.setItem(hn,String(e))}catch{}}const Kn=({position:e,isMobile:r,isSpeaking:o,onExpand:i,label:s="Open widget",avatarImageUrl:a,agentName:d})=>{const f=Gn(e),h=f==="right"?"left":"right",b=r?80:72,w=!!a,[c,l]=n.useState(null),[S,E]=n.useState(!1),L=n.useRef(null),x=n.useRef(!1),_=n.useCallback(A=>{if(typeof window>"u")return A;const $=b/2,U=Ut+$,K=window.innerHeight-Ut-$;return K<U?Math.max(U,A):Math.max(U,Math.min(K,A))},[b]);n.useEffect(()=>{const A=Jn();l(_(A??window.innerHeight/2));const $=()=>{l(U=>U===null?null:_(U))};return window.addEventListener("resize",$),()=>window.removeEventListener("resize",$)},[_]);const T=n.useCallback(A=>{if(!(A.pointerType==="mouse"&&A.button!==0)&&c!==null){try{A.currentTarget.setPointerCapture(A.pointerId)}catch{}L.current={startClientY:A.clientY,startCenterY:c,moved:!1}}},[c]),M=n.useCallback(A=>{const $=L.current;if(!$)return;const U=A.clientY-$.startClientY;!$.moved&&Math.abs(U)>Yn&&($.moved=!0,E(!0)),$.moved&&l(_($.startCenterY+U))},[_]),P=n.useCallback(A=>{const $=L.current;if($){try{A.currentTarget.releasePointerCapture(A.pointerId)}catch{}L.current=null,$.moved&&(E(!1),x.current=!0,l(U=>(U!==null&&Wt(U),U)))}},[]),g=n.useCallback(()=>{if(x.current){x.current=!1;return}i()},[i]),R=n.useCallback(A=>{if(A.key==="ArrowUp"||A.key==="ArrowDown"){A.preventDefault();const $=A.key==="ArrowUp"?-8:8;l(U=>{if(U===null)return U;const K=_(U+$);return Wt(K),K})}},[_]),z=["ll-hidden",`ll-hidden--${f}`,r?"ll-hidden--mobile":"ll-hidden--desktop",o?"ll-hidden--speaking":null,S?"is-dragging":null,w?"ll-hidden--with-avatar":null].filter(Boolean).join(" "),I=c===null?void 0:{top:`${c-b/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:z,onPointerDown:T,onPointerMove:M,onPointerUp:P,onPointerCancel:P,onClick:g,onKeyDown:R,"aria-label":s,"data-position":e,style:I,children:w?t.jsxs(t.Fragment,{children:[t.jsx(Ot,{direction:h,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:a,alt:d?`${d} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Ot,{direction:h,className:"ll-hidden__chevron"})})},Xn=({audioLevel:e,bars:r=20,maxHeight:o=20,minHeight:i=4,className:s,barClassName:a})=>{const d=n.useRef(null),f=n.useRef([]),h=n.useMemo(()=>{const w=(Math.sqrt(5)-1)/2;return Array.from({length:r},(c,l)=>.5+l*w%1*.5)},[r]);n.useEffect(()=>e.subscribe(c=>{for(let l=0;l<r;l++){const S=f.current[l];if(!S)continue;const E=Math.max(i,c*o*h[l]);S.style.height=`${E}px`}}),[e,r,o,i,h]);const b=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:d,className:b,"aria-hidden":"true",children:Array.from({length:r},(w,c)=>t.jsx("div",{ref:l=>{f.current[c]=l},className:["ll-waveform__bar",a].filter(Boolean).join(" "),style:{height:`${i}px`}},c))})},Qn=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,agentState:s,isMuted:a,audioLevel:d,onExpand:f,onToggleMute:h,onClose:b})=>r?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${o} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:f,"aria-label":`Expand ${o} widget`,children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsx(Xn,{audioLevel:d,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:w=>{w.stopPropagation(),h()},onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.stopPropagation(),w.preventDefault(),h())},"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(qt,{muted:a,className:"ll-minimized__icon"})}),t.jsx(Ht,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):t.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${o} widget`,children:t.jsxs("div",{className:"ll-minimized__surface",children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsxs("div",{className:"ll-minimized__meta",children:[t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsx("span",{className:"ll-minimized__state",children:s==="speaking"?"Speaking":s==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:h,"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(qt,{muted:a,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:f,"aria-label":`Expand ${o} widget`,children:t.jsx(Ht,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:b,"aria-label":"Close widget",children:t.jsx(Vn,{className:"ll-minimized__icon"})})]})]})}),Zn=({src:e,alt:r,preCannedPlaying:o=!1,className:i,style:s})=>{const[a,d]=n.useState(!1),f=n.useRef(e);if(n.useEffect(()=>{f.current!==e&&(f.current=e,d(!1))},[e]),!e)return null;const h={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:o?"scale(1.02)":"scale(1)",opacity:a?1:0,...s};return t.jsx("img",{src:e,alt:r,className:i,style:h,loading:"eager",fetchPriority:"high",onLoad:()=>d(!0)})},er=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,idleLoopUrl:s,greeting:a,branding:d,teamMembers:f,currentTeamMemberId:h,isSwitchingTeamMember:b,teamSwitcherOpen:w,onToggleTeamSwitcher:c,onSelectTeamMember:l,languageMenuOpen:S,onToggleLanguageMenu:E,connectionState:L,agentState:x,transcript:_,canResume:T,needsUserGesture:M,error:P,isMuted:g,micError:R,micDevices:z,isCameraEnabled:I,cameraPreviewEl:A,cameraDevices:$,activeCameraId:U,isScreenShareEnabled:K,screenPreviewEl:ne,isSpeakerMuted:ve,allowCamera:tt,allowScreenShare:nt,allowTyping:rt,avatarVideoContainerRef:ot,agentVideoEl:te,micGateOpen:ue,onConnect:we,onDisconnect:Le,onRetry:Ee,onResumeAudio:je,onToggleMute:Ne,onToggleCamera:Re,onSwitchCameraDevice:V,onToggleScreenShare:yt,onToggleSpeaker:bt,onSendMessage:it,onMinimize:re,onClose:Ae,onClearMicError:Oe})=>{var Pe;const _e=((f==null?void 0:f.length)??0)>1,Me=L==="connecting"||L==="connected",G=L==="connected",X=L==="idle"||L==="disconnected"||L==="error",[De,oe]=n.useState(!1);n.useEffect(()=>{if(!te){oe(!1);return}if(!te.paused&&te.readyState>=2){oe(!0);return}oe(!1);const m=()=>oe(!0);return te.addEventListener("playing",m),te.addEventListener("loadeddata",m),()=>{te.removeEventListener("playing",m),te.removeEventListener("loadeddata",m)}},[te]);const[de,ke]=n.useState(!1);n.useEffect(()=>{if(!G){ke(!1);return}if(De)return;const m=setTimeout(()=>ke(!0),8e3);return()=>clearTimeout(m)},[G,De]);const Ue=L==="connecting"||G&&!!i&&!De&&!de,Z=n.useRef(null),ie=n.useRef(null);n.useEffect(()=>{const m=Z.current;m&&(m.innerHTML="",A&&(A.style.width="100%",A.style.height="100%",A.style.objectFit="cover",A.style.transform="scaleX(-1)",m.appendChild(A)))},[A]),n.useEffect(()=>{const m=ie.current;m&&(m.innerHTML="",ne&&(ne.style.width="100%",ne.style.height="100%",ne.style.objectFit="contain",m.appendChild(ne)))},[ne]);const[se,fe]=n.useState(!1),[Ie,pe]=n.useState(!1);n.useEffect(()=>{if(!se&&!Ie&&!S&&!w)return;const m=()=>{fe(!1),pe(!1),S&&E(),w&&c()};return document.addEventListener("click",m),()=>document.removeEventListener("click",m)},[se,Ie,S,w,E,c]);const[he,We]=n.useState(""),Ve=n.useCallback(m=>{m.preventDefault();const F=he.trim();F&&(it(F),We(""))},[he,it]),Fe=d.productName||"Live Layer";let me=null,ge=null;for(let m=_.length-1;m>=0;m--){const F=_[m];if(!me&&F.role==="agent"?me=F:!ge&&F.role==="user"&&(ge=F),me&&ge)break}const Te=G?(me==null?void 0:me.text)||null:a||null,st=G&&(ge==null?void 0:ge.text)||null,Ge=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:Ge,"data-position":e,"data-state":G?"connected":Me?"connecting":"idle",role:"dialog","aria-label":`${o} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[i?t.jsx(Zn,{src:i,alt:o,className:"ll-expanded__bg-img"}):t.jsx("div",{className:"ll-expanded__bg-fallback",children:t.jsx("span",{className:"ll-expanded__bg-initial",children:((Pe=o==null?void 0:o.charAt(0))==null?void 0:Pe.toUpperCase())||"A"})}),s&&!G&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:ot,className:"ll-expanded__video"}),Ue&&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:b?"Switching...":"Connecting..."})]}),M&&G&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:je,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"})]}),Me?t.jsxs("div",{className:"ll-expanded__topbar",children:[t.jsxs("div",{className:"ll-expanded__topbar-left",children:[t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill",onClick:m=>{_e&&(m.stopPropagation(),c())},"aria-haspopup":_e?"listbox":void 0,"aria-expanded":_e?w:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:o}),_e&&t.jsx(ft,{})]}),_e&&w&&t.jsx("div",{className:"ll-hmenu",onClick:m=>m.stopPropagation(),role:"listbox",children:f==null?void 0:f.map(m=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${m.id===h?"is-active":""}`,onClick:()=>l(m.id),role:"option","aria-selected":m.id===h,children:[m.avatarImageUrl&&t.jsx("img",{src:m.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:m.name}),m.role&&t.jsx("span",{className:"ll-hmenu__role",children:m.role})]},m.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:m=>{m.stopPropagation(),E()},"aria-haspopup":"listbox","aria-expanded":S,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(ft,{})]}),S&&t.jsx("div",{className:"ll-hmenu",onClick:m=>m.stopPropagation(),role:"listbox",children:t.jsx("button",{type:"button",className:"ll-hmenu__item is-active",role:"option","aria-selected":!0,children:t.jsx("span",{className:"ll-hmenu__name",children:"English"})})})]}),t.jsx("span",{className:`ll-expanded__state ll-expanded__state--${x}`,children:x})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn",onClick:re,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(Ft,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Ae,"aria-label":"End call",title:"End call",children:t.jsx(Vt,{})})]})]}):t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:Fe}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:re,"aria-label":"Minimize widget",children:t.jsx(Ft,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Ae,"aria-label":"Close widget",children:t.jsx(Vt,{})})]})]}),X&&(()=>{const m=T?"Restart paused session":L==="disconnected"?"Reconnect to agent":"Start video call",F=T?"Pick up where you left off":null,at=L==="idle"&&!T&&!P;return t.jsxs(t.Fragment,{children:[at&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:we,"aria-label":m,children:[t.jsx("div",{className:"ll-expanded__play-circle",children:t.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:t.jsx("polygon",{points:"6 3 20 12 6 21 6 3"})})}),t.jsx("span",{className:"ll-expanded__play-label",children:m})]}),t.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[a&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:a})}),F&&t.jsx("p",{className:"ll-expanded__cta-sublabel",children:F}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:we,"aria-label":m,children:m})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${Me&&(I||K)?"is-visible":""}`,children:[t.jsx("div",{ref:ie,className:K?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:Z,className:!K&&I?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Me?t.jsxs("div",{className:"ll-expanded__bottom",children:[Te&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Te})}),st&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:st})}),t.jsxs("div",{className:"ll-toolbar",onClick:m=>m.stopPropagation(),children:[nt&&t.jsx("button",{type:"button",className:`ll-tool ${K?"is-on":""}`,onClick:yt,"aria-label":K?"Stop sharing screen":"Share screen",title:K?"Stop sharing":"Share screen",children:t.jsx(tr,{})}),tt&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${I?"is-on":""}`,onClick:Re,"aria-label":I?"Turn off camera":"Turn on camera",title:I?"Stop camera":"Start camera",children:t.jsx(nr,{})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${I?"is-on":""}`,onClick:m=>{m.stopPropagation(),pe(F=>!F),fe(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":Ie,children:t.jsx(ft,{})}),Ie&&$.length>0&&t.jsx(Gt,{label:"Camera",devices:$,activeId:U,onPick:m=>{pe(!1),V(m)}})]}),t.jsxs("div",{className:`ll-tool-split${!ue&&G?" ll-tool-split--gated":""}`,children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${g?"is-muted":""}`,onClick:Ne,disabled:!ue&&G,"aria-label":!ue&&G?"Microphone enables once the agent finishes its greeting":g?"Unmute microphone":"Mute microphone",title:!ue&&G?"Mic enables after greeting":g?"Unmute":"Mute",children:t.jsx(rr,{muted:g})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${g?"is-muted":""}`,onClick:m=>{m.stopPropagation(),fe(F=>!F),pe(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":se,children:t.jsx(ft,{})}),se&&z.length>0&&t.jsx(Gt,{label:"Microphone",devices:z,activeId:"",onPick:()=>fe(!1)})]}),t.jsx("button",{type:"button",className:`ll-tool ${ve?"is-muted":""}`,onClick:bt,"aria-label":ve?"Unmute speaker":"Mute speaker",title:ve?"Unmute speaker":"Mute speaker",children:t.jsx(or,{muted:ve})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:Le,"aria-label":"End conversation",title:"End conversation",children:t.jsx(sr,{})})]}),rt&&t.jsxs("form",{className:"ll-message-input",onSubmit:Ve,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:he,onChange:m=>We(m.target.value),"aria-label":"Message the agent"}),he.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(ir,{})})]})]}):null,(()=>{if(R&&L!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:R}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:Oe,"aria-label":"Dismiss",children:"×"})]});if(!P||L!=="error")return null;let m="Failed to connect",F="Try again";return P==="MIC_PERMISSION_DENIED"?m="Microphone blocked. Allow access to talk.":P==="MIC_NOT_FOUND"?m="No microphone found. Plug one in + retry.":P==="MIC_UNAVAILABLE"?m="Mic unavailable. Check other apps using it.":P==="AGENT_TIMEOUT"?m="Agent didn't pick up. Try again.":P==="CONNECT_FAILED"?m="Connection failed. Check your network.":P.length<80&&(m=P),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:m}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:Ee,children:F})]})})()]})};function ft(){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 Vt(){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 Ft(){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 tr(){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 nr(){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 rr({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 or({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 ir(){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 sr(){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 Gt=({label:e,devices:r,activeId:o,onPick:i})=>t.jsxs("div",{className:"ll-device-menu",onClick:s=>s.stopPropagation(),role:"listbox",children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),r.map((s,a)=>{const d=o===s.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${d?"is-active":""}`,onClick:()=>i(s.deviceId),role:"option","aria-selected":d,children:[d&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:s.label||`${e} ${a+1}`})]},s.deviceId||a)})]}),ar=['[data-ll-private="true"]',".ll-widget"];function St(e){let r=e;for(;r;){for(const o of ar)if(r.matches(o))return!0;r=r.parentElement}return!1}function gt(e){if(St(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const r=(e.getAttribute("autocomplete")||"").toLowerCase();if(r==="off"||r.startsWith("cc-"))return!1}return!0}const pt=4096,lr=20,cr=20,ur=10,dr=10,fr=30,Yt=500,pr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function Qe(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let r=e;for(;r;){for(const o of pr)if(r.matches(o))return!0;r=r.parentElement}return!1}function Ze(e){if(typeof window>"u")return!0;const r=e.getBoundingClientRect();if(r.width<=0||r.height<=0)return!1;const o=window.innerHeight||document.documentElement.clientHeight,i=window.innerWidth||document.documentElement.clientWidth;return r.bottom>0&&r.right>0&&r.top<o&&r.left<i}function Jt(e){const r=e.getAttribute("id");if(r){const a=document.querySelector(`label[for="${CSS.escape(r)}"]`);if(a!=null&&a.textContent)return a.textContent.trim()}const o=e.getAttribute("aria-label");if(o)return o.trim();const i=e.getAttribute("placeholder");if(i)return i.trim();const s=e.closest("label");return s!=null&&s.textContent?s.textContent.trim():""}function Ce(e,r){return e.length<=r?e:e.slice(0,r-1)+"…"}function Be(e){return e.length}function mn(e,r={}){const o=r.doc??(typeof document<"u"?document:null);if(!o)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const i=typeof window<"u"&&window.location.href||"",s=typeof window<"u"&&window.location.pathname||"/",a=o.title||"",d=Array.from(o.querySelectorAll("[data-ll-region]")),f=[];for(const g of d){if(f.length>=ur)break;if(Qe(g)||!Ze(g))continue;const R=g.getAttribute("data-ll-region")??"",z=g.getAttribute("data-ll-intent")??void 0,I=Ce((g.innerText||g.textContent||"").trim(),Yt*2);!R||!I||f.push({id:R,intent:z,text:I})}const h=[],b=["H1","H2","H3","H4","H5","H6"],w=Array.from(o.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const g of w){if(Qe(g)||!Ze(g))continue;const R=(g.textContent||"").trim();R&&h.push(`${g.tagName}: ${Ce(R,200)}`)}const c=Array.from(o.querySelectorAll("p, li"));for(const g of c){if(Qe(g)||!Ze(g)||b.includes(g.tagName))continue;const R=(g.textContent||"").trim();R.length>10&&h.push(Ce(R,Yt))}const l=h.join(`
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),n=require("react"),Dn=require("@livelayer/sdk"),ht=require("livekit-client");class Qt extends n.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,o){var i,s;(s=(i=this.props).onError)==null||s.call(i,r,o)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[t.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),t.jsx("p",{className:"ll-error-boundary__message",children:((r=this.state.error)==null?void 0:r.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function Zt(e){const[r,o]=n.useState("idle"),[i,s]=n.useState("idle"),[a,d]=n.useState([]),[f,h]=n.useState(null),[b,w]=n.useState(null),[c,l]=n.useState(null),[S,E]=n.useState(!1),[L,x]=n.useState(null),_=n.useRef(null),T=n.useRef(e.onDataMessage);T.current=e.onDataMessage,n.useEffect(()=>{const R={onConnectionStateChange:I=>{o(I),I==="connected"&&x(null)},onAgentStateChange:s,onTranscript:I=>d([...I]),onAgentConfig:h,onAudioTrack:I=>l(I),onVideoTrack:I=>w(I),onVideoTrackRemoved:()=>w(null),onError:I=>x(I),onDataMessage:I=>{var A;(A=T.current)==null||A.call(T,I)},onResumabilityChange:E},z=new Dn.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody,manageMic:!1},R);return _.current=z,o("idle"),s("idle"),d([]),h(null),w(null),l(null),E(!1),x(null),()=>{var I;(I=z.destroy)==null||I.call(z),_.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const M=n.useCallback(async()=>{const R=_.current;if(R)try{await R.connect()}catch(z){throw x(z instanceof Error?z.message:String(z)),z}},[]),P=n.useCallback(()=>{const R=_.current;R&&R.disconnect()},[]),g=n.useCallback(()=>{var R;return((R=_.current)==null?void 0:R.getRoom())??null},[]);return{connectionState:r,agentState:i,transcript:a,agentConfig:f,videoElement:b,audioElement:c,canResume:S,error:L,connect:M,disconnect:P,getRoom:g,session:_.current}}function en(){const e=n.useRef(null),r=n.useRef(null),o=n.useRef(null),i=n.useRef(null),s=n.useRef(new Set),a=n.useRef(null),d=n.useCallback(()=>{const c=r.current;if(!c){i.current=null;return}(!a.current||a.current.length!==c.frequencyBinCount)&&(a.current=new Uint8Array(new ArrayBuffer(c.frequencyBinCount)));const l=a.current;c.getByteFrequencyData(l);let S=0;for(let L=0;L<l.length;L++)S+=l[L];const E=S/l.length/255;for(const L of s.current)try{L(E)}catch(x){console.error("[useAudioLevel] subscriber threw:",x)}i.current=requestAnimationFrame(d)},[]),f=n.useCallback(()=>{if(e.current||typeof window>"u"||typeof AudioContext>"u")return;const c=new AudioContext,l=c.createAnalyser();l.fftSize=64,l.connect(c.destination),e.current=c,r.current=l},[]),h=n.useCallback(c=>{if(f(),!(!e.current||!r.current)){if(o.current){try{o.current.disconnect()}catch{}o.current=null}try{const l=e.current.createMediaElementSource(c);l.connect(r.current),o.current=l}catch(l){console.warn("[useAudioLevel] createMediaElementSource failed:",l);return}i.current===null&&(i.current=requestAnimationFrame(d))}},[f,d]),b=n.useCallback(()=>{if(i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),o.current){try{o.current.disconnect()}catch{}o.current=null}},[]),w=n.useCallback(c=>(s.current.add(c),()=>{s.current.delete(c)}),[]);return n.useEffect(()=>()=>{if(b(),r.current){try{r.current.disconnect()}catch{}r.current=null}if(e.current){try{e.current.close()}catch{}e.current=null}s.current.clear(),a.current=null},[b]),{attach:h,detach:b,subscribe:w}}function tn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),s=n.useRef(null),a=n.useRef(null),d=n.useCallback(async(c,l)=>{if(s.current&&a.current){try{await a.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}a.current=c,i(null);try{const S=await ht.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await c.localParticipant.publishTrack(S),s.current=S,r(S.isMuted)}catch(S){const E=S instanceof Error&&S.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw i(E),S}},[]),f=n.useCallback(()=>{const c=s.current;c&&(c.isMuted?(c.unmute(),r(!1)):(c.mute(),r(!0)))},[]),h=n.useCallback(c=>{const l=s.current;l&&(c&&!l.isMuted?(l.mute(),r(!0)):!c&&l.isMuted&&(l.unmute(),r(!1)))},[]),b=n.useCallback(()=>{const c=s.current,l=a.current;if(c&&l){try{l.localParticipant.unpublishTrack(c)}catch{}c.stop()}s.current=null,a.current=null,r(!1)},[]),w=n.useCallback(()=>i(null),[]);return{isMuted:e,micError:o,toggleMute:f,setMuted:h,setupMic:d,teardownMic:b,clearError:w}}const In={resolution:{width:640,height:480,frameRate:24}};function nn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),[d,f]=n.useState(""),h=n.useRef(null),b=n.useRef(null),w=n.useCallback(_=>{h.current=_},[]),c=n.useCallback(()=>{const _=h.current,T=b.current;if(T&&_){const M=_.localParticipant.getTrackPublication(ht.Track.Source.Camera);if(M!=null&&M.track){try{_.localParticipant.unpublishTrack(M.track)}catch{}M.track.stop()}else T.stop()}b.current=null,a(null),r(!1)},[]),l=n.useCallback(async _=>{const T=h.current;if(T){i(null);try{const M={...In};_&&(M.deviceId=_);const P=await ht.createLocalVideoTrack(M);await T.localParticipant.publishTrack(P),b.current=P;const g=P.attach();a(g),r(!0),_&&f(_);try{T.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(M){const P=M instanceof Error&&M.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";i(P)}}},[]),S=n.useCallback(async()=>{e?c():await l(d||void 0)},[e,d,c,l]),E=n.useCallback(async _=>{c(),await l(_)},[c,l]),L=n.useCallback(()=>{c(),h.current=null,i(null),f("")},[c]),x=n.useCallback(()=>i(null),[]);return n.useEffect(()=>()=>{b.current&&b.current.stop()},[]),{isEnabled:e,error:o,previewEl:s,activeDeviceId:d,toggle:S,switchDevice:E,attachRoom:w,teardown:L,clearError:x}}function rn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),d=n.useRef(null),f=n.useCallback(l=>{d.current=l},[]),h=n.useCallback(()=>a(null),[]),b=n.useCallback(async()=>{const l=d.current;if(l){if(e){try{await l.localParticipant.setScreenShareEnabled(!1)}catch{}h(),r(!1);return}i(null);try{await l.localParticipant.setScreenShareEnabled(!0);let S=0;const E=()=>{const L=l.localParticipant.getTrackPublication(ht.Track.Source.ScreenShare);if(L!=null&&L.track){const x=L.track.attach();a(x),r(!0);try{l.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}S++<10?setTimeout(E,100):r(!0)};E()}catch(S){const E=S instanceof Error?S.name:"";E!=="NotAllowedError"&&E!=="AbortError"&&i("Screen share unavailable. Try again."),r(!1)}}},[e,h]),w=n.useCallback(()=>{const l=d.current;if(l&&e)try{l.localParticipant.setScreenShareEnabled(!1)}catch{}h(),r(!1),i(null),d.current=null},[e,h]),c=n.useCallback(()=>i(null),[]);return{isEnabled:e,error:o,previewEl:s,toggle:b,attachRoom:f,teardown:w,clearError:c}}function on(){const[e,r]=n.useState([]),[o,i]=n.useState([]),s=n.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const a=await navigator.mediaDevices.enumerateDevices();r(a.filter(d=>d.kind==="audioinput")),i(a.filter(d=>d.kind==="videoinput"))}catch{}},[]);return n.useEffect(()=>{if(s(),typeof navigator>"u"||!navigator.mediaDevices)return;const a=()=>void s();return navigator.mediaDevices.addEventListener("devicechange",a),()=>navigator.mediaDevices.removeEventListener("devicechange",a)},[s]),{mics:e,cameras:o,refresh:s}}function sn(e,r,o=!1){const[i,s]=n.useState(null),[a,d]=n.useState(null),[f,h]=n.useState(!o&&!!e);return n.useEffect(()=>{if(o||!e){h(!1);return}const b=new AbortController,w=r||"https://app.livelayer.studio";return h(!0),d(null),fetch(`${w}/api/widget/agent/${encodeURIComponent(e)}`,{signal:b.signal}).then(async c=>{if(!c.ok){const l=await c.json().catch(()=>({}));throw new Error(l.error||`HTTP ${c.status}`)}return c.json()}).then(c=>{b.signal.aborted||(s(c),h(!1))}).catch(c=>{b.signal.aborted||(d(c instanceof Error?c.message:"Agent lookup failed"),h(!1))}),()=>b.abort()},[e,r,o]),{info:i,error:a,loading:f}}function Tn(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Pn(e,r){if(!(typeof window>"u"))try{window.localStorage.setItem(e,r)}catch{}}function an({value:e,defaultValue:r="expanded",onChange:o}={}){const i=e!==void 0,[s,a]=n.useState(r),d=i?e:s,f=n.useCallback(h=>{h!==d&&(i||a(h),o==null||o(h))},[d,i,o]);return[d,f]}const $n=["hidden","minimized","expanded"];function Bn(e){return e&&$n.includes(e)?e:null}function ln({value:e,defaultValue:r="expanded",onChange:o,persistKey:i="ll-widget",disablePersistence:s=!1}={}){const a=`${i}:display-mode`,d=n.useRef(!1),[f,h]=an({value:e,defaultValue:r,onChange:b=>{e===void 0&&!s&&Pn(a,b),o==null||o(b)}});return n.useEffect(()=>{if(d.current||(d.current=!0,s||e!==void 0))return;const b=Bn(Tn(a));b&&b!==f&&h(b)},[]),[f,h]}const zn=640;function cn(e=zn){const[r,o]=n.useState(!1);return n.useEffect(()=>{if(e===!1){o(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const i=`(max-width: ${e-1}px)`,s=window.matchMedia(i),a=()=>o(s.matches);return a(),typeof s.addEventListener=="function"?(s.addEventListener("change",a),()=>s.removeEventListener("change",a)):(s.addListener(a),()=>{s.removeListener(a)})},[e]),r}const Pt="__llHistoryPatched",mt="ll:pathname";function qn(){if(typeof window>"u"||window.history[Pt])return;const e=window.history.pushState,r=window.history.replaceState;window.history.pushState=function(...o){const i=e.apply(this,o);return window.dispatchEvent(new Event(mt)),i},window.history.replaceState=function(...o){const i=r.apply(this,o);return window.dispatchEvent(new Event(mt)),i},window.history[Pt]=!0}function $t(){return typeof window>"u"?"/":window.location.pathname||"/"}function un(e){const[r,o]=n.useState(()=>e??$t());return n.useEffect(()=>{if(e!==void 0)return;qn();const i=()=>o($t());return i(),window.addEventListener("popstate",i),window.addEventListener(mt,i),()=>{window.removeEventListener("popstate",i),window.removeEventListener(mt,i)}},[e]),e??r}const Bt=new Map,Hn=/[\\^$+?.()|{}[\]]/g;function On(e){return e.replace(Hn,"\\$&")}function Un(e){const r=Bt.get(e);if(r)return r;const o=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,i="",s="",a=o.replace(/\*\*/g,i).replace(/\*/g,s),f=On(a).replace(new RegExp(`\\/${i}`,"g"),"(?:\\/.*)?").replace(new RegExp(i,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),h=new RegExp(`^${f}\\/?$`);return Bt.set(e,h),h}function Wn(e,r){const o=r.length>1&&r.endsWith("/")?r.slice(0,-1):r;return Un(e).test(o)}function dn(e,r){return typeof e=="function"?e(r):e instanceof RegExp?e.test(r):Wn(e,r)}function zt(e,r){if(!e||e.length===0)return!1;for(const o of e)if(dn(o,r))return!0;return!1}function fn(e,r,o){return e===void 0?!0:zt(o,e)?!1:r&&r.length>0?zt(r,e):!0}function pn(e,r,o){return n.useMemo(()=>fn(e,r,o),[e,r,o])}const qt=({muted:e=!1,className:r})=>e?t.jsxs("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"})}),Ht=({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"})}),Vn=({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"})}),Fn={left:180,right:0,up:-90,down:90},Ot=({direction:e="right",className:r})=>t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${Fn[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function Gn(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const hn="ll-hidden-tab-center-y",Yn=5,Ut=16;function Jn(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(hn);if(!e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null}catch{return null}}function Wt(e){if(!(typeof window>"u"))try{window.localStorage.setItem(hn,String(e))}catch{}}const Kn=({position:e,isMobile:r,isSpeaking:o,onExpand:i,label:s="Open widget",avatarImageUrl:a,agentName:d})=>{const f=Gn(e),h=f==="right"?"left":"right",b=r?80:72,w=!!a,[c,l]=n.useState(null),[S,E]=n.useState(!1),L=n.useRef(null),x=n.useRef(!1),_=n.useCallback(A=>{if(typeof window>"u")return A;const $=b/2,U=Ut+$,K=window.innerHeight-Ut-$;return K<U?Math.max(U,A):Math.max(U,Math.min(K,A))},[b]);n.useEffect(()=>{const A=Jn();l(_(A??window.innerHeight/2));const $=()=>{l(U=>U===null?null:_(U))};return window.addEventListener("resize",$),()=>window.removeEventListener("resize",$)},[_]);const T=n.useCallback(A=>{if(!(A.pointerType==="mouse"&&A.button!==0)&&c!==null){try{A.currentTarget.setPointerCapture(A.pointerId)}catch{}L.current={startClientY:A.clientY,startCenterY:c,moved:!1}}},[c]),M=n.useCallback(A=>{const $=L.current;if(!$)return;const U=A.clientY-$.startClientY;!$.moved&&Math.abs(U)>Yn&&($.moved=!0,E(!0)),$.moved&&l(_($.startCenterY+U))},[_]),P=n.useCallback(A=>{const $=L.current;if($){try{A.currentTarget.releasePointerCapture(A.pointerId)}catch{}L.current=null,$.moved&&(E(!1),x.current=!0,l(U=>(U!==null&&Wt(U),U)))}},[]),g=n.useCallback(()=>{if(x.current){x.current=!1;return}i()},[i]),R=n.useCallback(A=>{if(A.key==="ArrowUp"||A.key==="ArrowDown"){A.preventDefault();const $=A.key==="ArrowUp"?-8:8;l(U=>{if(U===null)return U;const K=_(U+$);return Wt(K),K})}},[_]),z=["ll-hidden",`ll-hidden--${f}`,r?"ll-hidden--mobile":"ll-hidden--desktop",o?"ll-hidden--speaking":null,S?"is-dragging":null,w?"ll-hidden--with-avatar":null].filter(Boolean).join(" "),I=c===null?void 0:{top:`${c-b/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:z,onPointerDown:T,onPointerMove:M,onPointerUp:P,onPointerCancel:P,onClick:g,onKeyDown:R,"aria-label":s,"data-position":e,style:I,children:w?t.jsxs(t.Fragment,{children:[t.jsx(Ot,{direction:h,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:a,alt:d?`${d} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Ot,{direction:h,className:"ll-hidden__chevron"})})},Xn=({audioLevel:e,bars:r=20,maxHeight:o=20,minHeight:i=4,className:s,barClassName:a})=>{const d=n.useRef(null),f=n.useRef([]),h=n.useMemo(()=>{const w=(Math.sqrt(5)-1)/2;return Array.from({length:r},(c,l)=>.5+l*w%1*.5)},[r]);n.useEffect(()=>e.subscribe(c=>{for(let l=0;l<r;l++){const S=f.current[l];if(!S)continue;const E=Math.max(i,c*o*h[l]);S.style.height=`${E}px`}}),[e,r,o,i,h]);const b=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:d,className:b,"aria-hidden":"true",children:Array.from({length:r},(w,c)=>t.jsx("div",{ref:l=>{f.current[c]=l},className:["ll-waveform__bar",a].filter(Boolean).join(" "),style:{height:`${i}px`}},c))})},Qn=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,agentState:s,isMuted:a,audioLevel:d,onExpand:f,onToggleMute:h,onClose:b})=>r?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${o} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:f,"aria-label":`Expand ${o} widget`,children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsx(Xn,{audioLevel:d,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:w=>{w.stopPropagation(),h()},onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.stopPropagation(),w.preventDefault(),h())},"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(qt,{muted:a,className:"ll-minimized__icon"})}),t.jsx(Ht,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):t.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${o} widget`,children:t.jsxs("div",{className:"ll-minimized__surface",children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsxs("div",{className:"ll-minimized__meta",children:[t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsx("span",{className:"ll-minimized__state",children:s==="speaking"?"Speaking":s==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:h,"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(qt,{muted:a,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:f,"aria-label":`Expand ${o} widget`,children:t.jsx(Ht,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:b,"aria-label":"Close widget",children:t.jsx(Vn,{className:"ll-minimized__icon"})})]})]})}),Zn=({src:e,alt:r,preCannedPlaying:o=!1,className:i,style:s})=>{const[a,d]=n.useState(!1),f=n.useRef(e);if(n.useEffect(()=>{f.current!==e&&(f.current=e,d(!1))},[e]),!e)return null;const h={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:o?"scale(1.02)":"scale(1)",opacity:a?1:0,...s};return t.jsx("img",{src:e,alt:r,className:i,style:h,loading:"eager",fetchPriority:"high",onLoad:()=>d(!0)})},er=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,idleLoopUrl:s,greeting:a,branding:d,teamMembers:f,currentTeamMemberId:h,isSwitchingTeamMember:b,teamSwitcherOpen:w,onToggleTeamSwitcher:c,onSelectTeamMember:l,languageMenuOpen:S,onToggleLanguageMenu:E,connectionState:L,agentState:x,transcript:_,canResume:T,needsUserGesture:M,error:P,isMuted:g,micError:R,micDevices:z,isCameraEnabled:I,cameraPreviewEl:A,cameraDevices:$,activeCameraId:U,isScreenShareEnabled:K,screenPreviewEl:ne,isSpeakerMuted:ve,allowCamera:tt,allowScreenShare:nt,allowTyping:rt,avatarVideoContainerRef:ot,agentVideoEl:te,micGateOpen:ue,onConnect:we,onDisconnect:Le,onRetry:Ee,onResumeAudio:je,onToggleMute:Ne,onToggleCamera:Re,onSwitchCameraDevice:V,onToggleScreenShare:yt,onToggleSpeaker:bt,onSendMessage:it,onMinimize:re,onClose:Ae,onClearMicError:Oe})=>{var Pe;const _e=((f==null?void 0:f.length)??0)>1,Me=L==="connecting"||L==="connected",G=L==="connected",X=L==="idle"||L==="disconnected"||L==="error",[De,oe]=n.useState(!1);n.useEffect(()=>{if(!te){oe(!1);return}if(!te.paused&&te.readyState>=2){oe(!0);return}oe(!1);const m=()=>oe(!0);return te.addEventListener("playing",m),te.addEventListener("loadeddata",m),()=>{te.removeEventListener("playing",m),te.removeEventListener("loadeddata",m)}},[te]);const[de,ke]=n.useState(!1);n.useEffect(()=>{if(!G){ke(!1);return}if(De)return;const m=setTimeout(()=>ke(!0),8e3);return()=>clearTimeout(m)},[G,De]);const Ue=L==="connecting"||G&&!!i&&!De&&!de,Z=n.useRef(null),ie=n.useRef(null);n.useEffect(()=>{const m=Z.current;m&&(m.innerHTML="",A&&(A.style.width="100%",A.style.height="100%",A.style.objectFit="cover",A.style.transform="scaleX(-1)",m.appendChild(A)))},[A]),n.useEffect(()=>{const m=ie.current;m&&(m.innerHTML="",ne&&(ne.style.width="100%",ne.style.height="100%",ne.style.objectFit="contain",m.appendChild(ne)))},[ne]);const[se,fe]=n.useState(!1),[Ie,pe]=n.useState(!1);n.useEffect(()=>{if(!se&&!Ie&&!S&&!w)return;const m=()=>{fe(!1),pe(!1),S&&E(),w&&c()};return document.addEventListener("click",m),()=>document.removeEventListener("click",m)},[se,Ie,S,w,E,c]);const[he,We]=n.useState(""),Ve=n.useCallback(m=>{m.preventDefault();const F=he.trim();F&&(it(F),We(""))},[he,it]),Fe=d.productName||"Live Layer";let me=null,ge=null;for(let m=_.length-1;m>=0;m--){const F=_[m];if(!me&&F.role==="agent"?me=F:!ge&&F.role==="user"&&(ge=F),me&&ge)break}const Te=G?(me==null?void 0:me.text)||null:a||null,st=G&&(ge==null?void 0:ge.text)||null,Ge=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:Ge,"data-position":e,"data-state":G?"connected":Me?"connecting":"idle",role:"dialog","aria-label":`${o} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[i?t.jsx(Zn,{src:i,alt:o,className:"ll-expanded__bg-img"}):t.jsx("div",{className:"ll-expanded__bg-fallback",children:t.jsx("span",{className:"ll-expanded__bg-initial",children:((Pe=o==null?void 0:o.charAt(0))==null?void 0:Pe.toUpperCase())||"A"})}),s&&!G&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:ot,className:"ll-expanded__video"}),Ue&&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:b?"Switching...":"Connecting..."})]}),M&&G&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:je,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"})]}),Me?t.jsxs("div",{className:"ll-expanded__topbar",children:[t.jsxs("div",{className:"ll-expanded__topbar-left",children:[t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill",onClick:m=>{_e&&(m.stopPropagation(),c())},"aria-haspopup":_e?"listbox":void 0,"aria-expanded":_e?w:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:o}),_e&&t.jsx(ft,{})]}),_e&&w&&t.jsx("div",{className:"ll-hmenu",onClick:m=>m.stopPropagation(),role:"listbox",children:f==null?void 0:f.map(m=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${m.id===h?"is-active":""}`,onClick:()=>l(m.id),role:"option","aria-selected":m.id===h,children:[m.avatarImageUrl&&t.jsx("img",{src:m.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:m.name}),m.role&&t.jsx("span",{className:"ll-hmenu__role",children:m.role})]},m.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:m=>{m.stopPropagation(),E()},"aria-haspopup":"listbox","aria-expanded":S,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(ft,{})]}),S&&t.jsx("div",{className:"ll-hmenu",onClick:m=>m.stopPropagation(),role:"listbox",children:t.jsx("button",{type:"button",className:"ll-hmenu__item is-active",role:"option","aria-selected":!0,children:t.jsx("span",{className:"ll-hmenu__name",children:"English"})})})]}),t.jsx("span",{className:`ll-expanded__state ll-expanded__state--${x}`,children:x})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn",onClick:re,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(Ft,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Ae,"aria-label":"End call",title:"End call",children:t.jsx(Vt,{})})]})]}):t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:Fe}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:re,"aria-label":"Minimize widget",children:t.jsx(Ft,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Ae,"aria-label":"Close widget",children:t.jsx(Vt,{})})]})]}),X&&(()=>{const m=T?"Restart paused session":L==="disconnected"?"Reconnect to agent":"Start video call",F=T?"Pick up where you left off":null,at=L==="idle"&&!T&&!P;return t.jsxs(t.Fragment,{children:[at&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:we,"aria-label":m,children:[t.jsx("div",{className:"ll-expanded__play-circle",children:t.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:t.jsx("polygon",{points:"6 3 20 12 6 21 6 3"})})}),t.jsx("span",{className:"ll-expanded__play-label",children:m})]}),t.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[a&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:a})}),F&&t.jsx("p",{className:"ll-expanded__cta-sublabel",children:F}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:we,"aria-label":m,children:m})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${Me&&(I||K)?"is-visible":""}`,children:[t.jsx("div",{ref:ie,className:K?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:Z,className:!K&&I?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Me?t.jsxs("div",{className:"ll-expanded__bottom",children:[Te&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Te})}),st&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:st})}),t.jsxs("div",{className:"ll-toolbar",onClick:m=>m.stopPropagation(),children:[nt&&t.jsx("button",{type:"button",className:`ll-tool ${K?"is-on":""}`,onClick:yt,"aria-label":K?"Stop sharing screen":"Share screen",title:K?"Stop sharing":"Share screen",children:t.jsx(tr,{})}),tt&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${I?"is-on":""}`,onClick:Re,"aria-label":I?"Turn off camera":"Turn on camera",title:I?"Stop camera":"Start camera",children:t.jsx(nr,{})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${I?"is-on":""}`,onClick:m=>{m.stopPropagation(),pe(F=>!F),fe(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":Ie,children:t.jsx(ft,{})}),Ie&&$.length>0&&t.jsx(Gt,{label:"Camera",devices:$,activeId:U,onPick:m=>{pe(!1),V(m)}})]}),t.jsxs("div",{className:`ll-tool-split${!ue&&G?" ll-tool-split--gated":""}`,children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${g?"is-muted":""}`,onClick:Ne,disabled:!ue&&G,"aria-label":!ue&&G?"Microphone enables once the agent finishes its greeting":g?"Unmute microphone":"Mute microphone",title:!ue&&G?"Mic enables after greeting":g?"Unmute":"Mute",children:t.jsx(rr,{muted:g})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${g?"is-muted":""}`,onClick:m=>{m.stopPropagation(),fe(F=>!F),pe(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":se,children:t.jsx(ft,{})}),se&&z.length>0&&t.jsx(Gt,{label:"Microphone",devices:z,activeId:"",onPick:()=>fe(!1)})]}),t.jsx("button",{type:"button",className:`ll-tool ${ve?"is-muted":""}`,onClick:bt,"aria-label":ve?"Unmute speaker":"Mute speaker",title:ve?"Unmute speaker":"Mute speaker",children:t.jsx(or,{muted:ve})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:Le,"aria-label":"End conversation",title:"End conversation",children:t.jsx(sr,{})})]}),rt&&t.jsxs("form",{className:"ll-message-input",onSubmit:Ve,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:he,onChange:m=>We(m.target.value),"aria-label":"Message the agent"}),he.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(ir,{})})]})]}):null,(()=>{if(R&&L!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:R}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:Oe,"aria-label":"Dismiss",children:"×"})]});if(!P||L!=="error")return null;let m="Failed to connect",F="Try again";return P==="MIC_PERMISSION_DENIED"?m="Microphone blocked. Allow access to talk.":P==="MIC_NOT_FOUND"?m="No microphone found. Plug one in + retry.":P==="MIC_UNAVAILABLE"?m="Mic unavailable. Check other apps using it.":P==="AGENT_TIMEOUT"?m="Agent didn't pick up. Try again.":P==="CONNECT_FAILED"?m="Connection failed. Check your network.":P.length<80&&(m=P),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:m}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:Ee,children:F})]})})()]})};function ft(){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 Vt(){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 Ft(){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 tr(){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 nr(){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 rr({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 or({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 ir(){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 sr(){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 Gt=({label:e,devices:r,activeId:o,onPick:i})=>t.jsxs("div",{className:"ll-device-menu",onClick:s=>s.stopPropagation(),role:"listbox",children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),r.map((s,a)=>{const d=o===s.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${d?"is-active":""}`,onClick:()=>i(s.deviceId),role:"option","aria-selected":d,children:[d&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:s.label||`${e} ${a+1}`})]},s.deviceId||a)})]}),ar=['[data-ll-private="true"]',".ll-widget"];function St(e){let r=e;for(;r;){for(const o of ar)if(r.matches(o))return!0;r=r.parentElement}return!1}function gt(e){if(St(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const r=(e.getAttribute("autocomplete")||"").toLowerCase();if(r==="off"||r.startsWith("cc-"))return!1}return!0}const pt=4096,lr=20,cr=20,ur=10,dr=10,fr=30,Yt=500,pr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function Qe(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let r=e;for(;r;){for(const o of pr)if(r.matches(o))return!0;r=r.parentElement}return!1}function Ze(e){if(typeof window>"u")return!0;const r=e.getBoundingClientRect();if(r.width<=0||r.height<=0)return!1;const o=window.innerHeight||document.documentElement.clientHeight,i=window.innerWidth||document.documentElement.clientWidth;return r.bottom>0&&r.right>0&&r.top<o&&r.left<i}function Jt(e){const r=e.getAttribute("id");if(r){const a=document.querySelector(`label[for="${CSS.escape(r)}"]`);if(a!=null&&a.textContent)return a.textContent.trim()}const o=e.getAttribute("aria-label");if(o)return o.trim();const i=e.getAttribute("placeholder");if(i)return i.trim();const s=e.closest("label");return s!=null&&s.textContent?s.textContent.trim():""}function Ce(e,r){return e.length<=r?e:e.slice(0,r-1)+"…"}function Be(e){return e.length}function mn(e,r={}){const o=r.doc??(typeof document<"u"?document:null);if(!o)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const i=typeof window<"u"&&window.location.href||"",s=typeof window<"u"&&window.location.pathname||"/",a=o.title||"",d=Array.from(o.querySelectorAll("[data-ll-region]")),f=[];for(const g of d){if(f.length>=ur)break;if(Qe(g)||!Ze(g))continue;const R=g.getAttribute("data-ll-region")??"",z=g.getAttribute("data-ll-intent")??void 0,I=Ce((g.innerText||g.textContent||"").trim(),Yt*2);!R||!I||f.push({id:R,intent:z,text:I})}const h=[],b=["H1","H2","H3","H4","H5","H6"],w=Array.from(o.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const g of w){if(Qe(g)||!Ze(g))continue;const R=(g.textContent||"").trim();R&&h.push(`${g.tagName}: ${Ce(R,200)}`)}const c=Array.from(o.querySelectorAll("p, li"));for(const g of c){if(Qe(g)||!Ze(g)||b.includes(g.tagName))continue;const R=(g.textContent||"").trim();R.length>10&&h.push(Ce(R,Yt))}const l=h.join(`
2
2
  `),S=[],E=Array.from(o.querySelectorAll("a[href]"));for(const g of E){if(S.length>=lr)break;if(Qe(g)||!Ze(g))continue;const R=g.getAttribute("href")||"",z=(g.textContent||"").trim();!R||!z||S.push({href:R,text:Ce(z,100)})}const L=[],x=Array.from(o.querySelectorAll("input, textarea, select"));for(const g of x){if(L.length>=cr)break;if(Qe(g)||!gt(g)||!Ze(g))continue;const R=Jt(g),z=g instanceof HTMLInputElement?g.type:g.tagName.toLowerCase();R&&L.push({label:Ce(R,100),type:z})}const _=Array.from(o.querySelectorAll("[data-ll-form]")),T=[];for(const g of _){if(T.length>=dr)break;if(St(g))continue;const R=g.getAttribute("data-ll-form")||"";if(!R)continue;const z=g.getAttribute("data-ll-intent")||void 0,I=Array.from(g.querySelectorAll("[data-ll-field]")),A=[];for(const $ of I){if(A.length>=fr)break;if(!gt($))continue;const U=$.getAttribute("data-ll-field")||"";if(!U)continue;const K=Jt($)||U,ne=$ instanceof HTMLInputElement?$.type:$.tagName.toLowerCase();A.push({name:U,label:Ce(K,100),type:ne})}T.push({id:R,intent:z,fields:A})}const M={url:i,title:a,pathname:s,regions:f,visibleText:l,visibleLinks:S,visibleFields:L,forms:T,extras:e};let P=Be(JSON.stringify(M.regions))+Be(M.visibleText)+Be(JSON.stringify(M.visibleLinks))+Be(JSON.stringify(M.visibleFields));for(;P>pt&&M.visibleFields.length>0;)M.visibleFields.pop(),P=Be(JSON.stringify(M.visibleFields));for(;P>pt&&M.visibleLinks.length>0;)M.visibleLinks.pop(),P-=80;return Be(M.visibleText)>pt&&(M.visibleText=Ce(M.visibleText,pt-100)),M}let ze=null;function et(e,r={}){const o=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(ze&&ze.key===s&&o-ze.at<1e3)return ze.ctx;const a=mn(e,r);return ze={key:s,at:o,ctx:a},a}function gn(){ze=null}const hr=200;function yn(e){const r=String(e.href||"");return{href:r,text:String(e.text??e.title??r),internal:e.internal??!0,title:e.title,description:e.description}}function mr(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function bn(e){const r=e??(typeof document<"u"?document:null);if(!r)return[];const o=typeof window<"u"&&window.location.origin||"",i=new Set,s=[],a=Array.from(r.querySelectorAll("a[href]"));for(const d of a){if(s.length>=hr)break;if(St(d))continue;const f=d.getAttribute("href")||"";if(!mr(f))continue;let h=f,b=!0;try{if(typeof window<"u"){const c=new URL(f,o);b=c.origin===o,b&&f.startsWith("http")&&(h=c.pathname+c.search+c.hash)}}catch{continue}if(i.has(h))continue;i.add(h);const w=(d.textContent||"").trim().slice(0,120);s.push({href:h,text:w,internal:b})}return s}let qe=null;const gr=5e3;function He(){const e=Date.now(),r=typeof window<"u"&&window.location.pathname||"/";if(qe&&qe.pathname===r&&e-qe.at<gr)return qe.routes;const o=bn();return qe={at:e,pathname:r,routes:o},o}function xn(){qe=null}function yr(e,r){const o=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,i=Object.getOwnPropertyDescriptor(o,"value"),s=i==null?void 0:i.set;s?s.call(e,r):e.value=r}function br(e,r,o={}){const i=o.triggerInput??!0,s=o.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const a=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),d=a==null?void 0:a.set,f=r==="true"||r==="1"||r==="on";d?d.call(e,f):e.checked=f,i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}yr(e,r),i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function xr(){if(typeof window>"u"||typeof document>"u")return!1;const e=document.scrollingElement||document.documentElement;if(!e||e.scrollHeight<=e.clientHeight+2)return!1;const r=window.getComputedStyle(e);return!(r.overflowY==="hidden"||r.overflowY==="clip")}function vr(e){if(!(e instanceof HTMLElement))return!1;const o=window.getComputedStyle(e).overflowY;return!(o!=="auto"&&o!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function wr(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let r=null,o=0;for(const i of e){if(!vr(i))continue;const s=i.getBoundingClientRect();if(s.bottom<=0||s.top>=window.innerHeight||s.right<=0||s.left>=window.innerWidth||s.width<=0||s.height<=0||i.closest(".ll-widget"))continue;const a=s.width*s.height;a>o&&(o=a,r=i)}return r}function _r(){if(typeof window>"u")return null;if(xr())return window;const e=wr();return e||window}function Kt(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function kr(e){var r,o;return e instanceof Window?typeof document>"u"?0:Math.max(((r=document.body)==null?void 0:r.scrollHeight)??0,((o=document.documentElement)==null?void 0:o.scrollHeight)??0):e.scrollHeight-e.clientHeight}const Sr=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","request_initial_sync"]);function Cr(e){var Nt,Rt,At,Mt,Dt,It,Tt;const{agentId:r,apiKey:o,baseUrl:i="https://app.livelayer.studio",sessionEndpoint:s,sessionBody:a,autoConnect:d=!1,displayMode:f,defaultDisplayMode:h="expanded",onDisplayModeChange:b,position:w="bottom-right",mobileBreakpoint:c=640,persistKey:l="ll-widget",disablePersistence:S=!1,teamMembers:E,currentTeamMemberId:L,onTeamMemberChange:x,idleLoopUrl:_,greeting:T,avatarImageUrl:M,agentName:P,branding:g={},allowCamera:R=!0,allowScreenShare:z=!0,allowTyping:I=!0,showOn:A,hideOn:$,pathname:U,onNavigate:K,onScrollToSelector:ne,getPageContext:ve,pageContextExtras:tt,getRoutes:nt,onScrollPage:rt,onClick:ot,capabilities:te,onConnect:ue,onDisconnect:we,onTranscript:Le,onAgentState:Ee,onConnectionStateChange:je,onAgentEvent:Ne,onAgentCommand:Re,controlledSession:V,className:yt,style:bt,zIndex:it=2147483647}=e,re=un(U),Ae=pn(re,A,$);n.useEffect(()=>{gn(),xn()},[re]);const Oe=L!==void 0,[_e,Me]=n.useState(()=>{var p;return L??((p=E==null?void 0:E[0])==null?void 0:p.id)}),G=Oe?L:_e,X=n.useMemo(()=>(E==null?void 0:E.find(p=>p.id===G))??null,[E,G]),De=(X==null?void 0:X.agentId)??r,[oe,de]=ln({value:f,defaultValue:h,onChange:b,persistKey:l,disablePersistence:S}),ke=cn(c),Ue=en(),Z=tn(),ie=nn(),se=rn(),fe=on(),[Ie,pe]=n.useState(!1),[he,We]=n.useState(!1),[Ve,Fe]=n.useState(!1),[me,ge]=n.useState(!1),[Te,st]=n.useState(!1),Ge=n.useRef(K),Pe=n.useRef(ne),m=n.useRef(rt),F=n.useRef(ot),at=n.useRef(ve),lt=n.useRef(tt),ct=n.useRef(nt),xt=n.useRef(te),ee=n.useRef(null),ut=n.useRef(null),$e=n.useRef(null),Ct=n.useRef(void 0);Ct.current=re,Ge.current=K,Pe.current=ne,m.current=rt,F.current=ot,at.current=ve,lt.current=tt,ct.current=nt,xt.current=te;function ye(p){const u=xt.current;return u?u.includes(p):!0}function be(p,u){console.warn(`[LiveLayer] Agent command "${p}" blocked — capability "${u}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const Ye=n.useCallback(p=>{var q,Q,Y,ae,le,xe;const u=p;if(!(!u.type||typeof u.type!="string")){if(Ne==null||Ne({eventName:u.type,data:p}),u.type==="bot_ready"||u.type==="request_initial_sync"){console.log(`[NAV-DEBUG][widget] received ${u.type} → triggering pushSnapshot`);try{(q=ut.current)==null||q.call(ut)}catch(v){console.warn("[NAV-DEBUG][widget] pushSnapshot threw:",v)}}if(u.type==="navigate"){if(!ye("navigate")){be("navigate","navigate");return}const v=typeof u.href=="string"?u.href:null;if(!v){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(Ge.current){try{Ge.current(v)}catch(C){console.warn(`[LiveLayer] onNavigate threw for "${v}". Falling back. Error:`,C)}return}if(typeof document<"u"){const C=document.querySelector(`a[href="${v.replace(/"/g,'\\"')}"]`);if(C){C.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",v),window.dispatchEvent(new PopStateEvent("popstate"))}catch(C){console.warn(`[LiveLayer] history.pushState fallback failed for "${v}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,C)}return}if(u.type==="scroll_to"){if(!ye("scroll")){be("scroll_to","scroll");return}const v=typeof u.selector=="string"?u.selector:null;if(!v)return;const C=u.behavior==="instant"?"instant":"smooth";if(Pe.current){try{Pe.current(v,C)}catch(k){console.warn("[LiveLayer] onScrollToSelector threw.",k)}return}if(typeof document<"u"){let k=null;try{k=document.querySelector(v)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${v}".`);return}if(!k){console.warn(`[LiveLayer] scroll_to: no element matched "${v}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}k.scrollIntoView({behavior:C,block:"start"})}return}if(u.type==="request_page_context"){if(!ye("read_page")){be("request_page_context","read_page");return}const v=typeof u.requestId=="string"?u.requestId:void 0,C=(Q=ee.current)==null?void 0:Q.call(ee),k=O=>{const N=C,W=N==null?void 0:N.localParticipant;if(!(W!=null&&W.publishData)){console.warn("[NAV-DEBUG][widget] request_page_context response: no publishData");return}const D=v?{...O,requestId:v}:O,J=$e.current;J&&J(W,D,`request_page_context-resp/${String(O.type)}`)},j=lt.current,H=at.current;try{if(H){const O=H(j);if(O instanceof Promise){k({type:"page_context_pending"}),O.then(N=>k({type:"page_context",context:N})).catch(N=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",N),k({type:"page_context",context:et(j)})});return}k({type:"page_context",context:O});return}k({type:"page_context",context:et(j)})}catch(O){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",O),k({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:j}})}return}if(u.type==="scroll_page"){if(!ye("scroll")){be("scroll_page","scroll");return}const v=u.direction;if(v!=="up"&&v!=="down"&&v!=="top"&&v!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(v)}". Expected up | down | top | bottom.`);return}const C=u.behavior==="instant"?"instant":"smooth";if(m.current){try{m.current(v,C)}catch(N){console.warn("[LiveLayer] onScrollPage threw.",N)}return}if(typeof window>"u")return;const k={behavior:C},j=_r(),H=N=>{j instanceof Window?j.scrollBy({top:N,...k}):j.scrollBy({top:N,...k})},O=N=>{j instanceof Window?j.scrollTo({top:N,...k}):j.scrollTo({top:N,...k})};v==="up"?H(-Kt(j)):v==="down"?H(Kt(j)):O(v==="top"?0:kr(j));return}if(u.type==="click"){if(!ye("click")){be("click","click");return}const v=typeof u.selector=="string"?u.selector:null;if(!v){console.warn("[LiveLayer] click: missing selector.");return}if(F.current){try{F.current(v)}catch(k){console.warn("[LiveLayer] onClick threw.",k)}return}if(typeof document>"u")return;let C=null;try{C=document.querySelector(v)}catch{console.warn(`[LiveLayer] click: invalid selector "${v}".`);return}if(!C){console.warn(`[LiveLayer] click: no element matched "${v}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(C.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(Y=C.click)==null||Y.call(C);return}if(u.type==="fill_form"||u.type==="focus_field"){if(!ye("fill_forms")){be(u.type,"fill_forms");return}if(typeof document>"u")return;const v=typeof u.requestId=="string"?u.requestId:void 0,C=(ae=ee.current)==null?void 0:ae.call(ee),k=D=>{if(u.type!=="fill_form")return;const J=C,ce=J==null?void 0:J.localParticipant;if(ce!=null&&ce.publishData)try{const Se=v?{...D,requestId:v}:D,Mn=new TextEncoder().encode(JSON.stringify(Se));ce.publishData(Mn,{reliable:!0})}catch(Se){console.warn("[LiveLayer] publishData failed.",Se)}},j=typeof u.formId=="string"?u.formId:null;if(!j){console.warn(`[LiveLayer] ${u.type}: missing formId.`),k({type:"fill_form_result",ok:!1,reason:"missing formId"});return}const H=document.querySelector(`[data-ll-form="${j.replace(/"/g,'\\"')}"]`);if(!H){console.warn(`[LiveLayer] ${u.type}: no form with data-ll-form="${j}". Tag your form with <LiveLayerForm id> or data-ll-form. See https://livelayer.studio/docs/react/forms`),k({type:"fill_form_result",ok:!1,reason:`no form with data-ll-form="${j}" on this page`,formId:j});return}if(H.closest('[data-ll-private="true"], .ll-widget')){console.warn(`[LiveLayer] ${u.type}: refusing to touch a form in a private subtree.`),k({type:"fill_form_result",ok:!1,reason:"form is in a private subtree (data-ll-private)",formId:j});return}if(u.type==="focus_field"){const D=typeof u.fieldName=="string"?u.fieldName:null;if(!D){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const J=H.querySelector(`[data-ll-field="${D.replace(/"/g,'\\"')}"]`);if(!J){console.warn(`[LiveLayer] focus_field: no field "${D}" in form "${j}".`);return}if(!gt(J)){console.warn(`[LiveLayer] focus_field: field "${D}" is privacy-protected and not focusable.`);return}J.focus();return}const O=u.values&&typeof u.values=="object"?u.values:null;if(!O){console.warn("[LiveLayer] fill_form: missing or invalid values."),k({type:"fill_form_result",ok:!1,reason:"missing or invalid values",formId:j});return}const N=[],W=[];for(const[D,J]of Object.entries(O)){if(typeof J!="string")continue;const ce=H.querySelector(`[data-ll-field="${D.replace(/"/g,'\\"')}"]`);if(!ce){console.warn(`[LiveLayer] fill_form: no field "${D}" in form "${j}". Skipping.`),W.push(D);continue}if(!gt(ce)){console.warn(`[LiveLayer] fill_form: field "${D}" is privacy-protected (password / cc-* / private). Skipping.`),W.push(D);continue}try{br(ce,J),N.push(D)}catch(Se){console.warn(`[LiveLayer] fill_form: failed to set "${D}".`,Se),W.push(D)}}k({type:"fill_form_result",ok:N.length>0,formId:j,filled:N,skipped:W,reason:N.length===0?`none of the requested fields exist on this form (skipped: ${W.join(", ")})`:void 0});return}if(u.type==="submit_form"){if(!ye("submit_forms")){be("submit_form","submit_forms");return}if(typeof document>"u")return;const v=typeof u.formId=="string"?u.formId:null;if(!v){console.warn("[LiveLayer] submit_form: missing formId.");return}const C=document.querySelector(`[data-ll-form="${v.replace(/"/g,'\\"')}"]`);if(!C){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${v}".`);return}if(C.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private subtree.");return}const k=typeof u.requestId=="string"?u.requestId:void 0,j=(le=ee.current)==null?void 0:le.call(ee),H=W=>{const D=j,J=D==null?void 0:D.localParticipant;if(J!=null&&J.publishData)try{const ce=k?{...W,requestId:k}:W,Se=new TextEncoder().encode(JSON.stringify(ce));J.publishData(Se,{reliable:!0})}catch{}};let O=!1;const N=()=>{O=!0,H({type:"form_submitted",formId:v})};C.addEventListener("submit",N,{once:!0});try{typeof C.requestSubmit=="function"?C.requestSubmit():C.submit()}catch(W){console.warn("[LiveLayer] submit_form: requestSubmit threw.",W),C.removeEventListener("submit",N),H({type:"form_submit_blocked",formId:v,reason:"exception"});return}setTimeout(()=>{O||(C.removeEventListener("submit",N),H({type:"form_submit_blocked",formId:v,reason:"validation"}))},500);return}if(u.type==="request_routes"){if(!ye("read_page")){be("request_routes","read_page");return}const v=typeof u.requestId=="string"?u.requestId:void 0,k=(xe=ee.current)==null?void 0:xe.call(ee),j=k==null?void 0:k.localParticipant;if(!(j!=null&&j.publishData))return;const H=N=>{const W=v?{type:"routes",routes:N,requestId:v}:{type:"routes",routes:N},D=$e.current;D&&D(j,W,`request_routes-resp(${N.length})`)},O=ct.current;if(O){try{const N=O(),W=D=>{if(!Array.isArray(D)){H([]);return}H(D.map(yn).slice(0,200))};N instanceof Promise?N.then(W).catch(D=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",D),H(He())}):W(N)}catch(N){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",N),H(He())}return}try{H(He())}catch(N){console.warn("[LiveLayer] request_routes: extractRoutes threw.",N)}return}Sr.has(u.type)||Re==null||Re(u)}},[Re,Ne]),B=Zt({agentId:V?"__controlled__":De,baseUrl:i,apiKey:o,sessionEndpoint:s,sessionBody:a,onDataMessage:V?void 0:Ye});n.useEffect(()=>{if(V!=null&&V.subscribeToDataMessages)return V.subscribeToDataMessages(Ye)},[V,Ye]),ee.current=()=>{var p;return(p=B.getRoom)==null?void 0:p.call(B)};const vn=(p,u,q)=>{if(!(p!=null&&p.publishData))return console.warn(`[NAV-DEBUG][widget] ${q}: no publishData on lp`),Promise.resolve();const Q=new TextEncoder().encode(JSON.stringify(u));return Promise.resolve().then(()=>p.publishData(Q,{reliable:!0})).then(()=>{console.log(`[NAV-DEBUG][widget] ${q}: publishData resolved (${Q.byteLength}b)`)}).catch(Y=>{const ae=Y instanceof Error?Y.message:String(Y),le=Y instanceof Error?Y.name:"unknown";console.error(`[NAV-DEBUG][widget] ${q}: publishData REJECTED — ${le}: ${ae} (${Q.byteLength}b)`)})};$e.current=vn,ut.current=()=>{var ae,le,xe,v;const p=Ct.current;if(!p){console.log("[NAV-DEBUG][widget] pushSnapshot bailed: no pathname");return}const u=(ae=B.getRoom)==null?void 0:ae.call(B),q=u==null?void 0:u.localParticipant;if(!(q!=null&&q.publishData)){console.log("[NAV-DEBUG][widget] pushSnapshot bailed: no publishData (not connected)");return}const Q=$e.current;Q(q,{type:"pathname",pathname:p},"pushSnapshot/pathname");const Y=et(lt.current);Q(q,{type:"page_context_push",pathname:p,context:Y},`pushSnapshot/page_context_push(regions=${((le=Y.regions)==null?void 0:le.length)??0} forms=${((xe=Y.forms)==null?void 0:xe.length)??0} links=${((v=Y.visibleLinks)==null?void 0:v.length)??0})`),(async()=>{try{const C=ct.current;let k=[];if(C){const j=C(),H=j instanceof Promise?await j:j;k=Array.isArray(H)?H.slice(0,200):[]}else k=He();await Q(q,{type:"routes_push",routes:k},`pushSnapshot/routes_push(${k.length})`)}catch(C){console.warn("[NAV-DEBUG][widget] pushSnapshot routes outer threw:",C)}})()},n.useEffect(()=>{var Y;if(console.log(`[NAV-DEBUG][widget] pathname-effect fired pathname=${re} connState=${B.connectionState} t=${Date.now()}`),!re){console.log("[NAV-DEBUG][widget] effect bailed: no pathname");return}const p=(Y=B.getRoom)==null?void 0:Y.call(B),u=p==null?void 0:p.localParticipant;if(console.log(`[NAV-DEBUG][widget] immediate-push state: room=${!!p} lp=${!!u} publishData=${!!(u!=null&&u.publishData)}`),!(u!=null&&u.publishData)){console.log("[NAV-DEBUG][widget] effect bailed: no publishData (not connected yet)");return}const q=$e.current;q&&q(u,{type:"pathname",pathname:re},"pathname-effect/pathname");const Q=setTimeout(async()=>{var ae,le,xe,v;console.log("[NAV-DEBUG][widget] settle timer fired (250ms after pathname-effect)");try{const C=(ae=B.getRoom)==null?void 0:ae.call(B),k=C==null?void 0:C.localParticipant;if(console.log(`[NAV-DEBUG][widget] settle-time state: room=${!!C} lp=${!!k} publishData=${!!(k!=null&&k.publishData)}`),!(k!=null&&k.publishData)){console.log("[NAV-DEBUG][widget] settle bailed: no publishData");return}const j=et(lt.current),H=$e.current;if(!H)return;await H(k,{type:"page_context_push",pathname:re,context:j},`settle/page_context_push(regions=${((le=j.regions)==null?void 0:le.length)??0} forms=${((xe=j.forms)==null?void 0:xe.length)??0} links=${((v=j.visibleLinks)==null?void 0:v.length)??0})`);try{const O=ct.current;let N=[];if(O){const W=O(),D=W instanceof Promise?await W:W;N=Array.isArray(D)?D.slice(0,200):[]}else N=He();await H(k,{type:"routes_push",routes:N},`settle/routes_push(${N.length})`)}catch(O){console.warn("[NAV-DEBUG][widget] routes_push outer threw:",O)}}catch(C){console.warn("[NAV-DEBUG][widget] settle outer threw:",C)}},250);return()=>{clearTimeout(Q)}},[re,B,B.connectionState]),n.useEffect(()=>{var q;if(typeof window>"u")return;const p=((q=window.location)==null?void 0:q.hostname)||"";if(p==="localhost"||p==="127.0.0.1"||p==="0.0.0.0"||p.endsWith(".local")||p.endsWith(".test"))return window.__livelayerSimulateCommand=Q=>{try{Ye(Q)}catch(Y){console.warn("[LiveLayer] simulate-command threw:",Y)}},()=>{delete window.__livelayerSimulateCommand}},[Ye]);const y=n.useMemo(()=>V?{connectionState:V.connectionState,agentState:V.agentState,transcript:V.transcript,videoElement:V.videoElement,audioElement:V.audioElement,canResume:V.canResume,error:V.error,agentConfig:null,connect:async()=>{await V.onConnect()},disconnect:()=>V.onDisconnect(),getRoom:B.getRoom,isControlled:!0}:{connectionState:B.connectionState,agentState:B.agentState,transcript:B.transcript,videoElement:B.videoElement,audioElement:B.audioElement,canResume:B.canResume,error:B.error,agentConfig:B.agentConfig,connect:B.connect,disconnect:B.disconnect,getRoom:B.getRoom,isControlled:!1},[V,B]),Lt=n.useRef(null);n.useEffect(()=>{const p=y.videoElement,u=Lt.current;if(!(!p||!u))return u.appendChild(p),()=>{p.parentNode===u&&u.removeChild(p)}},[y.videoElement]),n.useEffect(()=>{const p=y.audioElement;if(!p)return;Ue.attach(p);const u=p.play();return u&&typeof u.catch=="function"&&u.catch(q=>{(q==null?void 0:q.name)==="NotAllowedError"&&pe(!0)}),()=>{Ue.detach()}},[y.audioElement]),n.useEffect(()=>{if(y.isControlled||y.connectionState!=="connected")return;const p=y.getRoom();if(p)return Z.setupMic(p,{startMuted:!0}).catch(()=>{}),ie.attachRoom(p),se.attachRoom(p),fe.refresh(),()=>{Z.teardownMic(),ie.teardown(),se.teardown()}},[y.isControlled,y.connectionState]);const[Je,vt]=n.useState(!1),wt=n.useRef("idle");n.useEffect(()=>{if(y.connectionState==="idle"||y.connectionState==="disconnected"){vt(!1),wt.current="idle";return}!Je&&wt.current==="speaking"&&y.agentState!=="speaking"&&(vt(!0),Z.setMuted(!1)),wt.current=y.agentState},[y.agentState,y.connectionState,Je]),n.useEffect(()=>{if(y.connectionState!=="connected"||Je)return;const p=setTimeout(()=>{vt(!0),Z.setMuted(!1)},4e3);return()=>clearTimeout(p)},[y.connectionState,Je]),n.useEffect(()=>{const p=y.audioElement;p&&(p.muted=Te)},[y.audioElement,Te]);const wn=n.useCallback(p=>{const u=y.getRoom();if(u)try{const q=new TextEncoder().encode(JSON.stringify({type:"user_message",text:p}));u.localParticipant.publishData(q,{reliable:!0})}catch{}},[y]),_n=n.useCallback(()=>{st(p=>!p)},[]);n.useEffect(()=>{je==null||je(y.connectionState),y.connectionState==="connected"?ue==null||ue():y.connectionState==="disconnected"&&(we==null||we())},[y.connectionState,ue,we,je]),n.useEffect(()=>{Le==null||Le(y.transcript)},[y.transcript,Le]),n.useEffect(()=>{Ee==null||Ee(y.agentState)},[y.agentState,Ee]);const Et=n.useRef(!1);n.useEffect(()=>{y.isControlled||!d||Et.current||Ae&&y.connectionState==="idle"&&(Et.current=!0,y.connect())},[d,y.connectionState,y,Ae]);const kn=n.useCallback(p=>{const u=E==null?void 0:E.find(q=>q.id===p);u&&(Fe(!1),p!==G&&(We(!0),y.disconnect(),Oe||Me(p),x==null||x(u)))},[E,G,y,Oe,x]);n.useEffect(()=>{he&&y.connectionState==="connected"&&We(!1)},[y.connectionState,he]),n.useEffect(()=>{if(!Ve)return;const p=u=>{u.key==="Escape"&&Fe(!1)};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[Ve]);const Sn=!!M||!!(X!=null&&X.avatarImageUrl)||y.isControlled,Ke=sn(De,i,Sn);te===void 0&&((Nt=Ke.info)!=null&&Nt.capabilities)&&(xt.current=Ke.info.capabilities);const dt=(X==null?void 0:X.name)??P??((Rt=y.agentConfig)==null?void 0:Rt.name)??((At=Ke.info)==null?void 0:At.name)??"Live Layer",_t=(X==null?void 0:X.avatarImageUrl)??M??((Mt=y.agentConfig)==null?void 0:Mt.avatarImageUrl)??((Dt=Ke.info)==null?void 0:Dt.avatarImageUrl)??null,Cn=_??((It=y.agentConfig)==null?void 0:It.idleLoopUrl)??((Tt=Ke.info)==null?void 0:Tt.idleLoopUrl)??null,Ln=T??null,En=n.useCallback(()=>de("expanded"),[de]),jn=n.useCallback(()=>de("minimized"),[de]),jt=n.useCallback(()=>{y.disconnect(),de("hidden")},[y,de]),Nn=n.useCallback(()=>{const p=y.audioElement;p&&p.play().then(()=>pe(!1)).catch(()=>{})},[y.audioElement]),Rn=n.useCallback(()=>{pe(!1),y.connect()},[y]),Xe={...bt,zIndex:it};g.primaryColor&&(Xe["--ll-color-primary"]=g.primaryColor),g.accentColor&&(Xe["--ll-color-accent"]=g.accentColor),g.backgroundColor&&(Xe["--ll-color-bg"]=g.backgroundColor),g.textColor&&(Xe["--ll-color-fg"]=g.textColor);const An=["ll-widget",`ll-widget--${oe}`,`ll-widget--${ke?"mobile":"desktop"}`,yt].filter(Boolean).join(" ");return Ae?t.jsxs("div",{className:An,style:Xe,"data-display-mode":oe,"data-position":w,children:[oe==="hidden"&&t.jsx(Kn,{position:w,isMobile:ke,isSpeaking:y.agentState==="speaking",onExpand:()=>de("expanded"),label:`Open ${dt} widget`,avatarImageUrl:_t,agentName:dt}),oe==="minimized"&&t.jsx(Qn,{position:w,isMobile:ke,agentName:dt,avatarImageUrl:_t,agentState:y.agentState,isMuted:Z.isMuted,audioLevel:Ue,onExpand:En,onToggleMute:Z.toggleMute,onClose:jt}),oe==="expanded"&&t.jsx(er,{position:w,isMobile:ke,agentName:dt,avatarImageUrl:_t,idleLoopUrl:Cn,greeting:Ln,branding:g,teamMembers:E,currentTeamMemberId:G,isSwitchingTeamMember:he,teamSwitcherOpen:Ve,onToggleTeamSwitcher:()=>Fe(p=>!p),onSelectTeamMember:kn,connectionState:y.connectionState,agentState:y.agentState,transcript:y.transcript,isMuted:Z.isMuted,micDevices:fe.mics,isCameraEnabled:ie.isEnabled,cameraPreviewEl:ie.previewEl,cameraDevices:fe.cameras,activeCameraId:ie.activeDeviceId,isScreenShareEnabled:se.isEnabled,screenPreviewEl:se.previewEl,isSpeakerMuted:Te,allowCamera:R,allowScreenShare:z,allowTyping:I,languageMenuOpen:me,onToggleLanguageMenu:()=>ge(p=>!p),needsUserGesture:Ie,canResume:y.canResume,micError:Z.micError,error:y.error,avatarVideoContainerRef:Lt,agentVideoEl:y.videoElement,micGateOpen:y.isControlled?!0:Je,onConnect:()=>void y.connect(),onDisconnect:()=>y.disconnect(),onRetry:Rn,onResumeAudio:Nn,onToggleMute:Z.toggleMute,onToggleCamera:()=>void ie.toggle(),onSwitchCameraDevice:p=>void ie.switchDevice(p),onToggleScreenShare:()=>void se.toggle(),onToggleSpeaker:_n,onSendMessage:wn,onMinimize:jn,onClose:jt,onClearMicError:Z.clearError})]}):null}function Lr(e){return t.jsx(Qt,{children:t.jsx(Cr,{...e})})}const Er=({agentId:e,baseUrl:r,apiKey:o,mode:i,onAgentEvent:s,className:a,style:d})=>{const f=n.useRef(null),h=n.useRef(null),b=n.useRef(s);b.current=s;const w=n.useCallback(c=>{var S;const l=c.detail;(S=b.current)==null||S.call(b,l)},[]);return n.useEffect(()=>{const c=f.current;if(!c)return;const l=document.createElement("livelayer-widget");return l.setAttribute("agent-id",e),r&&l.setAttribute("base-url",r),o&&l.setAttribute("api-key",o),i&&l.setAttribute("mode",i),l.addEventListener("agent-event",w),c.appendChild(l),h.current=l,()=>{l.removeEventListener("agent-event",w),c.removeChild(l),h.current=null}},[e]),n.useEffect(()=>{h.current&&(i?h.current.setAttribute("mode",i):h.current.removeAttribute("mode"))},[i]),t.jsx("div",{ref:f,className:a,style:d})},jr=n.forwardRef(function({id:r,intent:o,as:i="div",className:s,style:a,children:d},f){return n.createElement(i,{ref:f,"data-ll-region":r,"data-ll-intent":o,className:s,style:a},d)}),Nr=n.forwardRef(function({id:r,intent:o,children:i,...s},a){return t.jsx("form",{ref:a,"data-ll-form":r,"data-ll-intent":o,...s,children:i})}),Rr=n.forwardRef(function(r,o){const{name:i,label:s,labelClassName:a}=r,d={name:i,"data-ll-field":i};let f;if("as"in r&&r.as==="textarea"){const{name:h,label:b,labelClassName:w,as:c,...l}=r;f=t.jsx("textarea",{ref:o,...d,...l})}else if("as"in r&&r.as==="select"){const{name:h,label:b,labelClassName:w,as:c,children:l,...S}=r;f=t.jsx("select",{ref:o,...d,...S,children:l})}else{const{name:h,label:b,labelClassName:w,as:c,...l}=r;f=t.jsx("input",{ref:o,...d,...l})}return s===void 0?f:t.jsxs("label",{className:a,children:[s,f]})});let Xt=1;function Ar({onMount:e,defaultOpen:r=!1,storageKey:o="ll-debug-open"}){const[i,s]=n.useState(r),[a,d]=n.useState([]),[f,h]=n.useState(""),[b,w]=n.useState(!1),c=n.useRef(new Set),l=n.useRef([]),S=n.useRef(b);S.current=b,n.useEffect(()=>{try{const x=localStorage.getItem(o);x==="1"&&s(!0),x==="0"&&s(!1)}catch{}},[o]),n.useEffect(()=>{try{localStorage.setItem(o,i?"1":"0")}catch{}},[i,o]),n.useEffect(()=>{const x=_=>{(_.metaKey||_.ctrlKey)&&_.shiftKey&&_.key.toLowerCase()==="l"&&(_.preventDefault(),s(T=>!T))};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[]),n.useEffect(()=>{const x=setInterval(()=>{if(l.current.length===0||S.current)return;const _=l.current.splice(0,l.current.length);d(T=>[..._.reverse(),...T].slice(0,200))},100);return()=>clearInterval(x)},[]);const E=n.useRef(!1);if(n.useEffect(()=>{!e||E.current||(E.current=!0,e(x=>{l.current.push({id:Xt++,ts:Date.now(),kind:"event",type:x.eventName,data:x.data})}))},[e]),n.useEffect(()=>{const x=console.warn,_=console.log,T=(M,P)=>function(...g){try{const R=typeof g[0]=="string"?g[0]:"";R.startsWith("[LiveLayer]")&&l.current.push({id:Xt++,ts:Date.now(),kind:M,type:R.slice(0,120),data:{args:g.slice(1).map(z=>Dr(z))}})}catch{}return P.apply(this,g)};return console.warn=T("warn",x),console.log=T("log",_),()=>{console.warn=x,console.log=_}},[]),!i)return t.jsx("button",{type:"button",onClick:()=>s(!0),title:"Open LiveLayer debug panel (Cmd/Ctrl + Shift + L)","aria-label":"Open LiveLayer debug panel",style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.18)",borderRadius:999,padding:"6px 10px",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",cursor:"pointer",boxShadow:"0 4px 12px rgba(0,0,0,0.35)",opacity:.85},children:"🛰 LL debug"});const L=a.filter(x=>{if(!f)return!0;const _=f.toLowerCase();return x.type.toLowerCase().includes(_)||JSON.stringify(x.data||{}).toLowerCase().includes(_)});return t.jsxs("div",{style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,width:380,maxHeight:"60vh",background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:12,boxShadow:"0 16px 48px rgba(0,0,0,0.5)",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"8px 10px",background:"rgba(255,255,255,0.04)",borderBottom:"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),t.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[a.length," event",a.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>w(x=>!x),style:kt(b?"#f59e0b":"transparent"),title:"Pause / resume capture",children:b?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{d([]),l.current=[]},style:kt("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:kt("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:f,onChange:x=>h(x.target.value),placeholder:"filter by type or data…",style:{margin:8,padding:"6px 8px",background:"rgba(255,255,255,0.06)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:"#fff",fontSize:11,outline:"none"}}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 8px 8px"},children:L.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"
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsxs as x, jsx as n, Fragment as Nt } from "react/jsx-runtime";
3
- import { Component as wn, useState as C, useRef as N, useEffect as I, useCallback as S, useMemo as yt, forwardRef as At, createElement as _n } from "react";
3
+ import { Component as wn, useState as C, useRef as N, useEffect as I, useCallback as L, useMemo as yt, forwardRef as At, createElement as _n } from "react";
4
4
  import { LiveKitSession as xn } from "@livelayer/sdk";
5
5
  import { createLocalAudioTrack as kn, Track as on, createLocalVideoTrack as Ln } from "livekit-client";
6
6
  class Sn extends wn {
@@ -34,7 +34,7 @@ class Sn extends wn {
34
34
  }
35
35
  }
36
36
  function En(e) {
37
- const [t, r] = C("idle"), [o, i] = C("idle"), [l, u] = C([]), [d, p] = C(null), [y, w] = C(null), [s, a] = C(null), [L, R] = C(!1), [A, v] = C(null), _ = N(null), H = N(e.onDataMessage);
37
+ const [t, r] = C("idle"), [o, i] = C("idle"), [l, u] = C([]), [d, p] = C(null), [y, w] = C(null), [s, a] = C(null), [S, R] = C(!1), [A, v] = C(null), _ = N(null), H = N(e.onDataMessage);
38
38
  H.current = e.onDataMessage, I(() => {
39
39
  const T = {
40
40
  onConnectionStateChange: (z) => {
@@ -80,7 +80,7 @@ function En(e) {
80
80
  e.sessionEndpoint,
81
81
  JSON.stringify(e.sessionBody ?? {})
82
82
  ]);
83
- const $ = S(async () => {
83
+ const $ = L(async () => {
84
84
  const T = _.current;
85
85
  if (T)
86
86
  try {
@@ -88,10 +88,10 @@ function En(e) {
88
88
  } catch (V) {
89
89
  throw v(V instanceof Error ? V.message : String(V)), V;
90
90
  }
91
- }, []), q = S(() => {
91
+ }, []), q = L(() => {
92
92
  const T = _.current;
93
93
  T && T.disconnect();
94
- }, []), m = S(() => {
94
+ }, []), m = L(() => {
95
95
  var T;
96
96
  return ((T = _.current) == null ? void 0 : T.getRoom()) ?? null;
97
97
  }, []);
@@ -102,7 +102,7 @@ function En(e) {
102
102
  agentConfig: d,
103
103
  videoElement: y,
104
104
  audioElement: s,
105
- canResume: L,
105
+ canResume: S,
106
106
  error: A,
107
107
  connect: $,
108
108
  disconnect: q,
@@ -111,7 +111,7 @@ function En(e) {
111
111
  };
112
112
  }
113
113
  function Cn() {
114
- const e = N(null), t = N(null), r = N(null), o = N(null), i = N(/* @__PURE__ */ new Set()), l = N(null), u = S(() => {
114
+ const e = N(null), t = N(null), r = N(null), o = N(null), i = N(/* @__PURE__ */ new Set()), l = N(null), u = L(() => {
115
115
  const s = t.current;
116
116
  if (!s) {
117
117
  o.current = null;
@@ -122,9 +122,9 @@ function Cn() {
122
122
  ));
123
123
  const a = l.current;
124
124
  s.getByteFrequencyData(a);
125
- let L = 0;
126
- for (let A = 0; A < a.length; A++) L += a[A];
127
- const R = L / a.length / 255;
125
+ let S = 0;
126
+ for (let A = 0; A < a.length; A++) S += a[A];
127
+ const R = S / a.length / 255;
128
128
  for (const A of i.current)
129
129
  try {
130
130
  A(R);
@@ -132,11 +132,11 @@ function Cn() {
132
132
  console.error("[useAudioLevel] subscriber threw:", v);
133
133
  }
134
134
  o.current = requestAnimationFrame(u);
135
- }, []), d = S(() => {
135
+ }, []), d = L(() => {
136
136
  if (e.current || typeof window > "u" || typeof AudioContext > "u") return;
137
137
  const s = new AudioContext(), a = s.createAnalyser();
138
138
  a.fftSize = 64, a.connect(s.destination), e.current = s, t.current = a;
139
- }, []), p = S(
139
+ }, []), p = L(
140
140
  (s) => {
141
141
  if (d(), !(!e.current || !t.current)) {
142
142
  if (r.current) {
@@ -157,7 +157,7 @@ function Cn() {
157
157
  }
158
158
  },
159
159
  [d, u]
160
- ), y = S(() => {
160
+ ), y = L(() => {
161
161
  if (o.current !== null && (cancelAnimationFrame(o.current), o.current = null), r.current) {
162
162
  try {
163
163
  r.current.disconnect();
@@ -165,7 +165,7 @@ function Cn() {
165
165
  }
166
166
  r.current = null;
167
167
  }
168
- }, []), w = S((s) => (i.current.add(s), () => {
168
+ }, []), w = L((s) => (i.current.add(s), () => {
169
169
  i.current.delete(s);
170
170
  }), []);
171
171
  return I(() => () => {
@@ -187,7 +187,7 @@ function Cn() {
187
187
  }, [y]), { attach: p, detach: y, subscribe: w };
188
188
  }
189
189
  function Nn() {
190
- const [e, t] = C(!1), [r, o] = C(null), i = N(null), l = N(null), u = S(
190
+ const [e, t] = C(!1), [r, o] = C(null), i = N(null), l = N(null), u = L(
191
191
  async (s, a) => {
192
192
  if (i.current && l.current) {
193
193
  try {
@@ -198,24 +198,24 @@ function Nn() {
198
198
  }
199
199
  l.current = s, o(null);
200
200
  try {
201
- const L = await kn({
201
+ const S = await kn({
202
202
  echoCancellation: !0,
203
203
  noiseSuppression: !0
204
204
  });
205
- await s.localParticipant.publishTrack(L), i.current = L, a != null && a.startMuted && await L.mute(), t(L.isMuted);
206
- } catch (L) {
207
- const R = L instanceof Error && L.name === "NotAllowedError" ? "Enable your microphone to talk with the agent." : "Microphone unavailable. Check browser permissions and try again.";
208
- throw o(R), L;
205
+ await s.localParticipant.publishTrack(S), i.current = S, t(S.isMuted);
206
+ } catch (S) {
207
+ const R = S instanceof Error && S.name === "NotAllowedError" ? "Enable your microphone to talk with the agent." : "Microphone unavailable. Check browser permissions and try again.";
208
+ throw o(R), S;
209
209
  }
210
210
  },
211
211
  []
212
- ), d = S(() => {
212
+ ), d = L(() => {
213
213
  const s = i.current;
214
214
  s && (s.isMuted ? (s.unmute(), t(!1)) : (s.mute(), t(!0)));
215
- }, []), p = S((s) => {
215
+ }, []), p = L((s) => {
216
216
  const a = i.current;
217
217
  a && (s && !a.isMuted ? (a.mute(), t(!0)) : !s && a.isMuted && (a.unmute(), t(!1)));
218
- }, []), y = S(() => {
218
+ }, []), y = L(() => {
219
219
  const s = i.current, a = l.current;
220
220
  if (s && a) {
221
221
  try {
@@ -225,7 +225,7 @@ function Nn() {
225
225
  s.stop();
226
226
  }
227
227
  i.current = null, l.current = null, t(!1);
228
- }, []), w = S(() => o(null), []);
228
+ }, []), w = L(() => o(null), []);
229
229
  return {
230
230
  isMuted: e,
231
231
  micError: r,
@@ -238,9 +238,9 @@ function Nn() {
238
238
  }
239
239
  const An = { resolution: { width: 640, height: 480, frameRate: 24 } };
240
240
  function Rn() {
241
- const [e, t] = C(!1), [r, o] = C(null), [i, l] = C(null), [u, d] = C(""), p = N(null), y = N(null), w = S((_) => {
241
+ const [e, t] = C(!1), [r, o] = C(null), [i, l] = C(null), [u, d] = C(""), p = N(null), y = N(null), w = L((_) => {
242
242
  p.current = _;
243
- }, []), s = S(() => {
243
+ }, []), s = L(() => {
244
244
  const _ = p.current, H = y.current;
245
245
  if (H && _) {
246
246
  const $ = _.localParticipant.getTrackPublication(on.Source.Camera);
@@ -254,7 +254,7 @@ function Rn() {
254
254
  H.stop();
255
255
  }
256
256
  y.current = null, l(null), t(!1);
257
- }, []), a = S(async (_) => {
257
+ }, []), a = L(async (_) => {
258
258
  const H = p.current;
259
259
  if (H) {
260
260
  o(null);
@@ -277,13 +277,13 @@ function Rn() {
277
277
  o(q);
278
278
  }
279
279
  }
280
- }, []), L = S(async () => {
280
+ }, []), S = L(async () => {
281
281
  e ? s() : await a(u || void 0);
282
- }, [e, u, s, a]), R = S(async (_) => {
282
+ }, [e, u, s, a]), R = L(async (_) => {
283
283
  s(), await a(_);
284
- }, [s, a]), A = S(() => {
284
+ }, [s, a]), A = L(() => {
285
285
  s(), p.current = null, o(null), d("");
286
- }, [s]), v = S(() => o(null), []);
286
+ }, [s]), v = L(() => o(null), []);
287
287
  return I(() => () => {
288
288
  y.current && y.current.stop();
289
289
  }, []), {
@@ -291,7 +291,7 @@ function Rn() {
291
291
  error: r,
292
292
  previewEl: i,
293
293
  activeDeviceId: u,
294
- toggle: L,
294
+ toggle: S,
295
295
  switchDevice: R,
296
296
  attachRoom: w,
297
297
  teardown: A,
@@ -299,9 +299,9 @@ function Rn() {
299
299
  };
300
300
  }
301
301
  function Dn() {
302
- const [e, t] = C(!1), [r, o] = C(null), [i, l] = C(null), u = N(null), d = S((a) => {
302
+ const [e, t] = C(!1), [r, o] = C(null), [i, l] = C(null), u = N(null), d = L((a) => {
303
303
  u.current = a;
304
- }, []), p = S(() => l(null), []), y = S(async () => {
304
+ }, []), p = L(() => l(null), []), y = L(async () => {
305
305
  const a = u.current;
306
306
  if (a) {
307
307
  if (e) {
@@ -315,7 +315,7 @@ function Dn() {
315
315
  o(null);
316
316
  try {
317
317
  await a.localParticipant.setScreenShareEnabled(!0);
318
- let L = 0;
318
+ let S = 0;
319
319
  const R = () => {
320
320
  const A = a.localParticipant.getTrackPublication(on.Source.ScreenShare);
321
321
  if (A != null && A.track) {
@@ -330,15 +330,15 @@ function Dn() {
330
330
  }
331
331
  return;
332
332
  }
333
- L++ < 10 ? setTimeout(R, 100) : t(!0);
333
+ S++ < 10 ? setTimeout(R, 100) : t(!0);
334
334
  };
335
335
  R();
336
- } catch (L) {
337
- const R = L instanceof Error ? L.name : "";
336
+ } catch (S) {
337
+ const R = S instanceof Error ? S.name : "";
338
338
  R !== "NotAllowedError" && R !== "AbortError" && o("Screen share unavailable. Try again."), t(!1);
339
339
  }
340
340
  }
341
- }, [e, p]), w = S(() => {
341
+ }, [e, p]), w = L(() => {
342
342
  const a = u.current;
343
343
  if (a && e)
344
344
  try {
@@ -346,11 +346,11 @@ function Dn() {
346
346
  } catch {
347
347
  }
348
348
  p(), t(!1), o(null), u.current = null;
349
- }, [e, p]), s = S(() => o(null), []);
349
+ }, [e, p]), s = L(() => o(null), []);
350
350
  return { isEnabled: e, error: r, previewEl: i, toggle: y, attachRoom: d, teardown: w, clearError: s };
351
351
  }
352
352
  function Mn() {
353
- const [e, t] = C([]), [r, o] = C([]), i = S(async () => {
353
+ const [e, t] = C([]), [r, o] = C([]), i = L(async () => {
354
354
  if (!(typeof navigator > "u" || !navigator.mediaDevices))
355
355
  try {
356
356
  const l = await navigator.mediaDevices.enumerateDevices();
@@ -407,7 +407,7 @@ function $n({
407
407
  defaultValue: t = "expanded",
408
408
  onChange: r
409
409
  } = {}) {
410
- const o = e !== void 0, [i, l] = C(t), u = o ? e : i, d = S(
410
+ const o = e !== void 0, [i, l] = C(t), u = o ? e : i, d = L(
411
411
  (p) => {
412
412
  p !== u && (o || l(p), r == null || r(p));
413
413
  },
@@ -639,7 +639,7 @@ const nr = ({
639
639
  avatarImageUrl: l,
640
640
  agentName: u
641
641
  }) => {
642
- const d = Zn(e), p = d === "right" ? "left" : "right", y = t ? 80 : 72, w = !!l, [s, a] = C(null), [L, R] = C(!1), A = N(null), v = N(!1), _ = S(
642
+ const d = Zn(e), p = d === "right" ? "left" : "right", y = t ? 80 : 72, w = !!l, [s, a] = C(null), [S, R] = C(!1), A = N(null), v = N(!1), _ = L(
643
643
  (P) => {
644
644
  if (typeof window > "u") return P;
645
645
  const O = y / 2, G = Jt + O, ee = window.innerHeight - Jt - O;
@@ -655,7 +655,7 @@ const nr = ({
655
655
  };
656
656
  return window.addEventListener("resize", O), () => window.removeEventListener("resize", O);
657
657
  }, [_]);
658
- const H = S(
658
+ const H = L(
659
659
  (P) => {
660
660
  if (!(P.pointerType === "mouse" && P.button !== 0) && s !== null) {
661
661
  try {
@@ -670,7 +670,7 @@ const nr = ({
670
670
  }
671
671
  },
672
672
  [s]
673
- ), $ = S(
673
+ ), $ = L(
674
674
  (P) => {
675
675
  const O = A.current;
676
676
  if (!O) return;
@@ -678,7 +678,7 @@ const nr = ({
678
678
  !O.moved && Math.abs(G) > er && (O.moved = !0, R(!0)), O.moved && a(_(O.startCenterY + G));
679
679
  },
680
680
  [_]
681
- ), q = S(
681
+ ), q = L(
682
682
  (P) => {
683
683
  const O = A.current;
684
684
  if (O) {
@@ -690,13 +690,13 @@ const nr = ({
690
690
  }
691
691
  },
692
692
  []
693
- ), m = S(() => {
693
+ ), m = L(() => {
694
694
  if (v.current) {
695
695
  v.current = !1;
696
696
  return;
697
697
  }
698
698
  o();
699
- }, [o]), T = S(
699
+ }, [o]), T = L(
700
700
  (P) => {
701
701
  if (P.key === "ArrowUp" || P.key === "ArrowDown") {
702
702
  P.preventDefault();
@@ -714,7 +714,7 @@ const nr = ({
714
714
  `ll-hidden--${d}`,
715
715
  t ? "ll-hidden--mobile" : "ll-hidden--desktop",
716
716
  r ? "ll-hidden--speaking" : null,
717
- L ? "is-dragging" : null,
717
+ S ? "is-dragging" : null,
718
718
  w ? "ll-hidden--with-avatar" : null
719
719
  ].filter(Boolean).join(" "), z = s === null ? void 0 : { top: `${s - y / 2}px`, transform: "none" };
720
720
  return /* @__PURE__ */ n(
@@ -777,10 +777,10 @@ const nr = ({
777
777
  }, [t]);
778
778
  I(() => e.subscribe((s) => {
779
779
  for (let a = 0; a < t; a++) {
780
- const L = d.current[a];
781
- if (!L) continue;
780
+ const S = d.current[a];
781
+ if (!S) continue;
782
782
  const R = Math.max(o, s * r * p[a]);
783
- L.style.height = `${R}px`;
783
+ S.style.height = `${R}px`;
784
784
  }
785
785
  }), [e, t, r, o, p]);
786
786
  const y = ["ll-waveform", i].filter(Boolean).join(" ");
@@ -973,7 +973,7 @@ const nr = ({
973
973
  teamSwitcherOpen: w,
974
974
  onToggleTeamSwitcher: s,
975
975
  onSelectTeamMember: a,
976
- languageMenuOpen: L,
976
+ languageMenuOpen: S,
977
977
  onToggleLanguageMenu: R,
978
978
  connectionState: A,
979
979
  agentState: v,
@@ -1048,20 +1048,20 @@ const nr = ({
1048
1048
  }, [le]);
1049
1049
  const [ue, ge] = C(!1), [ze, ye] = C(!1);
1050
1050
  I(() => {
1051
- if (!ue && !ze && !L && !w) return;
1051
+ if (!ue && !ze && !S && !w) return;
1052
1052
  const h = () => {
1053
- ge(!1), ye(!1), L && R(), w && s();
1053
+ ge(!1), ye(!1), S && R(), w && s();
1054
1054
  };
1055
1055
  return document.addEventListener("click", h), () => document.removeEventListener("click", h);
1056
1056
  }, [
1057
1057
  ue,
1058
1058
  ze,
1059
- L,
1059
+ S,
1060
1060
  w,
1061
1061
  R,
1062
1062
  s
1063
1063
  ]);
1064
- const [ve, Ge] = C(""), Ye = S(
1064
+ const [ve, Ge] = C(""), Ye = L(
1065
1065
  (h) => {
1066
1066
  h.preventDefault();
1067
1067
  const K = ve.trim();
@@ -1186,7 +1186,7 @@ const nr = ({
1186
1186
  h.stopPropagation(), R();
1187
1187
  },
1188
1188
  "aria-haspopup": "listbox",
1189
- "aria-expanded": L,
1189
+ "aria-expanded": S,
1190
1190
  "aria-label": "Language: English",
1191
1191
  title: "Language: English",
1192
1192
  children: [
@@ -1195,7 +1195,7 @@ const nr = ({
1195
1195
  ]
1196
1196
  }
1197
1197
  ),
1198
- L && /* @__PURE__ */ n(
1198
+ S && /* @__PURE__ */ n(
1199
1199
  "div",
1200
1200
  {
1201
1201
  className: "ll-hmenu",
@@ -1710,12 +1710,12 @@ function wr(e, t = {}) {
1710
1710
  T.length > 10 && p.push(Ae(T, en));
1711
1711
  }
1712
1712
  const a = p.join(`
1713
- `), L = [], R = Array.from(r.querySelectorAll("a[href]"));
1713
+ `), S = [], R = Array.from(r.querySelectorAll("a[href]"));
1714
1714
  for (const m of R) {
1715
- if (L.length >= hr) break;
1715
+ if (S.length >= hr) break;
1716
1716
  if (tt(m) || !nt(m)) continue;
1717
1717
  const T = m.getAttribute("href") || "", V = (m.textContent || "").trim();
1718
- !T || !V || L.push({ href: T, text: Ae(V, 100) });
1718
+ !T || !V || S.push({ href: T, text: Ae(V, 100) });
1719
1719
  }
1720
1720
  const A = [], v = Array.from(
1721
1721
  r.querySelectorAll(
@@ -1757,7 +1757,7 @@ function wr(e, t = {}) {
1757
1757
  pathname: i,
1758
1758
  regions: d,
1759
1759
  visibleText: a,
1760
- visibleLinks: L,
1760
+ visibleLinks: S,
1761
1761
  visibleFields: A,
1762
1762
  forms: H,
1763
1763
  extras: e
@@ -1934,7 +1934,7 @@ function $r(e) {
1934
1934
  position: w = "bottom-right",
1935
1935
  mobileBreakpoint: s = 640,
1936
1936
  persistKey: a = "ll-widget",
1937
- disablePersistence: L = !1,
1937
+ disablePersistence: S = !1,
1938
1938
  teamMembers: R,
1939
1939
  currentTeamMemberId: A,
1940
1940
  onTeamMemberChange: v,
@@ -1983,7 +1983,7 @@ function $r(e) {
1983
1983
  defaultValue: p,
1984
1984
  onChange: y,
1985
1985
  persistKey: a,
1986
- disablePersistence: L
1986
+ disablePersistence: S
1987
1987
  }), Ce = On(s), je = Cn(), re = Nn(), ce = Rn(), ue = Dn(), ge = Mn(), [ze, ye] = C(!1), [ve, Ge] = C(!1), [Ye, Je] = C(!1), [be, we] = C(!1), [He, ct] = C(!1), Ke = N(ee), qe = N(le), h = N(lt), K = N(at), xt = N(Le), ut = N(ot), dt = N(it), kt = N(ie), oe = N(null), ft = N(null), Oe = N(null), Dt = N(void 0);
1988
1988
  Dt.current = ae, Ke.current = ee, qe.current = le, h.current = lt, K.current = at, xt.current = Le, ut.current = ot, dt.current = it, kt.current = ie;
1989
1989
  function _e(f) {
@@ -1995,7 +1995,7 @@ function $r(e) {
1995
1995
  `[LiveLayer] Agent command "${f}" blocked — capability "${c}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`
1996
1996
  );
1997
1997
  }
1998
- const Xe = S(
1998
+ const Xe = L(
1999
1999
  (f) => {
2000
2000
  var W, ne, Q, de, fe, ke;
2001
2001
  const c = f;
@@ -2651,7 +2651,7 @@ function $r(e) {
2651
2651
  const f = g.audioElement;
2652
2652
  f && (f.muted = He);
2653
2653
  }, [g.audioElement, He]);
2654
- const sn = S((f) => {
2654
+ const sn = L((f) => {
2655
2655
  const c = g.getRoom();
2656
2656
  if (c)
2657
2657
  try {
@@ -2661,7 +2661,7 @@ function $r(e) {
2661
2661
  c.localParticipant.publishData(W, { reliable: !0 });
2662
2662
  } catch {
2663
2663
  }
2664
- }, [g]), cn = S(() => {
2664
+ }, [g]), cn = L(() => {
2665
2665
  ct((f) => !f);
2666
2666
  }, []);
2667
2667
  I(() => {
@@ -2675,7 +2675,7 @@ function $r(e) {
2675
2675
  I(() => {
2676
2676
  g.isControlled || !u || It.current || Pe && g.connectionState === "idle" && (It.current = !0, g.connect());
2677
2677
  }, [u, g.connectionState, g, Pe]);
2678
- const un = S(
2678
+ const un = L(
2679
2679
  (f) => {
2680
2680
  const c = R == null ? void 0 : R.find((W) => W.id === f);
2681
2681
  c && (Je(!1), f !== X && (Ge(!0), g.disconnect(), Fe || $e(f), v == null || v(c)));
@@ -2699,16 +2699,16 @@ function $r(e) {
2699
2699
  }, [Ye]);
2700
2700
  const dn = !!$ || !!(te != null && te.avatarImageUrl) || g.isControlled, Ze = In(Be, o, dn);
2701
2701
  ie === void 0 && ((Pt = Ze.info) != null && Pt.capabilities) && (kt.current = Ze.info.capabilities);
2702
- const pt = (te == null ? void 0 : te.name) ?? q ?? (($t = g.agentConfig) == null ? void 0 : $t.name) ?? ((Bt = Ze.info) == null ? void 0 : Bt.name) ?? "Live Layer", Et = (te == null ? void 0 : te.avatarImageUrl) ?? $ ?? ((zt = g.agentConfig) == null ? void 0 : zt.avatarImageUrl) ?? ((Ht = Ze.info) == null ? void 0 : Ht.avatarImageUrl) ?? null, fn = _ ?? ((qt = g.agentConfig) == null ? void 0 : qt.idleLoopUrl) ?? ((Ot = Ze.info) == null ? void 0 : Ot.idleLoopUrl) ?? null, pn = H ?? null, hn = S(() => me("expanded"), [me]), mn = S(
2702
+ const pt = (te == null ? void 0 : te.name) ?? q ?? (($t = g.agentConfig) == null ? void 0 : $t.name) ?? ((Bt = Ze.info) == null ? void 0 : Bt.name) ?? "Live Layer", Et = (te == null ? void 0 : te.avatarImageUrl) ?? $ ?? ((zt = g.agentConfig) == null ? void 0 : zt.avatarImageUrl) ?? ((Ht = Ze.info) == null ? void 0 : Ht.avatarImageUrl) ?? null, fn = _ ?? ((qt = g.agentConfig) == null ? void 0 : qt.idleLoopUrl) ?? ((Ot = Ze.info) == null ? void 0 : Ot.idleLoopUrl) ?? null, pn = H ?? null, hn = L(() => me("expanded"), [me]), mn = L(
2703
2703
  () => me("minimized"),
2704
2704
  [me]
2705
- ), Tt = S(() => {
2705
+ ), Tt = L(() => {
2706
2706
  g.disconnect(), me("hidden");
2707
- }, [g, me]), gn = S(() => {
2707
+ }, [g, me]), gn = L(() => {
2708
2708
  const f = g.audioElement;
2709
2709
  f && f.play().then(() => ye(!1)).catch(() => {
2710
2710
  });
2711
- }, [g.audioElement]), yn = S(() => {
2711
+ }, [g.audioElement]), yn = L(() => {
2712
2712
  ye(!1), g.connect();
2713
2713
  }, [g]), et = {
2714
2714
  ..._t,
@@ -2829,10 +2829,10 @@ const Fr = ({
2829
2829
  }) => {
2830
2830
  const d = N(null), p = N(null), y = N(i);
2831
2831
  y.current = i;
2832
- const w = S((s) => {
2833
- var L;
2832
+ const w = L((s) => {
2833
+ var S;
2834
2834
  const a = s.detail;
2835
- (L = y.current) == null || L.call(y, a);
2835
+ (S = y.current) == null || S.call(y, a);
2836
2836
  }, []);
2837
2837
  return I(() => {
2838
2838
  const s = d.current;
@@ -2886,13 +2886,13 @@ const Fr = ({
2886
2886
  }
2887
2887
  );
2888
2888
  } else if ("as" in t && t.as === "select") {
2889
- const { name: p, label: y, labelClassName: w, as: s, children: a, ...L } = t;
2889
+ const { name: p, label: y, labelClassName: w, as: s, children: a, ...S } = t;
2890
2890
  d = /* @__PURE__ */ n(
2891
2891
  "select",
2892
2892
  {
2893
2893
  ref: r,
2894
2894
  ...u,
2895
- ...L,
2895
+ ...S,
2896
2896
  children: a
2897
2897
  }
2898
2898
  );
@@ -2919,8 +2919,8 @@ function Jr({
2919
2919
  defaultOpen: t = !1,
2920
2920
  storageKey: r = "ll-debug-open"
2921
2921
  }) {
2922
- const [o, i] = C(t), [l, u] = C([]), [d, p] = C(""), [y, w] = C(!1), s = N(/* @__PURE__ */ new Set()), a = N([]), L = N(y);
2923
- L.current = y, I(() => {
2922
+ const [o, i] = C(t), [l, u] = C([]), [d, p] = C(""), [y, w] = C(!1), s = N(/* @__PURE__ */ new Set()), a = N([]), S = N(y);
2923
+ S.current = y, I(() => {
2924
2924
  try {
2925
2925
  const v = localStorage.getItem(r);
2926
2926
  v === "1" && i(!0), v === "0" && i(!1);
@@ -2938,7 +2938,7 @@ function Jr({
2938
2938
  return window.addEventListener("keydown", v), () => window.removeEventListener("keydown", v);
2939
2939
  }, []), I(() => {
2940
2940
  const v = setInterval(() => {
2941
- if (a.current.length === 0 || L.current) return;
2941
+ if (a.current.length === 0 || S.current) return;
2942
2942
  const _ = a.current.splice(0, a.current.length);
2943
2943
  u(
2944
2944
  (H) => [..._.reverse(), ...H].slice(0, 200)
@@ -3247,7 +3247,7 @@ function zr(e) {
3247
3247
  }
3248
3248
  }
3249
3249
  function Kr() {
3250
- const [e, t] = C([]), r = S((i) => {
3250
+ const [e, t] = C([]), r = L((i) => {
3251
3251
  t((l) => {
3252
3252
  const u = l.findIndex((d) => d.id === i.id);
3253
3253
  if (u >= 0) {
@@ -3256,7 +3256,7 @@ function Kr() {
3256
3256
  }
3257
3257
  return [...l, i];
3258
3258
  });
3259
- }, []), o = S(() => t([]), []);
3259
+ }, []), o = L(() => t([]), []);
3260
3260
  return {
3261
3261
  entries: e,
3262
3262
  pushSegment: r,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livelayer/react",
3
- "version": "0.5.24-debug.3",
3
+ "version": "0.5.24-debug.4",
4
4
  "description": "LiveLayer agent widget for React — avatar video, team switching, responsive layouts, full-fidelity embed",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -21,8 +21,8 @@
21
21
  "react-dom": ">=18.0.0"
22
22
  },
23
23
  "dependencies": {
24
- "livekit-client": "^2.17.3",
25
- "@livelayer/sdk": "0.3.7"
24
+ "livekit-client": "~2.17.3",
25
+ "@livelayer/sdk": "0.3.8"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@testing-library/dom": "^10.4.1",