@livelayer/react 0.10.4 → 0.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),n=require("react"),Lt=require("react-dom"),Xn=require("@livelayer/sdk"),mt=require("livekit-client");class cn 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 un(e){const[r,o]=n.useState("idle"),[i,s]=n.useState("idle"),[a,d]=n.useState([]),[l,u]=n.useState(null),[f,y]=n.useState(null),[p,c]=n.useState(null),[L,w]=n.useState(!1),[_,x]=n.useState(null),v=n.useRef(null),C=n.useRef(e.onDataMessage);C.current=e.onDataMessage,n.useEffect(()=>{const S={onConnectionStateChange:z=>{o(z),z==="connected"&&x(null)},onAgentStateChange:s,onTranscript:z=>d([...z]),onAgentConfig:u,onAudioTrack:z=>c(z),onVideoTrack:z=>y(z),onVideoTrackRemoved:()=>y(null),onError:z=>x(z),onDataMessage:z=>{var O;(O=C.current)==null||O.call(C,z)},onResumabilityChange:w},$=new Xn.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},S);return v.current=$,o("idle"),s("idle"),d([]),u(null),y(null),c(null),w(!1),x(null),()=>{var z;(z=$.destroy)==null||z.call($),v.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=n.useCallback(async()=>{const S=v.current;if(S)try{await S.connect()}catch($){throw x($ instanceof Error?$.message:String($)),$}},[]),N=n.useCallback(()=>{const S=v.current;S&&S.disconnect()},[]),k=n.useCallback(()=>{var S;return((S=v.current)==null?void 0:S.getRoom())??null},[]);return{connectionState:r,agentState:i,transcript:a,agentConfig:l,videoElement:f,audioElement:p,canResume:L,error:_,connect:E,disconnect:N,getRoom:k,session:v.current}}function dn(){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 p=r.current;if(!p){i.current=null;return}(!a.current||a.current.length!==p.frequencyBinCount)&&(a.current=new Uint8Array(new ArrayBuffer(p.frequencyBinCount)));const c=a.current;p.getByteFrequencyData(c);let L=0;for(let _=0;_<c.length;_++)L+=c[_];const w=L/c.length/255;for(const _ of s.current)try{_(w)}catch(x){console.error("[useAudioLevel] subscriber threw:",x)}i.current=requestAnimationFrame(d)},[]),l=n.useCallback(()=>{if(e.current||typeof window>"u"||typeof AudioContext>"u")return;const p=new AudioContext,c=p.createAnalyser();c.fftSize=64,c.connect(p.destination),e.current=p,r.current=c},[]),u=n.useCallback(p=>{if(l(),!(!e.current||!r.current)){if(o.current){try{o.current.disconnect()}catch{}o.current=null}try{const c=e.current.createMediaElementSource(p);c.connect(r.current),o.current=c}catch(c){console.warn("[useAudioLevel] createMediaElementSource failed:",c);return}i.current===null&&(i.current=requestAnimationFrame(d))}},[l,d]),f=n.useCallback(()=>{if(i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),o.current){try{o.current.disconnect()}catch{}o.current=null}},[]),y=n.useCallback(p=>(s.current.add(p),()=>{s.current.delete(p)}),[]);return n.useEffect(()=>()=>{if(f(),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},[f]),{attach:u,detach:f,subscribe:y}}function fn(){const[e,r]=n.useState(!1),[o,i]=n.useState(""),[s,a]=n.useState(null),d=n.useRef(null),l=n.useRef(null),u=n.useCallback(async w=>{var _,x;if(d.current&&l.current){try{await l.current.localParticipant.unpublishTrack(d.current)}catch{}d.current.stop(),d.current=null}l.current=w,a(null);try{const v=await mt.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await w.localParticipant.publishTrack(v),d.current=v,r(v.isMuted);const C=(x=(_=v.mediaStreamTrack)==null?void 0:_.getSettings)==null?void 0:x.call(_);C!=null&&C.deviceId&&i(C.deviceId)}catch(v){const C=v instanceof Error&&v.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw a(C),v}},[]),f=n.useCallback(w=>{l.current=w},[]),y=n.useCallback(async w=>{const _=l.current;if(_)try{await _.switchActiveDevice("audioinput",w),i(w)}catch(x){console.warn("[useMicrophoneState] switchDevice failed:",x)}},[]),p=n.useCallback(()=>{const w=d.current,_=l.current;if(w){w.isMuted?(w.unmute(),r(!1)):(w.mute(),r(!0));return}if(_){const x=!e;r(x);try{_.localParticipant.setMicrophoneEnabled(!x)}catch(v){console.warn("[useMicrophoneState] setMicrophoneEnabled failed:",v)}}},[e]),c=n.useCallback(()=>{const w=d.current,_=l.current;if(w&&_){try{_.localParticipant.unpublishTrack(w)}catch{}w.stop()}d.current=null,l.current=null,r(!1),i("")},[]),L=n.useCallback(()=>a(null),[]);return{isMuted:e,activeDeviceId:o,micError:s,toggleMute:p,setupMic:u,attachRoom:f,switchDevice:y,teardownMic:c,clearError:L}}const Qn={resolution:{width:640,height:480,frameRate:24}};function pn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),[d,l]=n.useState(""),u=n.useRef(null),f=n.useRef(null),y=n.useCallback(v=>{u.current=v},[]),p=n.useCallback(()=>{var E;const v=u.current,C=f.current;if(C&&v){const N=v.localParticipant.getTrackPublication(mt.Track.Source.Camera),S=(N==null?void 0:N.track)??C;try{v.localParticipant.unpublishTrack(S)}catch{}try{(E=S.stop)==null||E.call(S)}catch{}}f.current=null,a(null),r(!1)},[]),c=n.useCallback(async v=>{const C=u.current;if(C){i(null);try{const E={...Qn};v&&(E.deviceId=v);const N=await mt.createLocalVideoTrack(E);await C.localParticipant.publishTrack(N),f.current=N;const k=N.attach();a(k),r(!0),v&&l(v);try{C.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const N=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";i(N)}}},[]),L=n.useCallback(async()=>{e?p():await c(d||void 0)},[e,d,p,c]),w=n.useCallback(async v=>{p(),await c(v)},[p,c]),_=n.useCallback(()=>{p(),u.current=null,i(null),l("")},[p]),x=n.useCallback(()=>i(null),[]);return n.useEffect(()=>()=>{f.current&&f.current.stop()},[]),{isEnabled:e,error:o,previewEl:s,activeDeviceId:d,toggle:L,switchDevice:w,attachRoom:y,teardown:_,clearError:x}}function hn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),d=n.useRef(null),l=n.useCallback(c=>{d.current=c},[]),u=n.useCallback(()=>a(null),[]),f=n.useCallback(async()=>{const c=d.current;if(c){if(e){try{await c.localParticipant.setScreenShareEnabled(!1)}catch{}u(),r(!1);return}i(null);try{await c.localParticipant.setScreenShareEnabled(!0);let L=0;const w=()=>{const _=c.localParticipant.getTrackPublication(mt.Track.Source.ScreenShare);if(_!=null&&_.track){const x=_.track.attach();a(x),r(!0);try{c.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}L++<10?setTimeout(w,100):r(!0)};w()}catch(L){const w=L instanceof Error?L.name:"";w!=="NotAllowedError"&&w!=="AbortError"&&i("Screen share unavailable. Try again."),r(!1)}}},[e,u]),y=n.useCallback(()=>{const c=d.current;if(c&&e)try{c.localParticipant.setScreenShareEnabled(!1)}catch{}u(),r(!1),i(null),d.current=null},[e,u]),p=n.useCallback(()=>i(null),[]);return{isEnabled:e,error:o,previewEl:s,toggle:f,attachRoom:l,teardown:y,clearError:p}}function mn(){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 gn(e,r,o=!1){const[i,s]=n.useState(null),[a,d]=n.useState(null),[l,u]=n.useState(!o&&!!e);return n.useEffect(()=>{if(o||!e){u(!1);return}const f=new AbortController,y=r||"https://app.livelayer.studio";return u(!0),d(null),fetch(`${y}/api/widget/agent/${encodeURIComponent(e)}`,{signal:f.signal}).then(async p=>{if(!p.ok){const c=await p.json().catch(()=>({}));throw new Error(c.error||`HTTP ${p.status}`)}return p.json()}).then(p=>{f.signal.aborted||(s(p),u(!1))}).catch(p=>{f.signal.aborted||(d(p instanceof Error?p.message:"Agent lookup failed"),u(!1))}),()=>f.abort()},[e,r,o]),{info:i,error:a,loading:l}}function Zn(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function er(e,r){if(!(typeof window>"u"))try{window.localStorage.setItem(e,r)}catch{}}function yn({value:e,defaultValue:r="expanded",onChange:o}={}){const i=e!==void 0,[s,a]=n.useState(r),d=i?e:s,l=n.useCallback(u=>{u!==d&&(i||a(u),o==null||o(u))},[d,i,o]);return[d,l]}const tr=["hidden","minimized","expanded"];function nr(e){return e&&tr.includes(e)?e:null}function vn({value:e,defaultValue:r="expanded",onChange:o,persistKey:i="ll-widget",disablePersistence:s=!1}={}){const a=`${i}:display-mode`,d=n.useRef(!1),[l,u]=yn({value:e,defaultValue:r,onChange:f=>{e===void 0&&!s&&er(a,f),o==null||o(f)}});return n.useEffect(()=>{if(d.current||(d.current=!0,s||e!==void 0))return;const f=nr(Zn(a));f&&f!==l&&u(f)},[]),[l,u]}const rr=640;function xn(e=rr){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 Ut="__llHistoryPatched",gt="ll:pathname";function or(){if(typeof window>"u"||window.history[Ut])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(gt)),i},window.history.replaceState=function(...o){const i=r.apply(this,o);return window.dispatchEvent(new Event(gt)),i},window.history[Ut]=!0}function Vt(){return typeof window>"u"?"/":window.location.pathname||"/"}function bn(e){const[r,o]=n.useState(()=>e??Vt());return n.useEffect(()=>{if(e!==void 0)return;or();const i=()=>o(Vt());return i(),window.addEventListener("popstate",i),window.addEventListener(gt,i),()=>{window.removeEventListener("popstate",i),window.removeEventListener(gt,i)}},[e]),e??r}const Yt=new Map,ir=/[\\^$+?.()|{}[\]]/g;function sr(e){return e.replace(ir,"\\$&")}function ar(e){const r=Yt.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),l=sr(a).replace(new RegExp(`\\/${i}`,"g"),"(?:\\/.*)?").replace(new RegExp(i,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),u=new RegExp(`^${l}\\/?$`);return Yt.set(e,u),u}function lr(e,r){const o=r.length>1&&r.endsWith("/")?r.slice(0,-1):r;return ar(e).test(o)}function wn(e,r){return typeof e=="function"?e(r):e instanceof RegExp?e.test(r):lr(e,r)}function Gt(e,r){if(!e||e.length===0)return!1;for(const o of e)if(wn(o,r))return!0;return!1}function _n(e,r,o){return e===void 0?!0:Gt(o,e)?!1:r&&r.length>0?Gt(r,e):!0}function kn(e,r,o){return n.useMemo(()=>_n(e,r,o),[e,r,o])}function cr(e){return e===!1?{navigate:!1,thinking:!1,action:!1}:e===void 0||e===!0?{navigate:!0,thinking:!0,action:!0}:{navigate:e.navigate!==!1,thinking:e.thinking!==!1,action:e.action!==!1}}function ur(e){const r=n.useMemo(()=>cr(e.config),[e.config]),o=e.baseUrl.replace(/\/+$/,""),i=n.useRef(null),s=n.useCallback(u=>{try{new Audio(`${o}${u}`).play().catch(()=>{})}catch{}},[o]),a=n.useCallback(()=>{r.navigate&&s("/audio/page-change-sound.mp3")},[r.navigate,s]),d=n.useCallback(()=>{r.action&&s("/audio/confirmation-sound.mp3")},[r.action,s]),l=n.useCallback(u=>{if(!r.thinking){if(i.current){try{i.current.pause()}catch{}i.current=null}return}if(u){if(i.current)return;try{const f=new Audio(`${o}/audio/thinking-sound.mp3`);f.loop=!0,f.volume=.3,f.play().catch(()=>{i.current=null}),i.current=f}catch{}}else if(i.current){try{i.current.pause()}catch{}i.current=null}},[o,r.thinking]);return n.useEffect(()=>()=>{if(i.current){try{i.current.pause()}catch{}i.current=null}},[]),n.useMemo(()=>({playPageChange:a,playConfirmation:d,setThinking:l}),[a,d,l])}const Kt=({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"})}),Jt=({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"})}),dr=({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"})}),fr={left:180,right:0,up:-90,down:90},Xt=({direction:e="right",className:r})=>t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${fr[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function pr(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const jn="ll-hidden-tab-center-y",hr=5,Qt=16;function mr(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(jn);if(!e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null}catch{return null}}function Zt(e){if(!(typeof window>"u"))try{window.localStorage.setItem(jn,String(e))}catch{}}const gr=({position:e,isMobile:r,isSpeaking:o,onExpand:i,label:s="Open widget",avatarImageUrl:a,agentName:d,containerEl:l})=>{const u=pr(e),f=u==="right"?"left":"right",y=r?80:72,p=!!a,c=!!l,[L,w]=n.useState(null),[_,x]=n.useState(!1),v=n.useRef(null),C=n.useRef(!1),E=n.useCallback(T=>{if(typeof window>"u")return T;const W=y/2,D=Qt+W,F=window.innerHeight-Qt-W;return F<D?Math.max(D,T):Math.max(D,Math.min(F,T))},[y]);n.useEffect(()=>{if(c){w(null);return}const T=mr();w(E(T??window.innerHeight/2));const W=()=>{w(D=>D===null?null:E(D))};return window.addEventListener("resize",W),()=>window.removeEventListener("resize",W)},[E,c]);const N=n.useCallback(T=>{if(!c&&!(T.pointerType==="mouse"&&T.button!==0)&&L!==null){try{T.currentTarget.setPointerCapture(T.pointerId)}catch{}v.current={startClientY:T.clientY,startCenterY:L,moved:!1}}},[L,c]),k=n.useCallback(T=>{const W=v.current;if(!W)return;const D=T.clientY-W.startClientY;!W.moved&&Math.abs(D)>hr&&(W.moved=!0,x(!0)),W.moved&&w(E(W.startCenterY+D))},[E]),S=n.useCallback(T=>{const W=v.current;if(W){try{T.currentTarget.releasePointerCapture(T.pointerId)}catch{}v.current=null,W.moved&&(x(!1),C.current=!0,w(D=>(D!==null&&Zt(D),D)))}},[]),$=n.useCallback(()=>{if(C.current){C.current=!1;return}i()},[i]),z=n.useCallback(T=>{if(T.key==="ArrowUp"||T.key==="ArrowDown"){T.preventDefault();const W=T.key==="ArrowUp"?-8:8;w(D=>{if(D===null)return D;const F=E(D+W);return Zt(F),F})}},[E]),O=["ll-hidden",`ll-hidden--${u}`,r?"ll-hidden--mobile":"ll-hidden--desktop",o?"ll-hidden--speaking":null,_?"is-dragging":null,p?"ll-hidden--with-avatar":null,c?"ll-hidden--scoped":null].filter(Boolean).join(" "),H=L===null?void 0:{top:`${L-y/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:O,onPointerDown:N,onPointerMove:k,onPointerUp:S,onPointerCancel:S,onClick:$,onKeyDown:z,"aria-label":s,"data-position":e,style:H,children:p?t.jsxs(t.Fragment,{children:[t.jsx(Xt,{direction:f,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:a,alt:d?`${d} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Xt,{direction:f,className:"ll-hidden__chevron"})})},yr=({audioLevel:e,bars:r=20,maxHeight:o=20,minHeight:i=4,className:s,barClassName:a})=>{const d=n.useRef(null),l=n.useRef([]),u=n.useMemo(()=>{const y=(Math.sqrt(5)-1)/2;return Array.from({length:r},(p,c)=>.5+c*y%1*.5)},[r]);n.useEffect(()=>e.subscribe(p=>{for(let c=0;c<r;c++){const L=l.current[c];if(!L)continue;const w=Math.max(i,p*o*u[c]);L.style.height=`${w}px`}}),[e,r,o,i,u]);const f=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:d,className:f,"aria-hidden":"true",children:Array.from({length:r},(y,p)=>t.jsx("div",{ref:c=>{l.current[p]=c},className:["ll-waveform__bar",a].filter(Boolean).join(" "),style:{height:`${i}px`}},p))})},vr=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,agentState:s,isMuted:a,audioLevel:d,onExpand:l,onToggleMute:u,onClose:f})=>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:l,"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(yr,{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:y=>{y.stopPropagation(),u()},onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.stopPropagation(),y.preventDefault(),u())},"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(Kt,{muted:a,className:"ll-minimized__icon"})}),t.jsx(Jt,{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:u,"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(Kt,{muted:a,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:l,"aria-label":`Expand ${o} widget`,children:t.jsx(Jt,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:f,"aria-label":"Close widget",children:t.jsx(dr,{className:"ll-minimized__icon"})})]})]})}),xr=({src:e,alt:r,preCannedPlaying:o=!1,className:i,style:s})=>{const[a,d]=n.useState(!1),l=n.useRef(e);if(n.useEffect(()=>{l.current!==e&&(l.current=e,d(!1))},[e]),!e)return null;const u={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:o?"scale(1.02)":"scale(1)",opacity:a?1:0,...s};return t.jsx("img",{src:e,alt:r,className:i,style:u,loading:"eager",fetchPriority:"high",onLoad:()=>d(!0)})},br=8,en=8,wr=({open:e,onClose:r,anchorRef:o,children:i})=>{const s=n.useRef(null),[a,d]=n.useState(null);return n.useLayoutEffect(()=>{if(!e){d(null);return}const l=o.current;if(!l)return;const u=()=>{const f=l.getBoundingClientRect(),y={top:f.top-br,left:f.left+f.width/2},p=en+90,c=window.innerWidth-en-90;y.left<p&&(y.left=p),y.left>c&&(y.left=c),d(y)};return u(),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[e,o]),n.useEffect(()=>{if(!e)return;const l=f=>{const y=f.target,p=s.current,c=o.current;p&&p.contains(y)||c&&c.contains(y)||r()},u=f=>{f.key==="Escape"&&(f.stopPropagation(),r())};return document.addEventListener("mousedown",l),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",u)}},[e,r,o]),!e||a===null||typeof document>"u"?null:Lt.createPortal(t.jsx("div",{ref:s,className:"ll-overflow-popover",role:"menu",style:{position:"fixed",top:a.top,left:a.left,transform:"translate(-50%, -100%)"},children:i}),document.body)},_r=({isMuted:e,onToggleMute:r,isCameraEnabled:o,onToggleCamera:i,allowCamera:s,isScreenShareEnabled:a,onToggleScreenShare:d,allowScreenShare:l,isSpeakerMuted:u,onToggleSpeaker:f,allowTyping:y,isTypingOpen:p,onToggleTyping:c,onDisconnect:L})=>{const[w,_]=n.useState(!1),x=n.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:v=>v.stopPropagation(),children:[t.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:r,"aria-label":e?"Unmute microphone":"Mute microphone",children:t.jsx(Sn,{muted:e})}),t.jsx("button",{ref:x,type:"button",className:`ll-tool ${w?"is-on":""}`,onClick:()=>_(v=>!v),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":w,children:t.jsx(kr,{})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:L,"aria-label":"End conversation",children:t.jsx(Rn,{})})]}),t.jsxs(wr,{open:w,onClose:()=>_(!1),anchorRef:x,children:[s&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${o?"is-on":""}`,onClick:()=>{i(),_(!1)},children:[t.jsx(Ln,{}),t.jsx("span",{children:o?"Stop camera":"Start camera"})]}),l&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${a?"is-on":""}`,onClick:()=>{d(),_(!1)},children:[t.jsx(Cn,{}),t.jsx("span",{children:a?"Stop sharing":"Share screen"})]}),t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${u?"is-on":""}`,onClick:()=>{f(),_(!1)},children:[t.jsx(En,{muted:u}),t.jsx("span",{children:u?"Unmute speaker":"Mute speaker"})]}),y&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${p?"is-on":""}`,onClick:()=>{c(),_(!1)},children:[t.jsx(jr,{}),t.jsx("span",{children:p?"Hide typing":"Type a message"})]}),t.jsxs("button",{type:"button",className:"ll-overflow-popover__item is-active",disabled:!0,"aria-current":"true",children:[t.jsx("span",{className:"ll-overflow-popover__lang-code",children:"EN"}),t.jsx("span",{children:"English"})]})]})]})};function kr(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[t.jsx("circle",{cx:"6",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"18",cy:"12",r:"1.5"})]})}function jr(){return t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}const Cr=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,idleLoopUrl:s,greeting:a,branding:d,teamMembers:l,currentTeamMemberId:u,isSwitchingTeamMember:f,teamSwitcherOpen:y,onToggleTeamSwitcher:p,onSelectTeamMember:c,languageMenuOpen:L,onToggleLanguageMenu:w,connectionState:_,agentState:x,transcript:v,canResume:C,needsUserGesture:E,error:N,isMuted:k,micError:S,micDevices:$,activeMicId:z,isCameraEnabled:O,cameraPreviewEl:H,cameraDevices:T,activeCameraId:W,isScreenShareEnabled:D,screenPreviewEl:F,isSpeakerMuted:oe,allowCamera:ie,allowScreenShare:fe,allowTyping:ce,showMinimize:pe=!0,showClose:we=!0,chromeless:Ae=!1,compactControls:Q=!1,transforming:it,transformingLabel:qe,avatarVideoContainerRef:st,agentVideoEl:ne,onConnect:Fe,onDisconnect:Ue,onRetry:at,onResumeAudio:Ve,onToggleMute:_e,onSwitchMicDevice:Me,onToggleCamera:ke,onSwitchCameraDevice:Ie,onToggleScreenShare:je,onToggleSpeaker:Ce,onSendMessage:Le,onMinimize:A,onClose:lt,onClearMicError:vt})=>{var Ne;const Se=((l==null?void 0:l.length)??0)>1,Ee=_==="connecting"||_==="connected",Z=_==="connected",Ye=_==="idle"||_==="disconnected"||_==="error",[Ge,Te]=n.useState(!1);n.useEffect(()=>{if(!ne){Te(!1);return}if(!ne.paused&&ne.readyState>=2){Te(!0);return}Te(!1);const m=()=>Te(!0);return ne.addEventListener("playing",m),ne.addEventListener("loadeddata",m),()=>{ne.removeEventListener("playing",m),ne.removeEventListener("loadeddata",m)}},[ne]);const[Re,J]=n.useState(!1);n.useEffect(()=>{if(!Z){J(!1);return}if(Ge)return;const m=setTimeout(()=>J(!0),8e3);return()=>clearTimeout(m)},[Z,Ge]);const ct=_==="connecting"||Z&&!!i&&!Ge&&!Re,Ke=n.useRef(null),ee=n.useRef(null);n.useEffect(()=>{const m=Ke.current;m&&(m.innerHTML="",H&&(H.style.width="100%",H.style.height="100%",H.style.objectFit="cover",H.style.transform="scaleX(-1)",m.appendChild(H)))},[H]),n.useEffect(()=>{const m=ee.current;m&&(m.innerHTML="",F&&(F.style.width="100%",F.style.height="100%",F.style.objectFit="contain",m.appendChild(F)))},[F]);const[te,se]=n.useState(!1),[he,Y]=n.useState(!1),ae=n.useRef(null),me=n.useRef(null);n.useEffect(()=>{if(!te&&!he&&!L&&!y)return;const m=()=>{se(!1),Y(!1),L&&w(),y&&p()};return document.addEventListener("click",m),()=>document.removeEventListener("click",m)},[te,he,L,y,w,p]);const[De,xt]=n.useState(!1),Je=n.useCallback(()=>xt(m=>!m),[]),[ge,Xe]=n.useState(""),Qe=n.useCallback(m=>{m.preventDefault();const U=ge.trim();U&&(Le(U),Xe(""))},[ge,Le]),Ze=d.productName||"Live Layer";let ye=null,ve=null;for(let m=v.length-1;m>=0;m--){const U=v[m];if(!ye&&U.role==="agent"?ye=U:!ve&&U.role==="user"&&(ve=U),ye&&ve)break}const Pe=Z?(ye==null?void 0:ye.text)||null:a||null,ut=Z&&(ve==null?void 0:ve.text)||null,$e=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:$e,"data-position":e,"data-state":Z?"connected":Ee?"connecting":"idle",role:"dialog","aria-label":`${o} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[i?t.jsx(xr,{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:((Ne=o==null?void 0:o.charAt(0))==null?void 0:Ne.toUpperCase())||"A"})}),s&&!Z&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:st,className:"ll-expanded__video"}),ct&&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:f?"Switching...":"Connecting..."})]}),E&&Z&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:Ve,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"})]}),it&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":qe,children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:qe})]}),Ee?t.jsxs(t.Fragment,{children:[!Q&&t.jsxs("div",{className:"ll-expanded__topbar",children:[!Ae&&t.jsxs("div",{className:"ll-expanded__topbar-left",children:[t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill",onClick:m=>{Se&&(m.stopPropagation(),p())},"aria-haspopup":Se?"listbox":void 0,"aria-expanded":Se?y:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:o}),Se&&t.jsx(ft,{})]}),Se&&y&&t.jsx("div",{className:"ll-hmenu",onClick:m=>m.stopPropagation(),role:"listbox",children:l==null?void 0:l.map(m=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${m.id===u?"is-active":""}`,onClick:()=>c(m.id),role:"option","aria-selected":m.id===u,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(),w()},"aria-haspopup":"listbox","aria-expanded":L,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(ft,{})]}),L&&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:[pe!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn",onClick:A,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(nn,{})}),we!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:lt,"aria-label":"End call",title:"End call",children:t.jsx(tn,{})})]})]}),Q&&t.jsxs("div",{className:"ll-compact-status","data-state":x,children:[t.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),t.jsx("span",{className:"ll-compact-status__label",children:x})]})]}):!Q&&t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:Ze}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[pe!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:A,"aria-label":"Minimize widget",children:t.jsx(nn,{})}),we!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:lt,"aria-label":"Close widget",children:t.jsx(tn,{})})]})]}),Ye&&(()=>{const m=C?"Resume session":_==="disconnected"?"Reconnect to agent":"Start video call",U=!N;return t.jsxs(t.Fragment,{children:[U&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:Fe,"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"})})}),Q&&t.jsx("span",{className:"ll-expanded__play-label",children:m})]}),!Q&&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})}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:Fe,"aria-label":m,children:m})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${Ee&&(O||D)?"is-visible":""}`,children:[t.jsx("div",{ref:ee,className:D?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:Ke,className:!D&&O?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Ee?t.jsxs("div",{className:"ll-expanded__bottom",children:[!Q&&Pe&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Pe})}),!Q&&ut&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:ut})}),!Ae&&!Q&&t.jsxs("div",{className:"ll-toolbar",onClick:m=>m.stopPropagation(),children:[fe&&t.jsx("button",{type:"button",className:`ll-tool ${D?"is-on":""}`,onClick:je,"aria-label":D?"Stop sharing screen":"Share screen",title:D?"Stop sharing":"Share screen",children:t.jsx(Cn,{})}),ie&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${O?"is-on":""}`,onClick:ke,"aria-label":O?"Turn off camera":"Turn on camera",title:O?"Stop camera":"Start camera",children:t.jsx(Ln,{})}),t.jsx("button",{ref:me,type:"button",className:`ll-tool ll-tool--right ${O?"is-on":""}`,onClick:m=>{m.stopPropagation(),Y(U=>!U),se(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":he,children:t.jsx(ft,{})}),he&&T.length>0&&t.jsx(rn,{label:"Camera",devices:T,activeId:W,anchorRef:me,onPick:m=>{Y(!1),Ie(m)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${k?"is-muted":""}`,onClick:_e,"aria-label":k?"Unmute microphone":"Mute microphone",title:k?"Unmute":"Mute",children:t.jsx(Sn,{muted:k})}),t.jsx("button",{ref:ae,type:"button",className:`ll-tool ll-tool--right ${k?"is-muted":""}`,onClick:m=>{m.stopPropagation(),se(U=>!U),Y(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":te,children:t.jsx(ft,{})}),te&&$.length>0&&t.jsx(rn,{label:"Microphone",devices:$,activeId:z,anchorRef:ae,onPick:m=>{se(!1),Me(m)}})]}),t.jsx("button",{type:"button",className:`ll-tool ${oe?"is-muted":""}`,onClick:Ce,"aria-label":oe?"Unmute speaker":"Mute speaker",title:oe?"Unmute speaker":"Mute speaker",children:t.jsx(En,{muted:oe})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:Ue,"aria-label":"End conversation",title:"End conversation",children:t.jsx(Rn,{})})]}),!Ae&&Q&&t.jsx(_r,{isMuted:k,onToggleMute:_e,isCameraEnabled:O,onToggleCamera:ke,allowCamera:ie,isScreenShareEnabled:D,onToggleScreenShare:je,allowScreenShare:fe,isSpeakerMuted:oe,onToggleSpeaker:Ce,allowTyping:ce,isTypingOpen:De,onToggleTyping:Je,onDisconnect:Ue}),!Ae&&ce&&(Q?De:!0)&&t.jsxs("form",{className:"ll-message-input",onSubmit:Qe,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:ge,onChange:m=>Xe(m.target.value),"aria-label":"Message the agent"}),ge.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(Lr,{})})]})]}):null,(()=>{if(S&&_!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:S}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:vt,"aria-label":"Dismiss",children:"×"})]});if(!N||_!=="error")return null;let m="Failed to connect",U="Try again";return N==="MIC_PERMISSION_DENIED"?m="Microphone blocked. Allow access to talk.":N==="MIC_NOT_FOUND"?m="No microphone found. Plug one in + retry.":N==="MIC_UNAVAILABLE"?m="Mic unavailable. Check other apps using it.":N==="AGENT_TIMEOUT"?m="Agent didn't pick up. Try again.":N==="CONNECT_FAILED"?m="Connection failed. Check your network.":N.length<80&&(m=N),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:at,children:U})]})})()]})};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 tn(){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 nn(){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 Cn(){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 Ln(){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 Sn({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 En({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 Lr(){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 Rn(){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 rn=({label:e,devices:r,activeId:o,onPick:i,anchorRef:s})=>{const[a,d]=n.useState(null);return n.useLayoutEffect(()=>{const l=()=>{const u=s.current;if(!u)return;const f=u.getBoundingClientRect(),y=126,p=window.innerWidth-16-110,c=f.left+f.width/2;d({top:f.top-8,left:Math.max(y,Math.min(p,c))})};return l(),window.addEventListener("scroll",l,!0),window.addEventListener("resize",l),()=>{window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[s]),a===null||typeof document>"u"?null:Lt.createPortal(t.jsxs("div",{className:"ll-device-menu ll-device-menu--floating",onClick:l=>l.stopPropagation(),role:"listbox",style:{position:"fixed",top:a.top,left:a.left,transform:"translate(-50%, -100%)"},children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),r.map((l,u)=>{const f=o===l.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${f?"is-active":""}`,onClick:()=>i(l.deviceId),role:"option","aria-selected":f,children:[f&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:l.label||`${e} ${u+1}`})]},l.deviceId||u)})]}),document.body)},Sr=['[data-ll-private="true"]',".ll-widget"];function St(e){let r=e;for(;r;){for(const o of Sr)if(r.matches(o))return!0;r=r.parentElement}return!1}function yt(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,Er=20,Rr=20,Nr=10,Ar=10,Mr=30,Ir=20,on=500,Tr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function rt(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let r=e;for(;r;){for(const o of Tr)if(r.matches(o))return!0;r=r.parentElement}return!1}function ot(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 sn(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 de(e,r){return e.length<=r?e:e.slice(0,r-1)+"…"}function He(e){return e.length}function Nn(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]")),l=[];for(const k of d){if(l.length>=Nr)break;if(rt(k)||!ot(k))continue;const S=k.getAttribute("data-ll-region")??"",$=k.getAttribute("data-ll-intent")??void 0,z=de((k.innerText||k.textContent||"").trim(),on*2);!S||!z||l.push({id:S,intent:$,text:z})}const u=[],f=["H1","H2","H3","H4","H5","H6"],y=Array.from(o.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const k of y){if(rt(k)||!ot(k))continue;const S=(k.textContent||"").trim();S&&u.push(`${k.tagName}: ${de(S,200)}`)}const p=Array.from(o.querySelectorAll("p, li"));for(const k of p){if(rt(k)||!ot(k)||f.includes(k.tagName))continue;const S=(k.textContent||"").trim();S.length>10&&u.push(de(S,on))}const c=u.join(`
2
- `),L=[],w=Array.from(o.querySelectorAll("a[href]"));for(const k of w){if(L.length>=Er)break;if(rt(k)||!ot(k))continue;const S=k.getAttribute("href")||"",$=(k.textContent||"").trim();!S||!$||L.push({href:S,text:de($,100)})}const _=[],x=Array.from(o.querySelectorAll("input, textarea, select"));for(const k of x){if(_.length>=Rr)break;if(rt(k)||!yt(k)||!ot(k))continue;const S=sn(k),$=k instanceof HTMLInputElement?k.type:k.tagName.toLowerCase();S&&_.push({label:de(S,100),type:$})}const v=Array.from(o.querySelectorAll("[data-ll-form]")),C=[];for(const k of v){if(C.length>=Ar)break;if(St(k))continue;const S=k.getAttribute("data-ll-form")||"";if(!S)continue;const $=k.getAttribute("data-ll-intent")||void 0,z=Array.from(k.querySelectorAll("[data-ll-field]")),O=[];for(const H of z){if(O.length>=Mr)break;if(!yt(H))continue;const T=H.getAttribute("data-ll-field")||"";if(!T)continue;const W=sn(H)||T,D=H instanceof HTMLInputElement?H.type:H.tagName.toLowerCase(),F={name:T,label:de(W,100),type:D};if(H.required===!0&&(F.required=!0),H instanceof HTMLSelectElement){const ie=[];for(let fe=0;fe<H.options.length&&!(ie.length>=Ir);fe++){const ce=H.options[fe];if(!ce||ce.disabled)continue;const pe=ce.value||"",we=(ce.textContent||"").trim()||pe;!pe&&!we||ie.push({value:pe,label:de(we,60)})}ie.length>0&&(F.options=ie)}const oe=typeof H.validationMessage=="string"?H.validationMessage:"";oe&&(F.validationMessage=de(oe,200)),O.push(F)}C.push({id:S,intent:$,fields:O})}const E={url:i,title:a,pathname:s,regions:l,visibleText:c,visibleLinks:L,visibleFields:_,forms:C,extras:e};let N=He(JSON.stringify(E.regions))+He(E.visibleText)+He(JSON.stringify(E.visibleLinks))+He(JSON.stringify(E.visibleFields));for(;N>pt&&E.visibleFields.length>0;)E.visibleFields.pop(),N=He(JSON.stringify(E.visibleFields));for(;N>pt&&E.visibleLinks.length>0;)E.visibleLinks.pop(),N-=80;return He(E.visibleText)>pt&&(E.visibleText=de(E.visibleText,pt-100)),E}let We=null;function Ct(e,r={}){const o=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(We&&We.key===s&&o-We.at<1e3)return We.ctx;const a=Nn(e,r);return We={key:s,at:o,ctx:a},a}function An(){We=null}const Dr=200;function Mn(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 Pr(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function In(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>=Dr)break;if(St(d))continue;const l=d.getAttribute("href")||"";if(!Pr(l))continue;let u=l,f=!0;try{if(typeof window<"u"){const p=new URL(l,o);f=p.origin===o,f&&l.startsWith("http")&&(u=p.pathname+p.search+p.hash)}}catch{continue}if(i.has(u))continue;i.add(u);const y=(d.textContent||"").trim().slice(0,120);s.push({href:u,text:y,internal:f})}return s}let Be=null;const $r=5e3;function ht(){const e=Date.now(),r=typeof window<"u"&&window.location.pathname||"/";if(Be&&Be.pathname===r&&e-Be.at<$r)return Be.routes;const o=In();return Be={at:e,pathname:r,routes:o},o}function Tn(){Be=null}function zr(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 Or(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,l=r==="true"||r==="1"||r==="on";d?d.call(e,l):e.checked=l,i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}zr(e,r),i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function Hr(){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 Wr(e){if(!(e instanceof HTMLElement))return!1;const o=window.getComputedStyle(e).overflowY;return!(o!=="auto"&&o!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function Br(){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(!Wr(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 qr(){if(typeof window>"u")return null;if(Hr())return window;const e=Br();return e||window}function an(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function Fr(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 Ur=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"]),Dn=n.forwardRef(function(r,o){var zt,Ot,Ht,Wt,Bt,qt,Ft;const{agentId:i,apiKey:s,baseUrl:a="https://app.livelayer.studio",sessionEndpoint:d,sessionBody:l,soundEffects:u,experienceMode:f="WIDGET",autoConnect:y=!1,displayMode:p,defaultDisplayMode:c="expanded",onDisplayModeChange:L,position:w="bottom-right",mobileBreakpoint:_=640,persistKey:x="ll-widget",disablePersistence:v=!1,teamMembers:C,currentTeamMemberId:E,onTeamMemberChange:N,idleLoopUrl:k,greeting:S,avatarImageUrl:$,agentName:z,branding:O={},allowCamera:H=!0,allowScreenShare:T=!0,allowTyping:W=!0,showMinimize:D=!0,showClose:F=!0,chromeless:oe=!1,floatingChromeContainer:ie=null,compactControls:fe=!1,transforming:ce=!1,transformingLabel:pe="Transforming…",showOn:we,hideOn:Ae,pathname:Q,onNavigate:it,onScrollToSelector:qe,getPageContext:st,pageContextExtras:ne,getRoutes:Fe,onScrollPage:Ue,onClick:at,capabilities:Ve,onConnect:_e,onDisconnect:Me,onTranscript:ke,onAgentState:Ie,onConnectionStateChange:je,onAgentEvent:Ce,onAgentCommand:Le,controlledSession:A,className:lt,style:vt,zIndex:Se=2147483647}=r,Ee=bn(Q),Z=kn(Ee,we,Ae);n.useEffect(()=>{An(),Tn()},[Ee]);const Ye=E!==void 0,[Ge,Te]=n.useState(()=>{var g;return E??((g=C==null?void 0:C[0])==null?void 0:g.id)}),Re=Ye?E:Ge,J=n.useMemo(()=>(C==null?void 0:C.find(g=>g.id===Re))??null,[C,Re]),ct=(J==null?void 0:J.agentId)??i,Ke=f==="EMBEDDED",[ee,te]=vn({value:p,defaultValue:c,onChange:L,persistKey:x,disablePersistence:Ke||v}),se=xn(_),he=dn(),Y=fn(),ae=pn(),me=hn(),De=mn(),[xt,Je]=n.useState(!1),[ge,Xe]=n.useState(!1),[Qe,Ze]=n.useState(!1),[ye,ve]=n.useState(!1),[Pe,ut]=n.useState(!1),$e=ur({baseUrl:a,config:u}),Ne=n.useRef($e);Ne.current=$e;const m=n.useRef(it),U=n.useRef(qe),bt=n.useRef(Ue),wt=n.useRef(at),Et=n.useRef(st),Rt=n.useRef(ne),Nt=n.useRef(Fe),_t=n.useRef(Ve),le=n.useRef(null);m.current=it,U.current=qe,bt.current=Ue,wt.current=at,Et.current=st,Rt.current=ne,Nt.current=Fe,_t.current=Ve;function xe(g){const h=_t.current;return h?h.includes(g):!0}function be(g,h){console.warn(`[LiveLayer] Agent command "${g}" blocked — capability "${h}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const et=n.useCallback(g=>{var V,re,ue,nt;const h=g;if(!(!h.type||typeof h.type!="string")){if(Ce==null||Ce({eventName:h.type,data:g}),h.type==="navigate"){if(!xe("navigate")){be("navigate","navigate");return}const j=typeof h.href=="string"?h.href:null;if(!j){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(Ne.current.playPageChange(),m.current){try{m.current(j)}catch(R){console.warn(`[LiveLayer] onNavigate threw for "${j}". Falling back. Error:`,R)}return}if(typeof document<"u"){const R=document.querySelector(`a[href="${j.replace(/"/g,'\\"')}"]`);if(R){R.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",j),window.dispatchEvent(new PopStateEvent("popstate"))}catch(R){console.warn(`[LiveLayer] history.pushState fallback failed for "${j}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,R)}return}if(h.type==="scroll_to"){if(!xe("scroll")){be("scroll_to","scroll");return}const j=typeof h.selector=="string"?h.selector:null;if(!j)return;const R=h.behavior==="instant"?"instant":"smooth";if(U.current){try{U.current(j,R)}catch(P){console.warn("[LiveLayer] onScrollToSelector threw.",P)}return}if(typeof document<"u"){let P=null;try{P=document.querySelector(j)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${j}".`);return}if(!P){console.warn(`[LiveLayer] scroll_to: no element matched "${j}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}P.scrollIntoView({behavior:R,block:"start"})}return}if(h.type==="request_page_context"){if(!xe("read_page")){be("request_page_context","read_page");return}const j=typeof h.requestId=="string"?h.requestId:void 0,R=(V=le.current)==null?void 0:V.call(le),P=q=>{const M=R,K=M==null?void 0:M.localParticipant;if(K!=null&&K.publishData)try{const X=j?{...q,requestId:j}:q,Oe=new TextEncoder().encode(JSON.stringify(X));K.publishData(Oe,{reliable:!0})}catch(X){console.warn("[LiveLayer] publishData failed.",X)}},I=Rt.current,B=Et.current;try{if(B){const q=B(I);if(q instanceof Promise){P({type:"page_context_pending"}),q.then(M=>P({type:"page_context",context:M})).catch(M=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",M),P({type:"page_context",context:Ct(I)})});return}P({type:"page_context",context:q});return}P({type:"page_context",context:Ct(I)})}catch(q){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",q),P({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:I}})}return}if(h.type==="scroll_page"){if(!xe("scroll")){be("scroll_page","scroll");return}const j=h.direction;if(j!=="up"&&j!=="down"&&j!=="top"&&j!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(j)}". Expected up | down | top | bottom.`);return}const R=h.behavior==="instant"?"instant":"smooth";if(bt.current){try{bt.current(j,R)}catch(M){console.warn("[LiveLayer] onScrollPage threw.",M)}return}if(typeof window>"u")return;const P={behavior:R},I=qr(),B=M=>{I instanceof Window?I.scrollBy({top:M,...P}):I.scrollBy({top:M,...P})},q=M=>{I instanceof Window?I.scrollTo({top:M,...P}):I.scrollTo({top:M,...P})};j==="up"?B(-an(I)):j==="down"?B(an(I)):q(j==="top"?0:Fr(I));return}if(h.type==="click"){if(!xe("click")){be("click","click");return}const j=typeof h.selector=="string"?h.selector:null;if(!j){console.warn("[LiveLayer] click: missing selector.");return}if(wt.current){try{wt.current(j)}catch(P){console.warn("[LiveLayer] onClick threw.",P)}return}if(typeof document>"u")return;let R=null;try{R=document.querySelector(j)}catch{console.warn(`[LiveLayer] click: invalid selector "${j}".`);return}if(!R){console.warn(`[LiveLayer] click: no element matched "${j}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(re=R.click)==null||re.call(R);return}if(h.type==="fill_form"||h.type==="focus_field"){if(!xe("fill_forms")){be(h.type,"fill_forms");return}if(typeof document>"u")return;h.type==="fill_form"&&Ne.current.playConfirmation();const j=typeof h.formId=="string"?h.formId:null;if(!j){console.warn(`[LiveLayer] ${h.type}: missing formId.`);return}const R=document.querySelector(`[data-ll-form="${j.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] ${h.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`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn(`[LiveLayer] ${h.type}: refusing to touch a form in a private subtree.`);return}if(h.type==="focus_field"){const I=typeof h.fieldName=="string"?h.fieldName:null;if(!I){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const B=R.querySelector(`[data-ll-field="${I.replace(/"/g,'\\"')}"]`);if(!B){console.warn(`[LiveLayer] focus_field: no field "${I}" in form "${j}".`);return}if(!yt(B)){console.warn(`[LiveLayer] focus_field: field "${I}" is privacy-protected and not focusable.`);return}B.focus();return}const P=h.values&&typeof h.values=="object"?h.values:null;if(!P){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[I,B]of Object.entries(P)){if(typeof B!="string")continue;const q=R.querySelector(`[data-ll-field="${I.replace(/"/g,'\\"')}"]`);if(!q){console.warn(`[LiveLayer] fill_form: no field "${I}" in form "${j}". Skipping.`);continue}if(!yt(q)){console.warn(`[LiveLayer] fill_form: field "${I}" is privacy-protected (password / cc-* / private). Skipping.`);continue}try{Or(q,B)}catch(M){console.warn(`[LiveLayer] fill_form: failed to set "${I}".`,M)}}return}if(h.type==="submit_form"){if(!xe("submit_forms")){be("submit_form","submit_forms");return}if(typeof document>"u")return;const j=typeof h.formId=="string"?h.formId:null;if(!j){console.warn("[LiveLayer] submit_form: missing formId.");return}Ne.current.playConfirmation();const R=document.querySelector(`[data-ll-form="${j.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${j}".`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private subtree.");return}const P=typeof h.requestId=="string"?h.requestId:void 0,I=(ue=le.current)==null?void 0:ue.call(le),B=K=>{const X=I,Oe=X==null?void 0:X.localParticipant;if(Oe!=null&&Oe.publishData)try{const Kn=P?{...K,requestId:P}:K,Jn=new TextEncoder().encode(JSON.stringify(Kn));Oe.publishData(Jn,{reliable:!0})}catch{}};let q=!1;const M=()=>{q=!0,B({type:"form_submitted",formId:j})};R.addEventListener("submit",M,{once:!0});try{typeof R.requestSubmit=="function"?R.requestSubmit():R.submit()}catch(K){console.warn("[LiveLayer] submit_form: requestSubmit threw.",K),R.removeEventListener("submit",M),B({type:"form_submit_blocked",formId:j,reason:"exception"});return}setTimeout(()=>{q||(R.removeEventListener("submit",M),B({type:"form_submit_blocked",formId:j,reason:"validation"}))},500);return}if(h.type==="request_routes"){if(!xe("read_page")){be("request_routes","read_page");return}const j=typeof h.requestId=="string"?h.requestId:void 0,P=(nt=le.current)==null?void 0:nt.call(le),I=P==null?void 0:P.localParticipant;if(!(I!=null&&I.publishData))return;const B=M=>{try{const K=j?{type:"routes",routes:M,requestId:j}:{type:"routes",routes:M},X=new TextEncoder().encode(JSON.stringify(K));I.publishData(X,{reliable:!0})}catch(K){console.warn("[LiveLayer] request_routes: publishData failed.",K)}},q=Nt.current;if(q){try{const M=q(),K=X=>{if(!Array.isArray(X)){B([]);return}B(X.map(Mn).slice(0,200))};M instanceof Promise?M.then(K).catch(X=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",X),B(ht())}):K(M)}catch(M){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",M),B(ht())}return}try{B(ht())}catch(M){console.warn("[LiveLayer] request_routes: extractRoutes threw.",M)}return}Ur.has(h.type)||Le==null||Le(h)}},[Le,Ce]),G=un({agentId:A?"__controlled__":ct,baseUrl:a,apiKey:s,sessionEndpoint:d,sessionBody:l,onDataMessage:A?void 0:et});n.useEffect(()=>{if(A!=null&&A.subscribeToDataMessages)return A.subscribeToDataMessages(et)},[A,et]),le.current=()=>{var g;return(g=G.getRoom)==null?void 0:g.call(G)},n.useEffect(()=>{var V;if(typeof window>"u")return;const g=((V=window.location)==null?void 0:V.hostname)||"";if(g==="localhost"||g==="127.0.0.1"||g==="0.0.0.0"||g.endsWith(".local")||g.endsWith(".test"))return window.__livelayerSimulateCommand=re=>{try{et(re)}catch(ue){console.warn("[LiveLayer] simulate-command threw:",ue)}},()=>{delete window.__livelayerSimulateCommand}},[et]);const b=n.useMemo(()=>A?{connectionState:A.connectionState,agentState:A.agentState,transcript:A.transcript,videoElement:A.videoElement,audioElement:A.audioElement,canResume:A.canResume,error:A.error,agentConfig:null,connect:async()=>{await A.onConnect()},disconnect:()=>A.onDisconnect(),getRoom:G.getRoom,isControlled:!0}:{connectionState:G.connectionState,agentState:G.agentState,transcript:G.transcript,videoElement:G.videoElement,audioElement:G.audioElement,canResume:G.canResume,error:G.error,agentConfig:G.agentConfig,connect:G.connect,disconnect:G.disconnect,getRoom:G.getRoom,isControlled:!1},[A,G]),At=n.useRef(b);At.current=b;const Mt=n.useRef(A);Mt.current=A,n.useImperativeHandle(o,()=>({sendData:async g=>{var ue,nt;const h=Mt.current;if(h!=null&&h.publishData){try{await h.publishData(g)}catch(j){console.warn("[AvatarWidget] sendData (controlled) failed:",j)}return}const V=(nt=(ue=At.current)==null?void 0:ue.getRoom)==null?void 0:nt.call(ue),re=V==null?void 0:V.localParticipant;if(re!=null&&re.publishData)try{const j=new TextEncoder().encode(JSON.stringify(g));await re.publishData(j,{reliable:!0})}catch(j){console.warn("[AvatarWidget] sendData failed:",j)}}}),[]);const It=n.useRef(null);n.useEffect(()=>{const g=b.videoElement,h=It.current;if(!(!g||!h))return h.appendChild(g),()=>{g.parentNode===h&&h.removeChild(g)}},[b.videoElement]),n.useEffect(()=>{const g=b.audioElement;if(!g)return;he.attach(g);const h=g.play();return h&&typeof h.catch=="function"&&h.catch(V=>{(V==null?void 0:V.name)==="NotAllowedError"&&Je(!0)}),()=>{he.detach()}},[b.audioElement]),n.useEffect(()=>{if(b.isControlled||b.connectionState!=="connected")return;const g=b.getRoom();if(g)return Y.setupMic(g).catch(()=>{}),()=>{Y.teardownMic()}},[b.isControlled,b.connectionState]),n.useEffect(()=>{var h;if(b.connectionState!=="connected")return;const g=b.isControlled?(h=A==null?void 0:A.getRoom)==null?void 0:h.call(A):b.getRoom();if(g)return ae.attachRoom(g),me.attachRoom(g),b.isControlled&&Y.attachRoom(g),De.refresh(),()=>{ae.teardown(),me.teardown()}},[b.isControlled,b.connectionState,A]),n.useEffect(()=>{const g=b.audioElement;g&&(g.muted=Pe)},[b.audioElement,Pe]);const $n=n.useCallback(g=>{const h={type:"user_message",text:g};if(A!=null&&A.publishData){try{A.publishData(h)}catch{}return}const V=b.getRoom();if(V)try{const re=new TextEncoder().encode(JSON.stringify(h));V.localParticipant.publishData(re,{reliable:!0})}catch{}},[b,A]),zn=n.useCallback(()=>{ut(g=>!g)},[]);n.useEffect(()=>{je==null||je(b.connectionState),b.connectionState==="connected"?_e==null||_e():b.connectionState==="disconnected"&&(Me==null||Me())},[b.connectionState,_e,Me,je]),n.useEffect(()=>{ke==null||ke(b.transcript)},[b.transcript,ke]),n.useEffect(()=>{Ie==null||Ie(b.agentState)},[b.agentState,Ie]),n.useEffect(()=>{$e.setThinking(b.agentState==="thinking")},[b.agentState,$e]);const Tt=n.useRef(!1);n.useEffect(()=>{b.isControlled||!y||Tt.current||Z&&b.connectionState==="idle"&&(Tt.current=!0,b.connect())},[y,b.connectionState,b,Z]);const On=n.useCallback(g=>{const h=C==null?void 0:C.find(V=>V.id===g);h&&(Ze(!1),g!==Re&&(Xe(!0),b.disconnect(),Ye||Te(g),N==null||N(h)))},[C,Re,b,Ye,N]);n.useEffect(()=>{ge&&b.connectionState==="connected"&&Xe(!1)},[b.connectionState,ge]),n.useEffect(()=>{if(!Qe)return;const g=h=>{h.key==="Escape"&&Ze(!1)};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[Qe]);const Hn=!!$||!!(J!=null&&J.avatarImageUrl)||b.isControlled,tt=gn(ct,a,Hn);Ve===void 0&&((zt=tt.info)!=null&&zt.capabilities)&&(_t.current=tt.info.capabilities);const dt=(J==null?void 0:J.name)??z??((Ot=b.agentConfig)==null?void 0:Ot.name)??((Ht=tt.info)==null?void 0:Ht.name)??"Live Layer",kt=(J==null?void 0:J.avatarImageUrl)??$??((Wt=b.agentConfig)==null?void 0:Wt.avatarImageUrl)??((Bt=tt.info)==null?void 0:Bt.avatarImageUrl)??null,Wn=k??((qt=b.agentConfig)==null?void 0:qt.idleLoopUrl)??((Ft=tt.info)==null?void 0:Ft.idleLoopUrl)??null,Bn=S??null,qn=n.useCallback(()=>te("expanded"),[te]),Fn=n.useCallback(()=>te("minimized"),[te]),Dt=n.useCallback(()=>{b.disconnect(),te("hidden")},[b,te]),Un=n.useCallback(()=>{const g=b.audioElement;g&&g.play().then(()=>Je(!1)).catch(()=>{})},[b.audioElement]),Vn=n.useCallback(()=>{Je(!1),b.connect()},[b]),ze={...vt,...Ke?{}:{zIndex:Se}};O.primaryColor&&(ze["--ll-color-primary"]=O.primaryColor),O.accentColor&&(ze["--ll-color-accent"]=O.accentColor),O.backgroundColor&&(ze["--ll-color-bg"]=O.backgroundColor),O.textColor&&(ze["--ll-color-fg"]=O.textColor);const Yn=["ll-widget",`ll-widget--${ee}`,`ll-widget--${se?"mobile":"desktop"}`,lt].filter(Boolean).join(" ");if(!Z)return null;const Gn=t.jsx("div",{className:Yn,style:ze,"data-display-mode":ee,"data-position":w,"data-experience-mode":f==="EMBEDDED"?"embedded":"widget",children:ee==="expanded"&&t.jsx(Cr,{position:w,isMobile:se,agentName:dt,avatarImageUrl:kt,idleLoopUrl:Wn,greeting:Bn,branding:O,teamMembers:C,currentTeamMemberId:Re,isSwitchingTeamMember:ge,teamSwitcherOpen:Qe,onToggleTeamSwitcher:()=>Ze(g=>!g),onSelectTeamMember:On,connectionState:b.connectionState,agentState:b.agentState,transcript:b.transcript,isMuted:Y.isMuted,micDevices:De.mics,activeMicId:Y.activeDeviceId,isCameraEnabled:ae.isEnabled,cameraPreviewEl:ae.previewEl,cameraDevices:De.cameras,activeCameraId:ae.activeDeviceId,isScreenShareEnabled:me.isEnabled,screenPreviewEl:me.previewEl,isSpeakerMuted:Pe,allowCamera:H,allowScreenShare:T,allowTyping:W,showMinimize:D,showClose:F,chromeless:oe,compactControls:fe,transforming:ce,transformingLabel:pe,languageMenuOpen:ye,onToggleLanguageMenu:()=>ve(g=>!g),needsUserGesture:xt,canResume:b.canResume,micError:Y.micError,error:b.error,avatarVideoContainerRef:It,agentVideoEl:b.videoElement,onConnect:()=>void b.connect(),onDisconnect:()=>b.disconnect(),onRetry:Vn,onResumeAudio:Un,onToggleMute:Y.toggleMute,onSwitchMicDevice:g=>void Y.switchDevice(g),onToggleCamera:()=>void ae.toggle(),onSwitchCameraDevice:g=>void ae.switchDevice(g),onToggleScreenShare:()=>void me.toggle(),onToggleSpeaker:zn,onSendMessage:$n,onMinimize:Fn,onClose:Dt,onClearMicError:Y.clearError})}),Pt=ee==="hidden"||ee==="minimized"?t.jsxs("div",{className:["ll-widget","ll-widget--floating",`ll-widget--${ee}`,`ll-widget--${se?"mobile":"desktop"}`].join(" "),style:ze,"data-display-mode":ee,"data-position":w,children:[ee==="hidden"&&t.jsx(gr,{position:w,isMobile:se,isSpeaking:b.agentState==="speaking",onExpand:()=>te("expanded"),label:`Open ${dt} widget`,avatarImageUrl:kt,agentName:dt,containerEl:ie}),ee==="minimized"&&t.jsx(vr,{position:w,isMobile:se,agentName:dt,avatarImageUrl:kt,agentState:b.agentState,isMuted:Y.isMuted,audioLevel:he,onExpand:qn,onToggleMute:Y.toggleMute,onClose:Dt})]}):null,$t=ie??(typeof document<"u"?document.body:null);return t.jsxs(t.Fragment,{children:[Gn,Pt&&$t&&Lt.createPortal(Pt,$t)]})});Dn.displayName="AvatarWidgetInner";const Pn=n.forwardRef(function(r,o){return t.jsx(cn,{children:t.jsx(Dn,{...r,ref:o})})});Pn.displayName="AvatarWidget";const Vr=({agentId:e,baseUrl:r,apiKey:o,mode:i,onAgentEvent:s,className:a,style:d})=>{const l=n.useRef(null),u=n.useRef(null),f=n.useRef(s);f.current=s;const y=n.useCallback(p=>{var L;const c=p.detail;(L=f.current)==null||L.call(f,c)},[]);return n.useEffect(()=>{const p=l.current;if(!p)return;const c=document.createElement("livelayer-widget");return c.setAttribute("agent-id",e),r&&c.setAttribute("base-url",r),o&&c.setAttribute("api-key",o),i&&c.setAttribute("mode",i),c.addEventListener("agent-event",y),p.appendChild(c),u.current=c,()=>{c.removeEventListener("agent-event",y),p.removeChild(c),u.current=null}},[e]),n.useEffect(()=>{u.current&&(i?u.current.setAttribute("mode",i):u.current.removeAttribute("mode"))},[i]),t.jsx("div",{ref:l,className:a,style:d})},Yr=n.forwardRef(function({id:r,intent:o,as:i="div",className:s,style:a,children:d},l){return n.createElement(i,{ref:l,"data-ll-region":r,"data-ll-intent":o,className:s,style:a},d)}),Gr=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})}),Kr=n.forwardRef(function(r,o){const{name:i,label:s,labelClassName:a}=r,d={name:i,"data-ll-field":i};let l;if("as"in r&&r.as==="textarea"){const{name:u,label:f,labelClassName:y,as:p,...c}=r;l=t.jsx("textarea",{ref:o,...d,...c})}else if("as"in r&&r.as==="select"){const{name:u,label:f,labelClassName:y,as:p,children:c,...L}=r;l=t.jsx("select",{ref:o,...d,...L,children:c})}else{const{name:u,label:f,labelClassName:y,as:p,...c}=r;l=t.jsx("input",{ref:o,...d,...c})}return s===void 0?l:t.jsxs("label",{className:a,children:[s,l]})});let ln=1;function Jr({onMount:e,defaultOpen:r=!1,storageKey:o="ll-debug-open"}){const[i,s]=n.useState(r),[a,d]=n.useState([]),[l,u]=n.useState(""),[f,y]=n.useState(!1),p=n.useRef(new Set),c=n.useRef([]),L=n.useRef(f);L.current=f,n.useEffect(()=>{try{const x=localStorage.getItem(o);x==="1"&&s(!0),x==="0"&&s(!1)}catch{}},[o]),n.useEffect(()=>{try{localStorage.setItem(o,i?"1":"0")}catch{}},[i,o]),n.useEffect(()=>{const x=v=>{(v.metaKey||v.ctrlKey)&&v.shiftKey&&v.key.toLowerCase()==="l"&&(v.preventDefault(),s(C=>!C))};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[]),n.useEffect(()=>{const x=setInterval(()=>{if(c.current.length===0||L.current)return;const v=c.current.splice(0,c.current.length);d(C=>[...v.reverse(),...C].slice(0,200))},100);return()=>clearInterval(x)},[]);const w=n.useRef(!1);if(n.useEffect(()=>{!e||w.current||(w.current=!0,e(x=>{c.current.push({id:ln++,ts:Date.now(),kind:"event",type:x.eventName,data:x.data})}))},[e]),n.useEffect(()=>{const x=console.warn,v=console.log,C=(E,N)=>function(...k){try{const S=typeof k[0]=="string"?k[0]:"";S.startsWith("[LiveLayer]")&&c.current.push({id:ln++,ts:Date.now(),kind:E,type:S.slice(0,120),data:{args:k.slice(1).map($=>Qr($))}})}catch{}return N.apply(this,k)};return console.warn=C("warn",x),console.log=C("log",v),()=>{console.warn=x,console.log=v}},[]),!i)return t.jsx("button",{type:"button",onClick:()=>s(!0),title:"Open LiveLayer debug panel (Cmd/Ctrl + Shift + L)","aria-label":"Open LiveLayer debug panel",style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.18)",borderRadius:999,padding:"6px 10px",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",cursor:"pointer",boxShadow:"0 4px 12px rgba(0,0,0,0.35)",opacity:.85},children:"🛰 LL debug"});const _=a.filter(x=>{if(!l)return!0;const v=l.toLowerCase();return x.type.toLowerCase().includes(v)||JSON.stringify(x.data||{}).toLowerCase().includes(v)});return t.jsxs("div",{style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,width:380,maxHeight:"60vh",background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:12,boxShadow:"0 16px 48px rgba(0,0,0,0.5)",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"8px 10px",background:"rgba(255,255,255,0.04)",borderBottom:"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),t.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[a.length," event",a.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>y(x=>!x),style:jt(f?"#f59e0b":"transparent"),title:"Pause / resume capture",children:f?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{d([]),c.current=[]},style:jt("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:jt("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:l,onChange:x=>u(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:_.length===0?t.jsxs("div",{style:{padding:14,fontSize:11,color:"rgba(255,255,255,0.4)",lineHeight:1.5},children:["No events yet. Connect to the agent and trigger a tool call — the events will stream in here. You can also dispatch commands manually in DevTools:",t.jsx("pre",{style:{marginTop:6,background:"rgba(255,255,255,0.04)",padding:6,borderRadius:4,fontSize:10,whiteSpace:"pre-wrap"},children:`window.__livelayerSimulateCommand({
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),n=require("react"),Lt=require("react-dom"),Xn=require("@livelayer/sdk"),mt=require("livekit-client");class cn 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 un(e){const[r,o]=n.useState("idle"),[i,s]=n.useState("idle"),[a,d]=n.useState([]),[l,u]=n.useState(null),[f,y]=n.useState(null),[p,c]=n.useState(null),[L,_]=n.useState(!1),[w,v]=n.useState(null),x=n.useRef(null),C=n.useRef(e.onDataMessage);C.current=e.onDataMessage,n.useEffect(()=>{const S={onConnectionStateChange:z=>{o(z),z==="connected"&&v(null)},onAgentStateChange:s,onTranscript:z=>d([...z]),onAgentConfig:u,onAudioTrack:z=>c(z),onVideoTrack:z=>y(z),onVideoTrackRemoved:()=>y(null),onError:z=>v(z),onDataMessage:z=>{var O;(O=C.current)==null||O.call(C,z)},onResumabilityChange:_},$=new Xn.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},S);return x.current=$,o("idle"),s("idle"),d([]),u(null),y(null),c(null),_(!1),v(null),()=>{var z;(z=$.destroy)==null||z.call($),x.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=n.useCallback(async()=>{const S=x.current;if(S)try{await S.connect()}catch($){throw v($ instanceof Error?$.message:String($)),$}},[]),N=n.useCallback(()=>{const S=x.current;S&&S.disconnect()},[]),k=n.useCallback(()=>{var S;return((S=x.current)==null?void 0:S.getRoom())??null},[]);return{connectionState:r,agentState:i,transcript:a,agentConfig:l,videoElement:f,audioElement:p,canResume:L,error:w,connect:E,disconnect:N,getRoom:k,session:x.current}}function dn(){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 p=r.current;if(!p){i.current=null;return}(!a.current||a.current.length!==p.frequencyBinCount)&&(a.current=new Uint8Array(new ArrayBuffer(p.frequencyBinCount)));const c=a.current;p.getByteFrequencyData(c);let L=0;for(let w=0;w<c.length;w++)L+=c[w];const _=L/c.length/255;for(const w of s.current)try{w(_)}catch(v){console.error("[useAudioLevel] subscriber threw:",v)}i.current=requestAnimationFrame(d)},[]),l=n.useCallback(()=>{if(e.current||typeof window>"u"||typeof AudioContext>"u")return;const p=new AudioContext,c=p.createAnalyser();c.fftSize=64,c.connect(p.destination),e.current=p,r.current=c},[]),u=n.useCallback(p=>{if(l(),!(!e.current||!r.current)){if(o.current){try{o.current.disconnect()}catch{}o.current=null}try{const c=e.current.createMediaElementSource(p);c.connect(r.current),o.current=c}catch(c){console.warn("[useAudioLevel] createMediaElementSource failed:",c);return}i.current===null&&(i.current=requestAnimationFrame(d))}},[l,d]),f=n.useCallback(()=>{if(i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),o.current){try{o.current.disconnect()}catch{}o.current=null}},[]),y=n.useCallback(p=>(s.current.add(p),()=>{s.current.delete(p)}),[]);return n.useEffect(()=>()=>{if(f(),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},[f]),{attach:u,detach:f,subscribe:y}}function fn(){const[e,r]=n.useState(!1),[o,i]=n.useState(""),[s,a]=n.useState(null),d=n.useRef(null),l=n.useRef(null),u=n.useCallback(async _=>{var w,v;if(d.current&&l.current){try{await l.current.localParticipant.unpublishTrack(d.current)}catch{}d.current.stop(),d.current=null}l.current=_,a(null);try{const x=await mt.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await _.localParticipant.publishTrack(x),d.current=x,r(x.isMuted);const C=(v=(w=x.mediaStreamTrack)==null?void 0:w.getSettings)==null?void 0:v.call(w);C!=null&&C.deviceId&&i(C.deviceId)}catch(x){const C=x instanceof Error&&x.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw a(C),x}},[]),f=n.useCallback(_=>{l.current=_},[]),y=n.useCallback(async _=>{const w=l.current;if(w)try{await w.switchActiveDevice("audioinput",_),i(_)}catch(v){console.warn("[useMicrophoneState] switchDevice failed:",v)}},[]),p=n.useCallback(async()=>{const _=l.current,w=!e;if(r(w),!!_)try{await _.localParticipant.setMicrophoneEnabled(!w)}catch(v){console.warn("[useMicrophoneState] setMicrophoneEnabled failed:",v),r(!w)}},[e]),c=n.useCallback(()=>{const _=d.current,w=l.current;if(_&&w){try{w.localParticipant.unpublishTrack(_)}catch{}_.stop()}d.current=null,l.current=null,r(!1),i("")},[]),L=n.useCallback(()=>a(null),[]);return{isMuted:e,activeDeviceId:o,micError:s,toggleMute:p,setupMic:u,attachRoom:f,switchDevice:y,teardownMic:c,clearError:L}}const Qn={resolution:{width:640,height:480,frameRate:24}};function pn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),[d,l]=n.useState(""),u=n.useRef(null),f=n.useRef(null),y=n.useCallback(x=>{u.current=x},[]),p=n.useCallback(()=>{var E;const x=u.current,C=f.current;if(C&&x){const N=x.localParticipant.getTrackPublication(mt.Track.Source.Camera),S=(N==null?void 0:N.track)??C;try{x.localParticipant.unpublishTrack(S)}catch{}try{(E=S.stop)==null||E.call(S)}catch{}}f.current=null,a(null),r(!1)},[]),c=n.useCallback(async x=>{const C=u.current;if(C){i(null);try{const E={...Qn};x&&(E.deviceId=x);const N=await mt.createLocalVideoTrack(E);await C.localParticipant.publishTrack(N),f.current=N;const k=N.attach();a(k),r(!0),x&&l(x);try{C.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const N=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";i(N)}}},[]),L=n.useCallback(async()=>{e?p():await c(d||void 0)},[e,d,p,c]),_=n.useCallback(async x=>{p(),await c(x)},[p,c]),w=n.useCallback(()=>{p(),u.current=null,i(null),l("")},[p]),v=n.useCallback(()=>i(null),[]);return n.useEffect(()=>()=>{f.current&&f.current.stop()},[]),{isEnabled:e,error:o,previewEl:s,activeDeviceId:d,toggle:L,switchDevice:_,attachRoom:y,teardown:w,clearError:v}}function hn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),d=n.useRef(null),l=n.useCallback(c=>{d.current=c},[]),u=n.useCallback(()=>a(null),[]),f=n.useCallback(async()=>{const c=d.current;if(c){if(e){try{await c.localParticipant.setScreenShareEnabled(!1)}catch{}u(),r(!1);return}i(null);try{await c.localParticipant.setScreenShareEnabled(!0);let L=0;const _=()=>{const w=c.localParticipant.getTrackPublication(mt.Track.Source.ScreenShare);if(w!=null&&w.track){const v=w.track.attach();a(v),r(!0);try{c.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}L++<10?setTimeout(_,100):r(!0)};_()}catch(L){const _=L instanceof Error?L.name:"";_!=="NotAllowedError"&&_!=="AbortError"&&i("Screen share unavailable. Try again."),r(!1)}}},[e,u]),y=n.useCallback(()=>{const c=d.current;if(c&&e)try{c.localParticipant.setScreenShareEnabled(!1)}catch{}u(),r(!1),i(null),d.current=null},[e,u]),p=n.useCallback(()=>i(null),[]);return{isEnabled:e,error:o,previewEl:s,toggle:f,attachRoom:l,teardown:y,clearError:p}}function mn(){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 gn(e,r,o=!1){const[i,s]=n.useState(null),[a,d]=n.useState(null),[l,u]=n.useState(!o&&!!e);return n.useEffect(()=>{if(o||!e){u(!1);return}const f=new AbortController,y=r||"https://app.livelayer.studio";return u(!0),d(null),fetch(`${y}/api/widget/agent/${encodeURIComponent(e)}`,{signal:f.signal}).then(async p=>{if(!p.ok){const c=await p.json().catch(()=>({}));throw new Error(c.error||`HTTP ${p.status}`)}return p.json()}).then(p=>{f.signal.aborted||(s(p),u(!1))}).catch(p=>{f.signal.aborted||(d(p instanceof Error?p.message:"Agent lookup failed"),u(!1))}),()=>f.abort()},[e,r,o]),{info:i,error:a,loading:l}}function Zn(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function er(e,r){if(!(typeof window>"u"))try{window.localStorage.setItem(e,r)}catch{}}function yn({value:e,defaultValue:r="expanded",onChange:o}={}){const i=e!==void 0,[s,a]=n.useState(r),d=i?e:s,l=n.useCallback(u=>{u!==d&&(i||a(u),o==null||o(u))},[d,i,o]);return[d,l]}const tr=["hidden","minimized","expanded"];function nr(e){return e&&tr.includes(e)?e:null}function vn({value:e,defaultValue:r="expanded",onChange:o,persistKey:i="ll-widget",disablePersistence:s=!1}={}){const a=`${i}:display-mode`,d=n.useRef(!1),[l,u]=yn({value:e,defaultValue:r,onChange:f=>{e===void 0&&!s&&er(a,f),o==null||o(f)}});return n.useEffect(()=>{if(d.current||(d.current=!0,s||e!==void 0))return;const f=nr(Zn(a));f&&f!==l&&u(f)},[]),[l,u]}const rr=640;function xn(e=rr){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 Ut="__llHistoryPatched",gt="ll:pathname";function or(){if(typeof window>"u"||window.history[Ut])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(gt)),i},window.history.replaceState=function(...o){const i=r.apply(this,o);return window.dispatchEvent(new Event(gt)),i},window.history[Ut]=!0}function Vt(){return typeof window>"u"?"/":window.location.pathname||"/"}function bn(e){const[r,o]=n.useState(()=>e??Vt());return n.useEffect(()=>{if(e!==void 0)return;or();const i=()=>o(Vt());return i(),window.addEventListener("popstate",i),window.addEventListener(gt,i),()=>{window.removeEventListener("popstate",i),window.removeEventListener(gt,i)}},[e]),e??r}const Yt=new Map,ir=/[\\^$+?.()|{}[\]]/g;function sr(e){return e.replace(ir,"\\$&")}function ar(e){const r=Yt.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),l=sr(a).replace(new RegExp(`\\/${i}`,"g"),"(?:\\/.*)?").replace(new RegExp(i,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),u=new RegExp(`^${l}\\/?$`);return Yt.set(e,u),u}function lr(e,r){const o=r.length>1&&r.endsWith("/")?r.slice(0,-1):r;return ar(e).test(o)}function wn(e,r){return typeof e=="function"?e(r):e instanceof RegExp?e.test(r):lr(e,r)}function Gt(e,r){if(!e||e.length===0)return!1;for(const o of e)if(wn(o,r))return!0;return!1}function _n(e,r,o){return e===void 0?!0:Gt(o,e)?!1:r&&r.length>0?Gt(r,e):!0}function kn(e,r,o){return n.useMemo(()=>_n(e,r,o),[e,r,o])}function cr(e){return e===!1?{navigate:!1,thinking:!1,action:!1}:e===void 0||e===!0?{navigate:!0,thinking:!0,action:!0}:{navigate:e.navigate!==!1,thinking:e.thinking!==!1,action:e.action!==!1}}function ur(e){const r=n.useMemo(()=>cr(e.config),[e.config]),o=e.baseUrl.replace(/\/+$/,""),i=n.useRef(null),s=n.useCallback(u=>{try{new Audio(`${o}${u}`).play().catch(()=>{})}catch{}},[o]),a=n.useCallback(()=>{r.navigate&&s("/audio/page-change-sound.mp3")},[r.navigate,s]),d=n.useCallback(()=>{r.action&&s("/audio/confirmation-sound.mp3")},[r.action,s]),l=n.useCallback(u=>{if(!r.thinking){if(i.current){try{i.current.pause()}catch{}i.current=null}return}if(u){if(i.current)return;try{const f=new Audio(`${o}/audio/thinking-sound.mp3`);f.loop=!0,f.volume=.3,f.play().catch(()=>{i.current=null}),i.current=f}catch{}}else if(i.current){try{i.current.pause()}catch{}i.current=null}},[o,r.thinking]);return n.useEffect(()=>()=>{if(i.current){try{i.current.pause()}catch{}i.current=null}},[]),n.useMemo(()=>({playPageChange:a,playConfirmation:d,setThinking:l}),[a,d,l])}const Kt=({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"})}),Jt=({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"})}),dr=({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"})}),fr={left:180,right:0,up:-90,down:90},Xt=({direction:e="right",className:r})=>t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${fr[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function pr(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const jn="ll-hidden-tab-center-y",hr=5,Qt=16;function mr(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(jn);if(!e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null}catch{return null}}function Zt(e){if(!(typeof window>"u"))try{window.localStorage.setItem(jn,String(e))}catch{}}const gr=({position:e,isMobile:r,isSpeaking:o,onExpand:i,label:s="Open widget",avatarImageUrl:a,agentName:d,containerEl:l})=>{const u=pr(e),f=u==="right"?"left":"right",y=r?80:72,p=!!a,c=!!l,[L,_]=n.useState(null),[w,v]=n.useState(!1),x=n.useRef(null),C=n.useRef(!1),E=n.useCallback(T=>{if(typeof window>"u")return T;const W=y/2,D=Qt+W,F=window.innerHeight-Qt-W;return F<D?Math.max(D,T):Math.max(D,Math.min(F,T))},[y]);n.useEffect(()=>{if(c){_(null);return}const T=mr();_(E(T??window.innerHeight/2));const W=()=>{_(D=>D===null?null:E(D))};return window.addEventListener("resize",W),()=>window.removeEventListener("resize",W)},[E,c]);const N=n.useCallback(T=>{if(!c&&!(T.pointerType==="mouse"&&T.button!==0)&&L!==null){try{T.currentTarget.setPointerCapture(T.pointerId)}catch{}x.current={startClientY:T.clientY,startCenterY:L,moved:!1}}},[L,c]),k=n.useCallback(T=>{const W=x.current;if(!W)return;const D=T.clientY-W.startClientY;!W.moved&&Math.abs(D)>hr&&(W.moved=!0,v(!0)),W.moved&&_(E(W.startCenterY+D))},[E]),S=n.useCallback(T=>{const W=x.current;if(W){try{T.currentTarget.releasePointerCapture(T.pointerId)}catch{}x.current=null,W.moved&&(v(!1),C.current=!0,_(D=>(D!==null&&Zt(D),D)))}},[]),$=n.useCallback(()=>{if(C.current){C.current=!1;return}i()},[i]),z=n.useCallback(T=>{if(T.key==="ArrowUp"||T.key==="ArrowDown"){T.preventDefault();const W=T.key==="ArrowUp"?-8:8;_(D=>{if(D===null)return D;const F=E(D+W);return Zt(F),F})}},[E]),O=["ll-hidden",`ll-hidden--${u}`,r?"ll-hidden--mobile":"ll-hidden--desktop",o?"ll-hidden--speaking":null,w?"is-dragging":null,p?"ll-hidden--with-avatar":null,c?"ll-hidden--scoped":null].filter(Boolean).join(" "),H=L===null?void 0:{top:`${L-y/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:O,onPointerDown:N,onPointerMove:k,onPointerUp:S,onPointerCancel:S,onClick:$,onKeyDown:z,"aria-label":s,"data-position":e,style:H,children:p?t.jsxs(t.Fragment,{children:[t.jsx(Xt,{direction:f,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:a,alt:d?`${d} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Xt,{direction:f,className:"ll-hidden__chevron"})})},yr=({audioLevel:e,bars:r=20,maxHeight:o=20,minHeight:i=4,className:s,barClassName:a})=>{const d=n.useRef(null),l=n.useRef([]),u=n.useMemo(()=>{const y=(Math.sqrt(5)-1)/2;return Array.from({length:r},(p,c)=>.5+c*y%1*.5)},[r]);n.useEffect(()=>e.subscribe(p=>{for(let c=0;c<r;c++){const L=l.current[c];if(!L)continue;const _=Math.max(i,p*o*u[c]);L.style.height=`${_}px`}}),[e,r,o,i,u]);const f=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:d,className:f,"aria-hidden":"true",children:Array.from({length:r},(y,p)=>t.jsx("div",{ref:c=>{l.current[p]=c},className:["ll-waveform__bar",a].filter(Boolean).join(" "),style:{height:`${i}px`}},p))})},vr=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,agentState:s,isMuted:a,audioLevel:d,onExpand:l,onToggleMute:u,onClose:f})=>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:l,"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(yr,{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:y=>{y.stopPropagation(),u()},onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.stopPropagation(),y.preventDefault(),u())},"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(Kt,{muted:a,className:"ll-minimized__icon"})}),t.jsx(Jt,{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:u,"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(Kt,{muted:a,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:l,"aria-label":`Expand ${o} widget`,children:t.jsx(Jt,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:f,"aria-label":"Close widget",children:t.jsx(dr,{className:"ll-minimized__icon"})})]})]})}),xr=({src:e,alt:r,preCannedPlaying:o=!1,className:i,style:s})=>{const[a,d]=n.useState(!1),l=n.useRef(e);if(n.useEffect(()=>{l.current!==e&&(l.current=e,d(!1))},[e]),!e)return null;const u={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:o?"scale(1.02)":"scale(1)",opacity:a?1:0,...s};return t.jsx("img",{src:e,alt:r,className:i,style:u,loading:"eager",fetchPriority:"high",onLoad:()=>d(!0)})},br=8,en=8,wr=({open:e,onClose:r,anchorRef:o,children:i})=>{const s=n.useRef(null),[a,d]=n.useState(null);return n.useLayoutEffect(()=>{if(!e){d(null);return}const l=o.current;if(!l)return;const u=()=>{const f=l.getBoundingClientRect(),y={top:f.top-br,left:f.left+f.width/2},p=en+90,c=window.innerWidth-en-90;y.left<p&&(y.left=p),y.left>c&&(y.left=c),d(y)};return u(),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[e,o]),n.useEffect(()=>{if(!e)return;const l=f=>{const y=f.target,p=s.current,c=o.current;p&&p.contains(y)||c&&c.contains(y)||r()},u=f=>{f.key==="Escape"&&(f.stopPropagation(),r())};return document.addEventListener("mousedown",l),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",u)}},[e,r,o]),!e||a===null||typeof document>"u"?null:Lt.createPortal(t.jsx("div",{ref:s,className:"ll-overflow-popover",role:"menu",style:{position:"fixed",top:a.top,left:a.left,transform:"translate(-50%, -100%)"},children:i}),document.body)},_r=({isMuted:e,onToggleMute:r,isCameraEnabled:o,onToggleCamera:i,allowCamera:s,isScreenShareEnabled:a,onToggleScreenShare:d,allowScreenShare:l,isSpeakerMuted:u,onToggleSpeaker:f,allowTyping:y,isTypingOpen:p,onToggleTyping:c,onDisconnect:L})=>{const[_,w]=n.useState(!1),v=n.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:x=>x.stopPropagation(),children:[t.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:r,"aria-label":e?"Unmute microphone":"Mute microphone",children:t.jsx(Sn,{muted:e})}),t.jsx("button",{ref:v,type:"button",className:`ll-tool ${_?"is-on":""}`,onClick:()=>w(x=>!x),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":_,children:t.jsx(kr,{})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:L,"aria-label":"End conversation",children:t.jsx(Rn,{})})]}),t.jsxs(wr,{open:_,onClose:()=>w(!1),anchorRef:v,children:[s&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${o?"is-on":""}`,onClick:()=>{i(),w(!1)},children:[t.jsx(Ln,{}),t.jsx("span",{children:o?"Stop camera":"Start camera"})]}),l&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${a?"is-on":""}`,onClick:()=>{d(),w(!1)},children:[t.jsx(Cn,{}),t.jsx("span",{children:a?"Stop sharing":"Share screen"})]}),t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${u?"is-on":""}`,onClick:()=>{f(),w(!1)},children:[t.jsx(En,{muted:u}),t.jsx("span",{children:u?"Unmute speaker":"Mute speaker"})]}),y&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${p?"is-on":""}`,onClick:()=>{c(),w(!1)},children:[t.jsx(jr,{}),t.jsx("span",{children:p?"Hide typing":"Type a message"})]}),t.jsxs("button",{type:"button",className:"ll-overflow-popover__item is-active",disabled:!0,"aria-current":"true",children:[t.jsx("span",{className:"ll-overflow-popover__lang-code",children:"EN"}),t.jsx("span",{children:"English"})]})]})]})};function kr(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[t.jsx("circle",{cx:"6",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"18",cy:"12",r:"1.5"})]})}function jr(){return t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}const Cr=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,idleLoopUrl:s,greeting:a,branding:d,teamMembers:l,currentTeamMemberId:u,isSwitchingTeamMember:f,teamSwitcherOpen:y,onToggleTeamSwitcher:p,onSelectTeamMember:c,languageMenuOpen:L,onToggleLanguageMenu:_,connectionState:w,agentState:v,transcript:x,canResume:C,needsUserGesture:E,error:N,isMuted:k,micError:S,micDevices:$,activeMicId:z,isCameraEnabled:O,cameraPreviewEl:H,cameraDevices:T,activeCameraId:W,isScreenShareEnabled:D,screenPreviewEl:F,isSpeakerMuted:oe,allowCamera:ie,allowScreenShare:fe,allowTyping:ce,showMinimize:pe=!0,showClose:we=!0,chromeless:Ae=!1,compactControls:Q=!1,transforming:it,transformingLabel:qe,avatarVideoContainerRef:st,agentVideoEl:ne,onConnect:Fe,onDisconnect:Ue,onRetry:at,onResumeAudio:Ve,onToggleMute:_e,onSwitchMicDevice:Me,onToggleCamera:ke,onSwitchCameraDevice:Ie,onToggleScreenShare:je,onToggleSpeaker:Ce,onSendMessage:Le,onMinimize:A,onClose:lt,onClearMicError:vt})=>{var Ne;const Se=((l==null?void 0:l.length)??0)>1,Ee=w==="connecting"||w==="connected",Z=w==="connected",Ye=w==="idle"||w==="disconnected"||w==="error",[Ge,Te]=n.useState(!1);n.useEffect(()=>{if(!ne){Te(!1);return}if(!ne.paused&&ne.readyState>=2){Te(!0);return}Te(!1);const m=()=>Te(!0);return ne.addEventListener("playing",m),ne.addEventListener("loadeddata",m),()=>{ne.removeEventListener("playing",m),ne.removeEventListener("loadeddata",m)}},[ne]);const[Re,J]=n.useState(!1);n.useEffect(()=>{if(!Z){J(!1);return}if(Ge)return;const m=setTimeout(()=>J(!0),8e3);return()=>clearTimeout(m)},[Z,Ge]);const ct=w==="connecting"||Z&&!!i&&!Ge&&!Re,Ke=n.useRef(null),ee=n.useRef(null);n.useEffect(()=>{const m=Ke.current;m&&(m.innerHTML="",H&&(H.style.width="100%",H.style.height="100%",H.style.objectFit="cover",H.style.transform="scaleX(-1)",m.appendChild(H)))},[H]),n.useEffect(()=>{const m=ee.current;m&&(m.innerHTML="",F&&(F.style.width="100%",F.style.height="100%",F.style.objectFit="contain",m.appendChild(F)))},[F]);const[te,se]=n.useState(!1),[he,Y]=n.useState(!1),ae=n.useRef(null),me=n.useRef(null);n.useEffect(()=>{if(!te&&!he&&!L&&!y)return;const m=()=>{se(!1),Y(!1),L&&_(),y&&p()};return document.addEventListener("click",m),()=>document.removeEventListener("click",m)},[te,he,L,y,_,p]);const[De,xt]=n.useState(!1),Je=n.useCallback(()=>xt(m=>!m),[]),[ge,Xe]=n.useState(""),Qe=n.useCallback(m=>{m.preventDefault();const U=ge.trim();U&&(Le(U),Xe(""))},[ge,Le]),Ze=d.productName||"Live Layer";let ye=null,ve=null;for(let m=x.length-1;m>=0;m--){const U=x[m];if(!ye&&U.role==="agent"?ye=U:!ve&&U.role==="user"&&(ve=U),ye&&ve)break}const Pe=Z?(ye==null?void 0:ye.text)||null:a||null,ut=Z&&(ve==null?void 0:ve.text)||null,$e=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:$e,"data-position":e,"data-state":Z?"connected":Ee?"connecting":"idle",role:"dialog","aria-label":`${o} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[i?t.jsx(xr,{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:((Ne=o==null?void 0:o.charAt(0))==null?void 0:Ne.toUpperCase())||"A"})}),s&&!Z&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:st,className:"ll-expanded__video"}),ct&&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:f?"Switching...":"Connecting..."})]}),E&&Z&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:Ve,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"})]}),it&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":qe,children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:qe})]}),Ee?t.jsxs(t.Fragment,{children:[!Q&&t.jsxs("div",{className:"ll-expanded__topbar",children:[!Ae&&t.jsxs("div",{className:"ll-expanded__topbar-left",children:[t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill",onClick:m=>{Se&&(m.stopPropagation(),p())},"aria-haspopup":Se?"listbox":void 0,"aria-expanded":Se?y:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:o}),Se&&t.jsx(ft,{})]}),Se&&y&&t.jsx("div",{className:"ll-hmenu",onClick:m=>m.stopPropagation(),role:"listbox",children:l==null?void 0:l.map(m=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${m.id===u?"is-active":""}`,onClick:()=>c(m.id),role:"option","aria-selected":m.id===u,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(),_()},"aria-haspopup":"listbox","aria-expanded":L,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(ft,{})]}),L&&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--${v}`,children:v})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[pe!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn",onClick:A,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(nn,{})}),we!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:lt,"aria-label":"End call",title:"End call",children:t.jsx(tn,{})})]})]}),Q&&t.jsxs("div",{className:"ll-compact-status","data-state":v,children:[t.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),t.jsx("span",{className:"ll-compact-status__label",children:v})]})]}):!Q&&t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:Ze}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[pe!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:A,"aria-label":"Minimize widget",children:t.jsx(nn,{})}),we!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:lt,"aria-label":"Close widget",children:t.jsx(tn,{})})]})]}),Ye&&(()=>{const m=C?"Resume session":w==="disconnected"?"Reconnect to agent":"Start video call",U=!N;return t.jsxs(t.Fragment,{children:[U&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:Fe,"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"})})}),Q&&t.jsx("span",{className:"ll-expanded__play-label",children:m})]}),!Q&&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})}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:Fe,"aria-label":m,children:m})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${Ee&&(O||D)?"is-visible":""}`,children:[t.jsx("div",{ref:ee,className:D?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:Ke,className:!D&&O?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Ee?t.jsxs("div",{className:"ll-expanded__bottom",children:[!Q&&Pe&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Pe})}),!Q&&ut&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:ut})}),!Ae&&!Q&&t.jsxs("div",{className:"ll-toolbar",onClick:m=>m.stopPropagation(),children:[fe&&t.jsx("button",{type:"button",className:`ll-tool ${D?"is-on":""}`,onClick:je,"aria-label":D?"Stop sharing screen":"Share screen",title:D?"Stop sharing":"Share screen",children:t.jsx(Cn,{})}),ie&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${O?"is-on":""}`,onClick:ke,"aria-label":O?"Turn off camera":"Turn on camera",title:O?"Stop camera":"Start camera",children:t.jsx(Ln,{})}),t.jsx("button",{ref:me,type:"button",className:`ll-tool ll-tool--right ${O?"is-on":""}`,onClick:m=>{m.stopPropagation(),Y(U=>!U),se(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":he,children:t.jsx(ft,{})}),he&&T.length>0&&t.jsx(rn,{label:"Camera",devices:T,activeId:W,anchorRef:me,onPick:m=>{Y(!1),Ie(m)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${k?"is-muted":""}`,onClick:_e,"aria-label":k?"Unmute microphone":"Mute microphone",title:k?"Unmute":"Mute",children:t.jsx(Sn,{muted:k})}),t.jsx("button",{ref:ae,type:"button",className:`ll-tool ll-tool--right ${k?"is-muted":""}`,onClick:m=>{m.stopPropagation(),se(U=>!U),Y(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":te,children:t.jsx(ft,{})}),te&&$.length>0&&t.jsx(rn,{label:"Microphone",devices:$,activeId:z,anchorRef:ae,onPick:m=>{se(!1),Me(m)}})]}),t.jsx("button",{type:"button",className:`ll-tool ${oe?"is-muted":""}`,onClick:Ce,"aria-label":oe?"Unmute speaker":"Mute speaker",title:oe?"Unmute speaker":"Mute speaker",children:t.jsx(En,{muted:oe})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:Ue,"aria-label":"End conversation",title:"End conversation",children:t.jsx(Rn,{})})]}),!Ae&&Q&&t.jsx(_r,{isMuted:k,onToggleMute:_e,isCameraEnabled:O,onToggleCamera:ke,allowCamera:ie,isScreenShareEnabled:D,onToggleScreenShare:je,allowScreenShare:fe,isSpeakerMuted:oe,onToggleSpeaker:Ce,allowTyping:ce,isTypingOpen:De,onToggleTyping:Je,onDisconnect:Ue}),!Ae&&ce&&(Q?De:!0)&&t.jsxs("form",{className:"ll-message-input",onSubmit:Qe,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:ge,onChange:m=>Xe(m.target.value),"aria-label":"Message the agent"}),ge.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(Lr,{})})]})]}):null,(()=>{if(S&&w!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:S}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:vt,"aria-label":"Dismiss",children:"×"})]});if(!N||w!=="error")return null;let m="Failed to connect",U="Try again";return N==="MIC_PERMISSION_DENIED"?m="Microphone blocked. Allow access to talk.":N==="MIC_NOT_FOUND"?m="No microphone found. Plug one in + retry.":N==="MIC_UNAVAILABLE"?m="Mic unavailable. Check other apps using it.":N==="AGENT_TIMEOUT"?m="Agent didn't pick up. Try again.":N==="CONNECT_FAILED"?m="Connection failed. Check your network.":N.length<80&&(m=N),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:at,children:U})]})})()]})};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 tn(){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 nn(){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 Cn(){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 Ln(){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 Sn({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 En({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 Lr(){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 Rn(){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 rn=({label:e,devices:r,activeId:o,onPick:i,anchorRef:s})=>{const[a,d]=n.useState(null);return n.useLayoutEffect(()=>{const l=()=>{const u=s.current;if(!u)return;const f=u.getBoundingClientRect(),y=126,p=window.innerWidth-16-110,c=f.left+f.width/2;d({top:f.top-8,left:Math.max(y,Math.min(p,c))})};return l(),window.addEventListener("scroll",l,!0),window.addEventListener("resize",l),()=>{window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[s]),a===null||typeof document>"u"?null:Lt.createPortal(t.jsxs("div",{className:"ll-device-menu ll-device-menu--floating",onClick:l=>l.stopPropagation(),role:"listbox",style:{position:"fixed",top:a.top,left:a.left,transform:"translate(-50%, -100%)"},children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),r.map((l,u)=>{const f=o===l.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${f?"is-active":""}`,onClick:()=>i(l.deviceId),role:"option","aria-selected":f,children:[f&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:l.label||`${e} ${u+1}`})]},l.deviceId||u)})]}),document.body)},Sr=['[data-ll-private="true"]',".ll-widget"];function St(e){let r=e;for(;r;){for(const o of Sr)if(r.matches(o))return!0;r=r.parentElement}return!1}function yt(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,Er=20,Rr=20,Nr=10,Ar=10,Mr=30,Ir=20,on=500,Tr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function rt(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let r=e;for(;r;){for(const o of Tr)if(r.matches(o))return!0;r=r.parentElement}return!1}function ot(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 sn(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 de(e,r){return e.length<=r?e:e.slice(0,r-1)+"…"}function He(e){return e.length}function Nn(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]")),l=[];for(const k of d){if(l.length>=Nr)break;if(rt(k)||!ot(k))continue;const S=k.getAttribute("data-ll-region")??"",$=k.getAttribute("data-ll-intent")??void 0,z=de((k.innerText||k.textContent||"").trim(),on*2);!S||!z||l.push({id:S,intent:$,text:z})}const u=[],f=["H1","H2","H3","H4","H5","H6"],y=Array.from(o.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const k of y){if(rt(k)||!ot(k))continue;const S=(k.textContent||"").trim();S&&u.push(`${k.tagName}: ${de(S,200)}`)}const p=Array.from(o.querySelectorAll("p, li"));for(const k of p){if(rt(k)||!ot(k)||f.includes(k.tagName))continue;const S=(k.textContent||"").trim();S.length>10&&u.push(de(S,on))}const c=u.join(`
2
+ `),L=[],_=Array.from(o.querySelectorAll("a[href]"));for(const k of _){if(L.length>=Er)break;if(rt(k)||!ot(k))continue;const S=k.getAttribute("href")||"",$=(k.textContent||"").trim();!S||!$||L.push({href:S,text:de($,100)})}const w=[],v=Array.from(o.querySelectorAll("input, textarea, select"));for(const k of v){if(w.length>=Rr)break;if(rt(k)||!yt(k)||!ot(k))continue;const S=sn(k),$=k instanceof HTMLInputElement?k.type:k.tagName.toLowerCase();S&&w.push({label:de(S,100),type:$})}const x=Array.from(o.querySelectorAll("[data-ll-form]")),C=[];for(const k of x){if(C.length>=Ar)break;if(St(k))continue;const S=k.getAttribute("data-ll-form")||"";if(!S)continue;const $=k.getAttribute("data-ll-intent")||void 0,z=Array.from(k.querySelectorAll("[data-ll-field]")),O=[];for(const H of z){if(O.length>=Mr)break;if(!yt(H))continue;const T=H.getAttribute("data-ll-field")||"";if(!T)continue;const W=sn(H)||T,D=H instanceof HTMLInputElement?H.type:H.tagName.toLowerCase(),F={name:T,label:de(W,100),type:D};if(H.required===!0&&(F.required=!0),H instanceof HTMLSelectElement){const ie=[];for(let fe=0;fe<H.options.length&&!(ie.length>=Ir);fe++){const ce=H.options[fe];if(!ce||ce.disabled)continue;const pe=ce.value||"",we=(ce.textContent||"").trim()||pe;!pe&&!we||ie.push({value:pe,label:de(we,60)})}ie.length>0&&(F.options=ie)}const oe=typeof H.validationMessage=="string"?H.validationMessage:"";oe&&(F.validationMessage=de(oe,200)),O.push(F)}C.push({id:S,intent:$,fields:O})}const E={url:i,title:a,pathname:s,regions:l,visibleText:c,visibleLinks:L,visibleFields:w,forms:C,extras:e};let N=He(JSON.stringify(E.regions))+He(E.visibleText)+He(JSON.stringify(E.visibleLinks))+He(JSON.stringify(E.visibleFields));for(;N>pt&&E.visibleFields.length>0;)E.visibleFields.pop(),N=He(JSON.stringify(E.visibleFields));for(;N>pt&&E.visibleLinks.length>0;)E.visibleLinks.pop(),N-=80;return He(E.visibleText)>pt&&(E.visibleText=de(E.visibleText,pt-100)),E}let We=null;function Ct(e,r={}){const o=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(We&&We.key===s&&o-We.at<1e3)return We.ctx;const a=Nn(e,r);return We={key:s,at:o,ctx:a},a}function An(){We=null}const Dr=200;function Mn(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 Pr(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function In(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>=Dr)break;if(St(d))continue;const l=d.getAttribute("href")||"";if(!Pr(l))continue;let u=l,f=!0;try{if(typeof window<"u"){const p=new URL(l,o);f=p.origin===o,f&&l.startsWith("http")&&(u=p.pathname+p.search+p.hash)}}catch{continue}if(i.has(u))continue;i.add(u);const y=(d.textContent||"").trim().slice(0,120);s.push({href:u,text:y,internal:f})}return s}let Be=null;const $r=5e3;function ht(){const e=Date.now(),r=typeof window<"u"&&window.location.pathname||"/";if(Be&&Be.pathname===r&&e-Be.at<$r)return Be.routes;const o=In();return Be={at:e,pathname:r,routes:o},o}function Tn(){Be=null}function zr(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 Or(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,l=r==="true"||r==="1"||r==="on";d?d.call(e,l):e.checked=l,i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}zr(e,r),i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function Hr(){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 Wr(e){if(!(e instanceof HTMLElement))return!1;const o=window.getComputedStyle(e).overflowY;return!(o!=="auto"&&o!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function Br(){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(!Wr(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 qr(){if(typeof window>"u")return null;if(Hr())return window;const e=Br();return e||window}function an(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function Fr(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 Ur=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"]),Dn=n.forwardRef(function(r,o){var zt,Ot,Ht,Wt,Bt,qt,Ft;const{agentId:i,apiKey:s,baseUrl:a="https://app.livelayer.studio",sessionEndpoint:d,sessionBody:l,soundEffects:u,experienceMode:f="WIDGET",autoConnect:y=!1,displayMode:p,defaultDisplayMode:c="expanded",onDisplayModeChange:L,position:_="bottom-right",mobileBreakpoint:w=640,persistKey:v="ll-widget",disablePersistence:x=!1,teamMembers:C,currentTeamMemberId:E,onTeamMemberChange:N,idleLoopUrl:k,greeting:S,avatarImageUrl:$,agentName:z,branding:O={},allowCamera:H=!0,allowScreenShare:T=!0,allowTyping:W=!0,showMinimize:D=!0,showClose:F=!0,chromeless:oe=!1,floatingChromeContainer:ie=null,compactControls:fe=!1,transforming:ce=!1,transformingLabel:pe="Transforming…",showOn:we,hideOn:Ae,pathname:Q,onNavigate:it,onScrollToSelector:qe,getPageContext:st,pageContextExtras:ne,getRoutes:Fe,onScrollPage:Ue,onClick:at,capabilities:Ve,onConnect:_e,onDisconnect:Me,onTranscript:ke,onAgentState:Ie,onConnectionStateChange:je,onAgentEvent:Ce,onAgentCommand:Le,controlledSession:A,className:lt,style:vt,zIndex:Se=2147483647}=r,Ee=bn(Q),Z=kn(Ee,we,Ae);n.useEffect(()=>{An(),Tn()},[Ee]);const Ye=E!==void 0,[Ge,Te]=n.useState(()=>{var g;return E??((g=C==null?void 0:C[0])==null?void 0:g.id)}),Re=Ye?E:Ge,J=n.useMemo(()=>(C==null?void 0:C.find(g=>g.id===Re))??null,[C,Re]),ct=(J==null?void 0:J.agentId)??i,Ke=f==="EMBEDDED",[ee,te]=vn({value:p,defaultValue:c,onChange:L,persistKey:v,disablePersistence:Ke||x}),se=xn(w),he=dn(),Y=fn(),ae=pn(),me=hn(),De=mn(),[xt,Je]=n.useState(!1),[ge,Xe]=n.useState(!1),[Qe,Ze]=n.useState(!1),[ye,ve]=n.useState(!1),[Pe,ut]=n.useState(!1),$e=ur({baseUrl:a,config:u}),Ne=n.useRef($e);Ne.current=$e;const m=n.useRef(it),U=n.useRef(qe),bt=n.useRef(Ue),wt=n.useRef(at),Et=n.useRef(st),Rt=n.useRef(ne),Nt=n.useRef(Fe),_t=n.useRef(Ve),le=n.useRef(null);m.current=it,U.current=qe,bt.current=Ue,wt.current=at,Et.current=st,Rt.current=ne,Nt.current=Fe,_t.current=Ve;function xe(g){const h=_t.current;return h?h.includes(g):!0}function be(g,h){console.warn(`[LiveLayer] Agent command "${g}" blocked — capability "${h}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const et=n.useCallback(g=>{var V,re,ue,nt;const h=g;if(!(!h.type||typeof h.type!="string")){if(Ce==null||Ce({eventName:h.type,data:g}),h.type==="navigate"){if(!xe("navigate")){be("navigate","navigate");return}const j=typeof h.href=="string"?h.href:null;if(!j){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(Ne.current.playPageChange(),m.current){try{m.current(j)}catch(R){console.warn(`[LiveLayer] onNavigate threw for "${j}". Falling back. Error:`,R)}return}if(typeof document<"u"){const R=document.querySelector(`a[href="${j.replace(/"/g,'\\"')}"]`);if(R){R.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",j),window.dispatchEvent(new PopStateEvent("popstate"))}catch(R){console.warn(`[LiveLayer] history.pushState fallback failed for "${j}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,R)}return}if(h.type==="scroll_to"){if(!xe("scroll")){be("scroll_to","scroll");return}const j=typeof h.selector=="string"?h.selector:null;if(!j)return;const R=h.behavior==="instant"?"instant":"smooth";if(U.current){try{U.current(j,R)}catch(P){console.warn("[LiveLayer] onScrollToSelector threw.",P)}return}if(typeof document<"u"){let P=null;try{P=document.querySelector(j)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${j}".`);return}if(!P){console.warn(`[LiveLayer] scroll_to: no element matched "${j}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}P.scrollIntoView({behavior:R,block:"start"})}return}if(h.type==="request_page_context"){if(!xe("read_page")){be("request_page_context","read_page");return}const j=typeof h.requestId=="string"?h.requestId:void 0,R=(V=le.current)==null?void 0:V.call(le),P=q=>{const M=R,K=M==null?void 0:M.localParticipant;if(K!=null&&K.publishData)try{const X=j?{...q,requestId:j}:q,Oe=new TextEncoder().encode(JSON.stringify(X));K.publishData(Oe,{reliable:!0})}catch(X){console.warn("[LiveLayer] publishData failed.",X)}},I=Rt.current,B=Et.current;try{if(B){const q=B(I);if(q instanceof Promise){P({type:"page_context_pending"}),q.then(M=>P({type:"page_context",context:M})).catch(M=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",M),P({type:"page_context",context:Ct(I)})});return}P({type:"page_context",context:q});return}P({type:"page_context",context:Ct(I)})}catch(q){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",q),P({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:I}})}return}if(h.type==="scroll_page"){if(!xe("scroll")){be("scroll_page","scroll");return}const j=h.direction;if(j!=="up"&&j!=="down"&&j!=="top"&&j!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(j)}". Expected up | down | top | bottom.`);return}const R=h.behavior==="instant"?"instant":"smooth";if(bt.current){try{bt.current(j,R)}catch(M){console.warn("[LiveLayer] onScrollPage threw.",M)}return}if(typeof window>"u")return;const P={behavior:R},I=qr(),B=M=>{I instanceof Window?I.scrollBy({top:M,...P}):I.scrollBy({top:M,...P})},q=M=>{I instanceof Window?I.scrollTo({top:M,...P}):I.scrollTo({top:M,...P})};j==="up"?B(-an(I)):j==="down"?B(an(I)):q(j==="top"?0:Fr(I));return}if(h.type==="click"){if(!xe("click")){be("click","click");return}const j=typeof h.selector=="string"?h.selector:null;if(!j){console.warn("[LiveLayer] click: missing selector.");return}if(wt.current){try{wt.current(j)}catch(P){console.warn("[LiveLayer] onClick threw.",P)}return}if(typeof document>"u")return;let R=null;try{R=document.querySelector(j)}catch{console.warn(`[LiveLayer] click: invalid selector "${j}".`);return}if(!R){console.warn(`[LiveLayer] click: no element matched "${j}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(re=R.click)==null||re.call(R);return}if(h.type==="fill_form"||h.type==="focus_field"){if(!xe("fill_forms")){be(h.type,"fill_forms");return}if(typeof document>"u")return;h.type==="fill_form"&&Ne.current.playConfirmation();const j=typeof h.formId=="string"?h.formId:null;if(!j){console.warn(`[LiveLayer] ${h.type}: missing formId.`);return}const R=document.querySelector(`[data-ll-form="${j.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] ${h.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`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn(`[LiveLayer] ${h.type}: refusing to touch a form in a private subtree.`);return}if(h.type==="focus_field"){const I=typeof h.fieldName=="string"?h.fieldName:null;if(!I){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const B=R.querySelector(`[data-ll-field="${I.replace(/"/g,'\\"')}"]`);if(!B){console.warn(`[LiveLayer] focus_field: no field "${I}" in form "${j}".`);return}if(!yt(B)){console.warn(`[LiveLayer] focus_field: field "${I}" is privacy-protected and not focusable.`);return}B.focus();return}const P=h.values&&typeof h.values=="object"?h.values:null;if(!P){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[I,B]of Object.entries(P)){if(typeof B!="string")continue;const q=R.querySelector(`[data-ll-field="${I.replace(/"/g,'\\"')}"]`);if(!q){console.warn(`[LiveLayer] fill_form: no field "${I}" in form "${j}". Skipping.`);continue}if(!yt(q)){console.warn(`[LiveLayer] fill_form: field "${I}" is privacy-protected (password / cc-* / private). Skipping.`);continue}try{Or(q,B)}catch(M){console.warn(`[LiveLayer] fill_form: failed to set "${I}".`,M)}}return}if(h.type==="submit_form"){if(!xe("submit_forms")){be("submit_form","submit_forms");return}if(typeof document>"u")return;const j=typeof h.formId=="string"?h.formId:null;if(!j){console.warn("[LiveLayer] submit_form: missing formId.");return}Ne.current.playConfirmation();const R=document.querySelector(`[data-ll-form="${j.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${j}".`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private subtree.");return}const P=typeof h.requestId=="string"?h.requestId:void 0,I=(ue=le.current)==null?void 0:ue.call(le),B=K=>{const X=I,Oe=X==null?void 0:X.localParticipant;if(Oe!=null&&Oe.publishData)try{const Kn=P?{...K,requestId:P}:K,Jn=new TextEncoder().encode(JSON.stringify(Kn));Oe.publishData(Jn,{reliable:!0})}catch{}};let q=!1;const M=()=>{q=!0,B({type:"form_submitted",formId:j})};R.addEventListener("submit",M,{once:!0});try{typeof R.requestSubmit=="function"?R.requestSubmit():R.submit()}catch(K){console.warn("[LiveLayer] submit_form: requestSubmit threw.",K),R.removeEventListener("submit",M),B({type:"form_submit_blocked",formId:j,reason:"exception"});return}setTimeout(()=>{q||(R.removeEventListener("submit",M),B({type:"form_submit_blocked",formId:j,reason:"validation"}))},500);return}if(h.type==="request_routes"){if(!xe("read_page")){be("request_routes","read_page");return}const j=typeof h.requestId=="string"?h.requestId:void 0,P=(nt=le.current)==null?void 0:nt.call(le),I=P==null?void 0:P.localParticipant;if(!(I!=null&&I.publishData))return;const B=M=>{try{const K=j?{type:"routes",routes:M,requestId:j}:{type:"routes",routes:M},X=new TextEncoder().encode(JSON.stringify(K));I.publishData(X,{reliable:!0})}catch(K){console.warn("[LiveLayer] request_routes: publishData failed.",K)}},q=Nt.current;if(q){try{const M=q(),K=X=>{if(!Array.isArray(X)){B([]);return}B(X.map(Mn).slice(0,200))};M instanceof Promise?M.then(K).catch(X=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",X),B(ht())}):K(M)}catch(M){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",M),B(ht())}return}try{B(ht())}catch(M){console.warn("[LiveLayer] request_routes: extractRoutes threw.",M)}return}Ur.has(h.type)||Le==null||Le(h)}},[Le,Ce]),G=un({agentId:A?"__controlled__":ct,baseUrl:a,apiKey:s,sessionEndpoint:d,sessionBody:l,onDataMessage:A?void 0:et});n.useEffect(()=>{if(A!=null&&A.subscribeToDataMessages)return A.subscribeToDataMessages(et)},[A,et]),le.current=()=>{var g;return(g=G.getRoom)==null?void 0:g.call(G)},n.useEffect(()=>{var V;if(typeof window>"u")return;const g=((V=window.location)==null?void 0:V.hostname)||"";if(g==="localhost"||g==="127.0.0.1"||g==="0.0.0.0"||g.endsWith(".local")||g.endsWith(".test"))return window.__livelayerSimulateCommand=re=>{try{et(re)}catch(ue){console.warn("[LiveLayer] simulate-command threw:",ue)}},()=>{delete window.__livelayerSimulateCommand}},[et]);const b=n.useMemo(()=>A?{connectionState:A.connectionState,agentState:A.agentState,transcript:A.transcript,videoElement:A.videoElement,audioElement:A.audioElement,canResume:A.canResume,error:A.error,agentConfig:null,connect:async()=>{await A.onConnect()},disconnect:()=>A.onDisconnect(),getRoom:G.getRoom,isControlled:!0}:{connectionState:G.connectionState,agentState:G.agentState,transcript:G.transcript,videoElement:G.videoElement,audioElement:G.audioElement,canResume:G.canResume,error:G.error,agentConfig:G.agentConfig,connect:G.connect,disconnect:G.disconnect,getRoom:G.getRoom,isControlled:!1},[A,G]),At=n.useRef(b);At.current=b;const Mt=n.useRef(A);Mt.current=A,n.useImperativeHandle(o,()=>({sendData:async g=>{var ue,nt;const h=Mt.current;if(h!=null&&h.publishData){try{await h.publishData(g)}catch(j){console.warn("[AvatarWidget] sendData (controlled) failed:",j)}return}const V=(nt=(ue=At.current)==null?void 0:ue.getRoom)==null?void 0:nt.call(ue),re=V==null?void 0:V.localParticipant;if(re!=null&&re.publishData)try{const j=new TextEncoder().encode(JSON.stringify(g));await re.publishData(j,{reliable:!0})}catch(j){console.warn("[AvatarWidget] sendData failed:",j)}}}),[]);const It=n.useRef(null);n.useEffect(()=>{const g=b.videoElement,h=It.current;if(!(!g||!h))return h.appendChild(g),()=>{g.parentNode===h&&h.removeChild(g)}},[b.videoElement]),n.useEffect(()=>{const g=b.audioElement;if(!g)return;he.attach(g);const h=g.play();return h&&typeof h.catch=="function"&&h.catch(V=>{(V==null?void 0:V.name)==="NotAllowedError"&&Je(!0)}),()=>{he.detach()}},[b.audioElement]),n.useEffect(()=>{if(b.isControlled||b.connectionState!=="connected")return;const g=b.getRoom();if(g)return Y.setupMic(g).catch(()=>{}),()=>{Y.teardownMic()}},[b.isControlled,b.connectionState]),n.useEffect(()=>{var h;if(b.connectionState!=="connected")return;const g=b.isControlled?(h=A==null?void 0:A.getRoom)==null?void 0:h.call(A):b.getRoom();if(g)return ae.attachRoom(g),me.attachRoom(g),b.isControlled&&Y.attachRoom(g),De.refresh(),()=>{ae.teardown(),me.teardown()}},[b.isControlled,b.connectionState,A]),n.useEffect(()=>{const g=b.audioElement;g&&(g.muted=Pe)},[b.audioElement,Pe]);const $n=n.useCallback(g=>{const h={type:"user_message",text:g};if(A!=null&&A.publishData){try{A.publishData(h)}catch{}return}const V=b.getRoom();if(V)try{const re=new TextEncoder().encode(JSON.stringify(h));V.localParticipant.publishData(re,{reliable:!0})}catch{}},[b,A]),zn=n.useCallback(()=>{ut(g=>!g)},[]);n.useEffect(()=>{je==null||je(b.connectionState),b.connectionState==="connected"?_e==null||_e():b.connectionState==="disconnected"&&(Me==null||Me())},[b.connectionState,_e,Me,je]),n.useEffect(()=>{ke==null||ke(b.transcript)},[b.transcript,ke]),n.useEffect(()=>{Ie==null||Ie(b.agentState)},[b.agentState,Ie]),n.useEffect(()=>{$e.setThinking(b.agentState==="thinking")},[b.agentState,$e]);const Tt=n.useRef(!1);n.useEffect(()=>{b.isControlled||!y||Tt.current||Z&&b.connectionState==="idle"&&(Tt.current=!0,b.connect())},[y,b.connectionState,b,Z]);const On=n.useCallback(g=>{const h=C==null?void 0:C.find(V=>V.id===g);h&&(Ze(!1),g!==Re&&(Xe(!0),b.disconnect(),Ye||Te(g),N==null||N(h)))},[C,Re,b,Ye,N]);n.useEffect(()=>{ge&&b.connectionState==="connected"&&Xe(!1)},[b.connectionState,ge]),n.useEffect(()=>{if(!Qe)return;const g=h=>{h.key==="Escape"&&Ze(!1)};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[Qe]);const Hn=!!$||!!(J!=null&&J.avatarImageUrl)||b.isControlled,tt=gn(ct,a,Hn);Ve===void 0&&((zt=tt.info)!=null&&zt.capabilities)&&(_t.current=tt.info.capabilities);const dt=(J==null?void 0:J.name)??z??((Ot=b.agentConfig)==null?void 0:Ot.name)??((Ht=tt.info)==null?void 0:Ht.name)??"Live Layer",kt=(J==null?void 0:J.avatarImageUrl)??$??((Wt=b.agentConfig)==null?void 0:Wt.avatarImageUrl)??((Bt=tt.info)==null?void 0:Bt.avatarImageUrl)??null,Wn=k??((qt=b.agentConfig)==null?void 0:qt.idleLoopUrl)??((Ft=tt.info)==null?void 0:Ft.idleLoopUrl)??null,Bn=S??null,qn=n.useCallback(()=>te("expanded"),[te]),Fn=n.useCallback(()=>te("minimized"),[te]),Dt=n.useCallback(()=>{b.disconnect(),te("hidden")},[b,te]),Un=n.useCallback(()=>{const g=b.audioElement;g&&g.play().then(()=>Je(!1)).catch(()=>{})},[b.audioElement]),Vn=n.useCallback(()=>{Je(!1),b.connect()},[b]),ze={...vt,...Ke?{}:{zIndex:Se}};O.primaryColor&&(ze["--ll-color-primary"]=O.primaryColor),O.accentColor&&(ze["--ll-color-accent"]=O.accentColor),O.backgroundColor&&(ze["--ll-color-bg"]=O.backgroundColor),O.textColor&&(ze["--ll-color-fg"]=O.textColor);const Yn=["ll-widget",`ll-widget--${ee}`,`ll-widget--${se?"mobile":"desktop"}`,lt].filter(Boolean).join(" ");if(!Z)return null;const Gn=t.jsx("div",{className:Yn,style:ze,"data-display-mode":ee,"data-position":_,"data-experience-mode":f==="EMBEDDED"?"embedded":"widget",children:ee==="expanded"&&t.jsx(Cr,{position:_,isMobile:se,agentName:dt,avatarImageUrl:kt,idleLoopUrl:Wn,greeting:Bn,branding:O,teamMembers:C,currentTeamMemberId:Re,isSwitchingTeamMember:ge,teamSwitcherOpen:Qe,onToggleTeamSwitcher:()=>Ze(g=>!g),onSelectTeamMember:On,connectionState:b.connectionState,agentState:b.agentState,transcript:b.transcript,isMuted:Y.isMuted,micDevices:De.mics,activeMicId:Y.activeDeviceId,isCameraEnabled:ae.isEnabled,cameraPreviewEl:ae.previewEl,cameraDevices:De.cameras,activeCameraId:ae.activeDeviceId,isScreenShareEnabled:me.isEnabled,screenPreviewEl:me.previewEl,isSpeakerMuted:Pe,allowCamera:H,allowScreenShare:T,allowTyping:W,showMinimize:D,showClose:F,chromeless:oe,compactControls:fe,transforming:ce,transformingLabel:pe,languageMenuOpen:ye,onToggleLanguageMenu:()=>ve(g=>!g),needsUserGesture:xt,canResume:b.canResume,micError:Y.micError,error:b.error,avatarVideoContainerRef:It,agentVideoEl:b.videoElement,onConnect:()=>void b.connect(),onDisconnect:()=>b.disconnect(),onRetry:Vn,onResumeAudio:Un,onToggleMute:Y.toggleMute,onSwitchMicDevice:g=>void Y.switchDevice(g),onToggleCamera:()=>void ae.toggle(),onSwitchCameraDevice:g=>void ae.switchDevice(g),onToggleScreenShare:()=>void me.toggle(),onToggleSpeaker:zn,onSendMessage:$n,onMinimize:Fn,onClose:Dt,onClearMicError:Y.clearError})}),Pt=ee==="hidden"||ee==="minimized"?t.jsxs("div",{className:["ll-widget","ll-widget--floating",`ll-widget--${ee}`,`ll-widget--${se?"mobile":"desktop"}`].join(" "),style:ze,"data-display-mode":ee,"data-position":_,children:[ee==="hidden"&&t.jsx(gr,{position:_,isMobile:se,isSpeaking:b.agentState==="speaking",onExpand:()=>te("expanded"),label:`Open ${dt} widget`,avatarImageUrl:kt,agentName:dt,containerEl:ie}),ee==="minimized"&&t.jsx(vr,{position:_,isMobile:se,agentName:dt,avatarImageUrl:kt,agentState:b.agentState,isMuted:Y.isMuted,audioLevel:he,onExpand:qn,onToggleMute:Y.toggleMute,onClose:Dt})]}):null,$t=ie??(typeof document<"u"?document.body:null);return t.jsxs(t.Fragment,{children:[Gn,Pt&&$t&&Lt.createPortal(Pt,$t)]})});Dn.displayName="AvatarWidgetInner";const Pn=n.forwardRef(function(r,o){return t.jsx(cn,{children:t.jsx(Dn,{...r,ref:o})})});Pn.displayName="AvatarWidget";const Vr=({agentId:e,baseUrl:r,apiKey:o,mode:i,onAgentEvent:s,className:a,style:d})=>{const l=n.useRef(null),u=n.useRef(null),f=n.useRef(s);f.current=s;const y=n.useCallback(p=>{var L;const c=p.detail;(L=f.current)==null||L.call(f,c)},[]);return n.useEffect(()=>{const p=l.current;if(!p)return;const c=document.createElement("livelayer-widget");return c.setAttribute("agent-id",e),r&&c.setAttribute("base-url",r),o&&c.setAttribute("api-key",o),i&&c.setAttribute("mode",i),c.addEventListener("agent-event",y),p.appendChild(c),u.current=c,()=>{c.removeEventListener("agent-event",y),p.removeChild(c),u.current=null}},[e]),n.useEffect(()=>{u.current&&(i?u.current.setAttribute("mode",i):u.current.removeAttribute("mode"))},[i]),t.jsx("div",{ref:l,className:a,style:d})},Yr=n.forwardRef(function({id:r,intent:o,as:i="div",className:s,style:a,children:d},l){return n.createElement(i,{ref:l,"data-ll-region":r,"data-ll-intent":o,className:s,style:a},d)}),Gr=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})}),Kr=n.forwardRef(function(r,o){const{name:i,label:s,labelClassName:a}=r,d={name:i,"data-ll-field":i};let l;if("as"in r&&r.as==="textarea"){const{name:u,label:f,labelClassName:y,as:p,...c}=r;l=t.jsx("textarea",{ref:o,...d,...c})}else if("as"in r&&r.as==="select"){const{name:u,label:f,labelClassName:y,as:p,children:c,...L}=r;l=t.jsx("select",{ref:o,...d,...L,children:c})}else{const{name:u,label:f,labelClassName:y,as:p,...c}=r;l=t.jsx("input",{ref:o,...d,...c})}return s===void 0?l:t.jsxs("label",{className:a,children:[s,l]})});let ln=1;function Jr({onMount:e,defaultOpen:r=!1,storageKey:o="ll-debug-open"}){const[i,s]=n.useState(r),[a,d]=n.useState([]),[l,u]=n.useState(""),[f,y]=n.useState(!1),p=n.useRef(new Set),c=n.useRef([]),L=n.useRef(f);L.current=f,n.useEffect(()=>{try{const v=localStorage.getItem(o);v==="1"&&s(!0),v==="0"&&s(!1)}catch{}},[o]),n.useEffect(()=>{try{localStorage.setItem(o,i?"1":"0")}catch{}},[i,o]),n.useEffect(()=>{const v=x=>{(x.metaKey||x.ctrlKey)&&x.shiftKey&&x.key.toLowerCase()==="l"&&(x.preventDefault(),s(C=>!C))};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[]),n.useEffect(()=>{const v=setInterval(()=>{if(c.current.length===0||L.current)return;const x=c.current.splice(0,c.current.length);d(C=>[...x.reverse(),...C].slice(0,200))},100);return()=>clearInterval(v)},[]);const _=n.useRef(!1);if(n.useEffect(()=>{!e||_.current||(_.current=!0,e(v=>{c.current.push({id:ln++,ts:Date.now(),kind:"event",type:v.eventName,data:v.data})}))},[e]),n.useEffect(()=>{const v=console.warn,x=console.log,C=(E,N)=>function(...k){try{const S=typeof k[0]=="string"?k[0]:"";S.startsWith("[LiveLayer]")&&c.current.push({id:ln++,ts:Date.now(),kind:E,type:S.slice(0,120),data:{args:k.slice(1).map($=>Qr($))}})}catch{}return N.apply(this,k)};return console.warn=C("warn",v),console.log=C("log",x),()=>{console.warn=v,console.log=x}},[]),!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 w=a.filter(v=>{if(!l)return!0;const x=l.toLowerCase();return v.type.toLowerCase().includes(x)||JSON.stringify(v.data||{}).toLowerCase().includes(x)});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:()=>y(v=>!v),style:jt(f?"#f59e0b":"transparent"),title:"Pause / resume capture",children:f?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{d([]),c.current=[]},style:jt("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:jt("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:l,onChange:v=>u(v.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:w.length===0?t.jsxs("div",{style:{padding:14,fontSize:11,color:"rgba(255,255,255,0.4)",lineHeight:1.5},children:["No events yet. Connect to the agent and trigger a tool call — the events will stream in here. You can also dispatch commands manually in DevTools:",t.jsx("pre",{style:{marginTop:6,background:"rgba(255,255,255,0.04)",padding:6,borderRadius:4,fontSize:10,whiteSpace:"pre-wrap"},children:`window.__livelayerSimulateCommand({
3
3
  type: "navigate",
4
4
  href: "/about"
5
- })`})]}):_.map(x=>t.jsx(Xr,{entry:x,expanded:p.current.has(x.id),onToggle:()=>{p.current.has(x.id)?p.current.delete(x.id):p.current.add(x.id),d(v=>[...v])}},x.id))})]})}function Xr({entry:e,expanded:r,onToggle:o}){const i=e.kind==="warn"?"#f59e0b":e.type.startsWith("[LiveLayer]")?"#94a3b8":e.type==="navigate"||e.type==="scroll_page"||e.type==="scroll_to"||e.type==="click"?"#22c55e":e.type==="fill_form"||e.type==="submit_form"||e.type==="focus_field"?"#a78bfa":e.type==="request_page_context"||e.type==="request_routes"?"#38bdf8":e.type==="agent_state"?"#facc15":"#cbd5e1",s=new Date(e.ts).toLocaleTimeString("en-US",{hour12:!1});return t.jsxs("button",{type:"button",onClick:o,style:{textAlign:"left",background:"transparent",border:0,color:"#fff",width:"100%",padding:"6px 4px",cursor:"pointer",borderBottom:"1px solid rgba(255,255,255,0.04)",fontSize:11,lineHeight:1.4},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums",fontSize:10},children:s}),t.jsx("span",{style:{color:i,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),r&&e.data&&t.jsx("pre",{style:{marginTop:6,padding:6,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:10,overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(e.data,null,2)})]})}function jt(e){return{background:e,color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:999,padding:"3px 8px",fontSize:10,cursor:"pointer"}}function Qr(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Zr(){const[e,r]=n.useState([]),o=n.useCallback(s=>{r(a=>{const d=a.findIndex(l=>l.id===s.id);if(d>=0){const l=a.slice();return l[d]=s,l}return[...a,s]})},[]),i=n.useCallback(()=>r([]),[]);return{entries:e,pushSegment:o,clear:i,latest:e.length>0?e[e.length-1]:null}}exports.AvatarWidget=Pn;exports.ErrorBoundary=cn;exports.LiveLayerDebugPanel=Jr;exports.LiveLayerField=Kr;exports.LiveLayerForm=Gr;exports.LiveLayerRegion=Yr;exports.LiveLayerWidget=Vr;exports.clearPageContextCache=An;exports.clearRoutesCache=Tn;exports.extractPageContext=Nn;exports.extractRoutes=In;exports.getCachedPageContext=Ct;exports.getCachedRoutes=ht;exports.matchesPattern=wn;exports.normalizeRouteInput=Mn;exports.shouldRenderAtPath=_n;exports.useAgentInfo=gn;exports.useAudioLevel=dn;exports.useCameraState=pn;exports.useDisplayMode=yn;exports.useDisplayModePersistence=vn;exports.useIsMobile=xn;exports.useLiveKitSession=un;exports.useMediaDevices=mn;exports.useMicrophoneState=fn;exports.usePathname=bn;exports.useRouteMatch=kn;exports.useScreenShareState=hn;exports.useTranscript=Zr;
5
+ })`})]}):w.map(v=>t.jsx(Xr,{entry:v,expanded:p.current.has(v.id),onToggle:()=>{p.current.has(v.id)?p.current.delete(v.id):p.current.add(v.id),d(x=>[...x])}},v.id))})]})}function Xr({entry:e,expanded:r,onToggle:o}){const i=e.kind==="warn"?"#f59e0b":e.type.startsWith("[LiveLayer]")?"#94a3b8":e.type==="navigate"||e.type==="scroll_page"||e.type==="scroll_to"||e.type==="click"?"#22c55e":e.type==="fill_form"||e.type==="submit_form"||e.type==="focus_field"?"#a78bfa":e.type==="request_page_context"||e.type==="request_routes"?"#38bdf8":e.type==="agent_state"?"#facc15":"#cbd5e1",s=new Date(e.ts).toLocaleTimeString("en-US",{hour12:!1});return t.jsxs("button",{type:"button",onClick:o,style:{textAlign:"left",background:"transparent",border:0,color:"#fff",width:"100%",padding:"6px 4px",cursor:"pointer",borderBottom:"1px solid rgba(255,255,255,0.04)",fontSize:11,lineHeight:1.4},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums",fontSize:10},children:s}),t.jsx("span",{style:{color:i,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),r&&e.data&&t.jsx("pre",{style:{marginTop:6,padding:6,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:10,overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(e.data,null,2)})]})}function jt(e){return{background:e,color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:999,padding:"3px 8px",fontSize:10,cursor:"pointer"}}function Qr(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Zr(){const[e,r]=n.useState([]),o=n.useCallback(s=>{r(a=>{const d=a.findIndex(l=>l.id===s.id);if(d>=0){const l=a.slice();return l[d]=s,l}return[...a,s]})},[]),i=n.useCallback(()=>r([]),[]);return{entries:e,pushSegment:o,clear:i,latest:e.length>0?e[e.length-1]:null}}exports.AvatarWidget=Pn;exports.ErrorBoundary=cn;exports.LiveLayerDebugPanel=Jr;exports.LiveLayerField=Kr;exports.LiveLayerForm=Gr;exports.LiveLayerRegion=Yr;exports.LiveLayerWidget=Vr;exports.clearPageContextCache=An;exports.clearRoutesCache=Tn;exports.extractPageContext=Nn;exports.extractRoutes=In;exports.getCachedPageContext=Ct;exports.getCachedRoutes=ht;exports.matchesPattern=wn;exports.normalizeRouteInput=Mn;exports.shouldRenderAtPath=_n;exports.useAgentInfo=gn;exports.useAudioLevel=dn;exports.useCameraState=pn;exports.useDisplayMode=yn;exports.useDisplayModePersistence=vn;exports.useIsMobile=xn;exports.useLiveKitSession=un;exports.useMediaDevices=mn;exports.useMicrophoneState=fn;exports.usePathname=bn;exports.useRouteMatch=kn;exports.useScreenShareState=hn;exports.useTranscript=Zr;
package/dist/index.mjs CHANGED
@@ -35,11 +35,11 @@ class Un extends On {
35
35
  }
36
36
  }
37
37
  function jn(e) {
38
- const [t, r] = C("idle"), [o, i] = C("idle"), [l, d] = C([]), [a, s] = C(null), [u, y] = C(null), [f, c] = C(null), [A, _] = C(!1), [x, b] = C(null), v = N(null), S = N(e.onDataMessage);
38
+ const [t, r] = C("idle"), [o, i] = C("idle"), [l, d] = C([]), [a, s] = C(null), [u, y] = C(null), [f, c] = C(null), [A, x] = C(!1), [_, v] = C(null), b = N(null), S = N(e.onDataMessage);
39
39
  S.current = e.onDataMessage, I(() => {
40
40
  const R = {
41
41
  onConnectionStateChange: (q) => {
42
- r(q), q === "connected" && b(null);
42
+ r(q), q === "connected" && v(null);
43
43
  },
44
44
  onAgentStateChange: i,
45
45
  onTranscript: (q) => d([...q]),
@@ -47,12 +47,12 @@ function jn(e) {
47
47
  onAudioTrack: (q) => c(q),
48
48
  onVideoTrack: (q) => y(q),
49
49
  onVideoTrackRemoved: () => y(null),
50
- onError: (q) => b(q),
50
+ onError: (q) => v(q),
51
51
  onDataMessage: (q) => {
52
52
  var F;
53
53
  (F = S.current) == null || F.call(S, q);
54
54
  },
55
- onResumabilityChange: _
55
+ onResumabilityChange: x
56
56
  }, B = new Bn(
57
57
  {
58
58
  agentId: e.agentId,
@@ -63,9 +63,9 @@ function jn(e) {
63
63
  },
64
64
  R
65
65
  );
66
- return v.current = B, r("idle"), i("idle"), d([]), s(null), y(null), c(null), _(!1), b(null), () => {
66
+ return b.current = B, r("idle"), i("idle"), d([]), s(null), y(null), c(null), x(!1), v(null), () => {
67
67
  var q;
68
- (q = B.destroy) == null || q.call(B), v.current = null;
68
+ (q = B.destroy) == null || q.call(B), b.current = null;
69
69
  };
70
70
  }, [
71
71
  e.agentId,
@@ -75,19 +75,19 @@ function jn(e) {
75
75
  JSON.stringify(e.sessionBody ?? {})
76
76
  ]);
77
77
  const M = E(async () => {
78
- const R = v.current;
78
+ const R = b.current;
79
79
  if (R)
80
80
  try {
81
81
  await R.connect();
82
82
  } catch (B) {
83
- throw b(B instanceof Error ? B.message : String(B)), B;
83
+ throw v(B instanceof Error ? B.message : String(B)), B;
84
84
  }
85
85
  }, []), D = E(() => {
86
- const R = v.current;
86
+ const R = b.current;
87
87
  R && R.disconnect();
88
88
  }, []), k = E(() => {
89
89
  var R;
90
- return ((R = v.current) == null ? void 0 : R.getRoom()) ?? null;
90
+ return ((R = b.current) == null ? void 0 : R.getRoom()) ?? null;
91
91
  }, []);
92
92
  return {
93
93
  connectionState: t,
@@ -97,11 +97,11 @@ function jn(e) {
97
97
  videoElement: u,
98
98
  audioElement: f,
99
99
  canResume: A,
100
- error: x,
100
+ error: _,
101
101
  connect: M,
102
102
  disconnect: D,
103
103
  getRoom: k,
104
- session: v.current
104
+ session: b.current
105
105
  };
106
106
  }
107
107
  function Vn() {
@@ -117,13 +117,13 @@ function Vn() {
117
117
  const c = l.current;
118
118
  f.getByteFrequencyData(c);
119
119
  let A = 0;
120
- for (let x = 0; x < c.length; x++) A += c[x];
121
- const _ = A / c.length / 255;
122
- for (const x of i.current)
120
+ for (let _ = 0; _ < c.length; _++) A += c[_];
121
+ const x = A / c.length / 255;
122
+ for (const _ of i.current)
123
123
  try {
124
- x(_);
125
- } catch (b) {
126
- console.error("[useAudioLevel] subscriber threw:", b);
124
+ _(x);
125
+ } catch (v) {
126
+ console.error("[useAudioLevel] subscriber threw:", v);
127
127
  }
128
128
  o.current = requestAnimationFrame(d);
129
129
  }, []), a = E(() => {
@@ -181,8 +181,8 @@ function Vn() {
181
181
  }, [u]), { attach: s, detach: u, subscribe: y };
182
182
  }
183
183
  function Yn() {
184
- const [e, t] = C(!1), [r, o] = C(""), [i, l] = C(null), d = N(null), a = N(null), s = E(async (_) => {
185
- var x, b;
184
+ const [e, t] = C(!1), [r, o] = C(""), [i, l] = C(null), d = N(null), a = N(null), s = E(async (x) => {
185
+ var _, v;
186
186
  if (d.current && a.current) {
187
187
  try {
188
188
  await a.current.localParticipant.unpublishTrack(d.current);
@@ -190,52 +190,45 @@ function Yn() {
190
190
  }
191
191
  d.current.stop(), d.current = null;
192
192
  }
193
- a.current = _, l(null);
193
+ a.current = x, l(null);
194
194
  try {
195
- const v = await qn({
195
+ const b = await qn({
196
196
  echoCancellation: !0,
197
197
  noiseSuppression: !0
198
198
  });
199
- await _.localParticipant.publishTrack(v), d.current = v, t(v.isMuted);
200
- const S = (b = (x = v.mediaStreamTrack) == null ? void 0 : x.getSettings) == null ? void 0 : b.call(x);
199
+ await x.localParticipant.publishTrack(b), d.current = b, t(b.isMuted);
200
+ const S = (v = (_ = b.mediaStreamTrack) == null ? void 0 : _.getSettings) == null ? void 0 : v.call(_);
201
201
  S != null && S.deviceId && o(S.deviceId);
202
- } catch (v) {
203
- const S = v instanceof Error && v.name === "NotAllowedError" ? "Enable your microphone to talk with the agent." : "Microphone unavailable. Check browser permissions and try again.";
204
- throw l(S), v;
202
+ } catch (b) {
203
+ const S = b instanceof Error && b.name === "NotAllowedError" ? "Enable your microphone to talk with the agent." : "Microphone unavailable. Check browser permissions and try again.";
204
+ throw l(S), b;
205
205
  }
206
- }, []), u = E((_) => {
207
- a.current = _;
208
- }, []), y = E(async (_) => {
209
- const x = a.current;
210
- if (x)
206
+ }, []), u = E((x) => {
207
+ a.current = x;
208
+ }, []), y = E(async (x) => {
209
+ const _ = a.current;
210
+ if (_)
211
211
  try {
212
- await x.switchActiveDevice("audioinput", _), o(_);
213
- } catch (b) {
214
- console.warn("[useMicrophoneState] switchDevice failed:", b);
212
+ await _.switchActiveDevice("audioinput", x), o(x);
213
+ } catch (v) {
214
+ console.warn("[useMicrophoneState] switchDevice failed:", v);
215
215
  }
216
- }, []), f = E(() => {
217
- const _ = d.current, x = a.current;
218
- if (_) {
219
- _.isMuted ? (_.unmute(), t(!1)) : (_.mute(), t(!0));
220
- return;
221
- }
222
- if (x) {
223
- const b = !e;
224
- t(b);
216
+ }, []), f = E(async () => {
217
+ const x = a.current, _ = !e;
218
+ if (t(_), !!x)
225
219
  try {
226
- x.localParticipant.setMicrophoneEnabled(!b);
220
+ await x.localParticipant.setMicrophoneEnabled(!_);
227
221
  } catch (v) {
228
- console.warn("[useMicrophoneState] setMicrophoneEnabled failed:", v);
222
+ console.warn("[useMicrophoneState] setMicrophoneEnabled failed:", v), t(!_);
229
223
  }
230
- }
231
224
  }, [e]), c = E(() => {
232
- const _ = d.current, x = a.current;
233
- if (_ && x) {
225
+ const x = d.current, _ = a.current;
226
+ if (x && _) {
234
227
  try {
235
- x.localParticipant.unpublishTrack(_);
228
+ _.localParticipant.unpublishTrack(x);
236
229
  } catch {
237
230
  }
238
- _.stop();
231
+ x.stop();
239
232
  }
240
233
  d.current = null, a.current = null, t(!1), o("");
241
234
  }, []), A = E(() => l(null), []);
@@ -253,15 +246,15 @@ function Yn() {
253
246
  }
254
247
  const Gn = { resolution: { width: 640, height: 480, frameRate: 24 } };
255
248
  function Jn() {
256
- const [e, t] = C(!1), [r, o] = C(null), [i, l] = C(null), [d, a] = C(""), s = N(null), u = N(null), y = E((v) => {
257
- s.current = v;
249
+ const [e, t] = C(!1), [r, o] = C(null), [i, l] = C(null), [d, a] = C(""), s = N(null), u = N(null), y = E((b) => {
250
+ s.current = b;
258
251
  }, []), f = E(() => {
259
252
  var M;
260
- const v = s.current, S = u.current;
261
- if (S && v) {
262
- const D = v.localParticipant.getTrackPublication(gn.Source.Camera), R = (D == null ? void 0 : D.track) ?? S;
253
+ const b = s.current, S = u.current;
254
+ if (S && b) {
255
+ const D = b.localParticipant.getTrackPublication(gn.Source.Camera), R = (D == null ? void 0 : D.track) ?? S;
263
256
  try {
264
- v.localParticipant.unpublishTrack(R);
257
+ b.localParticipant.unpublishTrack(R);
265
258
  } catch {
266
259
  }
267
260
  try {
@@ -270,17 +263,17 @@ function Jn() {
270
263
  }
271
264
  }
272
265
  u.current = null, l(null), t(!1);
273
- }, []), c = E(async (v) => {
266
+ }, []), c = E(async (b) => {
274
267
  const S = s.current;
275
268
  if (S) {
276
269
  o(null);
277
270
  try {
278
271
  const M = { ...Gn };
279
- v && (M.deviceId = v);
272
+ b && (M.deviceId = b);
280
273
  const D = await Fn(M);
281
274
  await S.localParticipant.publishTrack(D), u.current = D;
282
275
  const k = D.attach();
283
- l(k), t(!0), v && a(v);
276
+ l(k), t(!0), b && a(b);
284
277
  try {
285
278
  S.localParticipant.publishData(
286
279
  new TextEncoder().encode(JSON.stringify({ type: "user_camera_on" })),
@@ -295,11 +288,11 @@ function Jn() {
295
288
  }
296
289
  }, []), A = E(async () => {
297
290
  e ? f() : await c(d || void 0);
298
- }, [e, d, f, c]), _ = E(async (v) => {
299
- f(), await c(v);
300
- }, [f, c]), x = E(() => {
291
+ }, [e, d, f, c]), x = E(async (b) => {
292
+ f(), await c(b);
293
+ }, [f, c]), _ = E(() => {
301
294
  f(), s.current = null, o(null), a("");
302
- }, [f]), b = E(() => o(null), []);
295
+ }, [f]), v = E(() => o(null), []);
303
296
  return I(() => () => {
304
297
  u.current && u.current.stop();
305
298
  }, []), {
@@ -308,10 +301,10 @@ function Jn() {
308
301
  previewEl: i,
309
302
  activeDeviceId: d,
310
303
  toggle: A,
311
- switchDevice: _,
304
+ switchDevice: x,
312
305
  attachRoom: y,
313
- teardown: x,
314
- clearError: b
306
+ teardown: _,
307
+ clearError: v
315
308
  };
316
309
  }
317
310
  function Kn() {
@@ -332,11 +325,11 @@ function Kn() {
332
325
  try {
333
326
  await c.localParticipant.setScreenShareEnabled(!0);
334
327
  let A = 0;
335
- const _ = () => {
336
- const x = c.localParticipant.getTrackPublication(gn.Source.ScreenShare);
337
- if (x != null && x.track) {
338
- const b = x.track.attach();
339
- l(b), t(!0);
328
+ const x = () => {
329
+ const _ = c.localParticipant.getTrackPublication(gn.Source.ScreenShare);
330
+ if (_ != null && _.track) {
331
+ const v = _.track.attach();
332
+ l(v), t(!0);
340
333
  try {
341
334
  c.localParticipant.publishData(
342
335
  new TextEncoder().encode(JSON.stringify({ type: "user_screen_share_on" })),
@@ -346,12 +339,12 @@ function Kn() {
346
339
  }
347
340
  return;
348
341
  }
349
- A++ < 10 ? setTimeout(_, 100) : t(!0);
342
+ A++ < 10 ? setTimeout(x, 100) : t(!0);
350
343
  };
351
- _();
344
+ x();
352
345
  } catch (A) {
353
- const _ = A instanceof Error ? A.name : "";
354
- _ !== "NotAllowedError" && _ !== "AbortError" && o("Screen share unavailable. Try again."), t(!1);
346
+ const x = A instanceof Error ? A.name : "";
347
+ x !== "NotAllowedError" && x !== "AbortError" && o("Screen share unavailable. Try again."), t(!1);
355
348
  }
356
349
  }
357
350
  }, [e, s]), y = E(() => {
@@ -721,7 +714,7 @@ const kr = ({
721
714
  agentName: d,
722
715
  containerEl: a
723
716
  }) => {
724
- const s = wr(e), u = s === "right" ? "left" : "right", y = t ? 80 : 72, f = !!l, c = !!a, [A, _] = C(null), [x, b] = C(!1), v = N(null), S = N(!1), M = E(
717
+ const s = wr(e), u = s === "right" ? "left" : "right", y = t ? 80 : 72, f = !!l, c = !!a, [A, x] = C(null), [_, v] = C(!1), b = N(null), S = N(!1), M = E(
725
718
  (O) => {
726
719
  if (typeof window > "u") return O;
727
720
  const j = y / 2, H = rn + j, G = window.innerHeight - rn - j;
@@ -731,13 +724,13 @@ const kr = ({
731
724
  );
732
725
  I(() => {
733
726
  if (c) {
734
- _(null);
727
+ x(null);
735
728
  return;
736
729
  }
737
730
  const O = xr();
738
- _(M(O ?? window.innerHeight / 2));
731
+ x(M(O ?? window.innerHeight / 2));
739
732
  const j = () => {
740
- _((H) => H === null ? null : M(H));
733
+ x((H) => H === null ? null : M(H));
741
734
  };
742
735
  return window.addEventListener("resize", j), () => window.removeEventListener("resize", j);
743
736
  }, [M, c]);
@@ -748,7 +741,7 @@ const kr = ({
748
741
  O.currentTarget.setPointerCapture(O.pointerId);
749
742
  } catch {
750
743
  }
751
- v.current = {
744
+ b.current = {
752
745
  startClientY: O.clientY,
753
746
  startCenterY: A,
754
747
  moved: !1
@@ -758,21 +751,21 @@ const kr = ({
758
751
  [A, c]
759
752
  ), k = E(
760
753
  (O) => {
761
- const j = v.current;
754
+ const j = b.current;
762
755
  if (!j) return;
763
756
  const H = O.clientY - j.startClientY;
764
- !j.moved && Math.abs(H) > _r && (j.moved = !0, b(!0)), j.moved && _(M(j.startCenterY + H));
757
+ !j.moved && Math.abs(H) > _r && (j.moved = !0, v(!0)), j.moved && x(M(j.startCenterY + H));
765
758
  },
766
759
  [M]
767
760
  ), R = E(
768
761
  (O) => {
769
- const j = v.current;
762
+ const j = b.current;
770
763
  if (j) {
771
764
  try {
772
765
  O.currentTarget.releasePointerCapture(O.pointerId);
773
766
  } catch {
774
767
  }
775
- v.current = null, j.moved && (b(!1), S.current = !0, _((H) => (H !== null && on(H), H)));
768
+ b.current = null, j.moved && (v(!1), S.current = !0, x((H) => (H !== null && on(H), H)));
776
769
  }
777
770
  },
778
771
  []
@@ -787,7 +780,7 @@ const kr = ({
787
780
  if (O.key === "ArrowUp" || O.key === "ArrowDown") {
788
781
  O.preventDefault();
789
782
  const j = O.key === "ArrowUp" ? -8 : 8;
790
- _((H) => {
783
+ x((H) => {
791
784
  if (H === null) return H;
792
785
  const G = M(H + j);
793
786
  return on(G), G;
@@ -800,7 +793,7 @@ const kr = ({
800
793
  `ll-hidden--${s}`,
801
794
  t ? "ll-hidden--mobile" : "ll-hidden--desktop",
802
795
  r ? "ll-hidden--speaking" : null,
803
- x ? "is-dragging" : null,
796
+ _ ? "is-dragging" : null,
804
797
  f ? "ll-hidden--with-avatar" : null,
805
798
  c ? "ll-hidden--scoped" : null
806
799
  ].filter(Boolean).join(" "), U = A === null ? void 0 : { top: `${A - y / 2}px`, transform: "none" };
@@ -866,8 +859,8 @@ const kr = ({
866
859
  for (let c = 0; c < t; c++) {
867
860
  const A = a.current[c];
868
861
  if (!A) continue;
869
- const _ = Math.max(o, f * r * s[c]);
870
- A.style.height = `${_}px`;
862
+ const x = Math.max(o, f * r * s[c]);
863
+ A.style.height = `${x}px`;
871
864
  }
872
865
  }), [e, t, r, o, s]);
873
866
  const u = ["ll-waveform", i].filter(Boolean).join(" ");
@@ -1117,14 +1110,14 @@ const kr = ({
1117
1110
  onToggleTyping: c,
1118
1111
  onDisconnect: A
1119
1112
  }) => {
1120
- const [_, x] = C(!1), b = N(null);
1113
+ const [x, _] = C(!1), v = N(null);
1121
1114
  return /* @__PURE__ */ g(Ye, { children: [
1122
1115
  /* @__PURE__ */ g(
1123
1116
  "div",
1124
1117
  {
1125
1118
  className: "ll-toolbar ll-toolbar--compact",
1126
1119
  "data-testid": "compact-toolbar",
1127
- onClick: (v) => v.stopPropagation(),
1120
+ onClick: (b) => b.stopPropagation(),
1128
1121
  children: [
1129
1122
  /* @__PURE__ */ n(
1130
1123
  "button",
@@ -1139,13 +1132,13 @@ const kr = ({
1139
1132
  /* @__PURE__ */ n(
1140
1133
  "button",
1141
1134
  {
1142
- ref: b,
1135
+ ref: v,
1143
1136
  type: "button",
1144
- className: `ll-tool ${_ ? "is-on" : ""}`,
1145
- onClick: () => x((v) => !v),
1137
+ className: `ll-tool ${x ? "is-on" : ""}`,
1138
+ onClick: () => _((b) => !b),
1146
1139
  "aria-label": "More controls",
1147
1140
  "aria-haspopup": "menu",
1148
- "aria-expanded": _,
1141
+ "aria-expanded": x,
1149
1142
  children: /* @__PURE__ */ n(Rr, {})
1150
1143
  }
1151
1144
  ),
@@ -1165,9 +1158,9 @@ const kr = ({
1165
1158
  /* @__PURE__ */ g(
1166
1159
  Nr,
1167
1160
  {
1168
- open: _,
1169
- onClose: () => x(!1),
1170
- anchorRef: b,
1161
+ open: x,
1162
+ onClose: () => _(!1),
1163
+ anchorRef: v,
1171
1164
  children: [
1172
1165
  i && /* @__PURE__ */ g(
1173
1166
  "button",
@@ -1175,7 +1168,7 @@ const kr = ({
1175
1168
  type: "button",
1176
1169
  className: `ll-overflow-popover__item ${r ? "is-on" : ""}`,
1177
1170
  onClick: () => {
1178
- o(), x(!1);
1171
+ o(), _(!1);
1179
1172
  },
1180
1173
  children: [
1181
1174
  /* @__PURE__ */ n(bn, {}),
@@ -1189,7 +1182,7 @@ const kr = ({
1189
1182
  type: "button",
1190
1183
  className: `ll-overflow-popover__item ${l ? "is-on" : ""}`,
1191
1184
  onClick: () => {
1192
- d(), x(!1);
1185
+ d(), _(!1);
1193
1186
  },
1194
1187
  children: [
1195
1188
  /* @__PURE__ */ n(vn, {}),
@@ -1203,7 +1196,7 @@ const kr = ({
1203
1196
  type: "button",
1204
1197
  className: `ll-overflow-popover__item ${s ? "is-on" : ""}`,
1205
1198
  onClick: () => {
1206
- u(), x(!1);
1199
+ u(), _(!1);
1207
1200
  },
1208
1201
  children: [
1209
1202
  /* @__PURE__ */ n(_n, { muted: s }),
@@ -1217,7 +1210,7 @@ const kr = ({
1217
1210
  type: "button",
1218
1211
  className: `ll-overflow-popover__item ${f ? "is-on" : ""}`,
1219
1212
  onClick: () => {
1220
- c(), x(!1);
1213
+ c(), _(!1);
1221
1214
  },
1222
1215
  children: [
1223
1216
  /* @__PURE__ */ n(Ir, {}),
@@ -1292,10 +1285,10 @@ const Mr = ({
1292
1285
  onToggleTeamSwitcher: f,
1293
1286
  onSelectTeamMember: c,
1294
1287
  languageMenuOpen: A,
1295
- onToggleLanguageMenu: _,
1296
- connectionState: x,
1297
- agentState: b,
1298
- transcript: v,
1288
+ onToggleLanguageMenu: x,
1289
+ connectionState: _,
1290
+ agentState: v,
1291
+ transcript: b,
1299
1292
  canResume: S,
1300
1293
  needsUserGesture: M,
1301
1294
  error: D,
@@ -1337,7 +1330,7 @@ const Mr = ({
1337
1330
  onClearMicError: kt
1338
1331
  }) => {
1339
1332
  var De;
1340
- const Ie = ((a == null ? void 0 : a.length) ?? 0) > 1, Me = x === "connecting" || x === "connected", re = x === "connected", Ze = x === "idle" || x === "disconnected" || x === "error", [et, Oe] = C(!1);
1333
+ const Ie = ((a == null ? void 0 : a.length) ?? 0) > 1, Me = _ === "connecting" || _ === "connected", re = _ === "connected", Ze = _ === "idle" || _ === "disconnected" || _ === "error", [et, Oe] = C(!1);
1341
1334
  I(() => {
1342
1335
  if (!le) {
1343
1336
  Oe(!1);
@@ -1363,7 +1356,7 @@ const Mr = ({
1363
1356
  const h = setTimeout(() => ee(!0), 8e3);
1364
1357
  return () => clearTimeout(h);
1365
1358
  }, [re, et]);
1366
- const gt = x === "connecting" || re && !!o && !et && !Te, tt = N(null), oe = N(null);
1359
+ const gt = _ === "connecting" || re && !!o && !et && !Te, tt = N(null), oe = N(null);
1367
1360
  I(() => {
1368
1361
  const h = tt.current;
1369
1362
  h && (h.innerHTML = "", U && (U.style.width = "100%", U.style.height = "100%", U.style.objectFit = "cover", U.style.transform = "scaleX(-1)", h.appendChild(U)));
@@ -1375,7 +1368,7 @@ const Mr = ({
1375
1368
  I(() => {
1376
1369
  if (!ie && !ve && !A && !y) return;
1377
1370
  const h = () => {
1378
- de(!1), X(!1), A && _(), y && f();
1371
+ de(!1), X(!1), A && x(), y && f();
1379
1372
  };
1380
1373
  return document.addEventListener("click", h), () => document.removeEventListener("click", h);
1381
1374
  }, [
@@ -1383,7 +1376,7 @@ const Mr = ({
1383
1376
  ve,
1384
1377
  A,
1385
1378
  y,
1386
- _,
1379
+ x,
1387
1380
  f
1388
1381
  ]);
1389
1382
  const [He, Lt] = C(!1), nt = E(() => Lt((h) => !h), []), [we, rt] = C(""), ot = E(
@@ -1395,8 +1388,8 @@ const Mr = ({
1395
1388
  [we, Re]
1396
1389
  ), it = d.productName || "Live Layer";
1397
1390
  let _e = null, xe = null;
1398
- for (let h = v.length - 1; h >= 0; h--) {
1399
- const J = v[h];
1391
+ for (let h = b.length - 1; h >= 0; h--) {
1392
+ const J = b[h];
1400
1393
  if (!_e && J.role === "agent" ? _e = J : !xe && J.role === "user" && (xe = J), _e && xe) break;
1401
1394
  }
1402
1395
  const We = re ? (_e == null ? void 0 : _e.text) || null : l || null, yt = re && (xe == null ? void 0 : xe.text) || null, Be = [
@@ -1522,7 +1515,7 @@ const Mr = ({
1522
1515
  type: "button",
1523
1516
  className: "ll-hpill ll-hpill--compact",
1524
1517
  onClick: (h) => {
1525
- h.stopPropagation(), _();
1518
+ h.stopPropagation(), x();
1526
1519
  },
1527
1520
  "aria-haspopup": "listbox",
1528
1521
  "aria-expanded": A,
@@ -1556,8 +1549,8 @@ const Mr = ({
1556
1549
  /* @__PURE__ */ n(
1557
1550
  "span",
1558
1551
  {
1559
- className: `ll-expanded__state ll-expanded__state--${b}`,
1560
- children: b
1552
+ className: `ll-expanded__state ll-expanded__state--${v}`,
1553
+ children: v
1561
1554
  }
1562
1555
  )
1563
1556
  ] }),
@@ -1586,9 +1579,9 @@ const Mr = ({
1586
1579
  )
1587
1580
  ] })
1588
1581
  ] }),
1589
- ne && /* @__PURE__ */ g("div", { className: "ll-compact-status", "data-state": b, children: [
1582
+ ne && /* @__PURE__ */ g("div", { className: "ll-compact-status", "data-state": v, children: [
1590
1583
  /* @__PURE__ */ n("span", { className: "ll-compact-status__dot", "aria-hidden": !0 }),
1591
- /* @__PURE__ */ n("span", { className: "ll-compact-status__label", children: b })
1584
+ /* @__PURE__ */ n("span", { className: "ll-compact-status__label", children: v })
1592
1585
  ] })
1593
1586
  ] }) : (
1594
1587
  // Idle-state header with Live Layer product name + minimize/close.
@@ -1622,7 +1615,7 @@ const Mr = ({
1622
1615
  ] })
1623
1616
  ),
1624
1617
  Ze && /* @__PURE__ */ (() => {
1625
- const h = S ? "Resume session" : x === "disconnected" ? "Reconnect to agent" : "Start video call";
1618
+ const h = S ? "Resume session" : _ === "disconnected" ? "Reconnect to agent" : "Start video call";
1626
1619
  return /* @__PURE__ */ g(Ye, { children: [
1627
1620
  !D && /* @__PURE__ */ g(
1628
1621
  "button",
@@ -1849,7 +1842,7 @@ const Mr = ({
1849
1842
  ] })
1850
1843
  ] }) : null,
1851
1844
  (() => {
1852
- if (R && x !== "error")
1845
+ if (R && _ !== "error")
1853
1846
  return /* @__PURE__ */ g("div", { className: "ll-expanded__banner", role: "alert", children: [
1854
1847
  /* @__PURE__ */ n("span", { children: R }),
1855
1848
  /* @__PURE__ */ n(
@@ -1863,7 +1856,7 @@ const Mr = ({
1863
1856
  }
1864
1857
  )
1865
1858
  ] });
1866
- if (!D || x !== "error") return null;
1859
+ if (!D || _ !== "error") return null;
1867
1860
  let h = "Failed to connect", J = "Try again";
1868
1861
  return D === "MIC_PERMISSION_DENIED" ? h = "Microphone blocked. Allow access to talk." : D === "MIC_NOT_FOUND" ? h = "No microphone found. Plug one in + retry." : D === "MIC_UNAVAILABLE" ? h = "Mic unavailable. Check other apps using it." : D === "AGENT_TIMEOUT" ? h = "Agent didn't pick up. Try again." : D === "CONNECT_FAILED" ? h = "Connection failed. Check your network." : D.length < 80 && (h = D), /* @__PURE__ */ g("div", { className: "ll-expanded__banner ll-expanded__banner--error", role: "alert", children: [
1869
1862
  /* @__PURE__ */ n("span", { children: h }),
@@ -2106,28 +2099,28 @@ function qr(e, t = {}) {
2106
2099
  R.length > 10 && s.push(me(R, dn));
2107
2100
  }
2108
2101
  const c = s.join(`
2109
- `), A = [], _ = Array.from(r.querySelectorAll("a[href]"));
2110
- for (const k of _) {
2102
+ `), A = [], x = Array.from(r.querySelectorAll("a[href]"));
2103
+ for (const k of x) {
2111
2104
  if (A.length >= Pr) break;
2112
2105
  if (st(k) || !dt(k)) continue;
2113
2106
  const R = k.getAttribute("href") || "", B = (k.textContent || "").trim();
2114
2107
  !R || !B || A.push({ href: R, text: me(B, 100) });
2115
2108
  }
2116
- const x = [], b = Array.from(
2109
+ const _ = [], v = Array.from(
2117
2110
  r.querySelectorAll(
2118
2111
  "input, textarea, select"
2119
2112
  )
2120
2113
  );
2121
- for (const k of b) {
2122
- if (x.length >= $r) break;
2114
+ for (const k of v) {
2115
+ if (_.length >= $r) break;
2123
2116
  if (st(k) || !xt(k) || !dt(k)) continue;
2124
2117
  const R = un(k), B = k instanceof HTMLInputElement ? k.type : k.tagName.toLowerCase();
2125
- R && x.push({ label: me(R, 100), type: B });
2118
+ R && _.push({ label: me(R, 100), type: B });
2126
2119
  }
2127
- const v = Array.from(
2120
+ const b = Array.from(
2128
2121
  r.querySelectorAll("[data-ll-form]")
2129
2122
  ), S = [];
2130
- for (const k of v) {
2123
+ for (const k of b) {
2131
2124
  if (S.length >= Or) break;
2132
2125
  if (Mt(k)) continue;
2133
2126
  const R = k.getAttribute("data-ll-form") || "";
@@ -2169,7 +2162,7 @@ function qr(e, t = {}) {
2169
2162
  regions: a,
2170
2163
  visibleText: c,
2171
2164
  visibleLinks: A,
2172
- visibleFields: x,
2165
+ visibleFields: _,
2173
2166
  forms: S,
2174
2167
  extras: e
2175
2168
  };
@@ -2340,10 +2333,10 @@ const ro = /* @__PURE__ */ new Set([
2340
2333
  displayMode: f,
2341
2334
  defaultDisplayMode: c = "expanded",
2342
2335
  onDisplayModeChange: A,
2343
- position: _ = "bottom-right",
2344
- mobileBreakpoint: x = 640,
2345
- persistKey: b = "ll-widget",
2346
- disablePersistence: v = !1,
2336
+ position: x = "bottom-right",
2337
+ mobileBreakpoint: _ = 640,
2338
+ persistKey: v = "ll-widget",
2339
+ disablePersistence: b = !1,
2347
2340
  teamMembers: S,
2348
2341
  currentTeamMemberId: M,
2349
2342
  onTeamMemberChange: D,
@@ -2398,9 +2391,9 @@ const ro = /* @__PURE__ */ new Set([
2398
2391
  value: f,
2399
2392
  defaultValue: c,
2400
2393
  onChange: A,
2401
- persistKey: b,
2402
- disablePersistence: tt || v
2403
- }), de = lr(x), ve = Vn(), X = Yn(), ue = Jn(), be = Kn(), He = Xn(), [Lt, nt] = C(!1), [we, rt] = C(!1), [ot, it] = C(!1), [_e, xe] = C(!1), [We, yt] = C(!1), Be = yr({ baseUrl: l, config: s }), De = N(Be);
2394
+ persistKey: v,
2395
+ disablePersistence: tt || b
2396
+ }), de = lr(_), ve = Vn(), X = Yn(), ue = Jn(), be = Kn(), He = Xn(), [Lt, nt] = C(!1), [we, rt] = C(!1), [ot, it] = C(!1), [_e, xe] = C(!1), [We, yt] = C(!1), Be = yr({ baseUrl: l, config: s }), De = N(Be);
2404
2397
  De.current = Be;
2405
2398
  const h = N(ft), J = N(Je), Et = N(Xe), Ct = N(ht), Tt = N(pt), Dt = N(le), Pt = N(Ke), St = N(Qe), fe = N(null);
2406
2399
  h.current = ft, J.current = Je, Et.current = Xe, Ct.current = ht, Tt.current = pt, Dt.current = le, Pt.current = Ke, St.current = Qe;
@@ -3027,12 +3020,12 @@ const ro = /* @__PURE__ */ new Set([
3027
3020
  className: Dn,
3028
3021
  style: qe,
3029
3022
  "data-display-mode": oe,
3030
- "data-position": _,
3023
+ "data-position": x,
3031
3024
  "data-experience-mode": u === "EMBEDDED" ? "embedded" : "widget",
3032
3025
  children: oe === "expanded" && /* @__PURE__ */ n(
3033
3026
  Mr,
3034
3027
  {
3035
- position: _,
3028
+ position: x,
3036
3029
  isMobile: de,
3037
3030
  agentName: vt,
3038
3031
  avatarImageUrl: Nt,
@@ -3103,12 +3096,12 @@ const ro = /* @__PURE__ */ new Set([
3103
3096
  ].join(" "),
3104
3097
  style: qe,
3105
3098
  "data-display-mode": oe,
3106
- "data-position": _,
3099
+ "data-position": x,
3107
3100
  children: [
3108
3101
  oe === "hidden" && /* @__PURE__ */ n(
3109
3102
  kr,
3110
3103
  {
3111
- position: _,
3104
+ position: x,
3112
3105
  isMobile: de,
3113
3106
  isSpeaking: w.agentState === "speaking",
3114
3107
  onExpand: () => ie("expanded"),
@@ -3121,7 +3114,7 @@ const ro = /* @__PURE__ */ new Set([
3121
3114
  oe === "minimized" && /* @__PURE__ */ n(
3122
3115
  Er,
3123
3116
  {
3124
- position: _,
3117
+ position: x,
3125
3118
  isMobile: de,
3126
3119
  agentName: vt,
3127
3120
  avatarImageUrl: Nt,
@@ -3253,8 +3246,8 @@ function bo({
3253
3246
  const [o, i] = C(t), [l, d] = C([]), [a, s] = C(""), [u, y] = C(!1), f = N(/* @__PURE__ */ new Set()), c = N([]), A = N(u);
3254
3247
  A.current = u, I(() => {
3255
3248
  try {
3256
- const b = localStorage.getItem(r);
3257
- b === "1" && i(!0), b === "0" && i(!1);
3249
+ const v = localStorage.getItem(r);
3250
+ v === "1" && i(!0), v === "0" && i(!1);
3258
3251
  } catch {
3259
3252
  }
3260
3253
  }, [r]), I(() => {
@@ -3263,33 +3256,33 @@ function bo({
3263
3256
  } catch {
3264
3257
  }
3265
3258
  }, [o, r]), I(() => {
3266
- const b = (v) => {
3267
- (v.metaKey || v.ctrlKey) && v.shiftKey && v.key.toLowerCase() === "l" && (v.preventDefault(), i((S) => !S));
3259
+ const v = (b) => {
3260
+ (b.metaKey || b.ctrlKey) && b.shiftKey && b.key.toLowerCase() === "l" && (b.preventDefault(), i((S) => !S));
3268
3261
  };
3269
- return window.addEventListener("keydown", b), () => window.removeEventListener("keydown", b);
3262
+ return window.addEventListener("keydown", v), () => window.removeEventListener("keydown", v);
3270
3263
  }, []), I(() => {
3271
- const b = setInterval(() => {
3264
+ const v = setInterval(() => {
3272
3265
  if (c.current.length === 0 || A.current) return;
3273
- const v = c.current.splice(0, c.current.length);
3266
+ const b = c.current.splice(0, c.current.length);
3274
3267
  d(
3275
- (S) => [...v.reverse(), ...S].slice(0, 200)
3268
+ (S) => [...b.reverse(), ...S].slice(0, 200)
3276
3269
  );
3277
3270
  }, 100);
3278
- return () => clearInterval(b);
3271
+ return () => clearInterval(v);
3279
3272
  }, []);
3280
- const _ = N(!1);
3273
+ const x = N(!1);
3281
3274
  if (I(() => {
3282
- !e || _.current || (_.current = !0, e((b) => {
3275
+ !e || x.current || (x.current = !0, e((v) => {
3283
3276
  c.current.push({
3284
3277
  id: hn++,
3285
3278
  ts: Date.now(),
3286
3279
  kind: "event",
3287
- type: b.eventName,
3288
- data: b.data
3280
+ type: v.eventName,
3281
+ data: v.data
3289
3282
  });
3290
3283
  }));
3291
3284
  }, [e]), I(() => {
3292
- const b = console.warn, v = console.log, S = (M, D) => function(...k) {
3285
+ const v = console.warn, b = console.log, S = (M, D) => function(...k) {
3293
3286
  try {
3294
3287
  const R = typeof k[0] == "string" ? k[0] : "";
3295
3288
  R.startsWith("[LiveLayer]") && c.current.push({
@@ -3303,8 +3296,8 @@ function bo({
3303
3296
  }
3304
3297
  return D.apply(this, k);
3305
3298
  };
3306
- return console.warn = S("warn", b), console.log = S("log", v), () => {
3307
- console.warn = b, console.log = v;
3299
+ return console.warn = S("warn", v), console.log = S("log", b), () => {
3300
+ console.warn = v, console.log = b;
3308
3301
  };
3309
3302
  }, []), !o)
3310
3303
  return /* @__PURE__ */ n(
@@ -3333,10 +3326,10 @@ function bo({
3333
3326
  children: "🛰 LL debug"
3334
3327
  }
3335
3328
  );
3336
- const x = l.filter((b) => {
3329
+ const _ = l.filter((v) => {
3337
3330
  if (!a) return !0;
3338
- const v = a.toLowerCase();
3339
- return b.type.toLowerCase().includes(v) || JSON.stringify(b.data || {}).toLowerCase().includes(v);
3331
+ const b = a.toLowerCase();
3332
+ return v.type.toLowerCase().includes(b) || JSON.stringify(v.data || {}).toLowerCase().includes(b);
3340
3333
  });
3341
3334
  return /* @__PURE__ */ g(
3342
3335
  "div",
@@ -3383,7 +3376,7 @@ function bo({
3383
3376
  "button",
3384
3377
  {
3385
3378
  type: "button",
3386
- onClick: () => y((b) => !b),
3379
+ onClick: () => y((v) => !v),
3387
3380
  style: Rt(u ? "#f59e0b" : "transparent"),
3388
3381
  title: "Pause / resume capture",
3389
3382
  children: u ? "▶ resume" : "⏸ pause"
@@ -3420,7 +3413,7 @@ function bo({
3420
3413
  {
3421
3414
  type: "text",
3422
3415
  value: a,
3423
- onChange: (b) => s(b.target.value),
3416
+ onChange: (v) => s(v.target.value),
3424
3417
  placeholder: "filter by type or data…",
3425
3418
  style: {
3426
3419
  margin: 8,
@@ -3442,7 +3435,7 @@ function bo({
3442
3435
  overflowY: "auto",
3443
3436
  padding: "0 8px 8px"
3444
3437
  },
3445
- children: x.length === 0 ? /* @__PURE__ */ g(
3438
+ children: _.length === 0 ? /* @__PURE__ */ g(
3446
3439
  "div",
3447
3440
  {
3448
3441
  style: {
@@ -3472,16 +3465,16 @@ function bo({
3472
3465
  )
3473
3466
  ]
3474
3467
  }
3475
- ) : x.map((b) => /* @__PURE__ */ n(
3468
+ ) : _.map((v) => /* @__PURE__ */ n(
3476
3469
  io,
3477
3470
  {
3478
- entry: b,
3479
- expanded: f.current.has(b.id),
3471
+ entry: v,
3472
+ expanded: f.current.has(v.id),
3480
3473
  onToggle: () => {
3481
- f.current.has(b.id) ? f.current.delete(b.id) : f.current.add(b.id), d((v) => [...v]);
3474
+ f.current.has(v.id) ? f.current.delete(v.id) : f.current.add(v.id), d((b) => [...b]);
3482
3475
  }
3483
3476
  },
3484
- b.id
3477
+ v.id
3485
3478
  ))
3486
3479
  }
3487
3480
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livelayer/react",
3
- "version": "0.10.4",
3
+ "version": "0.10.6",
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",