@livelayer/react 0.23.0 → 0.23.2

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 n=require("react/jsx-runtime"),r=require("react"),tn=require("react-dom"),nt=require("@livelayer/sdk"),Pt=require("livekit-client");class Gn extends r.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,i){var o,a;(a=(o=this.props).onError)==null||a.call(o,t,i)}render(){var t;return this.state.hasError?this.props.fallback?this.props.fallback:n.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[n.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),n.jsx("p",{className:"ll-error-boundary__message",children:((t=this.state.error)==null?void 0:t.message)||"Something went wrong."}),n.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function Xn(e){const[t,i]=r.useState("idle"),[o,a]=r.useState("idle"),[s,c]=r.useState([]),[l,u]=r.useState(null),[d,g]=r.useState(null),[h,m]=r.useState(null),[N,_]=r.useState(!1),[S,y]=r.useState(null),w=r.useRef(null),R=r.useRef(e.onDataMessage);R.current=e.onDataMessage,r.useEffect(()=>{const b={onConnectionStateChange:z=>{i(z),z==="connected"&&y(null)},onAgentStateChange:a,onTranscript:z=>c([...z]),onAgentConfig:u,onAudioTrack:z=>m(z),onVideoTrack:z=>g(z),onVideoTrackRemoved:()=>g(null),onError:z=>y(z),onDataMessage:z=>{var Y;(Y=R.current)==null||Y.call(R,z)},onResumabilityChange:_},M=new nt.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},b);return w.current=M,i("idle"),a("idle"),c([]),u(null),g(null),m(null),_(!1),y(null),()=>{var z;(z=M.destroy)==null||z.call(M),w.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=r.useCallback(async()=>{const b=w.current;if(b)try{await b.connect()}catch(M){throw y(M instanceof Error?M.message:String(M)),M}},[]),v=r.useCallback(()=>{const b=w.current;b&&b.disconnect()},[]),P=r.useCallback(()=>{var b;return((b=w.current)==null?void 0:b.getRoom())??null},[]);return{connectionState:t,agentState:o,transcript:s,agentConfig:l,videoElement:d,audioElement:h,canResume:N,error:S,connect:E,disconnect:v,getRoom:P,session:w.current}}function Kn(){const e=r.useRef(null),t=r.useRef(new Map),i=r.useRef(null),o=r.useRef(new Set),a=r.useCallback(()=>{const _=t.current;if(_.size===0){i.current=null;return}let S=0;for(const{analyser:y,buffer:w}of _.values()){y.getByteFrequencyData(w);let R=0;for(let v=0;v<w.length;v++)R+=w[v];const E=R/w.length/255;E>S&&(S=E)}for(const y of o.current)try{y(S)}catch(w){console.error("[useAudioLevel] subscriber threw:",w)}i.current=requestAnimationFrame(a)},[]),s=r.useCallback(()=>e.current?e.current:typeof window>"u"||typeof AudioContext>"u"?null:(e.current=new AudioContext,e.current),[]),c=r.useCallback(()=>{i.current===null&&t.current.size>0&&(i.current=requestAnimationFrame(a))},[a]),l=r.useCallback(_=>{const S=t.current.get(_);if(S){try{S.node.disconnect()}catch{}try{S.analyser.disconnect()}catch{}t.current.delete(_)}},[]),u=r.useCallback((_,S)=>{const y=s();if(!y)return;l(_);const w=S(y);if(!w)return;const R=y.createAnalyser();R.fftSize=64;try{w.connect(R)}catch(E){console.warn("[useAudioLevel] connect failed for slot",_,E);return}t.current.set(_,{analyser:R,node:w,buffer:new Uint8Array(new ArrayBuffer(R.frequencyBinCount))}),c()},[l,s,c]),d=r.useCallback((_,S="agent")=>{u(S,y=>{try{return y.createMediaElementSource(_)}catch(w){return console.warn("[useAudioLevel] createMediaElementSource failed for slot",S,w),null}})},[u]),g=r.useCallback((_,S="mic")=>{u(S,y=>{try{return y.createMediaStreamSource(_)}catch(w){return console.warn("[useAudioLevel] createMediaStreamSource failed for slot",S,w),null}})},[u]),h=r.useCallback(_=>{l(_),t.current.size===0&&i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[l]),m=r.useCallback(()=>{i.current!==null&&(cancelAnimationFrame(i.current),i.current=null);for(const _ of Array.from(t.current.keys()))l(_)},[l]),N=r.useCallback(_=>(o.current.add(_),()=>{o.current.delete(_)}),[]);return r.useEffect(()=>()=>{if(m(),e.current){try{e.current.close()}catch{}e.current=null}o.current.clear()},[m]),{attach:d,attachStream:g,detach:m,detachSlot:h,subscribe:N}}function Or(e){const t=e==null?void 0:e.mediaStreamTrack;return t?new MediaStream([t]):null}function Jn(e={}){const t=e.gateUntilAgentReady??!1,i=e.agentState??null,[o,a]=r.useState(t),[s,c]=r.useState(""),[l,u]=r.useState(null),d=r.useRef(null),g=r.useRef(null),h=r.useRef({active:t,lastAutoIntent:null}),m=r.useCallback(async E=>{var v,P;if(d.current&&g.current){try{await g.current.localParticipant.unpublishTrack(d.current)}catch{}d.current.stop(),d.current=null}g.current=E,u(null);try{const b=await Pt.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await E.localParticipant.publishTrack(b),d.current=b,h.current.active?(await E.localParticipant.setMicrophoneEnabled(!1),h.current.lastAutoIntent=!1,a(!0)):a(b.isMuted);const M=(P=(v=b.mediaStreamTrack)==null?void 0:v.getSettings)==null?void 0:P.call(v);M!=null&&M.deviceId&&c(M.deviceId)}catch(b){const M=b instanceof Error&&b.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw u(M),b}},[]),N=r.useCallback(E=>{g.current=E},[]),_=r.useCallback(async E=>{const v=g.current;if(v)try{await v.switchActiveDevice("audioinput",E),c(E)}catch(P){console.warn("[useMicrophoneState] switchDevice failed:",P)}},[]),S=r.useCallback(async()=>{const E=g.current,v=!o;if(a(v),h.current.active=!1,!!E)try{await E.localParticipant.setMicrophoneEnabled(!v)}catch(P){console.warn("[useMicrophoneState] setMicrophoneEnabled failed:",P),a(!v)}},[o]);r.useEffect(()=>{if(!h.current.active||i!=="listening")return;const E=g.current,v=E==null?void 0:E.localParticipant;if(!v){h.current.active=!1;return}v.isMicrophoneEnabled===h.current.lastAutoIntent&&(v.setMicrophoneEnabled(!0),h.current.lastAutoIntent=!0,a(!1)),h.current.active=!1},[i]);const y=r.useCallback(()=>{const E=d.current,v=g.current;if(E&&v){try{v.localParticipant.unpublishTrack(E)}catch{}E.stop()}d.current=null,g.current=null,h.current={active:t,lastAutoIntent:null},a(t),c("")},[t]),w=r.useCallback(()=>u(null),[]),R=r.useCallback(()=>Or(d.current),[]);return{isMuted:o,activeDeviceId:s,micError:l,toggleMute:S,setupMic:m,attachRoom:N,switchDevice:_,teardownMic:y,clearError:w,getMicStream:R}}const Wr={resolution:{width:640,height:480,frameRate:24}};function Zn(){const[e,t]=r.useState(!1),[i,o]=r.useState(null),[a,s]=r.useState(null),[c,l]=r.useState(""),u=r.useRef(null),d=r.useRef(null),g=r.useCallback(w=>{u.current=w},[]),h=r.useCallback(()=>{var E;const w=u.current,R=d.current;if(R&&w){const v=w.localParticipant.getTrackPublication(Pt.Track.Source.Camera),b=(v==null?void 0:v.track)??R;try{w.localParticipant.unpublishTrack(b)}catch{}try{(E=b.stop)==null||E.call(b)}catch{}}d.current=null,s(null),t(!1)},[]),m=r.useCallback(async w=>{const R=u.current;if(R){o(null);try{const E={...Wr};w&&(E.deviceId=w);const v=await Pt.createLocalVideoTrack(E);await R.localParticipant.publishTrack(v),d.current=v;const P=v.attach();s(P),t(!0),w&&l(w);try{R.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const v=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";o(v)}}},[]),N=r.useCallback(async()=>{e?h():await m(c||void 0)},[e,c,h,m]),_=r.useCallback(async w=>{h(),await m(w)},[h,m]),S=r.useCallback(()=>{h(),u.current=null,o(null),l("")},[h]),y=r.useCallback(()=>o(null),[]);return r.useEffect(()=>()=>{d.current&&d.current.stop()},[]),{isEnabled:e,error:i,previewEl:a,activeDeviceId:c,toggle:N,switchDevice:_,attachRoom:g,teardown:S,clearError:y}}function Qn(){const[e,t]=r.useState(!1),[i,o]=r.useState(null),[a,s]=r.useState(null),c=r.useRef(null),l=r.useCallback(m=>{c.current=m},[]),u=r.useCallback(()=>s(null),[]),d=r.useCallback(async()=>{const m=c.current;if(m){if(e){try{await m.localParticipant.setScreenShareEnabled(!1)}catch{}u(),t(!1);return}o(null);try{await m.localParticipant.setScreenShareEnabled(!0);let N=0;const _=()=>{const S=m.localParticipant.getTrackPublication(Pt.Track.Source.ScreenShare);if(S!=null&&S.track){const y=S.track.attach();s(y),t(!0);try{m.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}N++<10?setTimeout(_,100):t(!0)};_()}catch(N){const _=N instanceof Error?N.name:"";_!=="NotAllowedError"&&_!=="AbortError"&&o("Screen share unavailable. Try again."),t(!1)}}},[e,u]),g=r.useCallback(()=>{const m=c.current;if(m&&e)try{m.localParticipant.setScreenShareEnabled(!1)}catch{}u(),t(!1),o(null),c.current=null},[e,u]),h=r.useCallback(()=>o(null),[]);return{isEnabled:e,error:i,previewEl:a,toggle:d,attachRoom:l,teardown:g,clearError:h}}function er(){const[e,t]=r.useState([]),[i,o]=r.useState([]),a=r.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const s=await navigator.mediaDevices.enumerateDevices();t(s.filter(c=>c.kind==="audioinput")),o(s.filter(c=>c.kind==="videoinput"))}catch{}},[]);return r.useEffect(()=>{if(a(),typeof navigator>"u"||!navigator.mediaDevices)return;const s=()=>void a();return navigator.mediaDevices.addEventListener("devicechange",s),()=>navigator.mediaDevices.removeEventListener("devicechange",s)},[a]),{mics:e,cameras:i,refresh:a}}function tr(e,t,i=!1){const[o,a]=r.useState(null),[s,c]=r.useState(null),[l,u]=r.useState(!i&&!!e);return r.useEffect(()=>{if(i||!e){u(!1);return}const d=new AbortController,g=t||"https://app.livelayer.studio";return u(!0),c(null),fetch(`${g}/api/widget/agent/${encodeURIComponent(e)}`,{signal:d.signal}).then(async h=>{if(!h.ok){const m=await h.json().catch(()=>({}));throw new Error(m.error||`HTTP ${h.status}`)}return h.json()}).then(h=>{d.signal.aborted||(a(h),u(!1))}).catch(h=>{d.signal.aborted||(c(h instanceof Error?h.message:"Agent lookup failed"),u(!1))}),()=>d.abort()},[e,t,i]),{info:o,error:s,loading:l}}function nr(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function rr(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function qr(e){if(!(typeof window>"u"))try{window.localStorage.removeItem(e)}catch{}}function ir({value:e,defaultValue:t="expanded",onChange:i}={}){const o=e!==void 0,[a,s]=r.useState(t),c=o?e:a,l=r.useCallback(u=>{u!==c&&(o||s(u),i==null||i(u))},[c,o,i]);return[c,l]}const Br=["hidden","minimized","expanded"];function Ur(e){return e&&Br.includes(e)?e:null}function or({value:e,defaultValue:t="expanded",onChange:i,persistKey:o="ll-widget",disablePersistence:a=!1}={}){const s=`${o}:display-mode`,c=r.useRef(!1),[l,u]=ir({value:e,defaultValue:t,onChange:d=>{e===void 0&&!a&&rr(s,d),i==null||i(d)}});return r.useEffect(()=>{if(c.current||(c.current=!0,a||e!==void 0))return;const d=Ur(nr(s));d&&d!==l&&u(d)},[]),[l,u]}const Vr=640;function sr(e=Vr){const[t,i]=r.useState(!1);return r.useEffect(()=>{if(e===!1){i(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const o=`(max-width: ${e-1}px)`,a=window.matchMedia(o),s=()=>i(a.matches);return s(),typeof a.addEventListener=="function"?(a.addEventListener("change",s),()=>a.removeEventListener("change",s)):(a.addListener(s),()=>{a.removeListener(s)})},[e]),t}const Yr=280,Gr=380,Xr=8,Kr=4;function Yt(e){return`${e}:geometry`}function Jr(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!="object"||t===null)return null;const i=t,{top:o,left:a,width:s,height:c}=i;return typeof o!="number"||typeof a!="number"||typeof s!="number"||typeof c!="number"||!Number.isFinite(o)||!Number.isFinite(a)||!Number.isFinite(s)||!Number.isFinite(c)?null:{top:o,left:a,width:s,height:c}}function Nt(){return typeof window>"u"?{vw:0,vh:0}:{vw:window.innerWidth,vh:window.innerHeight}}function Gt(e,t,i){const{minWidth:o,minHeight:a,edgeMargin:s,vw:c,vh:l}=i,u=Math.max(o,c-s*2),d=Math.max(a,l-s*2);return{width:Math.max(o,Math.min(u,e)),height:Math.max(a,Math.min(d,t))}}function Xt(e,t,i,o,a){const{edgeMargin:s,vw:c,vh:l}=a,u=s,d=s,g=Math.max(u,c-i-s),h=Math.max(d,l-o-s);return{top:Math.max(d,Math.min(h,e)),left:Math.max(u,Math.min(g,t))}}function Zr(e){const{draggable:t,resizable:i,persistKey:o,disablePersistence:a,minWidth:s=Yr,minHeight:c=Gr,edgeMargin:l=Xr}=e,[u,d]=r.useState(null),[g,h]=r.useState(!1),[m,N]=r.useState(!1),_=r.useRef(null),S=r.useRef(null),y=r.useRef(!1),w=r.useRef(null);w.current=u;const R=r.useCallback(p=>{a||(p===null?qr(Yt(o)):rr(Yt(o),JSON.stringify(p)))},[a,o]);r.useEffect(()=>{if(y.current||(y.current=!0,a))return;const p=Jr(nr(Yt(o)));if(!p)return;const{vw:L,vh:I}=Nt(),H=Gt(p.width,p.height,{minWidth:s,minHeight:c,edgeMargin:l,vw:L,vh:I}),U=Xt(p.top,p.left,H.width,H.height,{edgeMargin:l,vw:L,vh:I});d({...U,...H})},[]),r.useEffect(()=>{if(typeof window>"u")return;const p=()=>{d(L=>{if(L===null)return null;const{vw:I,vh:H}=Nt(),U=Gt(L.width,L.height,{minWidth:s,minHeight:c,edgeMargin:l,vw:I,vh:H});return{...Xt(L.top,L.left,U.width,U.height,{edgeMargin:l,vw:I,vh:H}),...U}})};return window.addEventListener("resize",p),()=>window.removeEventListener("resize",p)},[s,c,l]);const E=r.useCallback(p=>{if(!t||p.pointerType==="mouse"&&p.button!==0)return;const L=p.target;if(L&&typeof L.closest=="function"&&L.closest('button, a, input, select, textarea, [role="listbox"], [role="option"], [data-ll-no-drag]'))return;let I,H,U,K;const $=w.current;if($)({top:I,left:H,width:U,height:K}=$);else{const J=p.currentTarget.closest(".ll-widget"),te=J==null?void 0:J.getBoundingClientRect();if(!te)return;I=te.top,H=te.left,U=te.width,K=te.height}try{p.currentTarget.setPointerCapture(p.pointerId)}catch{}_.current={startClientX:p.clientX,startClientY:p.clientY,startTop:I,startLeft:H,width:U,height:K,moved:!1}},[t]),v=r.useCallback(p=>{const L=_.current;if(!L)return;const I=p.clientX-L.startClientX,H=p.clientY-L.startClientY;if(!L.moved&&Math.abs(I)+Math.abs(H)>Kr&&(L.moved=!0,h(!0)),!L.moved)return;const{vw:U,vh:K}=Nt(),$=Xt(L.startTop+H,L.startLeft+I,L.width,L.height,{edgeMargin:l,vw:U,vh:K});d({...$,width:L.width,height:L.height})},[l]),P=r.useCallback(p=>{const L=_.current;if(L){try{p.currentTarget.releasePointerCapture(p.pointerId)}catch{}_.current=null,L.moved&&(h(!1),d(I=>(I&&R(I),I)))}},[R]),b=r.useCallback(()=>{_.current=null,S.current=null,h(!1),N(!1),d(null),R(null)},[R]),M=r.useCallback(p=>{if(!i||p.pointerType==="mouse"&&p.button!==0)return;p.stopPropagation();let L,I,H,U;const K=w.current;if(K)({top:L,left:I,width:H,height:U}=K);else{const $=p.currentTarget.closest(".ll-widget"),J=$==null?void 0:$.getBoundingClientRect();if(!J)return;L=J.top,I=J.left,H=J.width,U=J.height}try{p.currentTarget.setPointerCapture(p.pointerId)}catch{}S.current={startClientX:p.clientX,startClientY:p.clientY,startWidth:H,startHeight:U,top:L,left:I},N(!0)},[i]),z=r.useCallback(p=>{const L=S.current;if(!L)return;const I=p.clientX-L.startClientX,H=p.clientY-L.startClientY,{vw:U,vh:K}=Nt(),$=U-L.left-l,J=K-L.top-l,te=Gt(L.startWidth+I,L.startHeight+H,{minWidth:s,minHeight:c,edgeMargin:l,vw:Math.min(U,L.left+$+l),vh:Math.min(K,L.top+J+l)});d({top:L.top,left:L.left,...te})},[l,s,c]),Y=r.useCallback(p=>{if(S.current){try{p.currentTarget.releasePointerCapture(p.pointerId)}catch{}S.current=null,N(!1),d(I=>(I&&R(I),I))}},[R]);return{style:u===null?{}:{position:"fixed",top:`${u.top}px`,left:`${u.left}px`,right:"auto",bottom:"auto",width:`${u.width}px`,height:`${u.height}px`},hasGeometry:u!==null,isDragging:g,isResizing:m,dragHandleProps:{onPointerDown:E,onPointerMove:v,onPointerUp:P,onPointerCancel:P,onDoubleClick:b,"data-ll-drag-handle":t?"":void 0},resizeHandleProps:{onPointerDown:M,onPointerMove:z,onPointerUp:Y,onPointerCancel:Y,"data-ll-resize-handle":i?"":void 0},reset:b}}const Sn="__llHistoryPatched",Dt="ll:pathname";function Qr(){if(typeof window>"u"||window.history[Sn])return;const e=window.history.pushState,t=window.history.replaceState;window.history.pushState=function(...i){const o=e.apply(this,i);return window.dispatchEvent(new Event(Dt)),o},window.history.replaceState=function(...i){const o=t.apply(this,i);return window.dispatchEvent(new Event(Dt)),o},window.history[Sn]=!0}function En(){return typeof window>"u"?"/":window.location.pathname||"/"}function ar(e){const[t,i]=r.useState(()=>e??En());return r.useEffect(()=>{if(e!==void 0)return;Qr();const o=()=>i(En());return o(),window.addEventListener("popstate",o),window.addEventListener(Dt,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(Dt,o)}},[e]),e??t}const Ln=new Map,ei=/[\\^$+?.()|{}[\]]/g;function ti(e){return e.replace(ei,"\\$&")}function ni(e){const t=Ln.get(e);if(t)return t;const i=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,o="",a="",s=i.replace(/\*\*/g,o).replace(/\*/g,a),l=ti(s).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(a,"g"),"[^/]+"),u=new RegExp(`^${l}\\/?$`);return Ln.set(e,u),u}function ri(e,t){const i=t.length>1&&t.endsWith("/")?t.slice(0,-1):t;return ni(e).test(i)}function lr(e,t){return typeof e=="function"?e(t):e instanceof RegExp?e.test(t):ri(e,t)}function jn(e,t){if(!e||e.length===0)return!1;for(const i of e)if(lr(i,t))return!0;return!1}function cr(e,t,i){return e===void 0?!0:jn(i,e)?!1:t&&t.length>0?jn(t,e):!0}function ur(e,t,i){return r.useMemo(()=>cr(e,t,i),[e,t,i])}function ii(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 oi(e){const t=r.useMemo(()=>ii(e.config),[e.config]),i=e.baseUrl.replace(/\/+$/,""),o=r.useRef(null),a=r.useCallback(u=>{try{new Audio(`${i}${u}`).play().catch(()=>{})}catch{}},[i]),s=r.useCallback(()=>{t.navigate&&a("/audio/page-change-sound.mp3")},[t.navigate,a]),c=r.useCallback(()=>{t.action&&a("/audio/confirmation-sound.mp3")},[t.action,a]),l=r.useCallback(u=>{if(!t.thinking){if(o.current){try{o.current.pause()}catch{}o.current=null}return}if(u){if(o.current)return;try{const d=new Audio(`${i}/audio/thinking-sound.mp3`);d.loop=!0,d.volume=.3,d.play().catch(()=>{o.current=null}),o.current=d}catch{}}else if(o.current){try{o.current.pause()}catch{}o.current=null}},[i,t.thinking]);return r.useEffect(()=>()=>{if(o.current){try{o.current.pause()}catch{}o.current=null}},[]),r.useMemo(()=>({playPageChange:s,playConfirmation:c,setThinking:l}),[s,c,l])}const An=({muted:e=!1,className:t})=>e?n.jsxs("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[n.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"}),n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):n.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"})}),Rn=({className:e})=>n.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:n.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"})}),si=({className:e})=>n.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),ai={left:180,right:0,up:-90,down:90},Nn=({direction:e="right",className:t})=>n.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${ai[e]}deg)`},"aria-hidden":"true",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function li(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const dr="ll-hidden-tab-center-y",ci=5,Mn=16;function ui(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(dr);if(!e)return null;const t=Number.parseFloat(e);return Number.isFinite(t)?t:null}catch{return null}}function In(e){if(!(typeof window>"u"))try{window.localStorage.setItem(dr,String(e))}catch{}}const di=({position:e,isMobile:t,isSpeaking:i,onExpand:o,label:a="Open widget",avatarImageUrl:s,agentName:c,containerEl:l})=>{const u=li(e),d=u==="right"?"left":"right",g=t?80:72,h=!!s,m=!!l,[N,_]=r.useState(null),[S,y]=r.useState(!1),w=r.useRef(null),R=r.useRef(!1),E=r.useCallback(T=>{if(typeof window>"u")return T;const B=g/2,p=Mn+B,L=window.innerHeight-Mn-B;return L<p?Math.max(p,T):Math.max(p,Math.min(L,T))},[g]);r.useEffect(()=>{if(m){_(null);return}const T=ui();_(E(T??window.innerHeight/2));const B=()=>{_(p=>p===null?null:E(p))};return window.addEventListener("resize",B),()=>window.removeEventListener("resize",B)},[E,m]);const v=r.useCallback(T=>{if(!m&&!(T.pointerType==="mouse"&&T.button!==0)&&N!==null){try{T.currentTarget.setPointerCapture(T.pointerId)}catch{}w.current={startClientY:T.clientY,startCenterY:N,moved:!1}}},[N,m]),P=r.useCallback(T=>{const B=w.current;if(!B)return;const p=T.clientY-B.startClientY;!B.moved&&Math.abs(p)>ci&&(B.moved=!0,y(!0)),B.moved&&_(E(B.startCenterY+p))},[E]),b=r.useCallback(T=>{const B=w.current;if(B){try{T.currentTarget.releasePointerCapture(T.pointerId)}catch{}w.current=null,B.moved&&(y(!1),R.current=!0,_(p=>(p!==null&&In(p),p)))}},[]),M=r.useCallback(()=>{if(R.current){R.current=!1;return}o()},[o]),z=r.useCallback(T=>{if(T.key==="ArrowUp"||T.key==="ArrowDown"){T.preventDefault();const B=T.key==="ArrowUp"?-8:8;_(p=>{if(p===null)return p;const L=E(p+B);return In(L),L})}},[E]),Y=["ll-hidden",`ll-hidden--${u}`,t?"ll-hidden--mobile":"ll-hidden--desktop",i?"ll-hidden--speaking":null,S?"is-dragging":null,h?"ll-hidden--with-avatar":null,m?"ll-hidden--scoped":null].filter(Boolean).join(" "),re=N===null?void 0:{top:`${N-g/2}px`,transform:"none"};return n.jsx("button",{type:"button",className:Y,onPointerDown:v,onPointerMove:P,onPointerUp:b,onPointerCancel:b,onClick:M,onKeyDown:z,"aria-label":a,"data-position":e,style:re,children:h?n.jsxs(n.Fragment,{children:[n.jsx(Nn,{direction:d,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),n.jsx("img",{src:s,alt:c?`${c} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):n.jsx(Nn,{direction:d,className:"ll-hidden__chevron"})})},fi=({audioLevel:e,bars:t=20,maxHeight:i=20,minHeight:o=4,className:a,barClassName:s})=>{const c=r.useRef(null),l=r.useRef([]),u=r.useMemo(()=>{const g=(Math.sqrt(5)-1)/2;return Array.from({length:t},(h,m)=>.5+m*g%1*.5)},[t]);r.useEffect(()=>e.subscribe(h=>{for(let m=0;m<t;m++){const N=l.current[m];if(!N)continue;const _=Math.max(o,h*i*u[m]);N.style.height=`${_}px`}}),[e,t,i,o,u]);const d=["ll-waveform",a].filter(Boolean).join(" ");return n.jsx("div",{ref:c,className:d,"aria-hidden":"true",children:Array.from({length:t},(g,h)=>n.jsx("div",{ref:m=>{l.current[h]=m},className:["ll-waveform__bar",s].filter(Boolean).join(" "),style:{height:`${o}px`}},h))})},pi=({position:e,isMobile:t,agentName:i,avatarImageUrl:o,agentState:a,isMuted:s,audioLevel:c,onExpand:l,onToggleMute:u,onClose:d})=>t?n.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${i} widget`,children:n.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:l,"aria-label":`Expand ${i} widget`,children:[o?n.jsx("img",{src:o,alt:i,className:"ll-minimized__avatar"}):n.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),n.jsx(fi,{audioLevel:c,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),n.jsx("span",{className:"ll-minimized__name",children:i}),n.jsxs("div",{className:"ll-minimized__controls",children:[n.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:g=>{g.stopPropagation(),u()},onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.stopPropagation(),g.preventDefault(),u())},"aria-label":s?"Unmute microphone":"Mute microphone",children:n.jsx(An,{muted:s,className:"ll-minimized__icon"})}),n.jsx(Rn,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):n.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${i} widget`,children:n.jsxs("div",{className:"ll-minimized__surface",children:[o?n.jsx("img",{src:o,alt:i,className:"ll-minimized__avatar"}):n.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),n.jsxs("div",{className:"ll-minimized__meta",children:[n.jsx("span",{className:"ll-minimized__name",children:i}),n.jsx("span",{className:"ll-minimized__state",children:a==="speaking"?"Speaking":a==="thinking"?"Thinking":"Listening"})]}),n.jsxs("div",{className:"ll-minimized__controls",children:[n.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:u,"aria-label":s?"Unmute microphone":"Mute microphone",children:n.jsx(An,{muted:s,className:"ll-minimized__icon"})}),n.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:l,"aria-label":`Expand ${i} widget`,children:n.jsx(Rn,{className:"ll-minimized__icon"})}),n.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:d,"aria-label":"Close widget",children:n.jsx(si,{className:"ll-minimized__icon"})})]})]})}),hi=({src:e,alt:t,preCannedPlaying:i=!1,className:o,style:a})=>{const[s,c]=r.useState(!1),l=r.useRef(e);if(r.useEffect(()=>{l.current!==e&&(l.current=e,c(!1))},[e]),!e)return null;const u={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:i?"scale(1.02)":"scale(1)",opacity:s?1:0,...a};return n.jsx("img",{src:e,alt:t,className:o,style:u,loading:"eager",fetchPriority:"high",onLoad:()=>c(!0)})},mi="#E06540";function gi({size:e=14,className:t,fill:i=mi}){return n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 52 52",fill:"none",className:t,"aria-hidden":!0,children:[n.jsx("path",{d:"M44.5714 26C44.5714 23.5612 44.0908 21.146 43.1575 18.8928C42.2242 16.6397 40.8565 14.5924 39.132 12.868C37.4076 11.1435 35.3603 9.77577 33.1072 8.84247C30.854 7.90917 28.4388 7.42857 26 7.42857C23.5612 7.42857 21.146 7.90916 18.8928 8.84247C16.6397 9.77577 14.5924 11.1435 12.868 12.868C11.1435 14.5924 9.77577 16.6397 8.84247 18.8928C7.90917 21.146 7.42857 23.5612 7.42857 26C7.42857 28.4388 7.90916 30.854 8.84247 33.1072C9.77577 35.3603 11.1435 37.4076 12.868 39.132C14.5924 40.8565 16.6397 42.2242 18.8928 43.1575C21.146 44.0908 23.5612 44.5714 26 44.5714H48.2857C50.3371 44.5714 52 46.2344 52 48.2857C52 50.3371 50.3371 52 48.2857 52H26C22.5857 52 19.2049 51.3275 16.0505 50.021C12.896 48.7144 10.0293 46.7993 7.61501 44.385C5.20069 41.9707 3.28564 39.104 1.97902 35.9495C0.67247 32.7951 -3.54212e-07 29.4143 0 26C-1.68163e-07 22.5857 0.672469 19.2049 1.97902 16.0505C3.28564 12.896 5.20069 10.0293 7.61501 7.61501C10.0293 5.20069 12.896 3.28564 16.0505 1.97902C19.2049 0.67247 22.5857 0 26 0C29.4143 1.86048e-07 32.7951 0.67247 35.9495 1.97902C39.104 3.28564 41.9707 5.20069 44.385 7.61501C46.7993 10.0293 48.7144 12.896 50.021 16.0505C51.3275 19.2049 52 22.5857 52 26C52 28.0513 50.3371 29.7143 48.2857 29.7143C46.2344 29.7143 44.5714 28.0513 44.5714 26Z",fill:i}),n.jsx("path",{d:"M28.9717 23.7714C28.9717 21.3098 30.9672 19.3143 33.4288 19.3143C35.8904 19.3143 37.886 21.3098 37.886 23.7714C37.886 26.233 35.8904 28.2286 33.4288 28.2286C30.9672 28.2286 28.9717 26.233 28.9717 23.7714Z",fill:i}),n.jsx("path",{d:"M18.5714 19.3143C16.1098 19.3143 14.1143 21.3098 14.1143 23.7714C14.1143 26.233 16.1098 28.2286 18.5714 28.2286C21.033 28.2286 23.0285 26.233 23.0285 23.7714C23.0285 21.3098 21.033 19.3143 18.5714 19.3143Z",fill:i})]})}const yi=8,Tn=8,bi=({open:e,onClose:t,anchorRef:i,children:o})=>{const a=r.useRef(null),[s,c]=r.useState(null);return r.useLayoutEffect(()=>{if(!e){c(null);return}const l=i.current;if(!l)return;const u=()=>{const d=l.getBoundingClientRect(),g={top:d.top-yi,left:d.left+d.width/2},h=Tn+90,m=window.innerWidth-Tn-90;g.left<h&&(g.left=h),g.left>m&&(g.left=m),c(g)};return u(),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[e,i]),r.useEffect(()=>{if(!e)return;const l=d=>{const g=d.target,h=a.current,m=i.current;h&&h.contains(g)||m&&m.contains(g)||t()},u=d=>{d.key==="Escape"&&(d.stopPropagation(),t())};return document.addEventListener("mousedown",l),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",u)}},[e,t,i]),!e||s===null||typeof document>"u"?null:tn.createPortal(n.jsx("div",{ref:a,className:"ll-overflow-popover",role:"menu",style:{position:"fixed",top:s.top,left:s.left,transform:"translate(-50%, -100%)"},children:o}),document.body)},vi=({isMuted:e,onToggleMute:t,isCameraEnabled:i,onToggleCamera:o,allowCamera:a,isScreenShareEnabled:s,onToggleScreenShare:c,allowScreenShare:l,isSpeakerMuted:u,onToggleSpeaker:d,allowTyping:g,isTypingOpen:h,onToggleTyping:m,onDisconnect:N})=>{const[_,S]=r.useState(!1),y=r.useRef(null);return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:w=>w.stopPropagation(),children:[n.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:t,"aria-label":e?"Unmute microphone":"Mute microphone",children:n.jsx(hr,{muted:e})}),n.jsx("button",{ref:y,type:"button",className:`ll-tool ${_?"is-on":""}`,onClick:()=>S(w=>!w),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":_,children:n.jsx(xi,{})}),n.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:N,"aria-label":"End conversation",children:n.jsx(gr,{})})]}),n.jsxs(bi,{open:_,onClose:()=>S(!1),anchorRef:y,children:[a&&n.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${i?"is-on":""}`,onClick:()=>{o(),S(!1)},children:[n.jsx(pr,{}),n.jsx("span",{children:i?"Stop camera":"Start camera"})]}),l&&n.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${s?"is-on":""}`,onClick:()=>{c(),S(!1)},children:[n.jsx(fr,{}),n.jsx("span",{children:s?"Stop sharing":"Share screen"})]}),n.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${u?"is-on":""}`,onClick:()=>{d(),S(!1)},children:[n.jsx(mr,{muted:u}),n.jsx("span",{children:u?"Unmute speaker":"Mute speaker"})]}),g&&n.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${h?"is-on":""}`,onClick:()=>{m(),S(!1)},children:[n.jsx(wi,{}),n.jsx("span",{children:h?"Hide typing":"Type a message"})]}),n.jsxs("button",{type:"button",className:"ll-overflow-popover__item is-active",disabled:!0,"aria-current":"true",children:[n.jsx("span",{className:"ll-overflow-popover__lang-code",children:"EN"}),n.jsx("span",{children:"English"})]})]})]})};function xi(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[n.jsx("circle",{cx:"6",cy:"12",r:"1.5"}),n.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),n.jsx("circle",{cx:"18",cy:"12",r:"1.5"})]})}function wi(){return n.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:n.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 _i=({position:e,isMobile:t,agentName:i,avatarImageUrl:o,idleLoopUrl:a,greeting:s,branding:c,teamMembers:l,currentTeamMemberId:u,isSwitchingTeamMember:d,teamSwitcherOpen:g,onToggleTeamSwitcher:h,onSelectTeamMember:m,languageMenuOpen:N,onToggleLanguageMenu:_,connectionState:S,agentState:y,transcript:w,canResume:R,needsUserGesture:E,error:v,isMuted:P,micError:b,micDevices:M,activeMicId:z,isCameraEnabled:Y,cameraPreviewEl:re,cameraDevices:T,activeCameraId:B,isScreenShareEnabled:p,screenPreviewEl:L,isSpeakerMuted:I,allowCamera:H,allowScreenShare:U,allowTyping:K,showMinimize:$=!0,showClose:J=!0,chromeless:te=!1,compactControls:F=!1,transforming:fe,transformingLabel:G,avatarVideoContainerRef:ve,agentVideoEl:Z,onConnect:je,onDisconnect:rt,onRetry:mt,onResumeAudio:gt,onToggleMute:it,onSwitchMicDevice:yt,onToggleCamera:We,onSwitchCameraDevice:qe,onToggleScreenShare:Ie,onToggleSpeaker:Te,onSendMessage:Pe,onMinimize:De,onClose:ze,onClearMicError:Be,dragHandleProps:$e,resizeHandleProps:D})=>{var Ct;const He=((l==null?void 0:l.length)??0)>1,Ue=S==="connecting"||S==="connected",xe=S==="connected",bt=S==="idle"||S==="disconnected"||S==="error",[ot,Ae]=r.useState(!1);r.useEffect(()=>{if(!Z){Ae(!1);return}if(!Z.paused&&Z.readyState>=2){Ae(!0);return}Ae(!1);const C=()=>Ae(!0);return Z.addEventListener("playing",C),Z.addEventListener("loadeddata",C),()=>{Z.removeEventListener("playing",C),Z.removeEventListener("loadeddata",C)}},[Z]);const[$t,vt]=r.useState(!1);r.useEffect(()=>{y==="speaking"&&vt(!0)},[y]),r.useEffect(()=>{(S==="disconnected"||S==="idle")&&vt(!1)},[S]);const Ee=$t&&ot,[ae,st]=r.useState(!1);r.useEffect(()=>{if(!xe){st(!1);return}if(Ee)return;const C=setTimeout(()=>st(!0),12e3);return()=>clearTimeout(C)},[xe,Ee]);const le=S==="connecting"||xe&&!Ee&&!ae,he=r.useRef(null),xt=r.useRef(null);r.useEffect(()=>{const C=he.current;C&&(C.innerHTML="",re&&(re.style.width="100%",re.style.height="100%",re.style.objectFit="cover",re.style.transform="scaleX(-1)",C.appendChild(re)))},[re]),r.useEffect(()=>{const C=xt.current;C&&(C.innerHTML="",L&&(L.style.width="100%",L.style.height="100%",L.style.objectFit="contain",C.appendChild(L)))},[L]);const[Ve,ce]=r.useState(!1),[me,Ye]=r.useState(!1),wt=r.useRef(null),_t=r.useRef(null);r.useEffect(()=>{if(!Ve&&!me&&!N&&!g)return;const C=()=>{ce(!1),Ye(!1),N&&_(),g&&h()};return document.addEventListener("click",C),()=>document.removeEventListener("click",C)},[Ve,me,N,g,_,h]);const[Ht,nn]=r.useState(!1),Re=r.useCallback(()=>nn(C=>!C),[]),[we,_e]=r.useState(""),Fe=r.useCallback(C=>{C.preventDefault();const Q=we.trim();Q&&(Pe(Q),_e(""))},[we,Pe]),Ge=c.productName||"Live Layer",Ft=!c.productName;let Ce=null,ke=null;for(let C=w.length-1;C>=0;C--){const Q=w[C];if(!Ce&&Q.role==="agent"?Ce=Q:!ke&&Q.role==="user"&&(ke=Q),Ce&&ke)break}const at=xe?(Ce==null?void 0:Ce.text)||null:s||null,Xe=xe&&(ke==null?void 0:ke.text)||null,lt=["ll-expanded",t?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return n.jsxs("div",{className:lt,"data-position":e,"data-state":xe?"connected":Ue?"connecting":"idle",role:"dialog","aria-label":`${i} widget`,children:[n.jsxs("div",{className:"ll-expanded__bg",children:[o?n.jsx(hi,{src:o,alt:i,className:"ll-expanded__bg-img"}):n.jsx("div",{className:"ll-expanded__bg-fallback",children:n.jsx("span",{className:"ll-expanded__bg-initial",children:((Ct=i==null?void 0:i.charAt(0))==null?void 0:Ct.toUpperCase())||"A"})}),a&&!xe&&n.jsx("video",{className:"ll-expanded__bg-idle",src:a,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),n.jsx("div",{ref:ve,className:"ll-expanded__video"}),le&&n.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--connecting",children:[n.jsx("div",{className:"ll-expanded__spinner"}),n.jsx("p",{className:"ll-expanded__overlay-text",children:d?"Switching...":"Connecting..."})]}),E&&xe&&n.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:gt,children:[n.jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:n.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"})}),n.jsx("p",{className:"ll-expanded__overlay-text",children:"Tap to enable audio"})]}),fe&&n.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":G,children:[n.jsx("div",{className:"ll-expanded__spinner"}),n.jsx("p",{className:"ll-expanded__overlay-text",children:G})]}),Ue?n.jsxs(n.Fragment,{children:[!F&&n.jsxs("div",{className:"ll-expanded__topbar",...$e,children:[!te&&n.jsxs("div",{className:"ll-expanded__topbar-left",children:[n.jsxs("div",{className:"ll-expanded__pill-wrap",children:[n.jsxs("button",{type:"button",className:"ll-hpill",onClick:C=>{He&&(C.stopPropagation(),h())},"aria-haspopup":He?"listbox":void 0,"aria-expanded":He?g:void 0,children:[n.jsx("span",{className:"ll-hpill__label",children:i}),He&&n.jsx(Mt,{})]}),He&&g&&n.jsx("div",{className:"ll-hmenu",onClick:C=>C.stopPropagation(),role:"listbox",children:l==null?void 0:l.map(C=>n.jsxs("button",{type:"button",className:`ll-hmenu__item ${C.id===u?"is-active":""}`,onClick:()=>m(C.id),role:"option","aria-selected":C.id===u,children:[C.avatarImageUrl&&n.jsx("img",{src:C.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),n.jsx("span",{className:"ll-hmenu__name",children:C.name}),C.role&&n.jsx("span",{className:"ll-hmenu__role",children:C.role})]},C.id))})]}),n.jsxs("div",{className:"ll-expanded__pill-wrap",children:[n.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:C=>{C.stopPropagation(),_()},"aria-haspopup":"listbox","aria-expanded":N,"aria-label":"Language: English",title:"Language: English",children:[n.jsx("span",{className:"ll-hpill__label",children:"EN"}),n.jsx(Mt,{})]}),N&&n.jsx("div",{className:"ll-hmenu",onClick:C=>C.stopPropagation(),role:"listbox",children:n.jsx("button",{type:"button",className:"ll-hmenu__item is-active",role:"option","aria-selected":!0,children:n.jsx("span",{className:"ll-hmenu__name",children:"English"})})})]}),n.jsx("span",{className:`ll-expanded__state ll-expanded__state--${y}`,children:y})]}),n.jsxs("div",{className:"ll-expanded__header-actions",children:[$!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn",onClick:De,"aria-label":"Minimize widget",title:"Minimize",children:n.jsx(Dn,{})}),J!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:ze,"aria-label":"End call",title:"End call",children:n.jsx(Pn,{})})]})]}),F&&n.jsxs("div",{className:"ll-compact-status","data-state":y,children:[n.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),n.jsx("span",{className:"ll-compact-status__label",children:y})]})]}):n.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",...$e,children:[!F&&(Ft?n.jsxs("a",{className:"ll-expanded__brand ll-expanded__brand--link",href:"https://livelayer.studio?utm_source=widget&utm_medium=brand-badge",target:"_blank",rel:"noopener noreferrer","aria-label":"Powered by LiveLayer — opens livelayer.studio in a new tab",title:"Powered by LiveLayer — visit livelayer.studio",children:[n.jsx(gi,{size:14,className:"ll-expanded__brand-mark"}),n.jsx("span",{children:Ge})]}):n.jsx("span",{className:"ll-expanded__brand",children:Ge})),n.jsxs("div",{className:"ll-expanded__header-actions",children:[!F&&$!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:De,"aria-label":"Minimize widget",children:n.jsx(Dn,{})}),J!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:ze,"aria-label":"Close widget",children:n.jsx(Pn,{})})]})]}),bt&&(()=>{const C=R?"Resume session":S==="disconnected"?"Reconnect to agent":"Start video call",Q=!v;return n.jsxs(n.Fragment,{children:[Q&&n.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:je,"aria-label":C,children:[n.jsx("div",{className:"ll-expanded__play-circle",children:n.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:n.jsx("polygon",{points:"6 3 20 12 6 21 6 3"})})}),F&&n.jsx("span",{className:"ll-expanded__play-label",children:C})]}),!F&&n.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[s&&n.jsx("div",{className:"ll-expanded__transcript",children:n.jsx("p",{className:"ll-expanded__transcript-text",children:s})}),n.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:je,"aria-label":C,children:C})]})]})})(),n.jsxs("div",{className:`ll-expanded__pip ${Ue&&(Y||p)?"is-visible":""}`,children:[n.jsx("div",{ref:xt,className:p?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),n.jsx("div",{ref:he,className:!p&&Y?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Ue?n.jsxs("div",{className:"ll-expanded__bottom",children:[!F&&at&&n.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:n.jsx("p",{className:"ll-expanded__transcript-text",children:at})}),!F&&Xe&&n.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:n.jsx("p",{className:"ll-expanded__transcript-text",children:Xe})}),!te&&!F&&n.jsxs("div",{className:"ll-toolbar",onClick:C=>C.stopPropagation(),children:[U&&n.jsx("button",{type:"button",className:`ll-tool ${p?"is-on":""}`,onClick:Ie,"aria-label":p?"Stop sharing screen":"Share screen",title:p?"Stop sharing":"Share screen",children:n.jsx(fr,{})}),H&&n.jsxs("div",{className:"ll-tool-split",children:[n.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${Y?"is-on":""}`,onClick:We,"aria-label":Y?"Turn off camera":"Turn on camera",title:Y?"Stop camera":"Start camera",children:n.jsx(pr,{})}),n.jsx("button",{ref:_t,type:"button",className:`ll-tool ll-tool--right ${Y?"is-on":""}`,onClick:C=>{C.stopPropagation(),Ye(Q=>!Q),ce(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":me,children:n.jsx(Mt,{})}),me&&T.length>0&&n.jsx(zn,{label:"Camera",devices:T,activeId:B,anchorRef:_t,onPick:C=>{Ye(!1),qe(C)}})]}),n.jsxs("div",{className:"ll-tool-split",children:[n.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${P?"is-muted":""}`,onClick:it,"aria-label":P?"Unmute microphone":"Mute microphone",title:P?"Unmute":"Mute",children:n.jsx(hr,{muted:P})}),n.jsx("button",{ref:wt,type:"button",className:`ll-tool ll-tool--right ${P?"is-muted":""}`,onClick:C=>{C.stopPropagation(),ce(Q=>!Q),Ye(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":Ve,children:n.jsx(Mt,{})}),Ve&&M.length>0&&n.jsx(zn,{label:"Microphone",devices:M,activeId:z,anchorRef:wt,onPick:C=>{ce(!1),yt(C)}})]}),n.jsx("button",{type:"button",className:`ll-tool ${I?"is-muted":""}`,onClick:Te,"aria-label":I?"Unmute speaker":"Mute speaker",title:I?"Unmute speaker":"Mute speaker",children:n.jsx(mr,{muted:I})}),n.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:rt,"aria-label":"End conversation",title:"End conversation",children:n.jsx(gr,{})})]}),!te&&F&&n.jsx(vi,{isMuted:P,onToggleMute:it,isCameraEnabled:Y,onToggleCamera:We,allowCamera:H,isScreenShareEnabled:p,onToggleScreenShare:Ie,allowScreenShare:U,isSpeakerMuted:I,onToggleSpeaker:Te,allowTyping:K,isTypingOpen:Ht,onToggleTyping:Re,onDisconnect:rt}),!te&&K&&(F?Ht:!0)&&n.jsxs("form",{className:"ll-message-input",onSubmit:Fe,children:[n.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:we,onChange:C=>_e(C.target.value),"aria-label":"Message the agent"}),we.trim()&&n.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:n.jsx(Ci,{})})]})]}):null,(()=>{if(b&&S!=="error")return n.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[n.jsx("span",{children:b}),n.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:Be,"aria-label":"Dismiss",children:"×"})]});if(!v||S!=="error")return null;let C="Failed to connect",Q="Try again";return v==="MIC_PERMISSION_DENIED"?C="Microphone blocked. Allow access to talk.":v==="MIC_NOT_FOUND"?C="No microphone found. Plug one in + retry.":v==="MIC_UNAVAILABLE"?C="Mic unavailable. Check other apps using it.":v==="AGENT_TIMEOUT"?C="Agent didn't pick up. Try again.":v==="CONNECT_FAILED"?C="Connection failed. Check your network.":v.length<80&&(C=v),n.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[n.jsx("span",{children:C}),n.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:mt,children:Q})]})})(),(D==null?void 0:D["data-ll-resize-handle"])!==void 0&&n.jsx("div",{className:"ll-expanded__resize-grip",...D,"aria-hidden":!0,children:n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[n.jsx("line",{x1:"11",y1:"4",x2:"4",y2:"11"}),n.jsx("line",{x1:"11",y1:"8",x2:"8",y2:"11"})]})})]})};function Mt(){return n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":!0,children:n.jsx("polyline",{points:"6 9 12 15 18 9"})})}function Pn(){return n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Dn(){return n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:n.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function fr(){return n.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:[n.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),n.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),n.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function pr(){return n.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:[n.jsx("path",{d:"M23 7l-7 5 7 5V7z"}),n.jsx("rect",{x:"1",y:"5",width:"15",height:"14",rx:"2"})]})}function hr({muted:e}){return n.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:[n.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),n.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),n.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),e&&n.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function mr({muted:e}){return n.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:[n.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e?n.jsx("line",{x1:"23",y1:"9",x2:"17",y2:"15"}):n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"}),n.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]})]})}function Ci(){return n.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:[n.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),n.jsx("polyline",{points:"12 5 19 12 12 19"})]})}function gr(){return n.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:n.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 zn=({label:e,devices:t,activeId:i,onPick:o,anchorRef:a})=>{const[s,c]=r.useState(null);return r.useLayoutEffect(()=>{const l=()=>{const u=a.current;if(!u)return;const d=u.getBoundingClientRect(),g=126,h=window.innerWidth-16-110,m=d.left+d.width/2;c({top:d.top-8,left:Math.max(g,Math.min(h,m))})};return l(),window.addEventListener("scroll",l,!0),window.addEventListener("resize",l),()=>{window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[a]),s===null||typeof document>"u"?null:tn.createPortal(n.jsxs("div",{className:"ll-device-menu ll-device-menu--floating",onClick:l=>l.stopPropagation(),role:"listbox",style:{position:"fixed",top:s.top,left:s.left,transform:"translate(-50%, -100%)"},children:[n.jsx("p",{className:"ll-device-menu__label",children:e}),t.map((l,u)=>{const d=i===l.deviceId;return n.jsxs("button",{type:"button",className:`ll-device-menu__item ${d?"is-active":""}`,onClick:()=>o(l.deviceId),role:"option","aria-selected":d,children:[d&&n.jsx("span",{className:"ll-device-menu__dot",children:"●"}),n.jsx("span",{className:"ll-device-menu__name",children:l.label||`${e} ${u+1}`})]},l.deviceId||u)})]}),document.body)},ki=["[data-ll-private]","[data-ll-skip]",".ll-widget"];function zt(e){let t=e;for(;t;){for(const i of ki)if(t.matches(i))return!0;t=t.parentElement}return!1}function Zt(e){if(zt(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const t=(e.getAttribute("autocomplete")||"").toLowerCase();if(t==="off"||t.startsWith("cc-"))return!1}return!0}const Si=/\b(continue|next|proceed|move\s*on|forward)\b|→|›/i,$n=/\b(back|previous|prev|go\s*back)\b|←|‹/i,Ei=/\b(submit|finish|done|complete|send)\b/i,ht=new Map;function Hn(e){const t=ht.get(e);return t&&t.isConnected?t:null}function Qe(e){if(zt(e)||e.hidden||e.getAttribute("aria-hidden")==="true")return!0;const t=typeof window<"u"&&window.getComputedStyle?window.getComputedStyle(e):null;return!!(t&&(t.display==="none"||t.visibility==="hidden"))}function Li(e){return!!(e.disabled||e.getAttribute("aria-disabled")==="true")}function ji(e){return(e.innerText||e.textContent||e.getAttribute("aria-label")||e.value||"").trim()}function Ai(e){return Array.from(e.querySelectorAll('button, [role="button"], input[type="submit"], input[type="button"]')).filter(i=>!Qe(i)&&!Li(i))}function yr(e){ht.clear();const t=Ai(e);let i,o,a;for(const l of t){const u=ji(l);if(!u||u.length>40)continue;const d=l.getAttribute("type")==="submit"||l.tagName==="BUTTON"&&!l.getAttribute("type")&&!!l.closest("form");!i&&Si.test(u)&&!$n.test(u)?(i={id:"ll-advance",label:u},ht.set("ll-advance",l)):!o&&$n.test(u)?(o={id:"ll-back",label:u},ht.set("ll-back",l)):!a&&(Ei.test(u)||d)&&(a={id:"ll-submit",label:u},ht.set("ll-submit",l))}const s=Di(e);return{kind:i||s.totalSteps?"multi-step":"single-page",advance:i,back:o,submit:a,...s}}const Ri=60;function br(e){return e.replace(/^\s*(step\s+)?\d{1,2}(?:[.):\-]+\s*|\s+)/i,"").replace(/\s+/g," ").trim().slice(0,Ri)}function Ni(e){const t=e.getAttribute("class");return t?t.toLowerCase():""}const Mi=/stepper|wizard|ant-steps|step-indicator/;function Ii(e){return Mi.test(Ni(e))}function Fn(e){const t=e.getAttribute("aria-current");return t==="step"||t==="true"?!0:Array.from(e.classList).some(i=>/(^|[-_])(active|current|selected)([-_]|$)/i.test(i))}const Ti='[aria-current="step"],[aria-current="true"],[class*="active"],[class*="Active"],[class*="current"],[class*="Current"],[class*="selected"],[class*="Selected"]';function Pi(e){return Fn(e)?!0:Array.from(e.querySelectorAll(Ti)).some(Fn)}function On(e,t){const i=br(e[t].innerText||e[t].textContent||"");return{totalSteps:e.length,currentStep:t+1,...i?{stepLabel:i}:{}}}function Di(e){const t=e.querySelector('[aria-current="step"]');if(t&&t.parentElement&&!Qe(t)){const a=Array.from(t.parentElement.children).filter(c=>c.tagName===t.tagName&&!Qe(c)),s=a.indexOf(t);if(s>=0&&a.length>=2)return On(a,s)}const i=e.querySelector('[role="progressbar"]');if(i&&!Qe(i)){const a=Number(i.getAttribute("aria-valuenow")),s=Number(i.getAttribute("aria-valuemax"));if(Number.isFinite(a)&&Number.isFinite(s)&&s>=2){const c=(i.getAttribute("aria-valuetext")||"").trim();return{totalSteps:s,currentStep:a,...c?{stepLabel:br(c)}:{}}}}const o=Array.from(e.querySelectorAll('[class*="step"], [class*="Step"], [class*="wizard"], [class*="Wizard"]')).filter(a=>!Qe(a)&&Ii(a));for(const a of o){const s=Array.from(a.children).filter(l=>!Qe(l)&&(l.textContent||"").trim().length>0);if(s.length<2||s.length>12)continue;const c=s.findIndex(Pi);if(!(c<0))return On(s,c)}return{}}const It=4096,zi=20,$i=20,Hi=10,Fi=10,Oi=30,Wi=20,Wn=500,qi=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function ft(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let t=e;for(;t;){for(const i of qi)if(t.matches(i))return!0;t=t.parentElement}return!1}function pt(e){if(typeof window>"u")return!0;const t=e.getBoundingClientRect();if(t.width<=0||t.height<=0)return!1;const i=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth;return t.bottom>0&&t.right>0&&t.top<i&&t.left<o}function qn(e){const t=e.getAttribute("id");if(t){const s=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(t):t.replace(/"/g,'\\"'),c=document.querySelector(`label[for="${s}"]`);if(c!=null&&c.textContent)return c.textContent.trim()}const i=e.getAttribute("aria-label");if(i)return i.trim();const o=e.closest("label");if(o){const s=[];for(const l of Array.from(o.childNodes))if(l.nodeType===Node.TEXT_NODE){const u=(l.textContent||"").trim();u&&s.push(u)}else if(l instanceof HTMLElement){if(l instanceof HTMLInputElement||l instanceof HTMLTextAreaElement||l instanceof HTMLSelectElement||l instanceof HTMLButtonElement)continue;const u=(l.textContent||"").trim();u&&s.push(u)}const c=s.join(" ").trim();if(c)return c}const a=e.getAttribute("placeholder");return a?a.trim():""}function oe(e,t){return e.length<=t?e:e.slice(0,t-1)+"…"}function Bi(e){return e&&e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function Ui(e){const t=e.getAttribute("aria-label");if(t)return t.trim().slice(0,80);const i=e.getAttribute("aria-labelledby");if(i){const s=document.getElementById(i);if(s!=null&&s.textContent)return s.textContent.trim().slice(0,80)}const o=e.querySelector('button[type="submit"], input[type="submit"], button:not([type])');if(o){const s=o instanceof HTMLInputElement?o.value:(o.textContent??"").trim();if(s&&s.length<60&&!/^(submit|ok|continue)$/i.test(s))return s}let a=e.parentElement;for(let s=0;a&&s<4;s++,a=a.parentElement){const c=a.querySelector("h1, h2, h3, h4");if(c!=null&&c.textContent){const l=c.textContent.trim();if(l&&l.length<80)return l}}return null}function Ze(e){return e.length}function vr(e,t={}){const i=t.doc??(typeof document<"u"?document:null);if(!i)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const o=typeof window<"u"&&window.location.href||"",a=typeof window<"u"&&window.location.pathname||"/",s=i.title||"",c=Array.from(i.querySelectorAll("[data-ll-region]")),l=[];for(const b of c){if(l.length>=Hi)break;if(ft(b)||!pt(b))continue;const M=b.getAttribute("data-ll-region")??"",z=b.getAttribute("data-ll-intent")??void 0,Y=oe((b.innerText||b.textContent||"").trim(),Wn*2);!M||!Y||l.push({id:M,intent:z,text:Y})}const u=[],d=["H1","H2","H3","H4","H5","H6"],g=Array.from(i.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const b of g){if(ft(b)||!pt(b))continue;const M=(b.textContent||"").trim();M&&u.push(`${b.tagName}: ${oe(M,200)}`)}const h=Array.from(i.querySelectorAll("p, li"));for(const b of h){if(ft(b)||!pt(b)||d.includes(b.tagName))continue;const M=(b.textContent||"").trim();M.length>10&&u.push(oe(M,Wn))}const m=u.join(`
2
- `),N=[],_=Array.from(i.querySelectorAll("a[href]"));for(const b of _){if(N.length>=zi)break;if(ft(b)||!pt(b))continue;const M=b.getAttribute("href")||"",z=(b.textContent||"").trim();!M||!z||N.push({href:M,text:oe(z,100)})}const S=[],y=Array.from(i.querySelectorAll("input, textarea, select"));for(const b of y){if(S.length>=$i)break;if(ft(b)||!Zt(b)||!pt(b))continue;const M=qn(b),z=b instanceof HTMLInputElement?b.type:b.tagName.toLowerCase();M&&S.push({label:oe(M,100),type:z})}const w=Array.from(i.querySelectorAll("form")),R=[];let E=0;for(const b of w){if(R.length>=Fi)break;if(zt(b)||b.matches(".ll-widget *, .ll-widget"))continue;const M=b.getAttribute("id")||b.getAttribute("name")||Bi(b.getAttribute("data-ll-intent"))||`form_${E++}`,z=b.getAttribute("data-ll-intent")||Ui(b)||void 0,Y=Array.from(b.querySelectorAll("input, textarea, select")),re=[];let T=0;const B=new Set;for(const p of Y){if(re.length>=Oi)break;if(!Zt(p))continue;if(p instanceof HTMLInputElement){const F=p.type;if(F==="submit"||F==="button"||F==="reset"||F==="hidden"||F==="image"||F==="file")continue}const L=p.getAttribute("name")||"",I=p.getAttribute("id")||"";let H=L||I||`field_${T}`;B.has(H)&&(H=`${H}__${T}`),B.add(H),T++;const U=qn(p)||H,K=p instanceof HTMLInputElement?p.type:p.tagName.toLowerCase(),$={name:H,label:oe(U,100),type:K};p.required===!0&&($.required=!0);const J=p.getAttribute("placeholder");if(J&&($.placeholder=oe(J.trim(),100)),p instanceof HTMLInputElement||p instanceof HTMLTextAreaElement){const F=p.getAttribute("minlength");if(F!==null){const G=parseInt(F,10);!Number.isNaN(G)&&G>=0&&($.minLength=G)}const fe=p.getAttribute("maxlength");if(fe!==null){const G=parseInt(fe,10);!Number.isNaN(G)&&G>=0&&($.maxLength=G)}}if(p instanceof HTMLInputElement){const F=p.getAttribute("min");F!==null&&($.min=oe(F,50));const fe=p.getAttribute("max");fe!==null&&($.max=oe(fe,50));const G=p.getAttribute("step");G!==null&&($.step=oe(G,20));const ve=p.getAttribute("pattern");ve!==null&&($.pattern=oe(ve,200));const Z=(p.getAttribute("autocomplete")||"").toLowerCase();Z&&Z!=="off"&&!Z.startsWith("cc-")&&($.autocomplete=oe(Z,50))}if(p instanceof HTMLSelectElement){const F=[];for(let fe=0;fe<p.options.length;fe++){const G=p.options[fe];if(!G)continue;if(G.value===""||G.disabled){const je=(G.textContent||"").trim();if(je&&!$.placeholderOption&&($.placeholderOption=oe(je,60)),$.hasEmptyOption=!0,G.disabled)continue}if(F.length>=Wi)break;const ve=G.value||"",Z=(G.textContent||"").trim()||ve;!ve&&!Z||F.push({value:ve,label:oe(Z,60)})}F.length>0&&($.options=F)}const te=typeof p.validationMessage=="string"?p.validationMessage:"";te&&($.validationMessage=oe(te,200)),re.push($)}R.push({id:M,intent:z,fields:re})}const v={url:o,title:s,pathname:a,regions:l,visibleText:m,visibleLinks:N,visibleFields:S,forms:R,flow:yr(i),extras:e};let P=Ze(JSON.stringify(v.regions))+Ze(v.visibleText)+Ze(JSON.stringify(v.visibleLinks))+Ze(JSON.stringify(v.visibleFields));for(;P>It&&v.visibleFields.length>0;)v.visibleFields.pop(),P=Ze(JSON.stringify(v.visibleFields));for(;P>It&&v.visibleLinks.length>0;)v.visibleLinks.pop(),P-=80;return Ze(v.visibleText)>It&&(v.visibleText=oe(v.visibleText,It-100)),v}let et=null;function Vi(e){const t=e.querySelectorAll("form");let i=`f${t.length}`;return t.forEach(o=>{i+=`|${o.id||o.getAttribute("name")||""}:${o.querySelectorAll("input,select,textarea").length}`}),i}function Qt(e,t={}){const i=Date.now(),o=t.doc??(typeof document<"u"?document:null),a=typeof window<"u"&&window.location.pathname||"/",s=typeof window<"u"?window.scrollY:0,c=`${a}::${s}::${o?Vi(o):""}`;if(et&&et.key===c&&i-et.at<1e3)return et.ctx;const l=vr(e,t);return et={key:c,at:i,ctx:l},l}function xr(){et=null}const Yi=200;function wr(e){const t=String(e.href||"");return{href:t,text:String(e.text??e.title??t),internal:e.internal??!0,title:e.title,description:e.description}}function Gi(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function _r(e){const t=e??(typeof document<"u"?document:null);if(!t)return[];const i=typeof window<"u"&&window.location.origin||"",o=new Set,a=[],s=Array.from(t.querySelectorAll("a[href]"));for(const c of s){if(a.length>=Yi)break;if(zt(c))continue;const l=c.getAttribute("href")||"";if(!Gi(l))continue;let u=l,d=!0;try{if(typeof window<"u"){const h=new URL(l,i);d=h.origin===i,d&&l.startsWith("http")&&(u=h.pathname+h.search+h.hash)}}catch{continue}if(o.has(u))continue;o.add(u);const g=(c.textContent||"").trim().slice(0,120);a.push({href:u,text:g,internal:d})}return a}let tt=null;const Xi=5e3;function Tt(){const e=Date.now(),t=typeof window<"u"&&window.location.pathname||"/";if(tt&&tt.pathname===t&&e-tt.at<Xi)return tt.routes;const i=_r();return tt={at:e,pathname:t,routes:i},i}function Cr(){tt=null}function en(e){if(e instanceof HTMLInputElement){const t=e.type;if(t==="submit"||t==="button"||t==="reset"||t==="hidden"||t==="image"||t==="file")return!1}return!0}function Ki(e,t){return e.getAttribute("name")||e.getAttribute("id")||`field_${t}`}function Me(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"")}function Kt(e){const t=e.lastIndexOf(".");return t>=0?e.slice(t+1):e}function Ji(e){var o;const t=e.getAttribute("id");if(t)try{const a=(o=e.ownerDocument)==null?void 0:o.querySelector(`label[for="${t.replace(/"/g,'\\"')}"]`);if(a!=null&&a.textContent)return a.textContent}catch{}const i=e.closest("label");return i!=null&&i.textContent?i.textContent:e.getAttribute("aria-label")||e.getAttribute("placeholder")||""}function Zi(e,t){const i=Me(t);if(i.length<2)return null;let o=null,a=0;for(const s of Array.from(e.querySelectorAll("input, textarea, select"))){if(!en(s))continue;const c=s.getAttribute("name")||"",l=s.getAttribute("id")||"",u=[Me(Kt(c)),Me(Kt(l)),Me(c),Me(l)];let d=0;u.some(g=>g.length>=2&&g===i)?d=4:[Me(c),Me(Kt(c)),Me(Ji(s))].some(h=>h.length>=3&&(h.includes(i)||i.includes(h)))&&(d=2),d>a&&(a=d,o=s)}return a>=2?o:null}function Qi(e,t){if(!t)return null;try{const s=e.querySelector(`[name="${t.replace(/"/g,'\\"')}"]`);if(s&&en(s))return s}catch{}const i=Array.from(e.querySelectorAll("input, textarea, select"));let o=0;const a=new Map;for(const s of i){if(!en(s))continue;const c=Ki(s,o);let l=c;if(a.has(c)&&(l=`${c}__${o}`),l===t)return s;a.set(c,s),o++}return Zi(e,t)}function Bn(e,t){const i=Qi(e,t);return i?Zt(i)?{el:i}:{el:null,reason:"private"}:{el:null,reason:"not_found"}}function eo(e,t){const i=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,o=Object.getOwnPropertyDescriptor(i,"value"),a=o==null?void 0:o.set;a?a.call(e,t):e.value=t}function to(e,t,i={}){const o=i.triggerInput??!0,a=i.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const s=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),c=s==null?void 0:s.set,l=t==="true"||t==="1"||t==="on";c?c.call(e,l):e.checked=l,o&&e.dispatchEvent(new Event("input",{bubbles:!0})),a&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}eo(e,t),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),a&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function Un(e,t){if(!t)return null;const i=t.replace(/"/g,'\\"'),o=l=>l.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')!==null;try{const l=e.querySelector(`form#${CSS.escape(t)}`);if(l&&!o(l))return l}catch{}const a=e.querySelector(`form[name="${i}"]`);if(a&&!o(a))return a;const s=e.querySelector(`form[data-ll-intent="${i}"]`);if(s&&!o(s))return s;const c=Array.from(e.querySelectorAll("form")).filter(l=>!o(l));for(const l of c){const u=l.getAttribute("data-ll-intent");if(u&&no(u)===t)return l}if(/^form_\d+$/.test(t)){const l=parseInt(t.slice(5),10);let u=0;for(const d of c)if(!(d.id||d.getAttribute("name")||d.getAttribute("data-ll-intent"))){if(u===l)return d;u++}}return c.length===1?c[0]:null}function no(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function ro(){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 t=window.getComputedStyle(e);return!(t.overflowY==="hidden"||t.overflowY==="clip")}function io(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function oo(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let t=null,i=0;for(const o of e){if(!io(o))continue;const a=o.getBoundingClientRect();if(a.bottom<=0||a.top>=window.innerHeight||a.right<=0||a.left>=window.innerWidth||a.width<=0||a.height<=0||o.closest(".ll-widget"))continue;const s=a.width*a.height;s>i&&(i=s,t=o)}return t}function so(){if(typeof window>"u")return null;if(ro())return window;const e=oo();return e||window}function Vn(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function ao(e){var t,i;return e instanceof Window?typeof document>"u"?0:Math.max(((t=document.body)==null?void 0:t.scrollHeight)??0,((i=document.documentElement)==null?void 0:i.scrollHeight)??0):e.scrollHeight-e.clientHeight}const lo=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","advance_step","go_back","submit_flow","task_field_updated","task_completed"]),kr=r.forwardRef(function(t,i){var hn,mn,gn,yn,bn,vn,xn;const{agentId:o,apiKey:a,baseUrl:s="https://app.livelayer.studio",sessionEndpoint:c,sessionBody:l,soundEffects:u,experienceMode:d="WIDGET",autoConnect:g=!1,displayMode:h,defaultDisplayMode:m="expanded",onDisplayModeChange:N,position:_="bottom-right",mobileBreakpoint:S=640,draggable:y,resizable:w,persistKey:R="ll-widget",disablePersistence:E=!1,teamMembers:v,currentTeamMemberId:P,onTeamMemberChange:b,idleLoopUrl:M,greeting:z,avatarImageUrl:Y,agentName:re,branding:T={},allowCamera:B=!0,allowScreenShare:p=!0,allowTyping:L=!0,blurUntilFirstSpeech:I=!0,showMinimize:H,showClose:U,chromeless:K=!1,floatingChromeContainer:$=null,compactControls:J=!1,transforming:te=!1,transformingLabel:F="Transforming…",showOn:fe,hideOn:G,pathname:ve,onNavigate:Z,onScrollToSelector:je,getPageContext:rt,pageContextExtras:mt,getRoutes:gt,onScrollPage:it,onClick:yt,capabilities:We,onConnect:qe,onDisconnect:Ie,onTranscript:Te,onAgentState:Pe,onConnectionStateChange:De,onAgentEvent:ze,onAgentCommand:Be,onCollect:$e,controlledSession:D,className:He,style:Ue,zIndex:xe=2147483647}=t,bt=ar(ve),ot=ur(bt,fe,G);r.useEffect(()=>{xr(),Cr()},[bt]);const Ae=P!==void 0,[$t,vt]=r.useState(()=>{var x;return P??((x=v==null?void 0:v[0])==null?void 0:x.id)}),Ee=Ae?P:$t,ae=r.useMemo(()=>(v==null?void 0:v.find(x=>x.id===Ee))??null,[v,Ee]),st=(ae==null?void 0:ae.agentId)??o,le=d==="EMBEDDED",he=sr(S),[xt,Ve]=or({value:h,defaultValue:m,onChange:N,persistKey:R,disablePersistence:le||E}),ce=le?"expanded":xt,me=le?()=>{}:Ve,Ye=H??!le,wt=U??!le,_t=J||!le&&he,Re=Zr({draggable:!le&&(y??!he),resizable:!le&&(w??!he),persistKey:R,disablePersistence:le||E}),we=Kn(),_e=Zn(),Fe=Qn(),Ge=er(),[Ft,Ce]=r.useState(!1),[ke,at]=r.useState(!1),[Xe,lt]=r.useState(!1),[Ct,C]=r.useState(!1),[Q,Lr]=r.useState(!1),kt=oi({baseUrl:s,config:u}),St=r.useRef(kt);St.current=kt;const Ot=r.useRef(Z),Wt=r.useRef(je),qt=r.useRef(it),Bt=r.useRef(yt),rn=r.useRef(rt),on=r.useRef(mt),sn=r.useRef(gt),Ut=r.useRef(We),Se=r.useRef(null);Ot.current=Z,Wt.current=je,qt.current=it,Bt.current=yt,rn.current=rt,on.current=mt,sn.current=gt,Ut.current=We;function ye(x){const f=Ut.current;return f?f.includes(x):!0}function be(x,f){console.warn(`[LiveLayer] Agent command "${x}" blocked — capability "${f}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const ct=r.useCallback(x=>{var ee,se,Le,dt,Ne,wn;const f=x;if(!(!f.type||typeof f.type!="string")){if(ze==null||ze({eventName:f.type,data:x}),f.type==="navigate"){if(!ye("navigate")){be("navigate","navigate");return}const j=typeof f.href=="string"?f.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(St.current.playPageChange(),Ot.current){try{Ot.current(j)}catch(A){console.warn(`[LiveLayer] onNavigate threw for "${j}". Falling back. Error:`,A)}return}if(typeof document<"u"){const A=document.querySelector(`a[href="${j.replace(/"/g,'\\"')}"]`);if(A){A.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",j),window.dispatchEvent(new PopStateEvent("popstate"))}catch(A){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`,A)}return}if(f.type==="scroll_to"){if(!ye("scroll")){be("scroll_to","scroll");return}const j=typeof f.selector=="string"?f.selector:null;if(!j)return;const A=f.behavior==="instant"?"instant":"smooth";if(Wt.current){try{Wt.current(j,A)}catch(q){console.warn("[LiveLayer] onScrollToSelector threw.",q)}return}if(typeof document<"u"){let q=null;try{q=document.querySelector(j)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${j}".`);return}if(!q){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}q.scrollIntoView({behavior:A,block:"start"})}return}if(f.type==="request_page_context"){if(!ye("read_page")){be("request_page_context","read_page");return}const j=typeof f.requestId=="string"?f.requestId:void 0,A=(ee=Se.current)==null?void 0:ee.call(Se),q=X=>{const W=A,ue=W==null?void 0:W.localParticipant;if(ue!=null&&ue.publishData)try{const de=j?{...X,requestId:j}:X,ne=new TextEncoder().encode(JSON.stringify(de));ue.publishData(ne,{reliable:!0})}catch(de){console.warn("[LiveLayer] publishData failed.",de)}},O=on.current,V=rn.current;try{if(V){const X=V(O);if(X instanceof Promise){q({type:"page_context_pending"}),X.then(W=>q({type:"page_context",context:W})).catch(W=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",W),q({type:"page_context",context:Qt(O)})});return}q({type:"page_context",context:X});return}q({type:"page_context",context:Qt(O)})}catch(X){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",X),q({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:O}})}return}if(f.type==="scroll_page"){if(!ye("scroll")){be("scroll_page","scroll");return}const j=f.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 A=f.behavior==="instant"?"instant":"smooth";if(qt.current){try{qt.current(j,A)}catch(W){console.warn("[LiveLayer] onScrollPage threw.",W)}return}if(typeof window>"u")return;const q={behavior:A},O=so(),V=W=>{O instanceof Window?O.scrollBy({top:W,...q}):O.scrollBy({top:W,...q})},X=W=>{O instanceof Window?O.scrollTo({top:W,...q}):O.scrollTo({top:W,...q})};j==="up"?V(-Vn(O)):j==="down"?V(Vn(O)):X(j==="top"?0:ao(O));return}if(f.type==="click"){if(!ye("click")){be("click","click");return}const j=typeof f.selector=="string"?f.selector:null;if(!j){console.warn("[LiveLayer] click: missing selector.");return}if(Bt.current){try{Bt.current(j)}catch(q){console.warn("[LiveLayer] onClick threw.",q)}return}if(typeof document>"u")return;let A=null;try{A=document.querySelector(j)}catch{console.warn(`[LiveLayer] click: invalid selector "${j}".`);return}if(!A){console.warn(`[LiveLayer] click: no element matched "${j}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(A.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(se=A.click)==null||se.call(A);return}if(f.type==="advance_step"||f.type==="go_back"||f.type==="submit_flow"){if(!ye("click")){be(f.type,"click");return}if(typeof document>"u")return;const j=f.type==="advance_step"?"ll-advance":f.type==="go_back"?"ll-back":"ll-submit";let A=Hn(j);if(A||(yr(document),A=Hn(j)),!A){console.warn(`[LiveLayer] ${f.type}: no "${j}" control found.`);return}(Le=A.click)==null||Le.call(A);return}if(f.type==="fill_form"||f.type==="focus_field"){if(!ye("fill_forms")){be(f.type,"fill_forms");return}if(typeof document>"u")return;f.type==="fill_form"&&St.current.playConfirmation();const j=typeof f.formId=="string"?f.formId:null;if(!j){console.warn(`[LiveLayer] ${f.type}: missing formId.`);return}const A=Un(document,j);if(!A){console.warn(`[LiveLayer] ${f.type}: no <form> matched id="${j}" (or matching name / data-ll-intent slug). Forms are auto-discovered — make sure the form has an \`id\`, \`name\`, or \`data-ll-intent\` attribute the agent observed in PageContext.forms.`);return}if(A.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')){console.warn(`[LiveLayer] ${f.type}: refusing to touch a form in a private / opted-out subtree.`);return}if(f.type==="focus_field"){const O=typeof f.fieldName=="string"?f.fieldName:null;if(!O){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const V=Bn(A,O);if(V.el===null){V.reason==="private"?console.warn(`[LiveLayer] focus_field: field "${O}" is privacy-protected and not focusable.`):console.warn(`[LiveLayer] focus_field: no input matching key="${O}" in form "${j}". The agent should use the field.name it observed in PageContext.forms[].fields[].`);return}V.el.focus();return}const q=f.values&&typeof f.values=="object"?f.values:null;if(!q){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[O,V]of Object.entries(q)){if(typeof V!="string")continue;const X=Bn(A,O);if(X.el===null){X.reason==="private"?console.warn(`[LiveLayer] fill_form: field "${O}" is privacy-protected (password / cc-* / data-ll-private). Skipping.`):console.warn(`[LiveLayer] fill_form: no input matching key="${O}" in form "${j}". The agent should use the field.name it observed in PageContext.forms[].fields[]. Skipping.`);continue}try{to(X.el,V)}catch(W){console.warn(`[LiveLayer] fill_form: failed to set "${O}".`,W)}}return}if(f.type==="submit_form"){if(!ye("submit_forms")){be("submit_form","submit_forms");return}if(typeof document>"u")return;const j=typeof f.formId=="string"?f.formId:null;if(!j){console.warn("[LiveLayer] submit_form: missing formId.");return}St.current.playConfirmation();const A=Un(document,j);if(!A){console.warn(`[LiveLayer] submit_form: no <form> matched id="${j}" (or matching name / data-ll-intent slug).`);return}if(A.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private / opted-out subtree.");return}const q=typeof f.requestId=="string"?f.requestId:void 0,O=(dt=Se.current)==null?void 0:dt.call(Se),V=ne=>{const pe=O,Oe=pe==null?void 0:pe.localParticipant;if(Oe!=null&&Oe.publishData)try{const jt=q?{...ne,requestId:q}:ne,At=new TextEncoder().encode(JSON.stringify(jt));Oe.publishData(At,{reliable:!0})}catch{}},X=ne=>{var At,_n,Cn,kn;const pe=ne,Oe=(At=pe.getAttribute)==null?void 0:At.call(pe,"aria-label");if(Oe)return Oe;const jt=pe.id;if(jt){const Rt=(_n=A.ownerDocument)==null?void 0:_n.querySelector(`label[for="${jt}"]`);if((Cn=Rt==null?void 0:Rt.textContent)!=null&&Cn.trim())return Rt.textContent.trim()}return((kn=pe.getAttribute)==null?void 0:kn.call(pe,"name"))||pe.id||pe.type||"field"},W=()=>{try{return Array.from(A.elements).filter(ne=>"willValidate"in ne&&ne.willValidate&&!ne.checkValidity()).map(ne=>`${X(ne)}: ${ne.validationMessage}`)}catch{return[]}};if(typeof A.checkValidity=="function"&&!A.checkValidity()){try{(Ne=A.reportValidity)==null||Ne.call(A)}catch{}V({type:"form_submit_blocked",formId:j,reason:"validation",invalidFields:W()});return}let ue=!1;const de=ne=>{ue=!0,queueMicrotask(()=>{ne.defaultPrevented?V({type:"form_submit_uncertain",formId:j,reason:"spa_prevented"}):V({type:"form_submitted",formId:j})})};A.addEventListener("submit",de,{once:!0});try{typeof A.requestSubmit=="function"?A.requestSubmit():A.submit()}catch(ne){console.warn("[LiveLayer] submit_form: requestSubmit threw.",ne),A.removeEventListener("submit",de),V({type:"form_submit_blocked",formId:j,reason:"exception"});return}setTimeout(()=>{ue||(A.removeEventListener("submit",de),V({type:"form_submit_blocked",formId:j,reason:"validation",invalidFields:W()}))},500);return}if(f.type==="request_routes"){if(!ye("read_page")){be("request_routes","read_page");return}const j=typeof f.requestId=="string"?f.requestId:void 0,q=(wn=Se.current)==null?void 0:wn.call(Se),O=q==null?void 0:q.localParticipant;if(!(O!=null&&O.publishData))return;const V=W=>{try{const ue=j?{type:"routes",routes:W,requestId:j}:{type:"routes",routes:W},de=new TextEncoder().encode(JSON.stringify(ue));O.publishData(de,{reliable:!0})}catch(ue){console.warn("[LiveLayer] request_routes: publishData failed.",ue)}},X=sn.current;if(X){try{const W=X(),ue=de=>{if(!Array.isArray(de)){V([]);return}V(de.map(wr).slice(0,200))};W instanceof Promise?W.then(ue).catch(de=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",de),V(Tt())}):ue(W)}catch(W){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",W),V(Tt())}return}try{V(Tt())}catch(W){console.warn("[LiveLayer] request_routes: extractRoutes threw.",W)}return}if(f.type==="task_field_updated"){if(!ye("collect_data")){be("task_field_updated","collect_data");return}const j={phase:"field",fieldId:typeof f.fieldId=="string"?f.fieldId:"",fieldName:typeof f.fieldName=="string"?f.fieldName:typeof f.fieldId=="string"?f.fieldId:"",value:typeof f.value=="string"?f.value:"",kind:typeof f.kind=="string"?f.kind:"text",source:f.source==="slide"?"slide":f.source==="page"?"page":"agent",...typeof f.slideId=="string"?{slideId:f.slideId}:{},...typeof f.formId=="string"?{formId:f.formId}:{}};if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:j}))}catch{}return}if(f.type==="task_completed"){if(!ye("collect_data")){be("task_completed","collect_data");return}const j=f.result;if(!j||typeof j!="object"){console.warn("[LiveLayer] task_completed missing `result` payload.");return}if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:{phase:"complete",result:j}}))}catch{}try{$e==null||$e(j)}catch(A){console.warn("[LiveLayer] onCollect threw.",A)}return}lo.has(f.type)||Be==null||Be(f)}},[Be,ze,$e]),ie=Xn({agentId:D?"__controlled__":st,baseUrl:s,apiKey:a,sessionEndpoint:c,sessionBody:l,onDataMessage:D?void 0:ct});r.useEffect(()=>{if(D!=null&&D.subscribeToDataMessages)return D.subscribeToDataMessages(ct)},[D,ct]),Se.current=()=>{var x;return(x=ie.getRoom)==null?void 0:x.call(ie)},r.useEffect(()=>{var ee;if(typeof window>"u")return;const x=((ee=window.location)==null?void 0:ee.hostname)||"";if(x==="localhost"||x==="127.0.0.1"||x==="0.0.0.0"||x.endsWith(".local")||x.endsWith(".test"))return window.__livelayerSimulateCommand=se=>{try{ct(se)}catch(Le){console.warn("[LiveLayer] simulate-command threw:",Le)}},()=>{delete window.__livelayerSimulateCommand}},[ct]);const k=r.useMemo(()=>D?{connectionState:D.connectionState,agentState:D.agentState,transcript:D.transcript,videoElement:D.videoElement,audioElement:D.audioElement,canResume:D.canResume,error:D.error,agentConfig:null,connect:async()=>{await D.onConnect()},disconnect:()=>D.onDisconnect(),getRoom:ie.getRoom,isControlled:!0}:{connectionState:ie.connectionState,agentState:ie.agentState,transcript:ie.transcript,videoElement:ie.videoElement,audioElement:ie.audioElement,canResume:ie.canResume,error:ie.error,agentConfig:ie.agentConfig,connect:ie.connect,disconnect:ie.disconnect,getRoom:ie.getRoom,isControlled:!1},[D,ie]),an=r.useRef(k);an.current=k;const ln=r.useRef(D);ln.current=D,r.useImperativeHandle(i,()=>({sendData:async x=>{var Le,dt;const f=ln.current;if(f!=null&&f.publishData){try{await f.publishData(x)}catch(Ne){console.warn("[AvatarWidget] sendData (controlled) failed:",Ne)}return}const ee=(dt=(Le=an.current)==null?void 0:Le.getRoom)==null?void 0:dt.call(Le),se=ee==null?void 0:ee.localParticipant;if(se!=null&&se.publishData)try{const Ne=new TextEncoder().encode(JSON.stringify(x));await se.publishData(Ne,{reliable:!0})}catch(Ne){console.warn("[AvatarWidget] sendData failed:",Ne)}}}),[]);const cn=r.useRef(null);r.useEffect(()=>{const x=k.videoElement,f=cn.current;if(!(!x||!f))return f.appendChild(x),()=>{x.parentNode===f&&f.removeChild(x)}},[k.videoElement]);const[Ke,Et]=r.useState(!1);r.useEffect(()=>{if(!I){Et(!0);return}k.agentState==="speaking"&&!Ke&&Et(!0)},[I,k.agentState,Ke]),r.useEffect(()=>{if(!I)return;const x=k.connectionState;(x==="disconnected"||x==="idle")&&Et(!1)},[I,k.connectionState]),r.useEffect(()=>{if(!I||!k.videoElement||Ke)return;const x=setTimeout(()=>Et(!0),5e3);return()=>clearTimeout(x)},[I,k.videoElement,Ke]),r.useEffect(()=>{const x=k.videoElement;if(x){if(!I){x.style.filter="";return}x.style.transition="filter 500ms ease-out",x.style.filter=Ke?"":"blur(8px)"}},[I,k.videoElement,Ke]),r.useEffect(()=>{const x=k.audioElement;if(!x)return;const f=document.createElement("div");f.className="ll-audio-sink",f.setAttribute("aria-hidden","true"),f.style.cssText="position:absolute;width:0;height:0;overflow:hidden;clip:rect(0 0 0 0);pointer-events:none;",f.appendChild(x),document.body.appendChild(f),we.attach(x);const ee=x.play();return ee&&typeof ee.catch=="function"&&ee.catch(se=>{(se==null?void 0:se.name)==="NotAllowedError"&&Ce(!0)}),()=>{we.detach(),x.parentNode===f&&f.removeChild(x),f.parentNode===document.body&&document.body.removeChild(f)}},[k.audioElement]);const ge=Jn({gateUntilAgentReady:!0,agentState:k.agentState});r.useEffect(()=>{if(k.isControlled||k.connectionState!=="connected")return;const x=k.getRoom();if(x)return ge.setupMic(x).then(()=>{const f=ge.getMicStream();f&&we.attachStream(f,"mic")}).catch(()=>{}),()=>{we.detachSlot("mic"),ge.teardownMic()}},[k.isControlled,k.connectionState]),r.useEffect(()=>{var f;if(k.connectionState!=="connected")return;const x=k.isControlled?(f=D==null?void 0:D.getRoom)==null?void 0:f.call(D):k.getRoom();if(x)return _e.attachRoom(x),Fe.attachRoom(x),k.isControlled&&ge.attachRoom(x),Ge.refresh(),()=>{_e.teardown(),Fe.teardown()}},[k.isControlled,k.connectionState,D]),r.useEffect(()=>{const x=k.audioElement;x&&(x.muted=Q)},[k.audioElement,Q]);const jr=r.useCallback(x=>{const f={type:"user_message",text:x};if(D!=null&&D.publishData){try{D.publishData(f)}catch{}return}const ee=k.getRoom();if(ee)try{const se=new TextEncoder().encode(JSON.stringify(f));ee.localParticipant.publishData(se,{reliable:!0})}catch{}},[k,D]),Ar=r.useCallback(()=>{Lr(x=>!x)},[]);r.useEffect(()=>{De==null||De(k.connectionState),k.connectionState==="connected"?qe==null||qe():k.connectionState==="disconnected"&&(Ie==null||Ie())},[k.connectionState,qe,Ie,De]),r.useEffect(()=>{Te==null||Te(k.transcript)},[k.transcript,Te]),r.useEffect(()=>{Pe==null||Pe(k.agentState)},[k.agentState,Pe]),r.useEffect(()=>{kt.setThinking(k.agentState==="thinking")},[k.agentState,kt]);const un=r.useRef(!1);r.useEffect(()=>{!g||un.current||ot&&k.connectionState==="idle"&&(un.current=!0,k.connect())},[g,k.connectionState,k,ot]);const Rr=r.useCallback(x=>{const f=v==null?void 0:v.find(ee=>ee.id===x);f&&(lt(!1),x!==Ee&&(at(!0),k.disconnect(),Ae||vt(x),b==null||b(f)))},[v,Ee,k,Ae,b]);r.useEffect(()=>{ke&&k.connectionState==="connected"&&at(!1)},[k.connectionState,ke]),r.useEffect(()=>{if(!Xe)return;const x=f=>{f.key==="Escape"&&lt(!1)};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[Xe]);const Nr=!!Y||!!(ae!=null&&ae.avatarImageUrl)||k.isControlled,ut=tr(st,s,Nr);We===void 0&&((hn=ut.info)!=null&&hn.capabilities)&&(Ut.current=ut.info.capabilities);const Lt=(ae==null?void 0:ae.name)??re??((mn=k.agentConfig)==null?void 0:mn.name)??((gn=ut.info)==null?void 0:gn.name)??"Live Layer",Vt=(ae==null?void 0:ae.avatarImageUrl)??Y??((yn=k.agentConfig)==null?void 0:yn.avatarImageUrl)??((bn=ut.info)==null?void 0:bn.avatarImageUrl)??null,Mr=M??((vn=k.agentConfig)==null?void 0:vn.idleLoopUrl)??((xn=ut.info)==null?void 0:xn.idleLoopUrl)??null,Ir=z??null,Tr=r.useCallback(()=>me("expanded"),[me]),Pr=r.useCallback(()=>me("minimized"),[me]),dn=r.useCallback(()=>{k.disconnect(),me("hidden")},[k,me]),Dr=r.useCallback(()=>{const x=k.audioElement;x&&x.play().then(()=>Ce(!1)).catch(()=>{})},[k.audioElement]),zr=r.useCallback(()=>{Ce(!1),k.connect()},[k]),Je={...Ue,...le?{}:{zIndex:xe}};T.primaryColor&&(Je["--ll-color-primary"]=T.primaryColor),T.accentColor&&(Je["--ll-color-accent"]=T.accentColor),T.backgroundColor&&(Je["--ll-color-bg"]=T.backgroundColor),T.textColor&&(Je["--ll-color-fg"]=T.textColor);const $r={...Je,...Re.style},Hr=["ll-widget",`ll-widget--${ce}`,`ll-widget--${he?"mobile":"desktop"}`,Re.hasGeometry?"ll-widget--has-geometry":null,Re.isDragging?"is-dragging":null,Re.isResizing?"is-resizing":null,He].filter(Boolean).join(" ");if(!ot)return null;const Fr=n.jsx("div",{className:Hr,style:$r,"data-display-mode":ce,"data-position":_,"data-experience-mode":d==="EMBEDDED"?"embedded":"widget",children:ce==="expanded"&&n.jsx(_i,{position:_,isMobile:he,agentName:Lt,avatarImageUrl:Vt,idleLoopUrl:Mr,greeting:Ir,branding:T,teamMembers:v,currentTeamMemberId:Ee,isSwitchingTeamMember:ke,teamSwitcherOpen:Xe,onToggleTeamSwitcher:()=>lt(x=>!x),onSelectTeamMember:Rr,connectionState:k.connectionState,agentState:k.agentState,transcript:k.transcript,isMuted:ge.isMuted,micDevices:Ge.mics,activeMicId:ge.activeDeviceId,isCameraEnabled:_e.isEnabled,cameraPreviewEl:_e.previewEl,cameraDevices:Ge.cameras,activeCameraId:_e.activeDeviceId,isScreenShareEnabled:Fe.isEnabled,screenPreviewEl:Fe.previewEl,isSpeakerMuted:Q,allowCamera:B,allowScreenShare:p,allowTyping:L,showMinimize:he&&!le?!1:Ye,showClose:wt,chromeless:K,compactControls:_t,transforming:te,transformingLabel:F,languageMenuOpen:Ct,onToggleLanguageMenu:()=>C(x=>!x),needsUserGesture:Ft,canResume:k.canResume,micError:ge.micError,error:k.error,avatarVideoContainerRef:cn,agentVideoEl:k.videoElement,onConnect:()=>void k.connect(),onDisconnect:()=>k.disconnect(),onRetry:zr,onResumeAudio:Dr,onToggleMute:ge.toggleMute,onSwitchMicDevice:x=>void ge.switchDevice(x),onToggleCamera:()=>void _e.toggle(),onSwitchCameraDevice:x=>void _e.switchDevice(x),onToggleScreenShare:()=>void Fe.toggle(),onToggleSpeaker:Ar,onSendMessage:jr,onMinimize:Pr,onClose:dn,onClearMicError:ge.clearError,dragHandleProps:Re.dragHandleProps,resizeHandleProps:Re.resizeHandleProps})}),fn=!le&&(ce==="hidden"||ce==="minimized")?n.jsxs("div",{className:["ll-widget","ll-widget--floating",`ll-widget--${ce}`,`ll-widget--${he?"mobile":"desktop"}`].join(" "),style:Je,"data-display-mode":ce,"data-position":_,children:[ce==="hidden"&&n.jsx(di,{position:_,isMobile:he,isSpeaking:k.agentState==="speaking",onExpand:()=>me("expanded"),label:`Open ${Lt} widget`,avatarImageUrl:Vt,agentName:Lt,containerEl:$}),ce==="minimized"&&n.jsx(pi,{position:_,isMobile:he,agentName:Lt,avatarImageUrl:Vt,agentState:k.agentState,isMuted:ge.isMuted,audioLevel:we,onExpand:Tr,onToggleMute:ge.toggleMute,onClose:dn})]}):null,pn=$??(typeof document<"u"?document.body:null);return n.jsxs(n.Fragment,{children:[Fr,fn&&pn&&tn.createPortal(fn,pn)]})});kr.displayName="AvatarWidgetInner";const Sr=r.forwardRef(function(t,i){return n.jsx(Gn,{children:n.jsx(kr,{...t,ref:i})})});Sr.displayName="AvatarWidget";const co=({agentId:e,baseUrl:t,apiKey:i,mode:o,onAgentEvent:a,className:s,style:c})=>{const l=r.useRef(null),u=r.useRef(null),d=r.useRef(a);d.current=a;const g=r.useCallback(h=>{var N;const m=h.detail;(N=d.current)==null||N.call(d,m)},[]);return r.useEffect(()=>{const h=l.current;if(!h)return;const m=document.createElement("livelayer-widget");return m.setAttribute("agent-id",e),t&&m.setAttribute("base-url",t),i&&m.setAttribute("api-key",i),o&&m.setAttribute("mode",o),m.addEventListener("agent-event",g),h.appendChild(m),u.current=m,()=>{m.removeEventListener("agent-event",g),h.removeChild(m),u.current=null}},[e]),r.useEffect(()=>{u.current&&(o?u.current.setAttribute("mode",o):u.current.removeAttribute("mode"))},[o]),n.jsx("div",{ref:l,className:s,style:c})},uo=r.forwardRef(function({id:t,intent:i,as:o="div",className:a,style:s,children:c},l){return r.createElement(o,{ref:l,"data-ll-region":t,"data-ll-intent":i,className:a,style:s},c)});function fo(e={}){const{onFieldUpdate:t,onComplete:i,source:o="all"}=e,[a,s]=r.useState({}),[c,l]=r.useState(!1),[u,d]=r.useState(null),g=r.useRef(t),h=r.useRef(i),m=r.useRef(o);r.useEffect(()=>{g.current=t,h.current=i,m.current=o},[t,i,o]);const N=r.useCallback(()=>{s({}),l(!1)},[]);return r.useEffect(()=>{if(typeof window>"u")return;const _=S=>{var w,R;const y=S.detail;if(y){if(y.phase==="field"){if(m.current!=="all"&&y.source!==m.current)return;l(!0),s(E=>E[y.fieldName]===y.value?E:{...E,[y.fieldName]:y.value});try{(w=g.current)==null||w.call(g,y)}catch(E){console.warn("[LiveLayer] useCollect onFieldUpdate threw.",E)}return}if(y.phase==="complete"){const E=y.result;if(m.current!=="all"&&E.source!==m.current)return;d(E),l(!1);try{(R=h.current)==null||R.call(h,E)}catch(v){console.warn("[LiveLayer] useCollect onComplete threw.",v)}}}};return document.addEventListener("ll-collected",_),()=>document.removeEventListener("ll-collected",_)},[]),{fields:a,isCollecting:c,lastResult:u,reset:N}}let Yn=1;function po({onMount:e,defaultOpen:t=!1,storageKey:i="ll-debug-open"}){const[o,a]=r.useState(t),[s,c]=r.useState([]),[l,u]=r.useState(""),[d,g]=r.useState(!1),h=r.useRef(new Set),m=r.useRef([]),N=r.useRef(d);N.current=d,r.useEffect(()=>{try{const y=localStorage.getItem(i);y==="1"&&a(!0),y==="0"&&a(!1)}catch{}},[i]),r.useEffect(()=>{try{localStorage.setItem(i,o?"1":"0")}catch{}},[o,i]),r.useEffect(()=>{const y=w=>{(w.metaKey||w.ctrlKey)&&w.shiftKey&&w.key.toLowerCase()==="l"&&(w.preventDefault(),a(R=>!R))};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[]),r.useEffect(()=>{const y=setInterval(()=>{if(m.current.length===0||N.current)return;const w=m.current.splice(0,m.current.length);c(R=>[...w.reverse(),...R].slice(0,200))},100);return()=>clearInterval(y)},[]);const _=r.useRef(!1);if(r.useEffect(()=>{!e||_.current||(_.current=!0,e(y=>{m.current.push({id:Yn++,ts:Date.now(),kind:"event",type:y.eventName,data:y.data})}))},[e]),r.useEffect(()=>{const y=console.warn,w=console.log,R=(E,v)=>function(...P){try{const b=typeof P[0]=="string"?P[0]:"";b.startsWith("[LiveLayer]")&&m.current.push({id:Yn++,ts:Date.now(),kind:E,type:b.slice(0,120),data:{args:P.slice(1).map(M=>mo(M))}})}catch{}return v.apply(this,P)};return console.warn=R("warn",y),console.log=R("log",w),()=>{console.warn=y,console.log=w}},[]),!o)return n.jsx("button",{type:"button",onClick:()=>a(!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 S=s.filter(y=>{if(!l)return!0;const w=l.toLowerCase();return y.type.toLowerCase().includes(w)||JSON.stringify(y.data||{}).toLowerCase().includes(w)});return n.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:[n.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:[n.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),n.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[s.length," event",s.length===1?"":"s"]}),n.jsx("span",{style:{flex:1}}),n.jsx("button",{type:"button",onClick:()=>g(y=>!y),style:Jt(d?"#f59e0b":"transparent"),title:"Pause / resume capture",children:d?"▶ resume":"⏸ pause"}),n.jsx("button",{type:"button",onClick:()=>{c([]),m.current=[]},style:Jt("transparent"),title:"Clear buffer",children:"clear"}),n.jsx("button",{type:"button",onClick:()=>a(!1),style:Jt("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),n.jsx("input",{type:"text",value:l,onChange:y=>u(y.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"}}),n.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 8px 8px"},children:S.length===0?n.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:",n.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 n=require("react/jsx-runtime"),r=require("react"),en=require("react-dom"),nt=require("@livelayer/sdk"),Dt=require("livekit-client");class Gn extends r.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,i){var o,a;(a=(o=this.props).onError)==null||a.call(o,t,i)}render(){var t;return this.state.hasError?this.props.fallback?this.props.fallback:n.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[n.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),n.jsx("p",{className:"ll-error-boundary__message",children:((t=this.state.error)==null?void 0:t.message)||"Something went wrong."}),n.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function Xn(e){const[t,i]=r.useState("idle"),[o,a]=r.useState("idle"),[s,c]=r.useState([]),[l,u]=r.useState(null),[d,g]=r.useState(null),[h,m]=r.useState(null),[N,_]=r.useState(!1),[S,y]=r.useState(null),w=r.useRef(null),R=r.useRef(e.onDataMessage);R.current=e.onDataMessage,r.useEffect(()=>{const b={onConnectionStateChange:z=>{i(z),z==="connected"&&y(null)},onAgentStateChange:a,onTranscript:z=>c([...z]),onAgentConfig:u,onAudioTrack:z=>m(z),onVideoTrack:z=>g(z),onVideoTrackRemoved:()=>g(null),onError:z=>y(z),onDataMessage:z=>{var Y;(Y=R.current)==null||Y.call(R,z)},onResumabilityChange:_},M=new nt.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},b);return w.current=M,i("idle"),a("idle"),c([]),u(null),g(null),m(null),_(!1),y(null),()=>{var z;(z=M.destroy)==null||z.call(M),w.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=r.useCallback(async()=>{const b=w.current;if(b)try{await b.connect()}catch(M){throw y(M instanceof Error?M.message:String(M)),M}},[]),v=r.useCallback(()=>{const b=w.current;b&&b.disconnect()},[]),P=r.useCallback(()=>{var b;return((b=w.current)==null?void 0:b.getRoom())??null},[]);return{connectionState:t,agentState:o,transcript:s,agentConfig:l,videoElement:d,audioElement:h,canResume:N,error:S,connect:E,disconnect:v,getRoom:P,session:w.current}}function Kn(){const e=r.useRef(null),t=r.useRef(new Map),i=r.useRef(null),o=r.useRef(new Set),a=r.useCallback(()=>{const _=t.current;if(_.size===0){i.current=null;return}let S=0;for(const{analyser:y,buffer:w}of _.values()){y.getByteFrequencyData(w);let R=0;for(let v=0;v<w.length;v++)R+=w[v];const E=R/w.length/255;E>S&&(S=E)}for(const y of o.current)try{y(S)}catch(w){console.error("[useAudioLevel] subscriber threw:",w)}i.current=requestAnimationFrame(a)},[]),s=r.useCallback(()=>e.current?e.current:typeof window>"u"||typeof AudioContext>"u"?null:(e.current=new AudioContext,e.current),[]),c=r.useCallback(()=>{i.current===null&&t.current.size>0&&(i.current=requestAnimationFrame(a))},[a]),l=r.useCallback(_=>{const S=t.current.get(_);if(S){try{S.node.disconnect()}catch{}try{S.analyser.disconnect()}catch{}t.current.delete(_)}},[]),u=r.useCallback((_,S)=>{const y=s();if(!y)return;l(_);const w=S(y);if(!w)return;const R=y.createAnalyser();R.fftSize=64;try{w.connect(R)}catch(E){console.warn("[useAudioLevel] connect failed for slot",_,E);return}t.current.set(_,{analyser:R,node:w,buffer:new Uint8Array(new ArrayBuffer(R.frequencyBinCount))}),c()},[l,s,c]),d=r.useCallback((_,S="agent")=>{u(S,y=>{try{return y.createMediaElementSource(_)}catch(w){return console.warn("[useAudioLevel] createMediaElementSource failed for slot",S,w),null}})},[u]),g=r.useCallback((_,S="mic")=>{u(S,y=>{try{return y.createMediaStreamSource(_)}catch(w){return console.warn("[useAudioLevel] createMediaStreamSource failed for slot",S,w),null}})},[u]),h=r.useCallback(_=>{l(_),t.current.size===0&&i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[l]),m=r.useCallback(()=>{i.current!==null&&(cancelAnimationFrame(i.current),i.current=null);for(const _ of Array.from(t.current.keys()))l(_)},[l]),N=r.useCallback(_=>(o.current.add(_),()=>{o.current.delete(_)}),[]);return r.useEffect(()=>()=>{if(m(),e.current){try{e.current.close()}catch{}e.current=null}o.current.clear()},[m]),{attach:d,attachStream:g,detach:m,detachSlot:h,subscribe:N}}function Or(e){const t=e==null?void 0:e.mediaStreamTrack;return t?new MediaStream([t]):null}function Jn(e={}){const t=e.gateUntilAgentReady??!1,i=e.agentState??null,[o,a]=r.useState(t),[s,c]=r.useState(""),[l,u]=r.useState(null),d=r.useRef(null),g=r.useRef(null),h=r.useRef({active:t,lastAutoIntent:null}),m=r.useCallback(async E=>{var v,P;if(d.current&&g.current){try{await g.current.localParticipant.unpublishTrack(d.current)}catch{}d.current.stop(),d.current=null}g.current=E,u(null);try{const b=await Dt.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await E.localParticipant.publishTrack(b),d.current=b,h.current.active?(await E.localParticipant.setMicrophoneEnabled(!1),h.current.lastAutoIntent=!1,a(!0)):a(b.isMuted);const M=(P=(v=b.mediaStreamTrack)==null?void 0:v.getSettings)==null?void 0:P.call(v);M!=null&&M.deviceId&&c(M.deviceId)}catch(b){const M=b instanceof Error&&b.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw u(M),b}},[]),N=r.useCallback(E=>{g.current=E},[]),_=r.useCallback(async E=>{const v=g.current;if(v)try{await v.switchActiveDevice("audioinput",E),c(E)}catch(P){console.warn("[useMicrophoneState] switchDevice failed:",P)}},[]),S=r.useCallback(async()=>{const E=g.current,v=!o;if(a(v),h.current.active=!1,!!E)try{await E.localParticipant.setMicrophoneEnabled(!v)}catch(P){console.warn("[useMicrophoneState] setMicrophoneEnabled failed:",P),a(!v)}},[o]);r.useEffect(()=>{if(!h.current.active||i!=="listening")return;const E=g.current,v=E==null?void 0:E.localParticipant;if(!v){h.current.active=!1;return}v.isMicrophoneEnabled===h.current.lastAutoIntent&&(v.setMicrophoneEnabled(!0),h.current.lastAutoIntent=!0,a(!1)),h.current.active=!1},[i]);const y=r.useCallback(()=>{const E=d.current,v=g.current;if(E&&v){try{v.localParticipant.unpublishTrack(E)}catch{}E.stop()}d.current=null,g.current=null,h.current={active:t,lastAutoIntent:null},a(t),c("")},[t]),w=r.useCallback(()=>u(null),[]),R=r.useCallback(()=>Or(d.current),[]);return{isMuted:o,activeDeviceId:s,micError:l,toggleMute:S,setupMic:m,attachRoom:N,switchDevice:_,teardownMic:y,clearError:w,getMicStream:R}}const Wr={resolution:{width:640,height:480,frameRate:24}};function Zn(){const[e,t]=r.useState(!1),[i,o]=r.useState(null),[a,s]=r.useState(null),[c,l]=r.useState(""),u=r.useRef(null),d=r.useRef(null),g=r.useCallback(w=>{u.current=w},[]),h=r.useCallback(()=>{var E;const w=u.current,R=d.current;if(R&&w){const v=w.localParticipant.getTrackPublication(Dt.Track.Source.Camera),b=(v==null?void 0:v.track)??R;try{w.localParticipant.unpublishTrack(b)}catch{}try{(E=b.stop)==null||E.call(b)}catch{}}d.current=null,s(null),t(!1)},[]),m=r.useCallback(async w=>{const R=u.current;if(R){o(null);try{const E={...Wr};w&&(E.deviceId=w);const v=await Dt.createLocalVideoTrack(E);await R.localParticipant.publishTrack(v),d.current=v;const P=v.attach();s(P),t(!0),w&&l(w);try{R.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const v=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";o(v)}}},[]),N=r.useCallback(async()=>{e?h():await m(c||void 0)},[e,c,h,m]),_=r.useCallback(async w=>{h(),await m(w)},[h,m]),S=r.useCallback(()=>{h(),u.current=null,o(null),l("")},[h]),y=r.useCallback(()=>o(null),[]);return r.useEffect(()=>()=>{d.current&&d.current.stop()},[]),{isEnabled:e,error:i,previewEl:a,activeDeviceId:c,toggle:N,switchDevice:_,attachRoom:g,teardown:S,clearError:y}}function Qn(){const[e,t]=r.useState(!1),[i,o]=r.useState(null),[a,s]=r.useState(null),c=r.useRef(null),l=r.useCallback(m=>{c.current=m},[]),u=r.useCallback(()=>s(null),[]),d=r.useCallback(async()=>{const m=c.current;if(m){if(e){try{await m.localParticipant.setScreenShareEnabled(!1)}catch{}u(),t(!1);return}o(null);try{await m.localParticipant.setScreenShareEnabled(!0);let N=0;const _=()=>{const S=m.localParticipant.getTrackPublication(Dt.Track.Source.ScreenShare);if(S!=null&&S.track){const y=S.track.attach();s(y),t(!0);try{m.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}N++<10?setTimeout(_,100):t(!0)};_()}catch(N){const _=N instanceof Error?N.name:"";_!=="NotAllowedError"&&_!=="AbortError"&&o("Screen share unavailable. Try again."),t(!1)}}},[e,u]),g=r.useCallback(()=>{const m=c.current;if(m&&e)try{m.localParticipant.setScreenShareEnabled(!1)}catch{}u(),t(!1),o(null),c.current=null},[e,u]),h=r.useCallback(()=>o(null),[]);return{isEnabled:e,error:i,previewEl:a,toggle:d,attachRoom:l,teardown:g,clearError:h}}function er(){const[e,t]=r.useState([]),[i,o]=r.useState([]),a=r.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const s=await navigator.mediaDevices.enumerateDevices();t(s.filter(c=>c.kind==="audioinput")),o(s.filter(c=>c.kind==="videoinput"))}catch{}},[]);return r.useEffect(()=>{if(a(),typeof navigator>"u"||!navigator.mediaDevices)return;const s=()=>void a();return navigator.mediaDevices.addEventListener("devicechange",s),()=>navigator.mediaDevices.removeEventListener("devicechange",s)},[a]),{mics:e,cameras:i,refresh:a}}function tr(e,t,i=!1){const[o,a]=r.useState(null),[s,c]=r.useState(null),[l,u]=r.useState(!i&&!!e);return r.useEffect(()=>{if(i||!e){u(!1);return}const d=new AbortController,g=t||"https://app.livelayer.studio";return u(!0),c(null),fetch(`${g}/api/widget/agent/${encodeURIComponent(e)}`,{signal:d.signal}).then(async h=>{if(!h.ok){const m=await h.json().catch(()=>({}));throw new Error(m.error||`HTTP ${h.status}`)}return h.json()}).then(h=>{d.signal.aborted||(a(h),u(!1))}).catch(h=>{d.signal.aborted||(c(h instanceof Error?h.message:"Agent lookup failed"),u(!1))}),()=>d.abort()},[e,t,i]),{info:o,error:s,loading:l}}function nr(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function rr(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function qr(e){if(!(typeof window>"u"))try{window.localStorage.removeItem(e)}catch{}}function ir({value:e,defaultValue:t="expanded",onChange:i}={}){const o=e!==void 0,[a,s]=r.useState(t),c=o?e:a,l=r.useCallback(u=>{u!==c&&(o||s(u),i==null||i(u))},[c,o,i]);return[c,l]}const Br=["hidden","minimized","expanded"];function Ur(e){return e&&Br.includes(e)?e:null}function or({value:e,defaultValue:t="expanded",onChange:i,persistKey:o="ll-widget",disablePersistence:a=!1}={}){const s=`${o}:display-mode`,c=r.useRef(!1),[l,u]=ir({value:e,defaultValue:t,onChange:d=>{e===void 0&&!a&&rr(s,d),i==null||i(d)}});return r.useEffect(()=>{if(c.current||(c.current=!0,a||e!==void 0))return;const d=Ur(nr(s));d&&d!==l&&u(d)},[]),[l,u]}const Vr=640;function sr(e=Vr){const[t,i]=r.useState(!1);return r.useEffect(()=>{if(e===!1){i(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const o=`(max-width: ${e-1}px)`,a=window.matchMedia(o),s=()=>i(a.matches);return s(),typeof a.addEventListener=="function"?(a.addEventListener("change",s),()=>a.removeEventListener("change",s)):(a.addListener(s),()=>{a.removeListener(s)})},[e]),t}const Yr=280,Gr=380,Xr=8,Kr=4;function Vt(e){return`${e}:geometry`}function Jr(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!="object"||t===null)return null;const i=t,{top:o,left:a,width:s,height:c}=i;return typeof o!="number"||typeof a!="number"||typeof s!="number"||typeof c!="number"||!Number.isFinite(o)||!Number.isFinite(a)||!Number.isFinite(s)||!Number.isFinite(c)?null:{top:o,left:a,width:s,height:c}}function Mt(){return typeof window>"u"?{vw:0,vh:0}:{vw:window.innerWidth,vh:window.innerHeight}}function Yt(e,t,i){const{minWidth:o,minHeight:a,edgeMargin:s,vw:c,vh:l}=i,u=Math.max(o,c-s*2),d=Math.max(a,l-s*2);return{width:Math.max(o,Math.min(u,e)),height:Math.max(a,Math.min(d,t))}}function Gt(e,t,i,o,a){const{edgeMargin:s,vw:c,vh:l}=a,u=s,d=s,g=Math.max(u,c-i-s),h=Math.max(d,l-o-s);return{top:Math.max(d,Math.min(h,e)),left:Math.max(u,Math.min(g,t))}}function Zr(e){const{draggable:t,resizable:i,persistKey:o,disablePersistence:a,minWidth:s=Yr,minHeight:c=Gr,edgeMargin:l=Xr}=e,[u,d]=r.useState(null),[g,h]=r.useState(!1),[m,N]=r.useState(!1),_=r.useRef(null),S=r.useRef(null),y=r.useRef(!1),w=r.useRef(null);w.current=u;const R=r.useCallback(p=>{a||(p===null?qr(Vt(o)):rr(Vt(o),JSON.stringify(p)))},[a,o]);r.useEffect(()=>{if(y.current||(y.current=!0,a))return;const p=Jr(nr(Vt(o)));if(!p)return;const{vw:L,vh:I}=Mt(),H=Yt(p.width,p.height,{minWidth:s,minHeight:c,edgeMargin:l,vw:L,vh:I}),U=Gt(p.top,p.left,H.width,H.height,{edgeMargin:l,vw:L,vh:I});d({...U,...H})},[]),r.useEffect(()=>{if(typeof window>"u")return;const p=()=>{d(L=>{if(L===null)return null;const{vw:I,vh:H}=Mt(),U=Yt(L.width,L.height,{minWidth:s,minHeight:c,edgeMargin:l,vw:I,vh:H});return{...Gt(L.top,L.left,U.width,U.height,{edgeMargin:l,vw:I,vh:H}),...U}})};return window.addEventListener("resize",p),()=>window.removeEventListener("resize",p)},[s,c,l]);const E=r.useCallback(p=>{if(!t||p.pointerType==="mouse"&&p.button!==0)return;const L=p.target;if(L&&typeof L.closest=="function"&&L.closest('button, a, input, select, textarea, [role="listbox"], [role="option"], [data-ll-no-drag]'))return;let I,H,U,K;const $=w.current;if($)({top:I,left:H,width:U,height:K}=$);else{const J=p.currentTarget.closest(".ll-widget"),ee=J==null?void 0:J.getBoundingClientRect();if(!ee)return;I=ee.top,H=ee.left,U=ee.width,K=ee.height}try{p.currentTarget.setPointerCapture(p.pointerId)}catch{}_.current={startClientX:p.clientX,startClientY:p.clientY,startTop:I,startLeft:H,width:U,height:K,moved:!1}},[t]),v=r.useCallback(p=>{const L=_.current;if(!L)return;const I=p.clientX-L.startClientX,H=p.clientY-L.startClientY;if(!L.moved&&Math.abs(I)+Math.abs(H)>Kr&&(L.moved=!0,h(!0)),!L.moved)return;const{vw:U,vh:K}=Mt(),$=Gt(L.startTop+H,L.startLeft+I,L.width,L.height,{edgeMargin:l,vw:U,vh:K});d({...$,width:L.width,height:L.height})},[l]),P=r.useCallback(p=>{const L=_.current;if(L){try{p.currentTarget.releasePointerCapture(p.pointerId)}catch{}_.current=null,L.moved&&(h(!1),d(I=>(I&&R(I),I)))}},[R]),b=r.useCallback(()=>{_.current=null,S.current=null,h(!1),N(!1),d(null),R(null)},[R]),M=r.useCallback(p=>{if(!i||p.pointerType==="mouse"&&p.button!==0)return;p.stopPropagation();let L,I,H,U;const K=w.current;if(K)({top:L,left:I,width:H,height:U}=K);else{const $=p.currentTarget.closest(".ll-widget"),J=$==null?void 0:$.getBoundingClientRect();if(!J)return;L=J.top,I=J.left,H=J.width,U=J.height}try{p.currentTarget.setPointerCapture(p.pointerId)}catch{}S.current={startClientX:p.clientX,startClientY:p.clientY,startWidth:H,startHeight:U,top:L,left:I},N(!0)},[i]),z=r.useCallback(p=>{const L=S.current;if(!L)return;const I=p.clientX-L.startClientX,H=p.clientY-L.startClientY,{vw:U,vh:K}=Mt(),$=U-L.left-l,J=K-L.top-l,ee=Yt(L.startWidth+I,L.startHeight+H,{minWidth:s,minHeight:c,edgeMargin:l,vw:Math.min(U,L.left+$+l),vh:Math.min(K,L.top+J+l)});d({top:L.top,left:L.left,...ee})},[l,s,c]),Y=r.useCallback(p=>{if(S.current){try{p.currentTarget.releasePointerCapture(p.pointerId)}catch{}S.current=null,N(!1),d(I=>(I&&R(I),I))}},[R]);return{style:u===null?{}:{position:"fixed",top:`${u.top}px`,left:`${u.left}px`,right:"auto",bottom:"auto",width:`${u.width}px`,height:`${u.height}px`},hasGeometry:u!==null,isDragging:g,isResizing:m,dragHandleProps:{onPointerDown:E,onPointerMove:v,onPointerUp:P,onPointerCancel:P,onDoubleClick:b,"data-ll-drag-handle":t?"":void 0},resizeHandleProps:{onPointerDown:M,onPointerMove:z,onPointerUp:Y,onPointerCancel:Y,"data-ll-resize-handle":i?"":void 0},reset:b}}const Sn="__llHistoryPatched",zt="ll:pathname";function Qr(){if(typeof window>"u"||window.history[Sn])return;const e=window.history.pushState,t=window.history.replaceState;window.history.pushState=function(...i){const o=e.apply(this,i);return window.dispatchEvent(new Event(zt)),o},window.history.replaceState=function(...i){const o=t.apply(this,i);return window.dispatchEvent(new Event(zt)),o},window.history[Sn]=!0}function En(){return typeof window>"u"?"/":window.location.pathname||"/"}function ar(e){const[t,i]=r.useState(()=>e??En());return r.useEffect(()=>{if(e!==void 0)return;Qr();const o=()=>i(En());return o(),window.addEventListener("popstate",o),window.addEventListener(zt,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(zt,o)}},[e]),e??t}const Ln=new Map,ei=/[\\^$+?.()|{}[\]]/g;function ti(e){return e.replace(ei,"\\$&")}function ni(e){const t=Ln.get(e);if(t)return t;const i=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,o="",a="",s=i.replace(/\*\*/g,o).replace(/\*/g,a),l=ti(s).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(a,"g"),"[^/]+"),u=new RegExp(`^${l}\\/?$`);return Ln.set(e,u),u}function ri(e,t){const i=t.length>1&&t.endsWith("/")?t.slice(0,-1):t;return ni(e).test(i)}function lr(e,t){return typeof e=="function"?e(t):e instanceof RegExp?e.test(t):ri(e,t)}function jn(e,t){if(!e||e.length===0)return!1;for(const i of e)if(lr(i,t))return!0;return!1}function cr(e,t,i){return e===void 0?!0:jn(i,e)?!1:t&&t.length>0?jn(t,e):!0}function ur(e,t,i){return r.useMemo(()=>cr(e,t,i),[e,t,i])}function ii(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 oi(e){const t=r.useMemo(()=>ii(e.config),[e.config]),i=e.baseUrl.replace(/\/+$/,""),o=r.useRef(null),a=r.useCallback(u=>{try{new Audio(`${i}${u}`).play().catch(()=>{})}catch{}},[i]),s=r.useCallback(()=>{t.navigate&&a("/audio/page-change-sound.mp3")},[t.navigate,a]),c=r.useCallback(()=>{t.action&&a("/audio/confirmation-sound.mp3")},[t.action,a]),l=r.useCallback(u=>{if(!t.thinking){if(o.current){try{o.current.pause()}catch{}o.current=null}return}if(u){if(o.current)return;try{const d=new Audio(`${i}/audio/thinking-sound.mp3`);d.loop=!0,d.volume=.3,d.play().catch(()=>{o.current=null}),o.current=d}catch{}}else if(o.current){try{o.current.pause()}catch{}o.current=null}},[i,t.thinking]);return r.useEffect(()=>()=>{if(o.current){try{o.current.pause()}catch{}o.current=null}},[]),r.useMemo(()=>({playPageChange:s,playConfirmation:c,setThinking:l}),[s,c,l])}const An=({muted:e=!1,className:t})=>e?n.jsxs("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[n.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"}),n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):n.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"})}),Rn=({className:e})=>n.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:n.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"})}),si=({className:e})=>n.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),ai={left:180,right:0,up:-90,down:90},Nn=({direction:e="right",className:t})=>n.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${ai[e]}deg)`},"aria-hidden":"true",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function li(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const dr="ll-hidden-tab-center-y",ci=5,Mn=16;function ui(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(dr);if(!e)return null;const t=Number.parseFloat(e);return Number.isFinite(t)?t:null}catch{return null}}function In(e){if(!(typeof window>"u"))try{window.localStorage.setItem(dr,String(e))}catch{}}const di=({position:e,isMobile:t,isSpeaking:i,onExpand:o,label:a="Open widget",avatarImageUrl:s,agentName:c,containerEl:l})=>{const u=li(e),d=u==="right"?"left":"right",g=t?80:72,h=!!s,m=!!l,[N,_]=r.useState(null),[S,y]=r.useState(!1),w=r.useRef(null),R=r.useRef(!1),E=r.useCallback(T=>{if(typeof window>"u")return T;const B=g/2,p=Mn+B,L=window.innerHeight-Mn-B;return L<p?Math.max(p,T):Math.max(p,Math.min(L,T))},[g]);r.useEffect(()=>{if(m){_(null);return}const T=ui();_(E(T??window.innerHeight/2));const B=()=>{_(p=>p===null?null:E(p))};return window.addEventListener("resize",B),()=>window.removeEventListener("resize",B)},[E,m]);const v=r.useCallback(T=>{if(!m&&!(T.pointerType==="mouse"&&T.button!==0)&&N!==null){try{T.currentTarget.setPointerCapture(T.pointerId)}catch{}w.current={startClientY:T.clientY,startCenterY:N,moved:!1}}},[N,m]),P=r.useCallback(T=>{const B=w.current;if(!B)return;const p=T.clientY-B.startClientY;!B.moved&&Math.abs(p)>ci&&(B.moved=!0,y(!0)),B.moved&&_(E(B.startCenterY+p))},[E]),b=r.useCallback(T=>{const B=w.current;if(B){try{T.currentTarget.releasePointerCapture(T.pointerId)}catch{}w.current=null,B.moved&&(y(!1),R.current=!0,_(p=>(p!==null&&In(p),p)))}},[]),M=r.useCallback(()=>{if(R.current){R.current=!1;return}o()},[o]),z=r.useCallback(T=>{if(T.key==="ArrowUp"||T.key==="ArrowDown"){T.preventDefault();const B=T.key==="ArrowUp"?-8:8;_(p=>{if(p===null)return p;const L=E(p+B);return In(L),L})}},[E]),Y=["ll-hidden",`ll-hidden--${u}`,t?"ll-hidden--mobile":"ll-hidden--desktop",i?"ll-hidden--speaking":null,S?"is-dragging":null,h?"ll-hidden--with-avatar":null,m?"ll-hidden--scoped":null].filter(Boolean).join(" "),re=N===null?void 0:{top:`${N-g/2}px`,transform:"none"};return n.jsx("button",{type:"button",className:Y,onPointerDown:v,onPointerMove:P,onPointerUp:b,onPointerCancel:b,onClick:M,onKeyDown:z,"aria-label":a,"data-position":e,style:re,children:h?n.jsxs(n.Fragment,{children:[n.jsx(Nn,{direction:d,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),n.jsx("img",{src:s,alt:c?`${c} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):n.jsx(Nn,{direction:d,className:"ll-hidden__chevron"})})},fi=({audioLevel:e,bars:t=20,maxHeight:i=20,minHeight:o=4,className:a,barClassName:s})=>{const c=r.useRef(null),l=r.useRef([]),u=r.useMemo(()=>{const g=(Math.sqrt(5)-1)/2;return Array.from({length:t},(h,m)=>.5+m*g%1*.5)},[t]);r.useEffect(()=>e.subscribe(h=>{for(let m=0;m<t;m++){const N=l.current[m];if(!N)continue;const _=Math.max(o,h*i*u[m]);N.style.height=`${_}px`}}),[e,t,i,o,u]);const d=["ll-waveform",a].filter(Boolean).join(" ");return n.jsx("div",{ref:c,className:d,"aria-hidden":"true",children:Array.from({length:t},(g,h)=>n.jsx("div",{ref:m=>{l.current[h]=m},className:["ll-waveform__bar",s].filter(Boolean).join(" "),style:{height:`${o}px`}},h))})},pi=({position:e,isMobile:t,agentName:i,avatarImageUrl:o,agentState:a,isMuted:s,audioLevel:c,onExpand:l,onToggleMute:u,onClose:d})=>t?n.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${i} widget`,children:n.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:l,"aria-label":`Expand ${i} widget`,children:[o?n.jsx("img",{src:o,alt:i,className:"ll-minimized__avatar"}):n.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),n.jsx(fi,{audioLevel:c,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),n.jsx("span",{className:"ll-minimized__name",children:i}),n.jsxs("div",{className:"ll-minimized__controls",children:[n.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:g=>{g.stopPropagation(),u()},onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.stopPropagation(),g.preventDefault(),u())},"aria-label":s?"Unmute microphone":"Mute microphone",children:n.jsx(An,{muted:s,className:"ll-minimized__icon"})}),n.jsx(Rn,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):n.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${i} widget`,children:n.jsxs("div",{className:"ll-minimized__surface",children:[o?n.jsx("img",{src:o,alt:i,className:"ll-minimized__avatar"}):n.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),n.jsxs("div",{className:"ll-minimized__meta",children:[n.jsx("span",{className:"ll-minimized__name",children:i}),n.jsx("span",{className:"ll-minimized__state",children:a==="speaking"?"Speaking":a==="thinking"?"Thinking":"Listening"})]}),n.jsxs("div",{className:"ll-minimized__controls",children:[n.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:u,"aria-label":s?"Unmute microphone":"Mute microphone",children:n.jsx(An,{muted:s,className:"ll-minimized__icon"})}),n.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:l,"aria-label":`Expand ${i} widget`,children:n.jsx(Rn,{className:"ll-minimized__icon"})}),n.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:d,"aria-label":"Close widget",children:n.jsx(si,{className:"ll-minimized__icon"})})]})]})}),hi=({src:e,alt:t,preCannedPlaying:i=!1,className:o,style:a})=>{const[s,c]=r.useState(!1),l=r.useRef(e);if(r.useEffect(()=>{l.current!==e&&(l.current=e,c(!1))},[e]),!e)return null;const u={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:i?"scale(1.02)":"scale(1)",opacity:s?1:0,...a};return n.jsx("img",{src:e,alt:t,className:o,style:u,loading:"eager",fetchPriority:"high",onLoad:()=>c(!0)})},mi="#E06540";function gi({size:e=14,className:t,fill:i=mi}){return n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 52 52",fill:"none",className:t,"aria-hidden":!0,children:[n.jsx("path",{d:"M44.5714 26C44.5714 23.5612 44.0908 21.146 43.1575 18.8928C42.2242 16.6397 40.8565 14.5924 39.132 12.868C37.4076 11.1435 35.3603 9.77577 33.1072 8.84247C30.854 7.90917 28.4388 7.42857 26 7.42857C23.5612 7.42857 21.146 7.90916 18.8928 8.84247C16.6397 9.77577 14.5924 11.1435 12.868 12.868C11.1435 14.5924 9.77577 16.6397 8.84247 18.8928C7.90917 21.146 7.42857 23.5612 7.42857 26C7.42857 28.4388 7.90916 30.854 8.84247 33.1072C9.77577 35.3603 11.1435 37.4076 12.868 39.132C14.5924 40.8565 16.6397 42.2242 18.8928 43.1575C21.146 44.0908 23.5612 44.5714 26 44.5714H48.2857C50.3371 44.5714 52 46.2344 52 48.2857C52 50.3371 50.3371 52 48.2857 52H26C22.5857 52 19.2049 51.3275 16.0505 50.021C12.896 48.7144 10.0293 46.7993 7.61501 44.385C5.20069 41.9707 3.28564 39.104 1.97902 35.9495C0.67247 32.7951 -3.54212e-07 29.4143 0 26C-1.68163e-07 22.5857 0.672469 19.2049 1.97902 16.0505C3.28564 12.896 5.20069 10.0293 7.61501 7.61501C10.0293 5.20069 12.896 3.28564 16.0505 1.97902C19.2049 0.67247 22.5857 0 26 0C29.4143 1.86048e-07 32.7951 0.67247 35.9495 1.97902C39.104 3.28564 41.9707 5.20069 44.385 7.61501C46.7993 10.0293 48.7144 12.896 50.021 16.0505C51.3275 19.2049 52 22.5857 52 26C52 28.0513 50.3371 29.7143 48.2857 29.7143C46.2344 29.7143 44.5714 28.0513 44.5714 26Z",fill:i}),n.jsx("path",{d:"M28.9717 23.7714C28.9717 21.3098 30.9672 19.3143 33.4288 19.3143C35.8904 19.3143 37.886 21.3098 37.886 23.7714C37.886 26.233 35.8904 28.2286 33.4288 28.2286C30.9672 28.2286 28.9717 26.233 28.9717 23.7714Z",fill:i}),n.jsx("path",{d:"M18.5714 19.3143C16.1098 19.3143 14.1143 21.3098 14.1143 23.7714C14.1143 26.233 16.1098 28.2286 18.5714 28.2286C21.033 28.2286 23.0285 26.233 23.0285 23.7714C23.0285 21.3098 21.033 19.3143 18.5714 19.3143Z",fill:i})]})}const yi=8,Tn=8,bi=({open:e,onClose:t,anchorRef:i,children:o})=>{const a=r.useRef(null),[s,c]=r.useState(null);return r.useLayoutEffect(()=>{if(!e){c(null);return}const l=i.current;if(!l)return;const u=()=>{const d=l.getBoundingClientRect(),g={top:d.top-yi,left:d.left+d.width/2},h=Tn+90,m=window.innerWidth-Tn-90;g.left<h&&(g.left=h),g.left>m&&(g.left=m),c(g)};return u(),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[e,i]),r.useEffect(()=>{if(!e)return;const l=d=>{const g=d.target,h=a.current,m=i.current;h&&h.contains(g)||m&&m.contains(g)||t()},u=d=>{d.key==="Escape"&&(d.stopPropagation(),t())};return document.addEventListener("mousedown",l),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",u)}},[e,t,i]),!e||s===null||typeof document>"u"?null:en.createPortal(n.jsx("div",{ref:a,className:"ll-overflow-popover",role:"menu",style:{position:"fixed",top:s.top,left:s.left,transform:"translate(-50%, -100%)"},children:o}),document.body)},vi=({isMuted:e,onToggleMute:t,isCameraEnabled:i,onToggleCamera:o,allowCamera:a,isScreenShareEnabled:s,onToggleScreenShare:c,allowScreenShare:l,isSpeakerMuted:u,onToggleSpeaker:d,allowTyping:g,isTypingOpen:h,onToggleTyping:m,onDisconnect:N})=>{const[_,S]=r.useState(!1),y=r.useRef(null);return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:w=>w.stopPropagation(),children:[n.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:t,"aria-label":e?"Unmute microphone":"Mute microphone",children:n.jsx(hr,{muted:e})}),n.jsx("button",{ref:y,type:"button",className:`ll-tool ${_?"is-on":""}`,onClick:()=>S(w=>!w),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":_,children:n.jsx(xi,{})}),n.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:N,"aria-label":"End conversation",children:n.jsx(gr,{})})]}),n.jsxs(bi,{open:_,onClose:()=>S(!1),anchorRef:y,children:[a&&n.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${i?"is-on":""}`,onClick:()=>{o(),S(!1)},children:[n.jsx(pr,{}),n.jsx("span",{children:i?"Stop camera":"Start camera"})]}),l&&n.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${s?"is-on":""}`,onClick:()=>{c(),S(!1)},children:[n.jsx(fr,{}),n.jsx("span",{children:s?"Stop sharing":"Share screen"})]}),n.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${u?"is-on":""}`,onClick:()=>{d(),S(!1)},children:[n.jsx(mr,{muted:u}),n.jsx("span",{children:u?"Unmute speaker":"Mute speaker"})]}),g&&n.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${h?"is-on":""}`,onClick:()=>{m(),S(!1)},children:[n.jsx(wi,{}),n.jsx("span",{children:h?"Hide typing":"Type a message"})]}),n.jsxs("button",{type:"button",className:"ll-overflow-popover__item is-active",disabled:!0,"aria-current":"true",children:[n.jsx("span",{className:"ll-overflow-popover__lang-code",children:"EN"}),n.jsx("span",{children:"English"})]})]})]})};function xi(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[n.jsx("circle",{cx:"6",cy:"12",r:"1.5"}),n.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),n.jsx("circle",{cx:"18",cy:"12",r:"1.5"})]})}function wi(){return n.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:n.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 _i=({position:e,isMobile:t,agentName:i,avatarImageUrl:o,idleLoopUrl:a,greeting:s,branding:c,teamMembers:l,currentTeamMemberId:u,isSwitchingTeamMember:d,teamSwitcherOpen:g,onToggleTeamSwitcher:h,onSelectTeamMember:m,languageMenuOpen:N,onToggleLanguageMenu:_,connectionState:S,agentState:y,transcript:w,canResume:R,needsUserGesture:E,error:v,isMuted:P,micError:b,micDevices:M,activeMicId:z,isCameraEnabled:Y,cameraPreviewEl:re,cameraDevices:T,activeCameraId:B,isScreenShareEnabled:p,screenPreviewEl:L,isSpeakerMuted:I,allowCamera:H,allowScreenShare:U,allowTyping:K,showMinimize:$=!0,showClose:J=!0,chromeless:ee=!1,compactControls:F=!1,transforming:fe,transformingLabel:G,avatarVideoContainerRef:xe,agentVideoEl:Z,onConnect:Ee,onDisconnect:rt,onRetry:gt,onResumeAudio:yt,onToggleMute:it,onSwitchMicDevice:bt,onToggleCamera:We,onSwitchCameraDevice:qe,onToggleScreenShare:Ie,onToggleSpeaker:Te,onSendMessage:Pe,onMinimize:De,onClose:ze,onClearMicError:Be,dragHandleProps:$e,resizeHandleProps:D})=>{var Xe;const He=((l==null?void 0:l.length)??0)>1,Ue=S==="connecting"||S==="connected",we=S==="connected",vt=S==="idle"||S==="disconnected"||S==="error",[ot,Le]=r.useState(!1);r.useEffect(()=>{if(!Z){Le(!1);return}if(!Z.paused&&Z.readyState>=2){Le(!0);return}Le(!1);const C=()=>Le(!0);return Z.addEventListener("playing",C),Z.addEventListener("loadeddata",C),()=>{Z.removeEventListener("playing",C),Z.removeEventListener("loadeddata",C)}},[Z]);const[st,xt]=r.useState(!1);r.useEffect(()=>{y==="speaking"&&xt(!0)},[y]),r.useEffect(()=>{(S==="disconnected"||S==="idle")&&xt(!1)},[S]);const[Fe,se]=r.useState(!1);r.useEffect(()=>{if(!we){se(!1);return}if(st)return;const C=setTimeout(()=>se(!0),12e3);return()=>clearTimeout(C)},[we,st]);const wt=S==="connecting"||we&&!st&&!Fe,ae=r.useRef(null),he=r.useRef(null);r.useEffect(()=>{const C=ae.current;C&&(C.innerHTML="",re&&(re.style.width="100%",re.style.height="100%",re.style.objectFit="cover",re.style.transform="scaleX(-1)",C.appendChild(re)))},[re]),r.useEffect(()=>{const C=he.current;C&&(C.innerHTML="",L&&(L.style.width="100%",L.style.height="100%",L.style.objectFit="contain",C.appendChild(L)))},[L]);const[Ve,Ye]=r.useState(!1),[ce,me]=r.useState(!1),_t=r.useRef(null),Ct=r.useRef(null);r.useEffect(()=>{if(!Ve&&!ce&&!N&&!g)return;const C=()=>{Ye(!1),me(!1),N&&_(),g&&h()};return document.addEventListener("click",C),()=>document.removeEventListener("click",C)},[Ve,ce,N,g,_,h]);const[kt,tn]=r.useState(!1),nn=r.useCallback(()=>tn(C=>!C),[]),[ye,je]=r.useState(""),ke=r.useCallback(C=>{C.preventDefault();const te=ye.trim();te&&(Pe(te),je(""))},[ye,Pe]),Ae=c.productName||"Live Layer",at=!c.productName;let Re=null,_e=null;for(let C=w.length-1;C>=0;C--){const te=w[C];if(!Re&&te.role==="agent"?Re=te:!_e&&te.role==="user"&&(_e=te),Re&&_e)break}const Ge=we?(Re==null?void 0:Re.text)||null:s||null,lt=we&&(_e==null?void 0:_e.text)||null,ct=["ll-expanded",t?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return n.jsxs("div",{className:ct,"data-position":e,"data-state":we?"connected":Ue?"connecting":"idle",role:"dialog","aria-label":`${i} widget`,children:[n.jsxs("div",{className:"ll-expanded__bg",children:[o?n.jsx(hi,{src:o,alt:i,className:"ll-expanded__bg-img"}):n.jsx("div",{className:"ll-expanded__bg-fallback",children:n.jsx("span",{className:"ll-expanded__bg-initial",children:((Xe=i==null?void 0:i.charAt(0))==null?void 0:Xe.toUpperCase())||"A"})}),a&&!we&&n.jsx("video",{className:"ll-expanded__bg-idle",src:a,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),n.jsx("div",{ref:xe,className:"ll-expanded__video","data-ready":ot}),wt&&n.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--connecting",children:[n.jsx("div",{className:"ll-expanded__spinner"}),n.jsx("p",{className:"ll-expanded__overlay-text",children:d?"Switching...":"Connecting..."})]}),E&&we&&n.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:yt,children:[n.jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:n.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"})}),n.jsx("p",{className:"ll-expanded__overlay-text",children:"Tap to enable audio"})]}),fe&&n.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":G,children:[n.jsx("div",{className:"ll-expanded__spinner"}),n.jsx("p",{className:"ll-expanded__overlay-text",children:G})]}),Ue?n.jsxs(n.Fragment,{children:[!F&&n.jsxs("div",{className:"ll-expanded__topbar",...$e,children:[!ee&&n.jsxs("div",{className:"ll-expanded__topbar-left",children:[n.jsxs("div",{className:"ll-expanded__pill-wrap",children:[n.jsxs("button",{type:"button",className:"ll-hpill",onClick:C=>{He&&(C.stopPropagation(),h())},"aria-haspopup":He?"listbox":void 0,"aria-expanded":He?g:void 0,children:[n.jsx("span",{className:"ll-hpill__label",children:i}),He&&n.jsx(It,{})]}),He&&g&&n.jsx("div",{className:"ll-hmenu",onClick:C=>C.stopPropagation(),role:"listbox",children:l==null?void 0:l.map(C=>n.jsxs("button",{type:"button",className:`ll-hmenu__item ${C.id===u?"is-active":""}`,onClick:()=>m(C.id),role:"option","aria-selected":C.id===u,children:[C.avatarImageUrl&&n.jsx("img",{src:C.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),n.jsx("span",{className:"ll-hmenu__name",children:C.name}),C.role&&n.jsx("span",{className:"ll-hmenu__role",children:C.role})]},C.id))})]}),n.jsxs("div",{className:"ll-expanded__pill-wrap",children:[n.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:C=>{C.stopPropagation(),_()},"aria-haspopup":"listbox","aria-expanded":N,"aria-label":"Language: English",title:"Language: English",children:[n.jsx("span",{className:"ll-hpill__label",children:"EN"}),n.jsx(It,{})]}),N&&n.jsx("div",{className:"ll-hmenu",onClick:C=>C.stopPropagation(),role:"listbox",children:n.jsx("button",{type:"button",className:"ll-hmenu__item is-active",role:"option","aria-selected":!0,children:n.jsx("span",{className:"ll-hmenu__name",children:"English"})})})]}),n.jsx("span",{className:`ll-expanded__state ll-expanded__state--${y}`,children:y})]}),n.jsxs("div",{className:"ll-expanded__header-actions",children:[$!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn",onClick:De,"aria-label":"Minimize widget",title:"Minimize",children:n.jsx(Dn,{})}),J!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:ze,"aria-label":"End call",title:"End call",children:n.jsx(Pn,{})})]})]}),F&&n.jsxs("div",{className:"ll-compact-status","data-state":y,children:[n.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),n.jsx("span",{className:"ll-compact-status__label",children:y})]})]}):n.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",...$e,children:[!F&&(at?n.jsxs("a",{className:"ll-expanded__brand ll-expanded__brand--link",href:"https://livelayer.studio?utm_source=widget&utm_medium=brand-badge",target:"_blank",rel:"noopener noreferrer","aria-label":"Powered by LiveLayer — opens livelayer.studio in a new tab",title:"Powered by LiveLayer — visit livelayer.studio",children:[n.jsx(gi,{size:14,className:"ll-expanded__brand-mark"}),n.jsx("span",{children:Ae})]}):n.jsx("span",{className:"ll-expanded__brand",children:Ae})),n.jsxs("div",{className:"ll-expanded__header-actions",children:[!F&&$!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:De,"aria-label":"Minimize widget",children:n.jsx(Dn,{})}),J!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:ze,"aria-label":"Close widget",children:n.jsx(Pn,{})})]})]}),vt&&(()=>{const C=R?"Resume session":S==="disconnected"?"Reconnect to agent":"Start video call",te=!v;return n.jsxs(n.Fragment,{children:[te&&n.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:Ee,"aria-label":C,children:[n.jsx("div",{className:"ll-expanded__play-circle",children:n.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:n.jsx("polygon",{points:"6 3 20 12 6 21 6 3"})})}),F&&n.jsx("span",{className:"ll-expanded__play-label",children:C})]}),!F&&n.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[s&&n.jsx("div",{className:"ll-expanded__transcript",children:n.jsx("p",{className:"ll-expanded__transcript-text",children:s})}),n.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:Ee,"aria-label":C,children:C})]})]})})(),n.jsxs("div",{className:`ll-expanded__pip ${Ue&&(Y||p)?"is-visible":""}`,children:[n.jsx("div",{ref:he,className:p?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),n.jsx("div",{ref:ae,className:!p&&Y?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Ue?n.jsxs("div",{className:"ll-expanded__bottom",children:[!F&&Ge&&n.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:n.jsx("p",{className:"ll-expanded__transcript-text",children:Ge})}),!F&&lt&&n.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:n.jsx("p",{className:"ll-expanded__transcript-text",children:lt})}),!ee&&!F&&n.jsxs("div",{className:"ll-toolbar",onClick:C=>C.stopPropagation(),children:[U&&n.jsx("button",{type:"button",className:`ll-tool ${p?"is-on":""}`,onClick:Ie,"aria-label":p?"Stop sharing screen":"Share screen",title:p?"Stop sharing":"Share screen",children:n.jsx(fr,{})}),H&&n.jsxs("div",{className:"ll-tool-split",children:[n.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${Y?"is-on":""}`,onClick:We,"aria-label":Y?"Turn off camera":"Turn on camera",title:Y?"Stop camera":"Start camera",children:n.jsx(pr,{})}),n.jsx("button",{ref:Ct,type:"button",className:`ll-tool ll-tool--right ${Y?"is-on":""}`,onClick:C=>{C.stopPropagation(),me(te=>!te),Ye(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":ce,children:n.jsx(It,{})}),ce&&T.length>0&&n.jsx(zn,{label:"Camera",devices:T,activeId:B,anchorRef:Ct,onPick:C=>{me(!1),qe(C)}})]}),n.jsxs("div",{className:"ll-tool-split",children:[n.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${P?"is-muted":""}`,onClick:it,"aria-label":P?"Unmute microphone":"Mute microphone",title:P?"Unmute":"Mute",children:n.jsx(hr,{muted:P})}),n.jsx("button",{ref:_t,type:"button",className:`ll-tool ll-tool--right ${P?"is-muted":""}`,onClick:C=>{C.stopPropagation(),Ye(te=>!te),me(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":Ve,children:n.jsx(It,{})}),Ve&&M.length>0&&n.jsx(zn,{label:"Microphone",devices:M,activeId:z,anchorRef:_t,onPick:C=>{Ye(!1),bt(C)}})]}),n.jsx("button",{type:"button",className:`ll-tool ${I?"is-muted":""}`,onClick:Te,"aria-label":I?"Unmute speaker":"Mute speaker",title:I?"Unmute speaker":"Mute speaker",children:n.jsx(mr,{muted:I})}),n.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:rt,"aria-label":"End conversation",title:"End conversation",children:n.jsx(gr,{})})]}),!ee&&F&&n.jsx(vi,{isMuted:P,onToggleMute:it,isCameraEnabled:Y,onToggleCamera:We,allowCamera:H,isScreenShareEnabled:p,onToggleScreenShare:Ie,allowScreenShare:U,isSpeakerMuted:I,onToggleSpeaker:Te,allowTyping:K,isTypingOpen:kt,onToggleTyping:nn,onDisconnect:rt}),!ee&&K&&(F?kt:!0)&&n.jsxs("form",{className:"ll-message-input",onSubmit:ke,children:[n.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:ye,onChange:C=>je(C.target.value),"aria-label":"Message the agent"}),ye.trim()&&n.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:n.jsx(Ci,{})})]})]}):null,(()=>{if(b&&S!=="error")return n.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[n.jsx("span",{children:b}),n.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:Be,"aria-label":"Dismiss",children:"×"})]});if(!v||S!=="error")return null;let C="Failed to connect",te="Try again";return v==="MIC_PERMISSION_DENIED"?C="Microphone blocked. Allow access to talk.":v==="MIC_NOT_FOUND"?C="No microphone found. Plug one in + retry.":v==="MIC_UNAVAILABLE"?C="Mic unavailable. Check other apps using it.":v==="AGENT_TIMEOUT"?C="Agent didn't pick up. Try again.":v==="CONNECT_FAILED"?C="Connection failed. Check your network.":v.length<80&&(C=v),n.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[n.jsx("span",{children:C}),n.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:gt,children:te})]})})(),(D==null?void 0:D["data-ll-resize-handle"])!==void 0&&n.jsx("div",{className:"ll-expanded__resize-grip",...D,"aria-hidden":!0,children:n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[n.jsx("line",{x1:"11",y1:"4",x2:"4",y2:"11"}),n.jsx("line",{x1:"11",y1:"8",x2:"8",y2:"11"})]})})]})};function It(){return n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":!0,children:n.jsx("polyline",{points:"6 9 12 15 18 9"})})}function Pn(){return n.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Dn(){return n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:n.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function fr(){return n.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:[n.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),n.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),n.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function pr(){return n.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:[n.jsx("path",{d:"M23 7l-7 5 7 5V7z"}),n.jsx("rect",{x:"1",y:"5",width:"15",height:"14",rx:"2"})]})}function hr({muted:e}){return n.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:[n.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),n.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),n.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),e&&n.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function mr({muted:e}){return n.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:[n.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e?n.jsx("line",{x1:"23",y1:"9",x2:"17",y2:"15"}):n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"}),n.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]})]})}function Ci(){return n.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:[n.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),n.jsx("polyline",{points:"12 5 19 12 12 19"})]})}function gr(){return n.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:n.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 zn=({label:e,devices:t,activeId:i,onPick:o,anchorRef:a})=>{const[s,c]=r.useState(null);return r.useLayoutEffect(()=>{const l=()=>{const u=a.current;if(!u)return;const d=u.getBoundingClientRect(),g=126,h=window.innerWidth-16-110,m=d.left+d.width/2;c({top:d.top-8,left:Math.max(g,Math.min(h,m))})};return l(),window.addEventListener("scroll",l,!0),window.addEventListener("resize",l),()=>{window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[a]),s===null||typeof document>"u"?null:en.createPortal(n.jsxs("div",{className:"ll-device-menu ll-device-menu--floating",onClick:l=>l.stopPropagation(),role:"listbox",style:{position:"fixed",top:s.top,left:s.left,transform:"translate(-50%, -100%)"},children:[n.jsx("p",{className:"ll-device-menu__label",children:e}),t.map((l,u)=>{const d=i===l.deviceId;return n.jsxs("button",{type:"button",className:`ll-device-menu__item ${d?"is-active":""}`,onClick:()=>o(l.deviceId),role:"option","aria-selected":d,children:[d&&n.jsx("span",{className:"ll-device-menu__dot",children:"●"}),n.jsx("span",{className:"ll-device-menu__name",children:l.label||`${e} ${u+1}`})]},l.deviceId||u)})]}),document.body)},ki=["[data-ll-private]","[data-ll-skip]",".ll-widget"];function $t(e){let t=e;for(;t;){for(const i of ki)if(t.matches(i))return!0;t=t.parentElement}return!1}function Jt(e){if($t(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const t=(e.getAttribute("autocomplete")||"").toLowerCase();if(t==="off"||t.startsWith("cc-"))return!1}return!0}const Si=/\b(continue|next|proceed|move\s*on|forward)\b|→|›/i,$n=/\b(back|previous|prev|go\s*back)\b|←|‹/i,Ei=/\b(submit|finish|done|complete|send)\b/i,mt=new Map;function Hn(e){const t=mt.get(e);return t&&t.isConnected?t:null}function Qe(e){if($t(e)||e.hidden||e.getAttribute("aria-hidden")==="true")return!0;const t=typeof window<"u"&&window.getComputedStyle?window.getComputedStyle(e):null;return!!(t&&(t.display==="none"||t.visibility==="hidden"))}function Li(e){return!!(e.disabled||e.getAttribute("aria-disabled")==="true")}function ji(e){return(e.innerText||e.textContent||e.getAttribute("aria-label")||e.value||"").trim()}function Ai(e){return Array.from(e.querySelectorAll('button, [role="button"], input[type="submit"], input[type="button"]')).filter(i=>!Qe(i)&&!Li(i))}function yr(e){mt.clear();const t=Ai(e);let i,o,a;for(const l of t){const u=ji(l);if(!u||u.length>40)continue;const d=l.getAttribute("type")==="submit"||l.tagName==="BUTTON"&&!l.getAttribute("type")&&!!l.closest("form");!i&&Si.test(u)&&!$n.test(u)?(i={id:"ll-advance",label:u},mt.set("ll-advance",l)):!o&&$n.test(u)?(o={id:"ll-back",label:u},mt.set("ll-back",l)):!a&&(Ei.test(u)||d)&&(a={id:"ll-submit",label:u},mt.set("ll-submit",l))}const s=Di(e);return{kind:i||s.totalSteps?"multi-step":"single-page",advance:i,back:o,submit:a,...s}}const Ri=60;function br(e){return e.replace(/^\s*(step\s+)?\d{1,2}(?:[.):\-]+\s*|\s+)/i,"").replace(/\s+/g," ").trim().slice(0,Ri)}function Ni(e){const t=e.getAttribute("class");return t?t.toLowerCase():""}const Mi=/stepper|wizard|ant-steps|step-indicator/;function Ii(e){return Mi.test(Ni(e))}function Fn(e){const t=e.getAttribute("aria-current");return t==="step"||t==="true"?!0:Array.from(e.classList).some(i=>/(^|[-_])(active|current|selected)([-_]|$)/i.test(i))}const Ti='[aria-current="step"],[aria-current="true"],[class*="active"],[class*="Active"],[class*="current"],[class*="Current"],[class*="selected"],[class*="Selected"]';function Pi(e){return Fn(e)?!0:Array.from(e.querySelectorAll(Ti)).some(Fn)}function On(e,t){const i=br(e[t].innerText||e[t].textContent||"");return{totalSteps:e.length,currentStep:t+1,...i?{stepLabel:i}:{}}}function Di(e){const t=e.querySelector('[aria-current="step"]');if(t&&t.parentElement&&!Qe(t)){const a=Array.from(t.parentElement.children).filter(c=>c.tagName===t.tagName&&!Qe(c)),s=a.indexOf(t);if(s>=0&&a.length>=2)return On(a,s)}const i=e.querySelector('[role="progressbar"]');if(i&&!Qe(i)){const a=Number(i.getAttribute("aria-valuenow")),s=Number(i.getAttribute("aria-valuemax"));if(Number.isFinite(a)&&Number.isFinite(s)&&s>=2){const c=(i.getAttribute("aria-valuetext")||"").trim();return{totalSteps:s,currentStep:a,...c?{stepLabel:br(c)}:{}}}}const o=Array.from(e.querySelectorAll('[class*="step"], [class*="Step"], [class*="wizard"], [class*="Wizard"]')).filter(a=>!Qe(a)&&Ii(a));for(const a of o){const s=Array.from(a.children).filter(l=>!Qe(l)&&(l.textContent||"").trim().length>0);if(s.length<2||s.length>12)continue;const c=s.findIndex(Pi);if(!(c<0))return On(s,c)}return{}}const Tt=4096,zi=20,$i=20,Hi=10,Fi=10,Oi=30,Wi=20,Wn=500,qi=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function pt(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let t=e;for(;t;){for(const i of qi)if(t.matches(i))return!0;t=t.parentElement}return!1}function ht(e){if(typeof window>"u")return!0;const t=e.getBoundingClientRect();if(t.width<=0||t.height<=0)return!1;const i=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth;return t.bottom>0&&t.right>0&&t.top<i&&t.left<o}function qn(e){const t=e.getAttribute("id");if(t){const s=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(t):t.replace(/"/g,'\\"'),c=document.querySelector(`label[for="${s}"]`);if(c!=null&&c.textContent)return c.textContent.trim()}const i=e.getAttribute("aria-label");if(i)return i.trim();const o=e.closest("label");if(o){const s=[];for(const l of Array.from(o.childNodes))if(l.nodeType===Node.TEXT_NODE){const u=(l.textContent||"").trim();u&&s.push(u)}else if(l instanceof HTMLElement){if(l instanceof HTMLInputElement||l instanceof HTMLTextAreaElement||l instanceof HTMLSelectElement||l instanceof HTMLButtonElement)continue;const u=(l.textContent||"").trim();u&&s.push(u)}const c=s.join(" ").trim();if(c)return c}const a=e.getAttribute("placeholder");return a?a.trim():""}function oe(e,t){return e.length<=t?e:e.slice(0,t-1)+"…"}function Bi(e){return e&&e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function Ui(e){const t=e.getAttribute("aria-label");if(t)return t.trim().slice(0,80);const i=e.getAttribute("aria-labelledby");if(i){const s=document.getElementById(i);if(s!=null&&s.textContent)return s.textContent.trim().slice(0,80)}const o=e.querySelector('button[type="submit"], input[type="submit"], button:not([type])');if(o){const s=o instanceof HTMLInputElement?o.value:(o.textContent??"").trim();if(s&&s.length<60&&!/^(submit|ok|continue)$/i.test(s))return s}let a=e.parentElement;for(let s=0;a&&s<4;s++,a=a.parentElement){const c=a.querySelector("h1, h2, h3, h4");if(c!=null&&c.textContent){const l=c.textContent.trim();if(l&&l.length<80)return l}}return null}function Ze(e){return e.length}function vr(e,t={}){const i=t.doc??(typeof document<"u"?document:null);if(!i)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const o=typeof window<"u"&&window.location.href||"",a=typeof window<"u"&&window.location.pathname||"/",s=i.title||"",c=Array.from(i.querySelectorAll("[data-ll-region]")),l=[];for(const b of c){if(l.length>=Hi)break;if(pt(b)||!ht(b))continue;const M=b.getAttribute("data-ll-region")??"",z=b.getAttribute("data-ll-intent")??void 0,Y=oe((b.innerText||b.textContent||"").trim(),Wn*2);!M||!Y||l.push({id:M,intent:z,text:Y})}const u=[],d=["H1","H2","H3","H4","H5","H6"],g=Array.from(i.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const b of g){if(pt(b)||!ht(b))continue;const M=(b.textContent||"").trim();M&&u.push(`${b.tagName}: ${oe(M,200)}`)}const h=Array.from(i.querySelectorAll("p, li"));for(const b of h){if(pt(b)||!ht(b)||d.includes(b.tagName))continue;const M=(b.textContent||"").trim();M.length>10&&u.push(oe(M,Wn))}const m=u.join(`
2
+ `),N=[],_=Array.from(i.querySelectorAll("a[href]"));for(const b of _){if(N.length>=zi)break;if(pt(b)||!ht(b))continue;const M=b.getAttribute("href")||"",z=(b.textContent||"").trim();!M||!z||N.push({href:M,text:oe(z,100)})}const S=[],y=Array.from(i.querySelectorAll("input, textarea, select"));for(const b of y){if(S.length>=$i)break;if(pt(b)||!Jt(b)||!ht(b))continue;const M=qn(b),z=b instanceof HTMLInputElement?b.type:b.tagName.toLowerCase();M&&S.push({label:oe(M,100),type:z})}const w=Array.from(i.querySelectorAll("form")),R=[];let E=0;for(const b of w){if(R.length>=Fi)break;if($t(b)||b.matches(".ll-widget *, .ll-widget"))continue;const M=b.getAttribute("id")||b.getAttribute("name")||Bi(b.getAttribute("data-ll-intent"))||`form_${E++}`,z=b.getAttribute("data-ll-intent")||Ui(b)||void 0,Y=Array.from(b.querySelectorAll("input, textarea, select")),re=[];let T=0;const B=new Set;for(const p of Y){if(re.length>=Oi)break;if(!Jt(p))continue;if(p instanceof HTMLInputElement){const F=p.type;if(F==="submit"||F==="button"||F==="reset"||F==="hidden"||F==="image"||F==="file")continue}const L=p.getAttribute("name")||"",I=p.getAttribute("id")||"";let H=L||I||`field_${T}`;B.has(H)&&(H=`${H}__${T}`),B.add(H),T++;const U=qn(p)||H,K=p instanceof HTMLInputElement?p.type:p.tagName.toLowerCase(),$={name:H,label:oe(U,100),type:K};p.required===!0&&($.required=!0);const J=p.getAttribute("placeholder");if(J&&($.placeholder=oe(J.trim(),100)),p instanceof HTMLInputElement||p instanceof HTMLTextAreaElement){const F=p.getAttribute("minlength");if(F!==null){const G=parseInt(F,10);!Number.isNaN(G)&&G>=0&&($.minLength=G)}const fe=p.getAttribute("maxlength");if(fe!==null){const G=parseInt(fe,10);!Number.isNaN(G)&&G>=0&&($.maxLength=G)}}if(p instanceof HTMLInputElement){const F=p.getAttribute("min");F!==null&&($.min=oe(F,50));const fe=p.getAttribute("max");fe!==null&&($.max=oe(fe,50));const G=p.getAttribute("step");G!==null&&($.step=oe(G,20));const xe=p.getAttribute("pattern");xe!==null&&($.pattern=oe(xe,200));const Z=(p.getAttribute("autocomplete")||"").toLowerCase();Z&&Z!=="off"&&!Z.startsWith("cc-")&&($.autocomplete=oe(Z,50))}if(p instanceof HTMLSelectElement){const F=[];for(let fe=0;fe<p.options.length;fe++){const G=p.options[fe];if(!G)continue;if(G.value===""||G.disabled){const Ee=(G.textContent||"").trim();if(Ee&&!$.placeholderOption&&($.placeholderOption=oe(Ee,60)),$.hasEmptyOption=!0,G.disabled)continue}if(F.length>=Wi)break;const xe=G.value||"",Z=(G.textContent||"").trim()||xe;!xe&&!Z||F.push({value:xe,label:oe(Z,60)})}F.length>0&&($.options=F)}const ee=typeof p.validationMessage=="string"?p.validationMessage:"";ee&&($.validationMessage=oe(ee,200)),re.push($)}R.push({id:M,intent:z,fields:re})}const v={url:o,title:s,pathname:a,regions:l,visibleText:m,visibleLinks:N,visibleFields:S,forms:R,flow:yr(i),extras:e};let P=Ze(JSON.stringify(v.regions))+Ze(v.visibleText)+Ze(JSON.stringify(v.visibleLinks))+Ze(JSON.stringify(v.visibleFields));for(;P>Tt&&v.visibleFields.length>0;)v.visibleFields.pop(),P=Ze(JSON.stringify(v.visibleFields));for(;P>Tt&&v.visibleLinks.length>0;)v.visibleLinks.pop(),P-=80;return Ze(v.visibleText)>Tt&&(v.visibleText=oe(v.visibleText,Tt-100)),v}let et=null;function Vi(e){const t=e.querySelectorAll("form");let i=`f${t.length}`;return t.forEach(o=>{i+=`|${o.id||o.getAttribute("name")||""}:${o.querySelectorAll("input,select,textarea").length}`}),i}function Zt(e,t={}){const i=Date.now(),o=t.doc??(typeof document<"u"?document:null),a=typeof window<"u"&&window.location.pathname||"/",s=typeof window<"u"?window.scrollY:0,c=`${a}::${s}::${o?Vi(o):""}`;if(et&&et.key===c&&i-et.at<1e3)return et.ctx;const l=vr(e,t);return et={key:c,at:i,ctx:l},l}function xr(){et=null}const Yi=200;function wr(e){const t=String(e.href||"");return{href:t,text:String(e.text??e.title??t),internal:e.internal??!0,title:e.title,description:e.description}}function Gi(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function _r(e){const t=e??(typeof document<"u"?document:null);if(!t)return[];const i=typeof window<"u"&&window.location.origin||"",o=new Set,a=[],s=Array.from(t.querySelectorAll("a[href]"));for(const c of s){if(a.length>=Yi)break;if($t(c))continue;const l=c.getAttribute("href")||"";if(!Gi(l))continue;let u=l,d=!0;try{if(typeof window<"u"){const h=new URL(l,i);d=h.origin===i,d&&l.startsWith("http")&&(u=h.pathname+h.search+h.hash)}}catch{continue}if(o.has(u))continue;o.add(u);const g=(c.textContent||"").trim().slice(0,120);a.push({href:u,text:g,internal:d})}return a}let tt=null;const Xi=5e3;function Pt(){const e=Date.now(),t=typeof window<"u"&&window.location.pathname||"/";if(tt&&tt.pathname===t&&e-tt.at<Xi)return tt.routes;const i=_r();return tt={at:e,pathname:t,routes:i},i}function Cr(){tt=null}function Qt(e){if(e instanceof HTMLInputElement){const t=e.type;if(t==="submit"||t==="button"||t==="reset"||t==="hidden"||t==="image"||t==="file")return!1}return!0}function Ki(e,t){return e.getAttribute("name")||e.getAttribute("id")||`field_${t}`}function Me(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"")}function Xt(e){const t=e.lastIndexOf(".");return t>=0?e.slice(t+1):e}function Ji(e){var o;const t=e.getAttribute("id");if(t)try{const a=(o=e.ownerDocument)==null?void 0:o.querySelector(`label[for="${t.replace(/"/g,'\\"')}"]`);if(a!=null&&a.textContent)return a.textContent}catch{}const i=e.closest("label");return i!=null&&i.textContent?i.textContent:e.getAttribute("aria-label")||e.getAttribute("placeholder")||""}function Zi(e,t){const i=Me(t);if(i.length<2)return null;let o=null,a=0;for(const s of Array.from(e.querySelectorAll("input, textarea, select"))){if(!Qt(s))continue;const c=s.getAttribute("name")||"",l=s.getAttribute("id")||"",u=[Me(Xt(c)),Me(Xt(l)),Me(c),Me(l)];let d=0;u.some(g=>g.length>=2&&g===i)?d=4:[Me(c),Me(Xt(c)),Me(Ji(s))].some(h=>h.length>=3&&(h.includes(i)||i.includes(h)))&&(d=2),d>a&&(a=d,o=s)}return a>=2?o:null}function Qi(e,t){if(!t)return null;try{const s=e.querySelector(`[name="${t.replace(/"/g,'\\"')}"]`);if(s&&Qt(s))return s}catch{}const i=Array.from(e.querySelectorAll("input, textarea, select"));let o=0;const a=new Map;for(const s of i){if(!Qt(s))continue;const c=Ki(s,o);let l=c;if(a.has(c)&&(l=`${c}__${o}`),l===t)return s;a.set(c,s),o++}return Zi(e,t)}function Bn(e,t){const i=Qi(e,t);return i?Jt(i)?{el:i}:{el:null,reason:"private"}:{el:null,reason:"not_found"}}function eo(e,t){const i=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,o=Object.getOwnPropertyDescriptor(i,"value"),a=o==null?void 0:o.set;a?a.call(e,t):e.value=t}function to(e,t,i={}){const o=i.triggerInput??!0,a=i.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const s=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),c=s==null?void 0:s.set,l=t==="true"||t==="1"||t==="on";c?c.call(e,l):e.checked=l,o&&e.dispatchEvent(new Event("input",{bubbles:!0})),a&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}eo(e,t),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),a&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function Un(e,t){if(!t)return null;const i=t.replace(/"/g,'\\"'),o=l=>l.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')!==null;try{const l=e.querySelector(`form#${CSS.escape(t)}`);if(l&&!o(l))return l}catch{}const a=e.querySelector(`form[name="${i}"]`);if(a&&!o(a))return a;const s=e.querySelector(`form[data-ll-intent="${i}"]`);if(s&&!o(s))return s;const c=Array.from(e.querySelectorAll("form")).filter(l=>!o(l));for(const l of c){const u=l.getAttribute("data-ll-intent");if(u&&no(u)===t)return l}if(/^form_\d+$/.test(t)){const l=parseInt(t.slice(5),10);let u=0;for(const d of c)if(!(d.id||d.getAttribute("name")||d.getAttribute("data-ll-intent"))){if(u===l)return d;u++}}return c.length===1?c[0]:null}function no(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function ro(){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 t=window.getComputedStyle(e);return!(t.overflowY==="hidden"||t.overflowY==="clip")}function io(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function oo(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let t=null,i=0;for(const o of e){if(!io(o))continue;const a=o.getBoundingClientRect();if(a.bottom<=0||a.top>=window.innerHeight||a.right<=0||a.left>=window.innerWidth||a.width<=0||a.height<=0||o.closest(".ll-widget"))continue;const s=a.width*a.height;s>i&&(i=s,t=o)}return t}function so(){if(typeof window>"u")return null;if(ro())return window;const e=oo();return e||window}function Vn(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function ao(e){var t,i;return e instanceof Window?typeof document>"u"?0:Math.max(((t=document.body)==null?void 0:t.scrollHeight)??0,((i=document.documentElement)==null?void 0:i.scrollHeight)??0):e.scrollHeight-e.clientHeight}const lo=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","advance_step","go_back","submit_flow","task_field_updated","task_completed"]),kr=r.forwardRef(function(t,i){var hn,mn,gn,yn,bn,vn,xn;const{agentId:o,apiKey:a,baseUrl:s="https://app.livelayer.studio",sessionEndpoint:c,sessionBody:l,soundEffects:u,experienceMode:d="WIDGET",autoConnect:g=!1,displayMode:h,defaultDisplayMode:m="expanded",onDisplayModeChange:N,position:_="bottom-right",mobileBreakpoint:S=640,draggable:y,resizable:w,persistKey:R="ll-widget",disablePersistence:E=!1,teamMembers:v,currentTeamMemberId:P,onTeamMemberChange:b,idleLoopUrl:M,greeting:z,avatarImageUrl:Y,agentName:re,branding:T={},allowCamera:B=!0,allowScreenShare:p=!0,allowTyping:L=!0,blurUntilFirstSpeech:I=!0,showMinimize:H,showClose:U,chromeless:K=!1,floatingChromeContainer:$=null,compactControls:J=!1,transforming:ee=!1,transformingLabel:F="Transforming…",showOn:fe,hideOn:G,pathname:xe,onNavigate:Z,onScrollToSelector:Ee,getPageContext:rt,pageContextExtras:gt,getRoutes:yt,onScrollPage:it,onClick:bt,capabilities:We,onConnect:qe,onDisconnect:Ie,onTranscript:Te,onAgentState:Pe,onConnectionStateChange:De,onAgentEvent:ze,onAgentCommand:Be,onCollect:$e,controlledSession:D,className:He,style:Ue,zIndex:we=2147483647}=t,vt=ar(xe),ot=ur(vt,fe,G);r.useEffect(()=>{xr(),Cr()},[vt]);const Le=P!==void 0,[st,xt]=r.useState(()=>{var x;return P??((x=v==null?void 0:v[0])==null?void 0:x.id)}),Fe=Le?P:st,se=r.useMemo(()=>(v==null?void 0:v.find(x=>x.id===Fe))??null,[v,Fe]),wt=(se==null?void 0:se.agentId)??o,ae=d==="EMBEDDED",he=sr(S),[Ve,Ye]=or({value:h,defaultValue:m,onChange:N,persistKey:R,disablePersistence:ae||E}),ce=ae?"expanded":Ve,me=ae?()=>{}:Ye,_t=H??!ae,Ct=U??!ae,kt=J||!ae&&he,ye=Zr({draggable:!ae&&(y??!he),resizable:!ae&&(w??!he),persistKey:R,disablePersistence:ae||E}),je=Kn(),ke=Zn(),Ae=Qn(),at=er(),[Re,_e]=r.useState(!1),[Ge,lt]=r.useState(!1),[ct,Xe]=r.useState(!1),[C,te]=r.useState(!1),[Ht,Lr]=r.useState(!1),St=oi({baseUrl:s,config:u}),Et=r.useRef(St);Et.current=St;const Ft=r.useRef(Z),Ot=r.useRef(Ee),Wt=r.useRef(it),qt=r.useRef(bt),rn=r.useRef(rt),on=r.useRef(gt),sn=r.useRef(yt),Bt=r.useRef(We),Ce=r.useRef(null);Ft.current=Z,Ot.current=Ee,Wt.current=it,qt.current=bt,rn.current=rt,on.current=gt,sn.current=yt,Bt.current=We;function be(x){const f=Bt.current;return f?f.includes(x):!0}function ve(x,f){console.warn(`[LiveLayer] Agent command "${x}" blocked — capability "${f}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const ut=r.useCallback(x=>{var Q,le,Se,ft,Ne,wn;const f=x;if(!(!f.type||typeof f.type!="string")){if(ze==null||ze({eventName:f.type,data:x}),f.type==="navigate"){if(!be("navigate")){ve("navigate","navigate");return}const j=typeof f.href=="string"?f.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(Et.current.playPageChange(),Ft.current){try{Ft.current(j)}catch(A){console.warn(`[LiveLayer] onNavigate threw for "${j}". Falling back. Error:`,A)}return}if(typeof document<"u"){const A=document.querySelector(`a[href="${j.replace(/"/g,'\\"')}"]`);if(A){A.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",j),window.dispatchEvent(new PopStateEvent("popstate"))}catch(A){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`,A)}return}if(f.type==="scroll_to"){if(!be("scroll")){ve("scroll_to","scroll");return}const j=typeof f.selector=="string"?f.selector:null;if(!j)return;const A=f.behavior==="instant"?"instant":"smooth";if(Ot.current){try{Ot.current(j,A)}catch(q){console.warn("[LiveLayer] onScrollToSelector threw.",q)}return}if(typeof document<"u"){let q=null;try{q=document.querySelector(j)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${j}".`);return}if(!q){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}q.scrollIntoView({behavior:A,block:"start"})}return}if(f.type==="request_page_context"){if(!be("read_page")){ve("request_page_context","read_page");return}const j=typeof f.requestId=="string"?f.requestId:void 0,A=(Q=Ce.current)==null?void 0:Q.call(Ce),q=X=>{const W=A,ue=W==null?void 0:W.localParticipant;if(ue!=null&&ue.publishData)try{const de=j?{...X,requestId:j}:X,ne=new TextEncoder().encode(JSON.stringify(de));ue.publishData(ne,{reliable:!0})}catch(de){console.warn("[LiveLayer] publishData failed.",de)}},O=on.current,V=rn.current;try{if(V){const X=V(O);if(X instanceof Promise){q({type:"page_context_pending"}),X.then(W=>q({type:"page_context",context:W})).catch(W=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",W),q({type:"page_context",context:Zt(O)})});return}q({type:"page_context",context:X});return}q({type:"page_context",context:Zt(O)})}catch(X){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",X),q({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:O}})}return}if(f.type==="scroll_page"){if(!be("scroll")){ve("scroll_page","scroll");return}const j=f.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 A=f.behavior==="instant"?"instant":"smooth";if(Wt.current){try{Wt.current(j,A)}catch(W){console.warn("[LiveLayer] onScrollPage threw.",W)}return}if(typeof window>"u")return;const q={behavior:A},O=so(),V=W=>{O instanceof Window?O.scrollBy({top:W,...q}):O.scrollBy({top:W,...q})},X=W=>{O instanceof Window?O.scrollTo({top:W,...q}):O.scrollTo({top:W,...q})};j==="up"?V(-Vn(O)):j==="down"?V(Vn(O)):X(j==="top"?0:ao(O));return}if(f.type==="click"){if(!be("click")){ve("click","click");return}const j=typeof f.selector=="string"?f.selector:null;if(!j){console.warn("[LiveLayer] click: missing selector.");return}if(qt.current){try{qt.current(j)}catch(q){console.warn("[LiveLayer] onClick threw.",q)}return}if(typeof document>"u")return;let A=null;try{A=document.querySelector(j)}catch{console.warn(`[LiveLayer] click: invalid selector "${j}".`);return}if(!A){console.warn(`[LiveLayer] click: no element matched "${j}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(A.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(le=A.click)==null||le.call(A);return}if(f.type==="advance_step"||f.type==="go_back"||f.type==="submit_flow"){if(!be("click")){ve(f.type,"click");return}if(typeof document>"u")return;const j=f.type==="advance_step"?"ll-advance":f.type==="go_back"?"ll-back":"ll-submit";let A=Hn(j);if(A||(yr(document),A=Hn(j)),!A){console.warn(`[LiveLayer] ${f.type}: no "${j}" control found.`);return}(Se=A.click)==null||Se.call(A);return}if(f.type==="fill_form"||f.type==="focus_field"){if(!be("fill_forms")){ve(f.type,"fill_forms");return}if(typeof document>"u")return;f.type==="fill_form"&&Et.current.playConfirmation();const j=typeof f.formId=="string"?f.formId:null;if(!j){console.warn(`[LiveLayer] ${f.type}: missing formId.`);return}const A=Un(document,j);if(!A){console.warn(`[LiveLayer] ${f.type}: no <form> matched id="${j}" (or matching name / data-ll-intent slug). Forms are auto-discovered — make sure the form has an \`id\`, \`name\`, or \`data-ll-intent\` attribute the agent observed in PageContext.forms.`);return}if(A.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')){console.warn(`[LiveLayer] ${f.type}: refusing to touch a form in a private / opted-out subtree.`);return}if(f.type==="focus_field"){const O=typeof f.fieldName=="string"?f.fieldName:null;if(!O){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const V=Bn(A,O);if(V.el===null){V.reason==="private"?console.warn(`[LiveLayer] focus_field: field "${O}" is privacy-protected and not focusable.`):console.warn(`[LiveLayer] focus_field: no input matching key="${O}" in form "${j}". The agent should use the field.name it observed in PageContext.forms[].fields[].`);return}V.el.focus();return}const q=f.values&&typeof f.values=="object"?f.values:null;if(!q){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[O,V]of Object.entries(q)){if(typeof V!="string")continue;const X=Bn(A,O);if(X.el===null){X.reason==="private"?console.warn(`[LiveLayer] fill_form: field "${O}" is privacy-protected (password / cc-* / data-ll-private). Skipping.`):console.warn(`[LiveLayer] fill_form: no input matching key="${O}" in form "${j}". The agent should use the field.name it observed in PageContext.forms[].fields[]. Skipping.`);continue}try{to(X.el,V)}catch(W){console.warn(`[LiveLayer] fill_form: failed to set "${O}".`,W)}}return}if(f.type==="submit_form"){if(!be("submit_forms")){ve("submit_form","submit_forms");return}if(typeof document>"u")return;const j=typeof f.formId=="string"?f.formId:null;if(!j){console.warn("[LiveLayer] submit_form: missing formId.");return}Et.current.playConfirmation();const A=Un(document,j);if(!A){console.warn(`[LiveLayer] submit_form: no <form> matched id="${j}" (or matching name / data-ll-intent slug).`);return}if(A.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private / opted-out subtree.");return}const q=typeof f.requestId=="string"?f.requestId:void 0,O=(ft=Ce.current)==null?void 0:ft.call(Ce),V=ne=>{const pe=O,Oe=pe==null?void 0:pe.localParticipant;if(Oe!=null&&Oe.publishData)try{const At=q?{...ne,requestId:q}:ne,Rt=new TextEncoder().encode(JSON.stringify(At));Oe.publishData(Rt,{reliable:!0})}catch{}},X=ne=>{var Rt,_n,Cn,kn;const pe=ne,Oe=(Rt=pe.getAttribute)==null?void 0:Rt.call(pe,"aria-label");if(Oe)return Oe;const At=pe.id;if(At){const Nt=(_n=A.ownerDocument)==null?void 0:_n.querySelector(`label[for="${At}"]`);if((Cn=Nt==null?void 0:Nt.textContent)!=null&&Cn.trim())return Nt.textContent.trim()}return((kn=pe.getAttribute)==null?void 0:kn.call(pe,"name"))||pe.id||pe.type||"field"},W=()=>{try{return Array.from(A.elements).filter(ne=>"willValidate"in ne&&ne.willValidate&&!ne.checkValidity()).map(ne=>`${X(ne)}: ${ne.validationMessage}`)}catch{return[]}};if(typeof A.checkValidity=="function"&&!A.checkValidity()){try{(Ne=A.reportValidity)==null||Ne.call(A)}catch{}V({type:"form_submit_blocked",formId:j,reason:"validation",invalidFields:W()});return}let ue=!1;const de=ne=>{ue=!0,queueMicrotask(()=>{ne.defaultPrevented?V({type:"form_submit_uncertain",formId:j,reason:"spa_prevented"}):V({type:"form_submitted",formId:j})})};A.addEventListener("submit",de,{once:!0});try{typeof A.requestSubmit=="function"?A.requestSubmit():A.submit()}catch(ne){console.warn("[LiveLayer] submit_form: requestSubmit threw.",ne),A.removeEventListener("submit",de),V({type:"form_submit_blocked",formId:j,reason:"exception"});return}setTimeout(()=>{ue||(A.removeEventListener("submit",de),V({type:"form_submit_blocked",formId:j,reason:"validation",invalidFields:W()}))},500);return}if(f.type==="request_routes"){if(!be("read_page")){ve("request_routes","read_page");return}const j=typeof f.requestId=="string"?f.requestId:void 0,q=(wn=Ce.current)==null?void 0:wn.call(Ce),O=q==null?void 0:q.localParticipant;if(!(O!=null&&O.publishData))return;const V=W=>{try{const ue=j?{type:"routes",routes:W,requestId:j}:{type:"routes",routes:W},de=new TextEncoder().encode(JSON.stringify(ue));O.publishData(de,{reliable:!0})}catch(ue){console.warn("[LiveLayer] request_routes: publishData failed.",ue)}},X=sn.current;if(X){try{const W=X(),ue=de=>{if(!Array.isArray(de)){V([]);return}V(de.map(wr).slice(0,200))};W instanceof Promise?W.then(ue).catch(de=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",de),V(Pt())}):ue(W)}catch(W){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",W),V(Pt())}return}try{V(Pt())}catch(W){console.warn("[LiveLayer] request_routes: extractRoutes threw.",W)}return}if(f.type==="task_field_updated"){if(!be("collect_data")){ve("task_field_updated","collect_data");return}const j={phase:"field",fieldId:typeof f.fieldId=="string"?f.fieldId:"",fieldName:typeof f.fieldName=="string"?f.fieldName:typeof f.fieldId=="string"?f.fieldId:"",value:typeof f.value=="string"?f.value:"",kind:typeof f.kind=="string"?f.kind:"text",source:f.source==="slide"?"slide":f.source==="page"?"page":"agent",...typeof f.slideId=="string"?{slideId:f.slideId}:{},...typeof f.formId=="string"?{formId:f.formId}:{}};if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:j}))}catch{}return}if(f.type==="task_completed"){if(!be("collect_data")){ve("task_completed","collect_data");return}const j=f.result;if(!j||typeof j!="object"){console.warn("[LiveLayer] task_completed missing `result` payload.");return}if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:{phase:"complete",result:j}}))}catch{}try{$e==null||$e(j)}catch(A){console.warn("[LiveLayer] onCollect threw.",A)}return}lo.has(f.type)||Be==null||Be(f)}},[Be,ze,$e]),ie=Xn({agentId:D?"__controlled__":wt,baseUrl:s,apiKey:a,sessionEndpoint:c,sessionBody:l,onDataMessage:D?void 0:ut});r.useEffect(()=>{if(D!=null&&D.subscribeToDataMessages)return D.subscribeToDataMessages(ut)},[D,ut]),Ce.current=()=>{var x;return(x=ie.getRoom)==null?void 0:x.call(ie)},r.useEffect(()=>{var Q;if(typeof window>"u")return;const x=((Q=window.location)==null?void 0:Q.hostname)||"";if(x==="localhost"||x==="127.0.0.1"||x==="0.0.0.0"||x.endsWith(".local")||x.endsWith(".test"))return window.__livelayerSimulateCommand=le=>{try{ut(le)}catch(Se){console.warn("[LiveLayer] simulate-command threw:",Se)}},()=>{delete window.__livelayerSimulateCommand}},[ut]);const k=r.useMemo(()=>D?{connectionState:D.connectionState,agentState:D.agentState,transcript:D.transcript,videoElement:D.videoElement,audioElement:D.audioElement,canResume:D.canResume,error:D.error,agentConfig:null,connect:async()=>{await D.onConnect()},disconnect:()=>D.onDisconnect(),getRoom:ie.getRoom,isControlled:!0}:{connectionState:ie.connectionState,agentState:ie.agentState,transcript:ie.transcript,videoElement:ie.videoElement,audioElement:ie.audioElement,canResume:ie.canResume,error:ie.error,agentConfig:ie.agentConfig,connect:ie.connect,disconnect:ie.disconnect,getRoom:ie.getRoom,isControlled:!1},[D,ie]),an=r.useRef(k);an.current=k;const ln=r.useRef(D);ln.current=D,r.useImperativeHandle(i,()=>({sendData:async x=>{var Se,ft;const f=ln.current;if(f!=null&&f.publishData){try{await f.publishData(x)}catch(Ne){console.warn("[AvatarWidget] sendData (controlled) failed:",Ne)}return}const Q=(ft=(Se=an.current)==null?void 0:Se.getRoom)==null?void 0:ft.call(Se),le=Q==null?void 0:Q.localParticipant;if(le!=null&&le.publishData)try{const Ne=new TextEncoder().encode(JSON.stringify(x));await le.publishData(Ne,{reliable:!0})}catch(Ne){console.warn("[AvatarWidget] sendData failed:",Ne)}}}),[]);const cn=r.useRef(null);r.useEffect(()=>{const x=k.videoElement,f=cn.current;if(!(!x||!f))return f.appendChild(x),()=>{x.parentNode===f&&f.removeChild(x)}},[k.videoElement]);const[Ke,Lt]=r.useState(!1);r.useEffect(()=>{if(!I){Lt(!0);return}k.agentState==="speaking"&&!Ke&&Lt(!0)},[I,k.agentState,Ke]),r.useEffect(()=>{if(!I)return;const x=k.connectionState;(x==="disconnected"||x==="idle")&&Lt(!1)},[I,k.connectionState]),r.useEffect(()=>{if(!I||!k.videoElement||Ke)return;const x=setTimeout(()=>Lt(!0),5e3);return()=>clearTimeout(x)},[I,k.videoElement,Ke]),r.useEffect(()=>{const x=k.videoElement;if(x){if(!I){x.style.filter="";return}x.style.transition="filter 500ms ease-out",x.style.filter=Ke?"":"blur(8px)"}},[I,k.videoElement,Ke]),r.useEffect(()=>{const x=k.audioElement;if(!x)return;const f=document.createElement("div");f.className="ll-audio-sink",f.setAttribute("aria-hidden","true"),f.style.cssText="position:absolute;width:0;height:0;overflow:hidden;clip:rect(0 0 0 0);pointer-events:none;",f.appendChild(x),document.body.appendChild(f),je.attach(x);const Q=x.play();return Q&&typeof Q.catch=="function"&&Q.catch(le=>{(le==null?void 0:le.name)==="NotAllowedError"&&_e(!0)}),()=>{je.detach(),x.parentNode===f&&f.removeChild(x),f.parentNode===document.body&&document.body.removeChild(f)}},[k.audioElement]);const ge=Jn({gateUntilAgentReady:!0,agentState:k.agentState});r.useEffect(()=>{if(k.isControlled||k.connectionState!=="connected")return;const x=k.getRoom();if(x)return ge.setupMic(x).then(()=>{const f=ge.getMicStream();f&&je.attachStream(f,"mic")}).catch(()=>{}),()=>{je.detachSlot("mic"),ge.teardownMic()}},[k.isControlled,k.connectionState]),r.useEffect(()=>{var f;if(k.connectionState!=="connected")return;const x=k.isControlled?(f=D==null?void 0:D.getRoom)==null?void 0:f.call(D):k.getRoom();if(x)return ke.attachRoom(x),Ae.attachRoom(x),k.isControlled&&ge.attachRoom(x),at.refresh(),()=>{ke.teardown(),Ae.teardown()}},[k.isControlled,k.connectionState,D]),r.useEffect(()=>{const x=k.audioElement;x&&(x.muted=Ht)},[k.audioElement,Ht]);const jr=r.useCallback(x=>{const f={type:"user_message",text:x};if(D!=null&&D.publishData){try{D.publishData(f)}catch{}return}const Q=k.getRoom();if(Q)try{const le=new TextEncoder().encode(JSON.stringify(f));Q.localParticipant.publishData(le,{reliable:!0})}catch{}},[k,D]),Ar=r.useCallback(()=>{Lr(x=>!x)},[]);r.useEffect(()=>{De==null||De(k.connectionState),k.connectionState==="connected"?qe==null||qe():k.connectionState==="disconnected"&&(Ie==null||Ie())},[k.connectionState,qe,Ie,De]),r.useEffect(()=>{Te==null||Te(k.transcript)},[k.transcript,Te]),r.useEffect(()=>{Pe==null||Pe(k.agentState)},[k.agentState,Pe]),r.useEffect(()=>{St.setThinking(k.agentState==="thinking")},[k.agentState,St]);const un=r.useRef(!1);r.useEffect(()=>{!g||un.current||ot&&k.connectionState==="idle"&&(un.current=!0,k.connect())},[g,k.connectionState,k,ot]);const Rr=r.useCallback(x=>{const f=v==null?void 0:v.find(Q=>Q.id===x);f&&(Xe(!1),x!==Fe&&(lt(!0),k.disconnect(),Le||xt(x),b==null||b(f)))},[v,Fe,k,Le,b]);r.useEffect(()=>{Ge&&k.connectionState==="connected"&&lt(!1)},[k.connectionState,Ge]),r.useEffect(()=>{if(!ct)return;const x=f=>{f.key==="Escape"&&Xe(!1)};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[ct]);const Nr=!!Y||!!(se!=null&&se.avatarImageUrl)||k.isControlled,dt=tr(wt,s,Nr);We===void 0&&((hn=dt.info)!=null&&hn.capabilities)&&(Bt.current=dt.info.capabilities);const jt=(se==null?void 0:se.name)??re??((mn=k.agentConfig)==null?void 0:mn.name)??((gn=dt.info)==null?void 0:gn.name)??"Live Layer",Ut=(se==null?void 0:se.avatarImageUrl)??Y??((yn=k.agentConfig)==null?void 0:yn.avatarImageUrl)??((bn=dt.info)==null?void 0:bn.avatarImageUrl)??null,Mr=M??((vn=k.agentConfig)==null?void 0:vn.idleLoopUrl)??((xn=dt.info)==null?void 0:xn.idleLoopUrl)??null,Ir=z??null,Tr=r.useCallback(()=>me("expanded"),[me]),Pr=r.useCallback(()=>me("minimized"),[me]),dn=r.useCallback(()=>{k.disconnect(),me("hidden")},[k,me]),Dr=r.useCallback(()=>{const x=k.audioElement;x&&x.play().then(()=>_e(!1)).catch(()=>{})},[k.audioElement]),zr=r.useCallback(()=>{_e(!1),k.connect()},[k]),Je={...Ue,...ae?{}:{zIndex:we}};T.primaryColor&&(Je["--ll-color-primary"]=T.primaryColor),T.accentColor&&(Je["--ll-color-accent"]=T.accentColor),T.backgroundColor&&(Je["--ll-color-bg"]=T.backgroundColor),T.textColor&&(Je["--ll-color-fg"]=T.textColor);const $r={...Je,...ye.style},Hr=["ll-widget",`ll-widget--${ce}`,`ll-widget--${he?"mobile":"desktop"}`,ye.hasGeometry?"ll-widget--has-geometry":null,ye.isDragging?"is-dragging":null,ye.isResizing?"is-resizing":null,He].filter(Boolean).join(" ");if(!ot)return null;const Fr=n.jsx("div",{className:Hr,style:$r,"data-display-mode":ce,"data-position":_,"data-experience-mode":d==="EMBEDDED"?"embedded":"widget",children:ce==="expanded"&&n.jsx(_i,{position:_,isMobile:he,agentName:jt,avatarImageUrl:Ut,idleLoopUrl:Mr,greeting:Ir,branding:T,teamMembers:v,currentTeamMemberId:Fe,isSwitchingTeamMember:Ge,teamSwitcherOpen:ct,onToggleTeamSwitcher:()=>Xe(x=>!x),onSelectTeamMember:Rr,connectionState:k.connectionState,agentState:k.agentState,transcript:k.transcript,isMuted:ge.isMuted,micDevices:at.mics,activeMicId:ge.activeDeviceId,isCameraEnabled:ke.isEnabled,cameraPreviewEl:ke.previewEl,cameraDevices:at.cameras,activeCameraId:ke.activeDeviceId,isScreenShareEnabled:Ae.isEnabled,screenPreviewEl:Ae.previewEl,isSpeakerMuted:Ht,allowCamera:B,allowScreenShare:p,allowTyping:L,showMinimize:he&&!ae?!1:_t,showClose:Ct,chromeless:K,compactControls:kt,transforming:ee,transformingLabel:F,languageMenuOpen:C,onToggleLanguageMenu:()=>te(x=>!x),needsUserGesture:Re,canResume:k.canResume,micError:ge.micError,error:k.error,avatarVideoContainerRef:cn,agentVideoEl:k.videoElement,onConnect:()=>void k.connect(),onDisconnect:()=>k.disconnect(),onRetry:zr,onResumeAudio:Dr,onToggleMute:ge.toggleMute,onSwitchMicDevice:x=>void ge.switchDevice(x),onToggleCamera:()=>void ke.toggle(),onSwitchCameraDevice:x=>void ke.switchDevice(x),onToggleScreenShare:()=>void Ae.toggle(),onToggleSpeaker:Ar,onSendMessage:jr,onMinimize:Pr,onClose:dn,onClearMicError:ge.clearError,dragHandleProps:ye.dragHandleProps,resizeHandleProps:ye.resizeHandleProps})}),fn=!ae&&(ce==="hidden"||ce==="minimized")?n.jsxs("div",{className:["ll-widget","ll-widget--floating",`ll-widget--${ce}`,`ll-widget--${he?"mobile":"desktop"}`].join(" "),style:Je,"data-display-mode":ce,"data-position":_,children:[ce==="hidden"&&n.jsx(di,{position:_,isMobile:he,isSpeaking:k.agentState==="speaking",onExpand:()=>me("expanded"),label:`Open ${jt} widget`,avatarImageUrl:Ut,agentName:jt,containerEl:$}),ce==="minimized"&&n.jsx(pi,{position:_,isMobile:he,agentName:jt,avatarImageUrl:Ut,agentState:k.agentState,isMuted:ge.isMuted,audioLevel:je,onExpand:Tr,onToggleMute:ge.toggleMute,onClose:dn})]}):null,pn=$??(typeof document<"u"?document.body:null);return n.jsxs(n.Fragment,{children:[Fr,fn&&pn&&en.createPortal(fn,pn)]})});kr.displayName="AvatarWidgetInner";const Sr=r.forwardRef(function(t,i){return n.jsx(Gn,{children:n.jsx(kr,{...t,ref:i})})});Sr.displayName="AvatarWidget";const co=({agentId:e,baseUrl:t,apiKey:i,mode:o,onAgentEvent:a,className:s,style:c})=>{const l=r.useRef(null),u=r.useRef(null),d=r.useRef(a);d.current=a;const g=r.useCallback(h=>{var N;const m=h.detail;(N=d.current)==null||N.call(d,m)},[]);return r.useEffect(()=>{const h=l.current;if(!h)return;const m=document.createElement("livelayer-widget");return m.setAttribute("agent-id",e),t&&m.setAttribute("base-url",t),i&&m.setAttribute("api-key",i),o&&m.setAttribute("mode",o),m.addEventListener("agent-event",g),h.appendChild(m),u.current=m,()=>{m.removeEventListener("agent-event",g),h.removeChild(m),u.current=null}},[e]),r.useEffect(()=>{u.current&&(o?u.current.setAttribute("mode",o):u.current.removeAttribute("mode"))},[o]),n.jsx("div",{ref:l,className:s,style:c})},uo=r.forwardRef(function({id:t,intent:i,as:o="div",className:a,style:s,children:c},l){return r.createElement(o,{ref:l,"data-ll-region":t,"data-ll-intent":i,className:a,style:s},c)});function fo(e={}){const{onFieldUpdate:t,onComplete:i,source:o="all"}=e,[a,s]=r.useState({}),[c,l]=r.useState(!1),[u,d]=r.useState(null),g=r.useRef(t),h=r.useRef(i),m=r.useRef(o);r.useEffect(()=>{g.current=t,h.current=i,m.current=o},[t,i,o]);const N=r.useCallback(()=>{s({}),l(!1)},[]);return r.useEffect(()=>{if(typeof window>"u")return;const _=S=>{var w,R;const y=S.detail;if(y){if(y.phase==="field"){if(m.current!=="all"&&y.source!==m.current)return;l(!0),s(E=>E[y.fieldName]===y.value?E:{...E,[y.fieldName]:y.value});try{(w=g.current)==null||w.call(g,y)}catch(E){console.warn("[LiveLayer] useCollect onFieldUpdate threw.",E)}return}if(y.phase==="complete"){const E=y.result;if(m.current!=="all"&&E.source!==m.current)return;d(E),l(!1);try{(R=h.current)==null||R.call(h,E)}catch(v){console.warn("[LiveLayer] useCollect onComplete threw.",v)}}}};return document.addEventListener("ll-collected",_),()=>document.removeEventListener("ll-collected",_)},[]),{fields:a,isCollecting:c,lastResult:u,reset:N}}let Yn=1;function po({onMount:e,defaultOpen:t=!1,storageKey:i="ll-debug-open"}){const[o,a]=r.useState(t),[s,c]=r.useState([]),[l,u]=r.useState(""),[d,g]=r.useState(!1),h=r.useRef(new Set),m=r.useRef([]),N=r.useRef(d);N.current=d,r.useEffect(()=>{try{const y=localStorage.getItem(i);y==="1"&&a(!0),y==="0"&&a(!1)}catch{}},[i]),r.useEffect(()=>{try{localStorage.setItem(i,o?"1":"0")}catch{}},[o,i]),r.useEffect(()=>{const y=w=>{(w.metaKey||w.ctrlKey)&&w.shiftKey&&w.key.toLowerCase()==="l"&&(w.preventDefault(),a(R=>!R))};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[]),r.useEffect(()=>{const y=setInterval(()=>{if(m.current.length===0||N.current)return;const w=m.current.splice(0,m.current.length);c(R=>[...w.reverse(),...R].slice(0,200))},100);return()=>clearInterval(y)},[]);const _=r.useRef(!1);if(r.useEffect(()=>{!e||_.current||(_.current=!0,e(y=>{m.current.push({id:Yn++,ts:Date.now(),kind:"event",type:y.eventName,data:y.data})}))},[e]),r.useEffect(()=>{const y=console.warn,w=console.log,R=(E,v)=>function(...P){try{const b=typeof P[0]=="string"?P[0]:"";b.startsWith("[LiveLayer]")&&m.current.push({id:Yn++,ts:Date.now(),kind:E,type:b.slice(0,120),data:{args:P.slice(1).map(M=>mo(M))}})}catch{}return v.apply(this,P)};return console.warn=R("warn",y),console.log=R("log",w),()=>{console.warn=y,console.log=w}},[]),!o)return n.jsx("button",{type:"button",onClick:()=>a(!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 S=s.filter(y=>{if(!l)return!0;const w=l.toLowerCase();return y.type.toLowerCase().includes(w)||JSON.stringify(y.data||{}).toLowerCase().includes(w)});return n.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:[n.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:[n.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),n.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[s.length," event",s.length===1?"":"s"]}),n.jsx("span",{style:{flex:1}}),n.jsx("button",{type:"button",onClick:()=>g(y=>!y),style:Kt(d?"#f59e0b":"transparent"),title:"Pause / resume capture",children:d?"▶ resume":"⏸ pause"}),n.jsx("button",{type:"button",onClick:()=>{c([]),m.current=[]},style:Kt("transparent"),title:"Clear buffer",children:"clear"}),n.jsx("button",{type:"button",onClick:()=>a(!1),style:Kt("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),n.jsx("input",{type:"text",value:l,onChange:y=>u(y.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"}}),n.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 8px 8px"},children:S.length===0?n.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:",n.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
- })`})]}):S.map(y=>n.jsx(ho,{entry:y,expanded:h.current.has(y.id),onToggle:()=>{h.current.has(y.id)?h.current.delete(y.id):h.current.add(y.id),c(w=>[...w])}},y.id))})]})}function ho({entry:e,expanded:t,onToggle:i}){const o=e.kind==="warn"?"#f59e0b":e.type.startsWith("[LiveLayer]")?"#94a3b8":e.type==="navigate"||e.type==="scroll_page"||e.type==="scroll_to"||e.type==="click"?"#22c55e":e.type==="fill_form"||e.type==="submit_form"||e.type==="focus_field"?"#a78bfa":e.type==="request_page_context"||e.type==="request_routes"?"#38bdf8":e.type==="agent_state"?"#facc15":"#cbd5e1",a=new Date(e.ts).toLocaleTimeString("en-US",{hour12:!1});return n.jsxs("button",{type:"button",onClick:i,style:{textAlign:"left",background:"transparent",border:0,color:"#fff",width:"100%",padding:"6px 4px",cursor:"pointer",borderBottom:"1px solid rgba(255,255,255,0.04)",fontSize:11,lineHeight:1.4},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("span",{style:{color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums",fontSize:10},children:a}),n.jsx("span",{style:{color:o,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),t&&e.data&&n.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 mo(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Er(e){const t=JSON.stringify(e);r.useEffect(()=>nt.registerFields(e),[t])}function go({fields:e,children:t}){return Er(e),n.jsx(n.Fragment,{children:t})}function yo(){const[e,t]=r.useState([]),i=r.useCallback(a=>{t(s=>{const c=s.findIndex(l=>l.id===a.id);if(c>=0){const l=s.slice();return l[c]=a,l}return[...s,a]})},[]),o=r.useCallback(()=>t([]),[]);return{entries:e,pushSegment:i,clear:o,latest:e.length>0?e[e.length-1]:null}}Object.defineProperty(exports,"clearFieldRegistry",{enumerable:!0,get:()=>nt.clearFieldRegistry});Object.defineProperty(exports,"getRegisteredFields",{enumerable:!0,get:()=>nt.getRegisteredFields});Object.defineProperty(exports,"registerFields",{enumerable:!0,get:()=>nt.registerFields});Object.defineProperty(exports,"setFieldValue",{enumerable:!0,get:()=>nt.setFieldValue});exports.AvatarWidget=Sr;exports.ErrorBoundary=Gn;exports.FieldProvider=go;exports.LiveLayerDebugPanel=po;exports.LiveLayerRegion=uo;exports.LiveLayerWidget=co;exports.clearPageContextCache=xr;exports.clearRoutesCache=Cr;exports.extractPageContext=vr;exports.extractRoutes=_r;exports.getCachedPageContext=Qt;exports.getCachedRoutes=Tt;exports.matchesPattern=lr;exports.normalizeRouteInput=wr;exports.shouldRenderAtPath=cr;exports.useAgentInfo=tr;exports.useAudioLevel=Kn;exports.useCameraState=Zn;exports.useCollect=fo;exports.useDisplayMode=ir;exports.useDisplayModePersistence=or;exports.useIsMobile=sr;exports.useLiveKitSession=Xn;exports.useMediaDevices=er;exports.useMicrophoneState=Jn;exports.usePathname=ar;exports.useRegisterFields=Er;exports.useRouteMatch=ur;exports.useScreenShareState=Qn;exports.useTranscript=yo;
5
+ })`})]}):S.map(y=>n.jsx(ho,{entry:y,expanded:h.current.has(y.id),onToggle:()=>{h.current.has(y.id)?h.current.delete(y.id):h.current.add(y.id),c(w=>[...w])}},y.id))})]})}function ho({entry:e,expanded:t,onToggle:i}){const o=e.kind==="warn"?"#f59e0b":e.type.startsWith("[LiveLayer]")?"#94a3b8":e.type==="navigate"||e.type==="scroll_page"||e.type==="scroll_to"||e.type==="click"?"#22c55e":e.type==="fill_form"||e.type==="submit_form"||e.type==="focus_field"?"#a78bfa":e.type==="request_page_context"||e.type==="request_routes"?"#38bdf8":e.type==="agent_state"?"#facc15":"#cbd5e1",a=new Date(e.ts).toLocaleTimeString("en-US",{hour12:!1});return n.jsxs("button",{type:"button",onClick:i,style:{textAlign:"left",background:"transparent",border:0,color:"#fff",width:"100%",padding:"6px 4px",cursor:"pointer",borderBottom:"1px solid rgba(255,255,255,0.04)",fontSize:11,lineHeight:1.4},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("span",{style:{color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums",fontSize:10},children:a}),n.jsx("span",{style:{color:o,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),t&&e.data&&n.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 Kt(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 mo(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Er(e){const t=JSON.stringify(e);r.useEffect(()=>nt.registerFields(e),[t])}function go({fields:e,children:t}){return Er(e),n.jsx(n.Fragment,{children:t})}function yo(){const[e,t]=r.useState([]),i=r.useCallback(a=>{t(s=>{const c=s.findIndex(l=>l.id===a.id);if(c>=0){const l=s.slice();return l[c]=a,l}return[...s,a]})},[]),o=r.useCallback(()=>t([]),[]);return{entries:e,pushSegment:i,clear:o,latest:e.length>0?e[e.length-1]:null}}Object.defineProperty(exports,"clearFieldRegistry",{enumerable:!0,get:()=>nt.clearFieldRegistry});Object.defineProperty(exports,"getRegisteredFields",{enumerable:!0,get:()=>nt.getRegisteredFields});Object.defineProperty(exports,"registerFields",{enumerable:!0,get:()=>nt.registerFields});Object.defineProperty(exports,"setFieldValue",{enumerable:!0,get:()=>nt.setFieldValue});exports.AvatarWidget=Sr;exports.ErrorBoundary=Gn;exports.FieldProvider=go;exports.LiveLayerDebugPanel=po;exports.LiveLayerRegion=uo;exports.LiveLayerWidget=co;exports.clearPageContextCache=xr;exports.clearRoutesCache=Cr;exports.extractPageContext=vr;exports.extractRoutes=_r;exports.getCachedPageContext=Zt;exports.getCachedRoutes=Pt;exports.matchesPattern=lr;exports.normalizeRouteInput=wr;exports.shouldRenderAtPath=cr;exports.useAgentInfo=tr;exports.useAudioLevel=Kn;exports.useCameraState=Zn;exports.useCollect=fo;exports.useDisplayMode=ir;exports.useDisplayModePersistence=or;exports.useIsMobile=sr;exports.useLiveKitSession=Xn;exports.useMediaDevices=er;exports.useMicrophoneState=Jn;exports.usePathname=ar;exports.useRegisterFields=Er;exports.useRouteMatch=ur;exports.useScreenShareState=Qn;exports.useTranscript=yo;