@livelayer/react 0.24.0 → 0.25.0

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,6 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("react"),an=require("react-dom"),st=require("@livelayer/sdk"),Ot=require("livekit-client");class rr 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 ir(e){const[t,i]=r.useState("idle"),[o,a]=r.useState("idle"),[s,c]=r.useState([]),[l,u]=r.useState(null),[f,y]=r.useState(null),[h,g]=r.useState(null),[N,C]=r.useState(!1),[S,b]=r.useState(null),w=r.useRef(null),R=r.useRef(e.onDataMessage);R.current=e.onDataMessage,r.useEffect(()=>{const v={onConnectionStateChange:z=>{i(z),z==="connected"&&b(null)},onAgentStateChange:a,onTranscript:z=>c([...z]),onAgentConfig:u,onAudioTrack:z=>g(z),onVideoTrack:z=>y(z),onVideoTrackRemoved:()=>y(null),onError:z=>b(z),onDataMessage:z=>{var G;(G=R.current)==null||G.call(R,z)},onResumabilityChange:C},M=new st.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},v);return w.current=M,i("idle"),a("idle"),c([]),u(null),y(null),g(null),C(!1),b(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 v=w.current;if(v)try{await v.connect()}catch(M){throw b(M instanceof Error?M.message:String(M)),M}},[]),x=r.useCallback(()=>{const v=w.current;v&&v.disconnect()},[]),P=r.useCallback(()=>{var v;return((v=w.current)==null?void 0:v.getRoom())??null},[]);return{connectionState:t,agentState:o,transcript:s,agentConfig:l,videoElement:f,audioElement:h,canResume:N,error:S,connect:E,disconnect:x,getRoom:P,session:w.current}}function or(){const e=r.useRef(null),t=r.useRef(new Map),i=r.useRef(null),o=r.useRef(new Set),a=r.useCallback(()=>{const C=t.current;if(C.size===0){i.current=null;return}let S=0;for(const{analyser:b,buffer:w}of C.values()){b.getByteFrequencyData(w);let R=0;for(let x=0;x<w.length;x++)R+=w[x];const E=R/w.length/255;E>S&&(S=E)}for(const b of o.current)try{b(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(C=>{const S=t.current.get(C);if(S){try{S.node.disconnect()}catch{}try{S.analyser.disconnect()}catch{}t.current.delete(C)}},[]),u=r.useCallback((C,S)=>{const b=s();if(!b)return;l(C);const w=S(b);if(!w)return;const R=b.createAnalyser();R.fftSize=64;try{w.connect(R)}catch(E){console.warn("[useAudioLevel] connect failed for slot",C,E);return}t.current.set(C,{analyser:R,node:w,buffer:new Uint8Array(new ArrayBuffer(R.frequencyBinCount))}),c()},[l,s,c]),f=r.useCallback((C,S="agent")=>{u(S,b=>{try{return b.createMediaElementSource(C)}catch(w){return console.warn("[useAudioLevel] createMediaElementSource failed for slot",S,w),null}})},[u]),y=r.useCallback((C,S="mic")=>{u(S,b=>{try{return b.createMediaStreamSource(C)}catch(w){return console.warn("[useAudioLevel] createMediaStreamSource failed for slot",S,w),null}})},[u]),h=r.useCallback(C=>{l(C),t.current.size===0&&i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[l]),g=r.useCallback(()=>{i.current!==null&&(cancelAnimationFrame(i.current),i.current=null);for(const C of Array.from(t.current.keys()))l(C)},[l]),N=r.useCallback(C=>(o.current.add(C),()=>{o.current.delete(C)}),[]);return r.useEffect(()=>()=>{if(g(),e.current){try{e.current.close()}catch{}e.current=null}o.current.clear()},[g]),{attach:f,attachStream:y,detach:g,detachSlot:h,subscribe:N}}function Zr(e){const t=e==null?void 0:e.mediaStreamTrack;return t?new MediaStream([t]):null}function sr(e={}){const t=e.gateUntilAgentReady??!1,i=e.agentState??null,[o,a]=r.useState(t),[s,c]=r.useState(""),[l,u]=r.useState(null),f=r.useRef(null),y=r.useRef(null),h=r.useRef({active:t,lastAutoIntent:null}),g=r.useCallback(async E=>{var x,P;if(f.current&&y.current){try{await y.current.localParticipant.unpublishTrack(f.current)}catch{}f.current.stop(),f.current=null}y.current=E,u(null);try{const v=await Ot.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await E.localParticipant.publishTrack(v),f.current=v,h.current.active?(await E.localParticipant.setMicrophoneEnabled(!1),h.current.lastAutoIntent=!1,a(!0)):a(v.isMuted);const M=(P=(x=v.mediaStreamTrack)==null?void 0:x.getSettings)==null?void 0:P.call(x);M!=null&&M.deviceId&&c(M.deviceId)}catch(v){const M=v instanceof Error&&v.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw u(M),v}},[]),N=r.useCallback(E=>{y.current=E},[]),C=r.useCallback(async E=>{const x=y.current;if(x)try{await x.switchActiveDevice("audioinput",E),c(E)}catch(P){console.warn("[useMicrophoneState] switchDevice failed:",P)}},[]),S=r.useCallback(async()=>{const E=y.current,x=!o;if(a(x),h.current.active=!1,!!E)try{await E.localParticipant.setMicrophoneEnabled(!x)}catch(P){console.warn("[useMicrophoneState] setMicrophoneEnabled failed:",P),a(!x)}},[o]);r.useEffect(()=>{if(!h.current.active||i!=="listening")return;const E=y.current,x=E==null?void 0:E.localParticipant;if(!x){h.current.active=!1;return}x.isMicrophoneEnabled===h.current.lastAutoIntent&&(x.setMicrophoneEnabled(!0),h.current.lastAutoIntent=!0,a(!1)),h.current.active=!1},[i]);const b=r.useCallback(()=>{const E=f.current,x=y.current;if(E&&x){try{x.localParticipant.unpublishTrack(E)}catch{}E.stop()}f.current=null,y.current=null,h.current={active:t,lastAutoIntent:null},a(t),c("")},[t]),w=r.useCallback(()=>u(null),[]),R=r.useCallback(()=>Zr(f.current),[]);return{isMuted:o,activeDeviceId:s,micError:l,toggleMute:S,setupMic:g,attachRoom:N,switchDevice:C,teardownMic:b,clearError:w,getMicStream:R}}const Qr={resolution:{width:640,height:480,frameRate:24}};function ar(){const[e,t]=r.useState(!1),[i,o]=r.useState(null),[a,s]=r.useState(null),[c,l]=r.useState(""),u=r.useRef(null),f=r.useRef(null),y=r.useCallback(w=>{u.current=w},[]),h=r.useCallback(()=>{var E;const w=u.current,R=f.current;if(R&&w){const x=w.localParticipant.getTrackPublication(Ot.Track.Source.Camera),v=(x==null?void 0:x.track)??R;try{w.localParticipant.unpublishTrack(v)}catch{}try{(E=v.stop)==null||E.call(v)}catch{}}f.current=null,s(null),t(!1)},[]),g=r.useCallback(async w=>{const R=u.current;if(R){o(null);try{const E={...Qr};w&&(E.deviceId=w);const x=await Ot.createLocalVideoTrack(E);await R.localParticipant.publishTrack(x),f.current=x;const P=x.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 x=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";o(x)}}},[]),N=r.useCallback(async()=>{e?h():await g(c||void 0)},[e,c,h,g]),C=r.useCallback(async w=>{h(),await g(w)},[h,g]),S=r.useCallback(()=>{h(),u.current=null,o(null),l("")},[h]),b=r.useCallback(()=>o(null),[]);return r.useEffect(()=>()=>{f.current&&f.current.stop()},[]),{isEnabled:e,error:i,previewEl:a,activeDeviceId:c,toggle:N,switchDevice:C,attachRoom:y,teardown:S,clearError:b}}function lr(){const[e,t]=r.useState(!1),[i,o]=r.useState(null),[a,s]=r.useState(null),c=r.useRef(null),l=r.useCallback(g=>{c.current=g},[]),u=r.useCallback(()=>s(null),[]),f=r.useCallback(async()=>{const g=c.current;if(g){if(e){try{await g.localParticipant.setScreenShareEnabled(!1)}catch{}u(),t(!1);return}o(null);try{await g.localParticipant.setScreenShareEnabled(!0);let N=0;const C=()=>{const S=g.localParticipant.getTrackPublication(Ot.Track.Source.ScreenShare);if(S!=null&&S.track){const b=S.track.attach();s(b),t(!0);try{g.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}N++<10?setTimeout(C,100):t(!0)};C()}catch(N){const C=N instanceof Error?N.name:"";C!=="NotAllowedError"&&C!=="AbortError"&&o("Screen share unavailable. Try again."),t(!1)}}},[e,u]),y=r.useCallback(()=>{const g=c.current;if(g&&e)try{g.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:f,attachRoom:l,teardown:y,clearError:h}}function cr(){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 ur(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 f=new AbortController,y=t||"https://app.livelayer.studio";return u(!0),c(null),fetch(`${y}/api/widget/agent/${encodeURIComponent(e)}`,{signal:f.signal}).then(async h=>{if(!h.ok){const g=await h.json().catch(()=>({}));throw new Error(g.error||`HTTP ${h.status}`)}return h.json()}).then(h=>{f.signal.aborted||(a(h),u(!1))}).catch(h=>{f.signal.aborted||(c(h instanceof Error?h.message:"Agent lookup failed"),u(!1))}),()=>f.abort()},[e,t,i]),{info:o,error:s,loading:l}}function dr(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function fr(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function ei(e){if(!(typeof window>"u"))try{window.localStorage.removeItem(e)}catch{}}function pr({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 ti=["hidden","minimized","expanded"];function ni(e){return e&&ti.includes(e)?e:null}function hr({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]=pr({value:e,defaultValue:t,onChange:f=>{e===void 0&&!a&&fr(s,f),i==null||i(f)}});return r.useEffect(()=>{if(c.current||(c.current=!0,a||e!==void 0))return;const f=ni(dr(s));f&&f!==l&&u(f)},[]),[l,u]}const ri=640;function mr(e=ri){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 ii=280,oi=380,si=8,ai=4;function Zt(e){return`${e}:geometry`}function li(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 zt(){return typeof window>"u"?{vw:0,vh:0}:{vw:window.innerWidth,vh:window.innerHeight}}function Qt(e,t,i){const{minWidth:o,minHeight:a,edgeMargin:s,vw:c,vh:l}=i,u=Math.max(o,c-s*2),f=Math.max(a,l-s*2);return{width:Math.max(o,Math.min(u,e)),height:Math.max(a,Math.min(f,t))}}function en(e,t,i,o,a){const{edgeMargin:s,vw:c,vh:l}=a,u=s,f=s,y=Math.max(u,c-i-s),h=Math.max(f,l-o-s);return{top:Math.max(f,Math.min(h,e)),left:Math.max(u,Math.min(y,t))}}function ci(e){const{draggable:t,resizable:i,persistKey:o,disablePersistence:a,minWidth:s=ii,minHeight:c=oi,edgeMargin:l=si}=e,[u,f]=r.useState(null),[y,h]=r.useState(!1),[g,N]=r.useState(!1),C=r.useRef(null),S=r.useRef(null),b=r.useRef(!1),w=r.useRef(null);w.current=u;const R=r.useCallback(p=>{a||(p===null?ei(Zt(o)):fr(Zt(o),JSON.stringify(p)))},[a,o]);r.useEffect(()=>{if(b.current||(b.current=!0,a))return;const p=li(dr(Zt(o)));if(!p)return;const{vw:j,vh:I}=zt(),F=Qt(p.width,p.height,{minWidth:s,minHeight:c,edgeMargin:l,vw:j,vh:I}),V=en(p.top,p.left,F.width,F.height,{edgeMargin:l,vw:j,vh:I});f({...V,...F})},[]),r.useEffect(()=>{if(typeof window>"u")return;const p=()=>{f(j=>{if(j===null)return null;const{vw:I,vh:F}=zt(),V=Qt(j.width,j.height,{minWidth:s,minHeight:c,edgeMargin:l,vw:I,vh:F});return{...en(j.top,j.left,V.width,V.height,{edgeMargin:l,vw:I,vh:F}),...V}})};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 j=p.target;if(j&&typeof j.closest=="function"&&j.closest('button, a, input, select, textarea, [role="listbox"], [role="option"], [data-ll-no-drag]'))return;let I,F,V,Q;const $=w.current;if($)({top:I,left:F,width:V,height:Q}=$);else{const ee=p.currentTarget.closest(".ll-widget"),ne=ee==null?void 0:ee.getBoundingClientRect();if(!ne)return;I=ne.top,F=ne.left,V=ne.width,Q=ne.height}try{p.currentTarget.setPointerCapture(p.pointerId)}catch{}C.current={startClientX:p.clientX,startClientY:p.clientY,startTop:I,startLeft:F,width:V,height:Q,moved:!1}},[t]),x=r.useCallback(p=>{const j=C.current;if(!j)return;const I=p.clientX-j.startClientX,F=p.clientY-j.startClientY;if(!j.moved&&Math.abs(I)+Math.abs(F)>ai&&(j.moved=!0,h(!0)),!j.moved)return;const{vw:V,vh:Q}=zt(),$=en(j.startTop+F,j.startLeft+I,j.width,j.height,{edgeMargin:l,vw:V,vh:Q});f({...$,width:j.width,height:j.height})},[l]),P=r.useCallback(p=>{const j=C.current;if(j){try{p.currentTarget.releasePointerCapture(p.pointerId)}catch{}C.current=null,j.moved&&(h(!1),f(I=>(I&&R(I),I)))}},[R]),v=r.useCallback(()=>{C.current=null,S.current=null,h(!1),N(!1),f(null),R(null)},[R]),M=r.useCallback(p=>{if(!i||p.pointerType==="mouse"&&p.button!==0)return;p.stopPropagation();let j,I,F,V;const Q=w.current;if(Q)({top:j,left:I,width:F,height:V}=Q);else{const $=p.currentTarget.closest(".ll-widget"),ee=$==null?void 0:$.getBoundingClientRect();if(!ee)return;j=ee.top,I=ee.left,F=ee.width,V=ee.height}try{p.currentTarget.setPointerCapture(p.pointerId)}catch{}S.current={startClientX:p.clientX,startClientY:p.clientY,startWidth:F,startHeight:V,top:j,left:I},N(!0)},[i]),z=r.useCallback(p=>{const j=S.current;if(!j)return;const I=p.clientX-j.startClientX,F=p.clientY-j.startClientY,{vw:V,vh:Q}=zt(),$=V-j.left-l,ee=Q-j.top-l,ne=Qt(j.startWidth+I,j.startHeight+F,{minWidth:s,minHeight:c,edgeMargin:l,vw:Math.min(V,j.left+$+l),vh:Math.min(Q,j.top+ee+l)});f({top:j.top,left:j.left,...ne})},[l,s,c]),G=r.useCallback(p=>{if(S.current){try{p.currentTarget.releasePointerCapture(p.pointerId)}catch{}S.current=null,N(!1),f(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:y,isResizing:g,dragHandleProps:{onPointerDown:E,onPointerMove:x,onPointerUp:P,onPointerCancel:P,onDoubleClick:v,"data-ll-drag-handle":t?"":void 0},resizeHandleProps:{onPointerDown:M,onPointerMove:z,onPointerUp:G,onPointerCancel:G,"data-ll-resize-handle":i?"":void 0},reset:v}}const Tn="__llHistoryPatched",Bt="ll:pathname";function ui(){if(typeof window>"u"||window.history[Tn])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(Bt)),o},window.history.replaceState=function(...i){const o=t.apply(this,i);return window.dispatchEvent(new Event(Bt)),o},window.history[Tn]=!0}function Pn(){return typeof window>"u"?"/":window.location.pathname||"/"}function gr(e){const[t,i]=r.useState(()=>e??Pn());return r.useEffect(()=>{if(e!==void 0)return;ui();const o=()=>i(Pn());return o(),window.addEventListener("popstate",o),window.addEventListener(Bt,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(Bt,o)}},[e]),e??t}const Dn=new Map,di=/[\\^$+?.()|{}[\]]/g;function fi(e){return e.replace(di,"\\$&")}function pi(e){const t=Dn.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=fi(s).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(a,"g"),"[^/]+"),u=new RegExp(`^${l}\\/?$`);return Dn.set(e,u),u}function hi(e,t){const i=t.length>1&&t.endsWith("/")?t.slice(0,-1):t;return pi(e).test(i)}function yr(e,t){return typeof e=="function"?e(t):e instanceof RegExp?e.test(t):hi(e,t)}function zn(e,t){if(!e||e.length===0)return!1;for(const i of e)if(yr(i,t))return!0;return!1}function br(e,t,i){return e===void 0?!0:zn(i,e)?!1:t&&t.length>0?zn(t,e):!0}function vr(e,t,i){return r.useMemo(()=>br(e,t,i),[e,t,i])}function mi(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 gi(e){const t=r.useMemo(()=>mi(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 f=new Audio(`${i}/audio/thinking-sound.mp3`);f.loop=!0,f.volume=.3,f.play().catch(()=>{o.current=null}),o.current=f}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 $n=({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"})}),Hn=({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"})}),yi=({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"})}),bi={left:180,right:0,up:-90,down:90},Fn=({direction:e="right",className:t})=>n.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${bi[e]}deg)`},"aria-hidden":"true",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function vi(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const xr="ll-hidden-tab-center-y",xi=5,On=16;function wi(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(xr);if(!e)return null;const t=Number.parseFloat(e);return Number.isFinite(t)?t:null}catch{return null}}function Bn(e){if(!(typeof window>"u"))try{window.localStorage.setItem(xr,String(e))}catch{}}const _i=({position:e,isMobile:t,isSpeaking:i,onExpand:o,label:a="Open widget",avatarImageUrl:s,agentName:c,containerEl:l})=>{const u=vi(e),f=u==="right"?"left":"right",y=t?80:72,h=!!s,g=!!l,[N,C]=r.useState(null),[S,b]=r.useState(!1),w=r.useRef(null),R=r.useRef(!1),E=r.useCallback(T=>{if(typeof window>"u")return T;const U=y/2,p=On+U,j=window.innerHeight-On-U;return j<p?Math.max(p,T):Math.max(p,Math.min(j,T))},[y]);r.useEffect(()=>{if(g){C(null);return}const T=wi();C(E(T??window.innerHeight/2));const U=()=>{C(p=>p===null?null:E(p))};return window.addEventListener("resize",U),()=>window.removeEventListener("resize",U)},[E,g]);const x=r.useCallback(T=>{if(!g&&!(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,g]),P=r.useCallback(T=>{const U=w.current;if(!U)return;const p=T.clientY-U.startClientY;!U.moved&&Math.abs(p)>xi&&(U.moved=!0,b(!0)),U.moved&&C(E(U.startCenterY+p))},[E]),v=r.useCallback(T=>{const U=w.current;if(U){try{T.currentTarget.releasePointerCapture(T.pointerId)}catch{}w.current=null,U.moved&&(b(!1),R.current=!0,C(p=>(p!==null&&Bn(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 U=T.key==="ArrowUp"?-8:8;C(p=>{if(p===null)return p;const j=E(p+U);return Bn(j),j})}},[E]),G=["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,g?"ll-hidden--scoped":null].filter(Boolean).join(" "),ie=N===null?void 0:{top:`${N-y/2}px`,transform:"none"};return n.jsx("button",{type:"button",className:G,onPointerDown:x,onPointerMove:P,onPointerUp:v,onPointerCancel:v,onClick:M,onKeyDown:z,"aria-label":a,"data-position":e,style:ie,children:h?n.jsxs(n.Fragment,{children:[n.jsx(Fn,{direction:f,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(Fn,{direction:f,className:"ll-hidden__chevron"})})},Ci=({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 y=(Math.sqrt(5)-1)/2;return Array.from({length:t},(h,g)=>.5+g*y%1*.5)},[t]);r.useEffect(()=>e.subscribe(h=>{for(let g=0;g<t;g++){const N=l.current[g];if(!N)continue;const C=Math.max(o,h*i*u[g]);N.style.height=`${C}px`}}),[e,t,i,o,u]);const f=["ll-waveform",a].filter(Boolean).join(" ");return n.jsx("div",{ref:c,className:f,"aria-hidden":"true",children:Array.from({length:t},(y,h)=>n.jsx("div",{ref:g=>{l.current[h]=g},className:["ll-waveform__bar",s].filter(Boolean).join(" "),style:{height:`${o}px`}},h))})},ki=({position:e,isMobile:t,agentName:i,avatarImageUrl:o,agentState:a,isMuted:s,audioLevel:c,onExpand:l,onToggleMute:u,onClose:f})=>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(Ci,{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:y=>{y.stopPropagation(),u()},onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.stopPropagation(),y.preventDefault(),u())},"aria-label":s?"Unmute microphone":"Mute microphone",children:n.jsx($n,{muted:s,className:"ll-minimized__icon"})}),n.jsx(Hn,{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($n,{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(Hn,{className:"ll-minimized__icon"})}),n.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:f,"aria-label":"Close widget",children:n.jsx(yi,{className:"ll-minimized__icon"})})]})]})}),Si=({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)})},Ei="#E06540";function Li({size:e=14,className:t,fill:i=Ei}){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 ji=8,Wn=8,Ai=({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 f=l.getBoundingClientRect(),y={top:f.top-ji,left:f.left+f.width/2},h=Wn+90,g=window.innerWidth-Wn-90;y.left<h&&(y.left=h),y.left>g&&(y.left=g),c(y)};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=f=>{const y=f.target,h=a.current,g=i.current;h&&h.contains(y)||g&&g.contains(y)||t()},u=f=>{f.key==="Escape"&&(f.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:an.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)},Ri=({isMuted:e,onToggleMute:t,isCameraEnabled:i,onToggleCamera:o,allowCamera:a,isScreenShareEnabled:s,onToggleScreenShare:c,allowScreenShare:l,isSpeakerMuted:u,onToggleSpeaker:f,allowTyping:y,isTypingOpen:h,onToggleTyping:g,onDisconnect:N})=>{const[C,S]=r.useState(!1),b=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(Cr,{muted:e})}),n.jsx("button",{ref:b,type:"button",className:`ll-tool ${C?"is-on":""}`,onClick:()=>S(w=>!w),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":C,children:n.jsx(Ni,{})}),n.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:N,"aria-label":"End conversation",children:n.jsx(Sr,{})})]}),n.jsxs(Ai,{open:C,onClose:()=>S(!1),anchorRef:b,children:[a&&n.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${i?"is-on":""}`,onClick:()=>{o(),S(!1)},children:[n.jsx(_r,{}),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(wr,{}),n.jsx("span",{children:s?"Stop sharing":"Share screen"})]}),n.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${u?"is-on":""}`,onClick:()=>{f(),S(!1)},children:[n.jsx(kr,{muted:u}),n.jsx("span",{children:u?"Unmute speaker":"Mute speaker"})]}),y&&n.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${h?"is-on":""}`,onClick:()=>{g(),S(!1)},children:[n.jsx(Mi,{}),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 Ni(){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 Mi(){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 Ii=({position:e,isMobile:t,agentName:i,avatarImageUrl:o,idleLoopUrl:a,greeting:s,branding:c,teamMembers:l,currentTeamMemberId:u,isSwitchingTeamMember:f,teamSwitcherOpen:y,onToggleTeamSwitcher:h,onSelectTeamMember:g,languageMenuOpen:N,onToggleLanguageMenu:C,connectionState:S,agentState:b,transcript:w,canResume:R,needsUserGesture:E,error:x,isMuted:P,micError:v,micDevices:M,activeMicId:z,isCameraEnabled:G,cameraPreviewEl:ie,cameraDevices:T,activeCameraId:U,isScreenShareEnabled:p,screenPreviewEl:j,isSpeakerMuted:I,allowCamera:F,allowScreenShare:V,allowTyping:Q,showMinimize:$=!0,showClose:ee=!0,chromeless:ne=!1,compactControls:O=!1,transforming:fe,transformingLabel:X,avatarVideoContainerRef:we,agentVideoEl:te,onConnect:Le,onDisconnect:at,onRetry:vt,onResumeAudio:xt,onToggleMute:lt,onSwitchMicDevice:wt,onToggleCamera:Ue,onSwitchCameraDevice:Ve,onToggleScreenShare:De,onToggleSpeaker:ze,onSendMessage:$e,onMinimize:He,onClose:Fe,onClearMicError:Ye,dragHandleProps:Oe,resizeHandleProps:D})=>{var Ze;const Be=((l==null?void 0:l.length)??0)>1,Ge=S==="connecting"||S==="connected",_e=S==="connected",_t=S==="idle"||S==="disconnected"||S==="error",[ct,je]=r.useState(!1);r.useEffect(()=>{if(!te){je(!1);return}if(!te.paused&&te.readyState>=2){je(!0);return}je(!1);const k=()=>je(!0);return te.addEventListener("playing",k),te.addEventListener("loadeddata",k),()=>{te.removeEventListener("playing",k),te.removeEventListener("loadeddata",k)}},[te]);const[ut,Ct]=r.useState(!1);r.useEffect(()=>{b==="speaking"&&Ct(!0)},[b]),r.useEffect(()=>{(S==="disconnected"||S==="idle")&&Ct(!1)},[S]);const[We,le]=r.useState(!1);r.useEffect(()=>{if(!_e){le(!1);return}if(ut)return;const k=setTimeout(()=>le(!0),12e3);return()=>clearTimeout(k)},[_e,ut]);const kt=S==="connecting"||_e&&!ut&&!We,ce=r.useRef(null),me=r.useRef(null);r.useEffect(()=>{const k=ce.current;k&&(k.innerHTML="",ie&&(ie.style.width="100%",ie.style.height="100%",ie.style.objectFit="cover",ie.style.transform="scaleX(-1)",k.appendChild(ie)))},[ie]),r.useEffect(()=>{const k=me.current;k&&(k.innerHTML="",j&&(j.style.width="100%",j.style.height="100%",j.style.objectFit="contain",k.appendChild(j)))},[j]);const[Xe,Ke]=r.useState(!1),[de,ge]=r.useState(!1),St=r.useRef(null),Et=r.useRef(null);r.useEffect(()=>{if(!Xe&&!de&&!N&&!y)return;const k=()=>{Ke(!1),ge(!1),N&&C(),y&&h()};return document.addEventListener("click",k),()=>document.removeEventListener("click",k)},[Xe,de,N,y,C,h]);const[Lt,ln]=r.useState(!1),cn=r.useCallback(()=>ln(k=>!k),[]),[be,Ae]=r.useState(""),Se=r.useCallback(k=>{k.preventDefault();const re=be.trim();re&&($e(re),Ae(""))},[be,$e]),Re=c.productName||"Live Layer",dt=!c.hideBranding&&!c.productName;let Ne=null,Ce=null;for(let k=w.length-1;k>=0;k--){const re=w[k];if(!Ne&&re.role==="agent"?Ne=re:!Ce&&re.role==="user"&&(Ce=re),Ne&&Ce)break}const Je=_e?(Ne==null?void 0:Ne.text)||null:s||null,ft=_e&&(Ce==null?void 0:Ce.text)||null,pt=["ll-expanded",t?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return n.jsxs("div",{className:pt,"data-position":e,"data-state":_e?"connected":Ge?"connecting":"idle",role:"dialog","aria-label":`${i} widget`,children:[n.jsxs("div",{className:"ll-expanded__bg",children:[o?n.jsx(Si,{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:((Ze=i==null?void 0:i.charAt(0))==null?void 0:Ze.toUpperCase())||"A"})}),a&&!_e&&n.jsx("video",{className:"ll-expanded__bg-idle",src:a,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),n.jsx("div",{ref:we,className:"ll-expanded__video","data-ready":ct}),kt&&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:f?"Switching...":"Connecting..."})]}),E&&_e&&n.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:xt,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":X,children:[n.jsx("div",{className:"ll-expanded__spinner"}),n.jsx("p",{className:"ll-expanded__overlay-text",children:X})]}),Ge?n.jsxs(n.Fragment,{children:[!O&&n.jsxs("div",{className:"ll-expanded__topbar",...Oe,children:[!ne&&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:k=>{Be&&(k.stopPropagation(),h())},"aria-haspopup":Be?"listbox":void 0,"aria-expanded":Be?y:void 0,children:[n.jsx("span",{className:"ll-hpill__label",children:i}),Be&&n.jsx($t,{})]}),Be&&y&&n.jsx("div",{className:"ll-hmenu",onClick:k=>k.stopPropagation(),role:"listbox",children:l==null?void 0:l.map(k=>n.jsxs("button",{type:"button",className:`ll-hmenu__item ${k.id===u?"is-active":""}`,onClick:()=>g(k.id),role:"option","aria-selected":k.id===u,children:[k.avatarImageUrl&&n.jsx("img",{src:k.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),n.jsx("span",{className:"ll-hmenu__name",children:k.name}),k.role&&n.jsx("span",{className:"ll-hmenu__role",children:k.role})]},k.id))})]}),n.jsxs("div",{className:"ll-expanded__pill-wrap",children:[n.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:k=>{k.stopPropagation(),C()},"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($t,{})]}),N&&n.jsx("div",{className:"ll-hmenu",onClick:k=>k.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--${b}`,children:b})]}),n.jsxs("div",{className:"ll-expanded__header-actions",children:[$!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn",onClick:He,"aria-label":"Minimize widget",title:"Minimize",children:n.jsx(Un,{})}),ee!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Fe,"aria-label":"End call",title:"End call",children:n.jsx(qn,{})})]})]}),O&&n.jsxs("div",{className:"ll-compact-status","data-state":b,children:[n.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),n.jsx("span",{className:"ll-compact-status__label",children:b})]})]}):n.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",...Oe,children:[!O&&(dt?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(Li,{size:14,className:"ll-expanded__brand-mark"}),n.jsx("span",{children:Re})]}):n.jsx("span",{className:"ll-expanded__brand",children:Re})),n.jsxs("div",{className:"ll-expanded__header-actions",children:[!O&&$!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:He,"aria-label":"Minimize widget",children:n.jsx(Un,{})}),ee!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Fe,"aria-label":"Close widget",children:n.jsx(qn,{})})]})]}),_t&&(()=>{const k=R?"Resume session":S==="disconnected"?"Reconnect to agent":"Start video call",re=!x;return n.jsxs(n.Fragment,{children:[re&&n.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:Le,"aria-label":k,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"})})}),O&&n.jsx("span",{className:"ll-expanded__play-label",children:k})]}),!O&&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:Le,"aria-label":k,children:k})]})]})})(),n.jsxs("div",{className:`ll-expanded__pip ${Ge&&(G||p)?"is-visible":""}`,children:[n.jsx("div",{ref:me,className:p?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),n.jsx("div",{ref:ce,className:!p&&G?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Ge?n.jsxs("div",{className:"ll-expanded__bottom",children:[!O&&Je&&n.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:n.jsx("p",{className:"ll-expanded__transcript-text",children:Je})}),!O&&ft&&n.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:n.jsx("p",{className:"ll-expanded__transcript-text",children:ft})}),!ne&&!O&&n.jsxs("div",{className:"ll-toolbar",onClick:k=>k.stopPropagation(),children:[V&&n.jsx("button",{type:"button",className:`ll-tool ${p?"is-on":""}`,onClick:De,"aria-label":p?"Stop sharing screen":"Share screen",title:p?"Stop sharing":"Share screen",children:n.jsx(wr,{})}),F&&n.jsxs("div",{className:"ll-tool-split",children:[n.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${G?"is-on":""}`,onClick:Ue,"aria-label":G?"Turn off camera":"Turn on camera",title:G?"Stop camera":"Start camera",children:n.jsx(_r,{})}),n.jsx("button",{ref:Et,type:"button",className:`ll-tool ll-tool--right ${G?"is-on":""}`,onClick:k=>{k.stopPropagation(),ge(re=>!re),Ke(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":de,children:n.jsx($t,{})}),de&&T.length>0&&n.jsx(Vn,{label:"Camera",devices:T,activeId:U,anchorRef:Et,onPick:k=>{ge(!1),Ve(k)}})]}),n.jsxs("div",{className:"ll-tool-split",children:[n.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${P?"is-muted":""}`,onClick:lt,"aria-label":P?"Unmute microphone":"Mute microphone",title:P?"Unmute":"Mute",children:n.jsx(Cr,{muted:P})}),n.jsx("button",{ref:St,type:"button",className:`ll-tool ll-tool--right ${P?"is-muted":""}`,onClick:k=>{k.stopPropagation(),Ke(re=>!re),ge(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":Xe,children:n.jsx($t,{})}),Xe&&M.length>0&&n.jsx(Vn,{label:"Microphone",devices:M,activeId:z,anchorRef:St,onPick:k=>{Ke(!1),wt(k)}})]}),n.jsx("button",{type:"button",className:`ll-tool ${I?"is-muted":""}`,onClick:ze,"aria-label":I?"Unmute speaker":"Mute speaker",title:I?"Unmute speaker":"Mute speaker",children:n.jsx(kr,{muted:I})}),n.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:at,"aria-label":"End conversation",title:"End conversation",children:n.jsx(Sr,{})})]}),!ne&&O&&n.jsx(Ri,{isMuted:P,onToggleMute:lt,isCameraEnabled:G,onToggleCamera:Ue,allowCamera:F,isScreenShareEnabled:p,onToggleScreenShare:De,allowScreenShare:V,isSpeakerMuted:I,onToggleSpeaker:ze,allowTyping:Q,isTypingOpen:Lt,onToggleTyping:cn,onDisconnect:at}),!ne&&Q&&(O?Lt:!0)&&n.jsxs("form",{className:"ll-message-input",onSubmit:Se,children:[n.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:be,onChange:k=>Ae(k.target.value),"aria-label":"Message the agent"}),be.trim()&&n.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:n.jsx(Ti,{})})]})]}):null,(()=>{if(v&&S!=="error")return n.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[n.jsx("span",{children:v}),n.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:Ye,"aria-label":"Dismiss",children:"×"})]});if(!x||S!=="error")return null;let k="Failed to connect",re="Try again";return x==="MIC_PERMISSION_DENIED"?k="Microphone blocked. Allow access to talk.":x==="MIC_NOT_FOUND"?k="No microphone found. Plug one in + retry.":x==="MIC_UNAVAILABLE"?k="Mic unavailable. Check other apps using it.":x==="AGENT_TIMEOUT"?k="Agent didn't pick up. Try again.":x==="CONNECT_FAILED"?k="Connection failed. Check your network.":x.length<80&&(k=x),n.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[n.jsx("span",{children:k}),n.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:vt,children:re})]})})(),(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 $t(){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 qn(){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 Un(){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 wr(){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 _r(){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 Cr({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 kr({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 Ti(){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 Sr(){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 Vn=({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 f=u.getBoundingClientRect(),y=126,h=window.innerWidth-16-110,g=f.left+f.width/2;c({top:f.top-8,left:Math.max(y,Math.min(h,g))})};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:an.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 f=i===l.deviceId;return n.jsxs("button",{type:"button",className:`ll-device-menu__item ${f?"is-active":""}`,onClick:()=>o(l.deviceId),role:"option","aria-selected":f,children:[f&&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)},Pi=["[data-ll-private]","[data-ll-skip]",".ll-widget"];function Wt(e){let t=e;for(;t;){for(const i of Pi)if(t.matches(i))return!0;t=t.parentElement}return!1}function rn(e){if(Wt(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 Di=/\b(continue|next|proceed|move\s*on|forward)\b|→|›/i,Yn=/\b(back|previous|prev|go\s*back)\b|←|‹/i,zi=/\b(submit|finish|done|complete|send)\b/i,bt=new Map;function Gn(e){const t=bt.get(e);return t&&t.isConnected?t:null}function rt(e){if(Wt(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 $i(e){return!!(e.disabled||e.getAttribute("aria-disabled")==="true")}function Hi(e){return(e.innerText||e.textContent||e.getAttribute("aria-label")||e.value||"").trim()}function Fi(e){return Array.from(e.querySelectorAll('button, [role="button"], input[type="submit"], input[type="button"]')).filter(i=>!rt(i)&&!$i(i))}function Er(e){bt.clear();const t=Fi(e);let i,o,a;for(const l of t){const u=Hi(l);if(!u||u.length>40)continue;const f=l.getAttribute("type")==="submit"||l.tagName==="BUTTON"&&!l.getAttribute("type")&&!!l.closest("form");!i&&Di.test(u)&&!Yn.test(u)?(i={id:"ll-advance",label:u},bt.set("ll-advance",l)):!o&&Yn.test(u)?(o={id:"ll-back",label:u},bt.set("ll-back",l)):!a&&(zi.test(u)||f)&&(a={id:"ll-submit",label:u},bt.set("ll-submit",l))}const s=Yi(e);return{kind:i||s.totalSteps?"multi-step":"single-page",advance:i,back:o,submit:a,...s}}const Oi=60;function Lr(e){return e.replace(/^\s*(step\s+)?\d{1,2}(?:[.):\-]+\s*|\s+)/i,"").replace(/\s+/g," ").trim().slice(0,Oi)}function Bi(e){const t=e.getAttribute("class");return t?t.toLowerCase():""}const Wi=/stepper|wizard|ant-steps|step-indicator/;function qi(e){return Wi.test(Bi(e))}function Xn(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 Ui='[aria-current="step"],[aria-current="true"],[class*="active"],[class*="Active"],[class*="current"],[class*="Current"],[class*="selected"],[class*="Selected"]';function Vi(e){return Xn(e)?!0:Array.from(e.querySelectorAll(Ui)).some(Xn)}function Kn(e,t){const i=Lr(e[t].innerText||e[t].textContent||"");return{totalSteps:e.length,currentStep:t+1,...i?{stepLabel:i}:{}}}function Yi(e){const t=e.querySelector('[aria-current="step"]');if(t&&t.parentElement&&!rt(t)){const a=Array.from(t.parentElement.children).filter(c=>c.tagName===t.tagName&&!rt(c)),s=a.indexOf(t);if(s>=0&&a.length>=2)return Kn(a,s)}const i=e.querySelector('[role="progressbar"]');if(i&&!rt(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:Lr(c)}:{}}}}const o=Array.from(e.querySelectorAll('[class*="step"], [class*="Step"], [class*="wizard"], [class*="Wizard"]')).filter(a=>!rt(a)&&qi(a));for(const a of o){const s=Array.from(a.children).filter(l=>!rt(l)&&(l.textContent||"").trim().length>0);if(s.length<2||s.length>12)continue;const c=s.findIndex(Vi);if(!(c<0))return Kn(s,c)}return{}}const Ht=4096,Gi=20,Xi=20,Ki=10,Ji=10,Zi=30,Qi=20,Jn=500,eo=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function gt(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let t=e;for(;t;){for(const i of eo)if(t.matches(i))return!0;t=t.parentElement}return!1}function yt(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 Zn(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 ae(e,t){return e.length<=t?e:e.slice(0,t-1)+"…"}function to(e){return e&&e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function no(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 nt(e){return e.length}function jr(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 v of c){if(l.length>=Ki)break;if(gt(v)||!yt(v))continue;const M=v.getAttribute("data-ll-region")??"",z=v.getAttribute("data-ll-intent")??void 0,G=ae((v.innerText||v.textContent||"").trim(),Jn*2);!M||!G||l.push({id:M,intent:z,text:G})}const u=[],f=["H1","H2","H3","H4","H5","H6"],y=Array.from(i.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const v of y){if(gt(v)||!yt(v))continue;const M=(v.textContent||"").trim();M&&u.push(`${v.tagName}: ${ae(M,200)}`)}const h=Array.from(i.querySelectorAll("p, li"));for(const v of h){if(gt(v)||!yt(v)||f.includes(v.tagName))continue;const M=(v.textContent||"").trim();M.length>10&&u.push(ae(M,Jn))}const g=u.join(`
2
- `),N=[],C=Array.from(i.querySelectorAll("a[href]"));for(const v of C){if(N.length>=Gi)break;if(gt(v)||!yt(v))continue;const M=v.getAttribute("href")||"",z=(v.textContent||"").trim();!M||!z||N.push({href:M,text:ae(z,100)})}const S=[],b=Array.from(i.querySelectorAll("input, textarea, select"));for(const v of b){if(S.length>=Xi)break;if(gt(v)||!rn(v)||!yt(v))continue;const M=Zn(v),z=v instanceof HTMLInputElement?v.type:v.tagName.toLowerCase();M&&S.push({label:ae(M,100),type:z})}const w=Array.from(i.querySelectorAll("form")),R=[];let E=0;for(const v of w){if(R.length>=Ji)break;if(Wt(v)||v.matches(".ll-widget *, .ll-widget"))continue;const M=v.getAttribute("id")||v.getAttribute("name")||to(v.getAttribute("data-ll-intent"))||`form_${E++}`,z=v.getAttribute("data-ll-intent")||no(v)||void 0,G=Array.from(v.querySelectorAll("input, textarea, select")),ie=[];let T=0;const U=new Set;for(const p of G){if(ie.length>=Zi)break;if(!rn(p))continue;if(p instanceof HTMLInputElement){const O=p.type;if(O==="submit"||O==="button"||O==="reset"||O==="hidden"||O==="image"||O==="file")continue}const j=p.getAttribute("name")||"",I=p.getAttribute("id")||"";let F=j||I||`field_${T}`;U.has(F)&&(F=`${F}__${T}`),U.add(F),T++;const V=Zn(p)||F,Q=p instanceof HTMLInputElement?p.type:p.tagName.toLowerCase(),$={name:F,label:ae(V,100),type:Q};p.required===!0&&($.required=!0);const ee=p.getAttribute("placeholder");if(ee&&($.placeholder=ae(ee.trim(),100)),p instanceof HTMLInputElement||p instanceof HTMLTextAreaElement){const O=p.getAttribute("minlength");if(O!==null){const X=parseInt(O,10);!Number.isNaN(X)&&X>=0&&($.minLength=X)}const fe=p.getAttribute("maxlength");if(fe!==null){const X=parseInt(fe,10);!Number.isNaN(X)&&X>=0&&($.maxLength=X)}}if(p instanceof HTMLInputElement){const O=p.getAttribute("min");O!==null&&($.min=ae(O,50));const fe=p.getAttribute("max");fe!==null&&($.max=ae(fe,50));const X=p.getAttribute("step");X!==null&&($.step=ae(X,20));const we=p.getAttribute("pattern");we!==null&&($.pattern=ae(we,200));const te=(p.getAttribute("autocomplete")||"").toLowerCase();te&&te!=="off"&&!te.startsWith("cc-")&&($.autocomplete=ae(te,50))}if(p instanceof HTMLSelectElement){const O=[];for(let fe=0;fe<p.options.length;fe++){const X=p.options[fe];if(!X)continue;if(X.value===""||X.disabled){const Le=(X.textContent||"").trim();if(Le&&!$.placeholderOption&&($.placeholderOption=ae(Le,60)),$.hasEmptyOption=!0,X.disabled)continue}if(O.length>=Qi)break;const we=X.value||"",te=(X.textContent||"").trim()||we;!we&&!te||O.push({value:we,label:ae(te,60)})}O.length>0&&($.options=O)}const ne=typeof p.validationMessage=="string"?p.validationMessage:"";ne&&($.validationMessage=ae(ne,200)),ie.push($)}R.push({id:M,intent:z,fields:ie})}const x={url:o,title:s,pathname:a,regions:l,visibleText:g,visibleLinks:N,visibleFields:S,forms:R,flow:Er(i),extras:e};let P=nt(JSON.stringify(x.regions))+nt(x.visibleText)+nt(JSON.stringify(x.visibleLinks))+nt(JSON.stringify(x.visibleFields));for(;P>Ht&&x.visibleFields.length>0;)x.visibleFields.pop(),P=nt(JSON.stringify(x.visibleFields));for(;P>Ht&&x.visibleLinks.length>0;)x.visibleLinks.pop(),P-=80;return nt(x.visibleText)>Ht&&(x.visibleText=ae(x.visibleText,Ht-100)),x}let it=null;function ro(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 on(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?ro(o):""}`;if(it&&it.key===c&&i-it.at<1e3)return it.ctx;const l=jr(e,t);return it={key:c,at:i,ctx:l},l}function Ar(){it=null}const io=200;function Rr(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 oo(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function Nr(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>=io)break;if(Wt(c))continue;const l=c.getAttribute("href")||"";if(!oo(l))continue;let u=l,f=!0;try{if(typeof window<"u"){const h=new URL(l,i);f=h.origin===i,f&&l.startsWith("http")&&(u=h.pathname+h.search+h.hash)}}catch{continue}if(o.has(u))continue;o.add(u);const y=(c.textContent||"").trim().slice(0,120);a.push({href:u,text:y,internal:f})}return a}let ot=null;const so=5e3;function Ft(){const e=Date.now(),t=typeof window<"u"&&window.location.pathname||"/";if(ot&&ot.pathname===t&&e-ot.at<so)return ot.routes;const i=Nr();return ot={at:e,pathname:t,routes:i},i}function Mr(){ot=null}function sn(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 ao(e,t){return e.getAttribute("name")||e.getAttribute("id")||`field_${t}`}function Pe(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"")}function tn(e){const t=e.lastIndexOf(".");return t>=0?e.slice(t+1):e}function lo(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 co(e,t){const i=Pe(t);if(i.length<2)return null;let o=null,a=0;for(const s of Array.from(e.querySelectorAll("input, textarea, select"))){if(!sn(s))continue;const c=s.getAttribute("name")||"",l=s.getAttribute("id")||"",u=[Pe(tn(c)),Pe(tn(l)),Pe(c),Pe(l)];let f=0;u.some(y=>y.length>=2&&y===i)?f=4:[Pe(c),Pe(tn(c)),Pe(lo(s))].some(h=>h.length>=3&&(h.includes(i)||i.includes(h)))&&(f=2),f>a&&(a=f,o=s)}return a>=2?o:null}function uo(e,t){if(!t)return null;try{const s=e.querySelector(`[name="${t.replace(/"/g,'\\"')}"]`);if(s&&sn(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(!sn(s))continue;const c=ao(s,o);let l=c;if(a.has(c)&&(l=`${c}__${o}`),l===t)return s;a.set(c,s),o++}return co(e,t)}function Qn(e,t){const i=uo(e,t);return i?rn(i)?{el:i}:{el:null,reason:"private"}:{el:null,reason:"not_found"}}function fo(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 po(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}fo(e,t),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),a&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function er(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&&ho(u)===t)return l}if(/^form_\d+$/.test(t)){const l=parseInt(t.slice(5),10);let u=0;for(const f of c)if(!(f.id||f.getAttribute("name")||f.getAttribute("data-ll-intent"))){if(u===l)return f;u++}}return c.length===1?c[0]:null}function ho(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function mo(){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 go(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function yo(){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(!go(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 bo(){if(typeof window>"u")return null;if(mo())return window;const e=yo();return e||window}function tr(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function vo(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 xo=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"]),Ir=r.forwardRef(function(t,i){var xn,wn,_n,Cn,kn,Sn,En,Ln;const{agentId:o,apiKey:a,baseUrl:s="https://app.livelayer.studio",sessionEndpoint:c,sessionBody:l,soundEffects:u,experienceMode:f="WIDGET",autoConnect:y=!1,displayMode:h,defaultDisplayMode:g="expanded",onDisplayModeChange:N,position:C="bottom-right",mobileBreakpoint:S=640,draggable:b,resizable:w,persistKey:R="ll-widget",disablePersistence:E=!1,teamMembers:x,currentTeamMemberId:P,onTeamMemberChange:v,idleLoopUrl:M,greeting:z,avatarImageUrl:G,agentName:ie,branding:T={},allowCamera:U=!0,allowScreenShare:p=!0,allowTyping:j=!0,blurUntilFirstSpeech:I=!0,showMinimize:F,showClose:V,chromeless:Q=!1,floatingChromeContainer:$=null,compactControls:ee=!1,transforming:ne=!1,transformingLabel:O="Transforming…",showOn:fe,hideOn:X,pathname:we,onNavigate:te,onScrollToSelector:Le,getPageContext:at,pageContextExtras:vt,getRoutes:xt,onScrollPage:lt,onClick:wt,capabilities:Ue,onConnect:Ve,onDisconnect:De,onTranscript:ze,onAgentState:$e,onConnectionStateChange:He,onAgentEvent:Fe,onAgentCommand:Ye,onCollect:Oe,controlledSession:D,className:Be,style:Ge,zIndex:_e=2147483647}=t,_t=gr(we),ct=vr(_t,fe,X);r.useEffect(()=>{Ar(),Mr()},[_t]);const je=P!==void 0,[ut,Ct]=r.useState(()=>{var m;return P??((m=x==null?void 0:x[0])==null?void 0:m.id)}),We=je?P:ut,le=r.useMemo(()=>(x==null?void 0:x.find(m=>m.id===We))??null,[x,We]),kt=(le==null?void 0:le.agentId)??o,ce=f==="EMBEDDED",me=mr(S),[Xe,Ke]=hr({value:h,defaultValue:g,onChange:N,persistKey:R,disablePersistence:ce||E}),de=ce?"expanded":Xe,ge=ce?()=>{}:Ke,St=F??!ce,Et=V??!ce,Lt=ee||!ce&&me,be=ci({draggable:!ce&&(b??!me),resizable:!ce&&(w??!me),persistKey:R,disablePersistence:ce||E}),Ae=or(),Se=ar(),Re=lr(),dt=cr(),[Ne,Ce]=r.useState(!1),[Je,ft]=r.useState(!1),[pt,Ze]=r.useState(!1),[k,re]=r.useState(!1),[qt,Dr]=r.useState(!1),jt=gi({baseUrl:s,config:u}),At=r.useRef(jt);At.current=jt;const Ut=r.useRef(te),Vt=r.useRef(Le),Yt=r.useRef(lt),Gt=r.useRef(wt),un=r.useRef(at),dn=r.useRef(vt),fn=r.useRef(xt),Xt=r.useRef(Ue),ke=r.useRef(null);Ut.current=te,Vt.current=Le,Yt.current=lt,Gt.current=wt,un.current=at,dn.current=vt,fn.current=xt,Xt.current=Ue;function ve(m){const d=Xt.current;return d?d.includes(m):!0}function xe(m,d){console.warn(`[LiveLayer] Agent command "${m}" blocked — capability "${d}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const ht=r.useCallback(m=>{var K,ue,Ee,mt,Me,jn,An;const d=m;if(!(!d.type||typeof d.type!="string")){if(Fe==null||Fe({eventName:d.type,data:m}),d.type==="navigate"){if(!ve("navigate")){xe("navigate","navigate");return}const L=typeof d.href=="string"?d.href:null;if(!L){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(At.current.playPageChange(),Ut.current){try{Ut.current(L)}catch(A){console.warn(`[LiveLayer] onNavigate threw for "${L}". Falling back. Error:`,A)}return}if(typeof document<"u"){const A=document.querySelector(`a[href="${L.replace(/"/g,'\\"')}"]`);if(A){A.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",L),window.dispatchEvent(new PopStateEvent("popstate"))}catch(A){console.warn(`[LiveLayer] history.pushState fallback failed for "${L}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,A)}return}if(d.type==="scroll_to"){if(!ve("scroll")){xe("scroll_to","scroll");return}const L=typeof d.selector=="string"?d.selector:null;if(!L)return;const A=d.behavior==="instant"?"instant":"smooth";if(Vt.current){try{Vt.current(L,A)}catch(W){console.warn("[LiveLayer] onScrollToSelector threw.",W)}return}if(typeof document<"u"){let W=null;try{W=document.querySelector(L)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${L}".`);return}if(!W){console.warn(`[LiveLayer] scroll_to: no element matched "${L}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}W.scrollIntoView({behavior:A,block:"start"})}return}if(d.type==="request_page_context"){if(!ve("read_page")){xe("request_page_context","read_page");return}const L=typeof d.requestId=="string"?d.requestId:void 0,A=(K=ke.current)==null?void 0:K.call(ke),W=Z=>{const H=A,pe=H==null?void 0:H.localParticipant;if(pe!=null&&pe.publishData)try{const he=L?{...Z,requestId:L}:Z,It=new TextEncoder().encode(JSON.stringify(he));pe.publishData(It,{reliable:!0})}catch(he){console.warn("[LiveLayer] publishData failed.",he)}},B=dn.current,J=un.current;try{if(J){const Z=J(B);if(Z instanceof Promise){W({type:"page_context_pending"}),Z.then(H=>W({type:"page_context",context:H})).catch(H=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",H),W({type:"page_context",context:on(B)})});return}W({type:"page_context",context:Z});return}W({type:"page_context",context:on(B)})}catch(Z){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",Z),W({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:B}})}return}if(d.type==="scroll_page"){if(!ve("scroll")){xe("scroll_page","scroll");return}const L=d.direction;if(L!=="up"&&L!=="down"&&L!=="top"&&L!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(L)}". Expected up | down | top | bottom.`);return}const A=d.behavior==="instant"?"instant":"smooth";if(Yt.current){try{Yt.current(L,A)}catch(H){console.warn("[LiveLayer] onScrollPage threw.",H)}return}if(typeof window>"u")return;const W={behavior:A},B=bo(),J=H=>{B instanceof Window?B.scrollBy({top:H,...W}):B.scrollBy({top:H,...W})},Z=H=>{B instanceof Window?B.scrollTo({top:H,...W}):B.scrollTo({top:H,...W})};L==="up"?J(-tr(B)):L==="down"?J(tr(B)):Z(L==="top"?0:vo(B));return}if(d.type==="click"){if(!ve("click")){xe("click","click");return}const L=typeof d.selector=="string"?d.selector:null;if(!L){console.warn("[LiveLayer] click: missing selector.");return}if(Gt.current){try{Gt.current(L)}catch(W){console.warn("[LiveLayer] onClick threw.",W)}return}if(typeof document>"u")return;let A=null;try{A=document.querySelector(L)}catch{console.warn(`[LiveLayer] click: invalid selector "${L}".`);return}if(!A){console.warn(`[LiveLayer] click: no element matched "${L}". 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}(ue=A.click)==null||ue.call(A);return}if(d.type==="advance_step"||d.type==="go_back"||d.type==="submit_flow"){if(!ve("click")){xe(d.type,"click");return}if(typeof document>"u")return;const L=d.type==="advance_step"?"ll-advance":d.type==="go_back"?"ll-back":"ll-submit";let A=Gn(L);if(A||(Er(document),A=Gn(L)),!A){console.warn(`[LiveLayer] ${d.type}: no "${L}" control found.`);return}(Ee=A.click)==null||Ee.call(A);return}if(d.type==="fill_form"||d.type==="focus_field"){if(!ve("fill_forms")){xe(d.type,"fill_forms");return}if(typeof document>"u")return;d.type==="fill_form"&&At.current.playConfirmation();const L=typeof d.formId=="string"?d.formId:null;if(!L){console.warn(`[LiveLayer] ${d.type}: missing formId.`);return}const A=er(document,L);if(!A){console.warn(`[LiveLayer] ${d.type}: no <form> matched id="${L}" (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] ${d.type}: refusing to touch a form in a private / opted-out subtree.`);return}if(d.type==="focus_field"){const B=typeof d.fieldName=="string"?d.fieldName:null;if(!B){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const J=Qn(A,B);if(J.el===null){J.reason==="private"?console.warn(`[LiveLayer] focus_field: field "${B}" is privacy-protected and not focusable.`):console.warn(`[LiveLayer] focus_field: no input matching key="${B}" in form "${L}". The agent should use the field.name it observed in PageContext.forms[].fields[].`);return}J.el.focus();return}const W=d.values&&typeof d.values=="object"?d.values:null;if(!W){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[B,J]of Object.entries(W)){if(typeof J!="string")continue;const Z=Qn(A,B);if(Z.el===null){Z.reason==="private"?console.warn(`[LiveLayer] fill_form: field "${B}" is privacy-protected (password / cc-* / data-ll-private). Skipping.`):console.warn(`[LiveLayer] fill_form: no input matching key="${B}" in form "${L}". The agent should use the field.name it observed in PageContext.forms[].fields[]. Skipping.`);continue}try{po(Z.el,J)}catch(H){console.warn(`[LiveLayer] fill_form: failed to set "${B}".`,H)}}return}if(d.type==="submit_form"){if(!ve("submit_forms")){xe("submit_form","submit_forms");return}if(typeof document>"u")return;const L=typeof d.formId=="string"?d.formId:null;if(!L){console.warn("[LiveLayer] submit_form: missing formId.");return}At.current.playConfirmation();const A=er(document,L);if(!A){console.warn(`[LiveLayer] submit_form: no <form> matched id="${L}" (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 W=typeof d.requestId=="string"?d.requestId:void 0,B=(mt=ke.current)==null?void 0:mt.call(ke),J=q=>{const Y=B,se=Y==null?void 0:Y.localParticipant;if(se!=null&&se.publishData)try{const Te=W?{...q,requestId:W}:q,qe=new TextEncoder().encode(JSON.stringify(Te));se.publishData(qe,{reliable:!0})}catch{}},Z=q=>{var qe,Pt,Mn,In;const Y=q,se=(qe=Y.getAttribute)==null?void 0:qe.call(Y,"aria-label");if(se)return se;const Te=Y.id;if(Te){const Dt=(Pt=A.ownerDocument)==null?void 0:Pt.querySelector(`label[for="${Te}"]`);if((Mn=Dt==null?void 0:Dt.textContent)!=null&&Mn.trim())return Dt.textContent.trim()}return((In=Y.getAttribute)==null?void 0:In.call(Y,"name"))||Y.id||Y.type||"field"},H=()=>{try{return Array.from(A.elements).filter(q=>"willValidate"in q&&q.willValidate&&!q.checkValidity()).map(q=>`${Z(q)}: ${q.validationMessage}`)}catch{return[]}};if(typeof A.checkValidity=="function"&&!A.checkValidity()){try{(Me=A.reportValidity)==null||Me.call(A)}catch{}J({type:"form_submit_blocked",formId:L,reason:"validation",invalidFields:H()});return}const pe=q=>{var se;const Y=(se=q.tagName)==null?void 0:se.toLowerCase();if(Y==="textarea"||Y==="select")return!0;if(Y==="input"){const Te=(q.type||"text").toLowerCase();return!["hidden","submit","button","reset","file","image"].includes(Te)}return!1},he=q=>{var se;const Y=q;return((se=q.tagName)==null?void 0:se.toLowerCase())==="input"&&(Y.type==="checkbox"||Y.type==="radio")?Y.checked?"on":"":(Y.value||"").trim()},It=Array.from(A.elements).filter(q=>pe(q)&&he(q).length>0),Rn=/(thank you|thanks|we'?ll be in touch|message sent|message has been sent|successfully|submission received|got your message|we received|talk soon|be in touch)/i,Kr=(((jn=A.parentElement)==null?void 0:jn.textContent)||"").toLowerCase();let Nn=!1,Tt=!1;const Ie=q=>{Tt||(Tt=!0,J(q))},Jr=()=>{const q=Date.now(),Y=()=>{var qe;if(Tt)return;const se=H();if(se.length>0){Ie({type:"form_submit_blocked",formId:L,reason:"validation",invalidFields:se});return}if(!A.isConnected){Ie({type:"form_submitted",formId:L,reason:"form_removed"});return}if(It.length>0&&It.every(Pt=>he(Pt).length===0)){Ie({type:"form_submitted",formId:L,reason:"form_reset"});return}const Te=(((qe=A.parentElement)==null?void 0:qe.textContent)||"").toLowerCase();if(Rn.test(Te)&&!Rn.test(Kr)){Ie({type:"form_submitted",formId:L,reason:"success_text"});return}Date.now()-q<2e3?setTimeout(Y,250):Ie({type:"form_submit_uncertain",formId:L,reason:"spa_prevented"})};setTimeout(Y,200)},Jt=q=>{Nn=!0,queueMicrotask(()=>{q.defaultPrevented?Jr():Ie({type:"form_submitted",formId:L})})};A.addEventListener("submit",Jt,{once:!0});try{typeof A.requestSubmit=="function"?A.requestSubmit():A.submit()}catch(q){console.warn("[LiveLayer] submit_form: requestSubmit threw.",q),A.removeEventListener("submit",Jt),Ie({type:"form_submit_blocked",formId:L,reason:"exception"});return}setTimeout(()=>{!Nn&&!Tt&&(A.removeEventListener("submit",Jt),Ie({type:"form_submit_blocked",formId:L,reason:"validation",invalidFields:H()}))},500);return}if(d.type==="request_routes"){if(!ve("read_page")){xe("request_routes","read_page");return}const L=typeof d.requestId=="string"?d.requestId:void 0,W=(An=ke.current)==null?void 0:An.call(ke),B=W==null?void 0:W.localParticipant;if(!(B!=null&&B.publishData))return;const J=H=>{try{const pe=L?{type:"routes",routes:H,requestId:L}:{type:"routes",routes:H},he=new TextEncoder().encode(JSON.stringify(pe));B.publishData(he,{reliable:!0})}catch(pe){console.warn("[LiveLayer] request_routes: publishData failed.",pe)}},Z=fn.current;if(Z){try{const H=Z(),pe=he=>{if(!Array.isArray(he)){J([]);return}J(he.map(Rr).slice(0,200))};H instanceof Promise?H.then(pe).catch(he=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",he),J(Ft())}):pe(H)}catch(H){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",H),J(Ft())}return}try{J(Ft())}catch(H){console.warn("[LiveLayer] request_routes: extractRoutes threw.",H)}return}if(d.type==="task_field_updated"){if(!ve("collect_data")){xe("task_field_updated","collect_data");return}const L={phase:"field",fieldId:typeof d.fieldId=="string"?d.fieldId:"",fieldName:typeof d.fieldName=="string"?d.fieldName:typeof d.fieldId=="string"?d.fieldId:"",value:typeof d.value=="string"?d.value:"",kind:typeof d.kind=="string"?d.kind:"text",source:d.source==="slide"?"slide":d.source==="page"?"page":"agent",...typeof d.slideId=="string"?{slideId:d.slideId}:{},...typeof d.formId=="string"?{formId:d.formId}:{}};if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:L}))}catch{}return}if(d.type==="task_completed"){if(!ve("collect_data")){xe("task_completed","collect_data");return}const L=d.result;if(!L||typeof L!="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:L}}))}catch{}try{Oe==null||Oe(L)}catch(A){console.warn("[LiveLayer] onCollect threw.",A)}return}xo.has(d.type)||Ye==null||Ye(d)}},[Ye,Fe,Oe]),oe=ir({agentId:D?"__controlled__":kt,baseUrl:s,apiKey:a,sessionEndpoint:c,sessionBody:l,onDataMessage:D?void 0:ht});r.useEffect(()=>{if(D!=null&&D.subscribeToDataMessages)return D.subscribeToDataMessages(ht)},[D,ht]),ke.current=()=>{var m;return(m=oe.getRoom)==null?void 0:m.call(oe)},r.useEffect(()=>{var K;if(typeof window>"u")return;const m=((K=window.location)==null?void 0:K.hostname)||"";if(m==="localhost"||m==="127.0.0.1"||m==="0.0.0.0"||m.endsWith(".local")||m.endsWith(".test"))return window.__livelayerSimulateCommand=ue=>{try{ht(ue)}catch(Ee){console.warn("[LiveLayer] simulate-command threw:",Ee)}},()=>{delete window.__livelayerSimulateCommand}},[ht]);const _=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:oe.getRoom,isControlled:!0}:{connectionState:oe.connectionState,agentState:oe.agentState,transcript:oe.transcript,videoElement:oe.videoElement,audioElement:oe.audioElement,canResume:oe.canResume,error:oe.error,agentConfig:oe.agentConfig,connect:oe.connect,disconnect:oe.disconnect,getRoom:oe.getRoom,isControlled:!1},[D,oe]),pn=r.useRef(_);pn.current=_;const hn=r.useRef(D);hn.current=D,r.useImperativeHandle(i,()=>({sendData:async m=>{var Ee,mt;const d=hn.current;if(d!=null&&d.publishData){try{await d.publishData(m)}catch(Me){console.warn("[AvatarWidget] sendData (controlled) failed:",Me)}return}const K=(mt=(Ee=pn.current)==null?void 0:Ee.getRoom)==null?void 0:mt.call(Ee),ue=K==null?void 0:K.localParticipant;if(ue!=null&&ue.publishData)try{const Me=new TextEncoder().encode(JSON.stringify(m));await ue.publishData(Me,{reliable:!0})}catch(Me){console.warn("[AvatarWidget] sendData failed:",Me)}}}),[]);const mn=r.useRef(null);r.useEffect(()=>{const m=_.videoElement,d=mn.current;if(!(!m||!d))return d.appendChild(m),()=>{m.parentNode===d&&d.removeChild(m)}},[_.videoElement]);const[Qe,Rt]=r.useState(!1);r.useEffect(()=>{if(!I){Rt(!0);return}_.agentState==="speaking"&&!Qe&&Rt(!0)},[I,_.agentState,Qe]),r.useEffect(()=>{if(!I)return;const m=_.connectionState;(m==="disconnected"||m==="idle")&&Rt(!1)},[I,_.connectionState]),r.useEffect(()=>{if(!I||!_.videoElement||Qe)return;const m=setTimeout(()=>Rt(!0),5e3);return()=>clearTimeout(m)},[I,_.videoElement,Qe]),r.useEffect(()=>{const m=_.videoElement;if(m){if(!I){m.style.filter="";return}m.style.transition="filter 500ms ease-out",m.style.filter=Qe?"":"blur(8px)"}},[I,_.videoElement,Qe]);const Nt=r.useRef(new Map);r.useEffect(()=>{const m=_.audioElement;if(!m||Nt.current.has(m))return;const d=document.createElement("div");d.className="ll-audio-sink",d.setAttribute("aria-hidden","true"),d.style.cssText="position:absolute;width:0;height:0;overflow:hidden;clip:rect(0 0 0 0);pointer-events:none;",d.appendChild(m),document.body.appendChild(d),Nt.current.set(m,d),Ae.attach(m);const K=m.play();K&&typeof K.catch=="function"&&K.catch(ue=>{(ue==null?void 0:ue.name)==="NotAllowedError"&&Ce(!0)})},[_.audioElement]),r.useEffect(()=>{const m=_.connectionState;if(!(m!=="disconnected"&&m!=="idle"&&m!=="error")){Ae.detach();for(const[d,K]of Nt.current)d.parentNode===K&&K.removeChild(d),K.parentNode===document.body&&document.body.removeChild(K);Nt.current.clear()}},[_.connectionState]);const ye=sr({gateUntilAgentReady:!0,agentState:_.agentState});r.useEffect(()=>{if(_.isControlled||_.connectionState!=="connected")return;const m=_.getRoom();if(m)return ye.setupMic(m).then(()=>{const d=ye.getMicStream();d&&Ae.attachStream(d,"mic")}).catch(()=>{}),()=>{Ae.detachSlot("mic"),ye.teardownMic()}},[_.isControlled,_.connectionState]),r.useEffect(()=>{var d;if(_.connectionState!=="connected")return;const m=_.isControlled?(d=D==null?void 0:D.getRoom)==null?void 0:d.call(D):_.getRoom();if(m)return Se.attachRoom(m),Re.attachRoom(m),_.isControlled&&ye.attachRoom(m),dt.refresh(),()=>{Se.teardown(),Re.teardown()}},[_.isControlled,_.connectionState,D]),r.useEffect(()=>{const m=_.audioElement;m&&(m.muted=qt)},[_.audioElement,qt]);const zr=r.useCallback(m=>{const d={type:"user_message",text:m};if(D!=null&&D.publishData){try{D.publishData(d)}catch{}return}const K=_.getRoom();if(K)try{const ue=new TextEncoder().encode(JSON.stringify(d));K.localParticipant.publishData(ue,{reliable:!0})}catch{}},[_,D]),$r=r.useCallback(()=>{Dr(m=>!m)},[]);r.useEffect(()=>{He==null||He(_.connectionState),_.connectionState==="connected"?Ve==null||Ve():_.connectionState==="disconnected"&&(De==null||De())},[_.connectionState,Ve,De,He]),r.useEffect(()=>{ze==null||ze(_.transcript)},[_.transcript,ze]),r.useEffect(()=>{$e==null||$e(_.agentState)},[_.agentState,$e]),r.useEffect(()=>{jt.setThinking(_.agentState==="thinking")},[_.agentState,jt]);const gn=r.useRef(!1);r.useEffect(()=>{!y||gn.current||ct&&_.connectionState==="idle"&&(gn.current=!0,_.connect())},[y,_.connectionState,_,ct]);const Hr=r.useCallback(m=>{const d=x==null?void 0:x.find(K=>K.id===m);d&&(Ze(!1),m!==We&&(ft(!0),_.disconnect(),je||Ct(m),v==null||v(d)))},[x,We,_,je,v]);r.useEffect(()=>{Je&&_.connectionState==="connected"&&ft(!1)},[_.connectionState,Je]),r.useEffect(()=>{if(!pt)return;const m=d=>{d.key==="Escape"&&Ze(!1)};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[pt]);const Fr=!!G||!!(le!=null&&le.avatarImageUrl)||_.isControlled,et=ur(kt,s,Fr);Ue===void 0&&((xn=et.info)!=null&&xn.capabilities)&&(Xt.current=et.info.capabilities);const Mt=(le==null?void 0:le.name)??ie??((wn=_.agentConfig)==null?void 0:wn.name)??((_n=et.info)==null?void 0:_n.name)??"Live Layer",Kt=(le==null?void 0:le.avatarImageUrl)??G??((Cn=_.agentConfig)==null?void 0:Cn.avatarImageUrl)??((kn=et.info)==null?void 0:kn.avatarImageUrl)??null,Or=M??((Sn=_.agentConfig)==null?void 0:Sn.idleLoopUrl)??((En=et.info)==null?void 0:En.idleLoopUrl)??null,Br=z??null,Wr=r.useCallback(()=>ge("expanded"),[ge]),qr=r.useCallback(()=>ge("minimized"),[ge]),yn=r.useCallback(()=>{_.disconnect(),ge("hidden")},[_,ge]),Ur=r.useCallback(()=>{const m=_.audioElement;m&&m.play().then(()=>Ce(!1)).catch(()=>{})},[_.audioElement]),Vr=r.useCallback(()=>{Ce(!1),_.connect()},[_]),tt={...Ge,...ce?{}:{zIndex:_e}};T.primaryColor&&(tt["--ll-color-primary"]=T.primaryColor),T.accentColor&&(tt["--ll-color-accent"]=T.accentColor),T.backgroundColor&&(tt["--ll-color-bg"]=T.backgroundColor),T.textColor&&(tt["--ll-color-fg"]=T.textColor);const Yr={...tt,...be.style},Gr=["ll-widget",`ll-widget--${de}`,`ll-widget--${me?"mobile":"desktop"}`,be.hasGeometry?"ll-widget--has-geometry":null,be.isDragging?"is-dragging":null,be.isResizing?"is-resizing":null,Be].filter(Boolean).join(" ");if(!ct)return null;const Xr=n.jsx("div",{className:Gr,style:Yr,"data-display-mode":de,"data-position":C,"data-experience-mode":f==="EMBEDDED"?"embedded":"widget",children:de==="expanded"&&n.jsx(Ii,{position:C,isMobile:me,agentName:Mt,avatarImageUrl:Kt,idleLoopUrl:Or,greeting:Br,branding:{...T,hideBranding:T.hideBranding??((Ln=et.info)==null?void 0:Ln.hideBranding)},teamMembers:x,currentTeamMemberId:We,isSwitchingTeamMember:Je,teamSwitcherOpen:pt,onToggleTeamSwitcher:()=>Ze(m=>!m),onSelectTeamMember:Hr,connectionState:_.connectionState,agentState:_.agentState,transcript:_.transcript,isMuted:ye.isMuted,micDevices:dt.mics,activeMicId:ye.activeDeviceId,isCameraEnabled:Se.isEnabled,cameraPreviewEl:Se.previewEl,cameraDevices:dt.cameras,activeCameraId:Se.activeDeviceId,isScreenShareEnabled:Re.isEnabled,screenPreviewEl:Re.previewEl,isSpeakerMuted:qt,allowCamera:U,allowScreenShare:p,allowTyping:j,showMinimize:me&&!ce?!1:St,showClose:Et,chromeless:Q,compactControls:Lt,transforming:ne,transformingLabel:O,languageMenuOpen:k,onToggleLanguageMenu:()=>re(m=>!m),needsUserGesture:Ne,canResume:_.canResume,micError:ye.micError,error:_.error,avatarVideoContainerRef:mn,agentVideoEl:_.videoElement,onConnect:()=>{Promise.resolve(_.connect()).then(()=>{var d;const m=(d=_.getRoom)==null?void 0:d.call(_);m!=null&&m.startAudio&&m.canPlaybackAudio===!1&&m.startAudio().catch(()=>{})})},onDisconnect:()=>_.disconnect(),onRetry:Vr,onResumeAudio:Ur,onToggleMute:ye.toggleMute,onSwitchMicDevice:m=>void ye.switchDevice(m),onToggleCamera:()=>void Se.toggle(),onSwitchCameraDevice:m=>void Se.switchDevice(m),onToggleScreenShare:()=>void Re.toggle(),onToggleSpeaker:$r,onSendMessage:zr,onMinimize:qr,onClose:yn,onClearMicError:ye.clearError,dragHandleProps:be.dragHandleProps,resizeHandleProps:be.resizeHandleProps})}),bn=!ce&&(de==="hidden"||de==="minimized")?n.jsxs("div",{className:["ll-widget","ll-widget--floating",`ll-widget--${de}`,`ll-widget--${me?"mobile":"desktop"}`].join(" "),style:tt,"data-display-mode":de,"data-position":C,children:[de==="hidden"&&n.jsx(_i,{position:C,isMobile:me,isSpeaking:_.agentState==="speaking",onExpand:()=>ge("expanded"),label:`Open ${Mt} widget`,avatarImageUrl:Kt,agentName:Mt,containerEl:$}),de==="minimized"&&n.jsx(ki,{position:C,isMobile:me,agentName:Mt,avatarImageUrl:Kt,agentState:_.agentState,isMuted:ye.isMuted,audioLevel:Ae,onExpand:Wr,onToggleMute:ye.toggleMute,onClose:yn})]}):null,vn=$??(typeof document<"u"?document.body:null);return n.jsxs(n.Fragment,{children:[Xr,bn&&vn&&an.createPortal(bn,vn)]})});Ir.displayName="AvatarWidgetInner";const Tr=r.forwardRef(function(t,i){return n.jsx(rr,{children:n.jsx(Ir,{...t,ref:i})})});Tr.displayName="AvatarWidget";const wo=({agentId:e,baseUrl:t,apiKey:i,mode:o,onAgentEvent:a,className:s,style:c})=>{const l=r.useRef(null),u=r.useRef(null),f=r.useRef(a);f.current=a;const y=r.useCallback(h=>{var N;const g=h.detail;(N=f.current)==null||N.call(f,g)},[]);return r.useEffect(()=>{const h=l.current;if(!h)return;const g=document.createElement("livelayer-widget");return g.setAttribute("agent-id",e),t&&g.setAttribute("base-url",t),i&&g.setAttribute("api-key",i),o&&g.setAttribute("mode",o),g.addEventListener("agent-event",y),h.appendChild(g),u.current=g,()=>{g.removeEventListener("agent-event",y),h.removeChild(g),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})},_o=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 Co(e={}){const{onFieldUpdate:t,onComplete:i,source:o="all"}=e,[a,s]=r.useState({}),[c,l]=r.useState(!1),[u,f]=r.useState(null),y=r.useRef(t),h=r.useRef(i),g=r.useRef(o);r.useEffect(()=>{y.current=t,h.current=i,g.current=o},[t,i,o]);const N=r.useCallback(()=>{s({}),l(!1)},[]);return r.useEffect(()=>{if(typeof window>"u")return;const C=S=>{var w,R;const b=S.detail;if(b){if(b.phase==="field"){if(g.current!=="all"&&b.source!==g.current)return;l(!0),s(E=>E[b.fieldName]===b.value?E:{...E,[b.fieldName]:b.value});try{(w=y.current)==null||w.call(y,b)}catch(E){console.warn("[LiveLayer] useCollect onFieldUpdate threw.",E)}return}if(b.phase==="complete"){const E=b.result;if(g.current!=="all"&&E.source!==g.current)return;f(E),l(!1);try{(R=h.current)==null||R.call(h,E)}catch(x){console.warn("[LiveLayer] useCollect onComplete threw.",x)}}}};return document.addEventListener("ll-collected",C),()=>document.removeEventListener("ll-collected",C)},[]),{fields:a,isCollecting:c,lastResult:u,reset:N}}let nr=1;function ko({onMount:e,defaultOpen:t=!1,storageKey:i="ll-debug-open"}){const[o,a]=r.useState(t),[s,c]=r.useState([]),[l,u]=r.useState(""),[f,y]=r.useState(!1),h=r.useRef(new Set),g=r.useRef([]),N=r.useRef(f);N.current=f,r.useEffect(()=>{try{const b=localStorage.getItem(i);b==="1"&&a(!0),b==="0"&&a(!1)}catch{}},[i]),r.useEffect(()=>{try{localStorage.setItem(i,o?"1":"0")}catch{}},[o,i]),r.useEffect(()=>{const b=w=>{(w.metaKey||w.ctrlKey)&&w.shiftKey&&w.key.toLowerCase()==="l"&&(w.preventDefault(),a(R=>!R))};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[]),r.useEffect(()=>{const b=setInterval(()=>{if(g.current.length===0||N.current)return;const w=g.current.splice(0,g.current.length);c(R=>[...w.reverse(),...R].slice(0,200))},100);return()=>clearInterval(b)},[]);const C=r.useRef(!1);if(r.useEffect(()=>{!e||C.current||(C.current=!0,e(b=>{g.current.push({id:nr++,ts:Date.now(),kind:"event",type:b.eventName,data:b.data})}))},[e]),r.useEffect(()=>{const b=console.warn,w=console.log,R=(E,x)=>function(...P){try{const v=typeof P[0]=="string"?P[0]:"";v.startsWith("[LiveLayer]")&&g.current.push({id:nr++,ts:Date.now(),kind:E,type:v.slice(0,120),data:{args:P.slice(1).map(M=>Eo(M))}})}catch{}return x.apply(this,P)};return console.warn=R("warn",b),console.log=R("log",w),()=>{console.warn=b,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(b=>{if(!l)return!0;const w=l.toLowerCase();return b.type.toLowerCase().includes(w)||JSON.stringify(b.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:()=>y(b=>!b),style:nn(f?"#f59e0b":"transparent"),title:"Pause / resume capture",children:f?"▶ resume":"⏸ pause"}),n.jsx("button",{type:"button",onClick:()=>{c([]),g.current=[]},style:nn("transparent"),title:"Clear buffer",children:"clear"}),n.jsx("button",{type:"button",onClick:()=>a(!1),style:nn("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),n.jsx("input",{type:"text",value:l,onChange:b=>u(b.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 a=require("react/jsx-runtime"),s=require("react"),Cn=require("react-dom"),ht=require("@livelayer/sdk"),Vt=require("livekit-client");class Er extends s.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,n){var r,i;(i=(r=this.props).onError)==null||i.call(r,t,n)}render(){var t;return this.state.hasError?this.props.fallback?this.props.fallback:a.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[a.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),a.jsx("p",{className:"ll-error-boundary__message",children:((t=this.state.error)==null?void 0:t.message)||"Something went wrong."}),a.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function Lr(e){const[t,n]=s.useState("idle"),[r,i]=s.useState("idle"),[o,c]=s.useState([]),[l,u]=s.useState(null),[d,h]=s.useState(null),[p,y]=s.useState(null),[T,S]=s.useState(!1),[_,b]=s.useState(null),x=s.useRef(null),A=s.useRef(e.onDataMessage);A.current=e.onDataMessage,s.useEffect(()=>{const w={onConnectionStateChange:$=>{n($),$==="connected"&&b(null)},onAgentStateChange:i,onTranscript:$=>c([...$]),onAgentConfig:u,onAudioTrack:$=>y($),onVideoTrack:$=>h($),onVideoTrackRemoved:()=>h(null),onError:$=>b($),onDataMessage:$=>{var Y;(Y=A.current)==null||Y.call(A,$)},onResumabilityChange:S},I=new ht.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},w);return x.current=I,n("idle"),i("idle"),c([]),u(null),h(null),y(null),S(!1),b(null),()=>{var $;($=I.destroy)==null||$.call(I),x.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=s.useCallback(async()=>{const w=x.current;if(w)try{await w.connect()}catch(I){throw b(I instanceof Error?I.message:String(I)),I}},[]),v=s.useCallback(()=>{const w=x.current;w&&w.disconnect()},[]),N=s.useCallback(()=>{var w;return((w=x.current)==null?void 0:w.getRoom())??null},[]);return{connectionState:t,agentState:r,transcript:o,agentConfig:l,videoElement:d,audioElement:p,canResume:T,error:_,connect:E,disconnect:v,getRoom:N,session:x.current}}function Rr(){const e=s.useRef(null),t=s.useRef(new Map),n=s.useRef(null),r=s.useRef(new Set),i=s.useCallback(()=>{const S=t.current;if(S.size===0){n.current=null;return}let _=0;for(const{analyser:b,buffer:x}of S.values()){b.getByteFrequencyData(x);let A=0;for(let v=0;v<x.length;v++)A+=x[v];const E=A/x.length/255;E>_&&(_=E)}for(const b of r.current)try{b(_)}catch(x){console.error("[useAudioLevel] subscriber threw:",x)}n.current=requestAnimationFrame(i)},[]),o=s.useCallback(()=>e.current?e.current:typeof window>"u"||typeof AudioContext>"u"?null:(e.current=new AudioContext,e.current),[]),c=s.useCallback(()=>{n.current===null&&t.current.size>0&&(n.current=requestAnimationFrame(i))},[i]),l=s.useCallback(S=>{const _=t.current.get(S);if(_){try{_.node.disconnect()}catch{}try{_.analyser.disconnect()}catch{}t.current.delete(S)}},[]),u=s.useCallback((S,_)=>{const b=o();if(!b)return;l(S);const x=_(b);if(!x)return;const A=b.createAnalyser();A.fftSize=64;try{x.connect(A)}catch(E){console.warn("[useAudioLevel] connect failed for slot",S,E);return}t.current.set(S,{analyser:A,node:x,buffer:new Uint8Array(new ArrayBuffer(A.frequencyBinCount))}),c()},[l,o,c]),d=s.useCallback((S,_="agent")=>{u(_,b=>{try{return b.createMediaElementSource(S)}catch(x){return console.warn("[useAudioLevel] createMediaElementSource failed for slot",_,x),null}})},[u]),h=s.useCallback((S,_="mic")=>{u(_,b=>{try{return b.createMediaStreamSource(S)}catch(x){return console.warn("[useAudioLevel] createMediaStreamSource failed for slot",_,x),null}})},[u]),p=s.useCallback(S=>{l(S),t.current.size===0&&n.current!==null&&(cancelAnimationFrame(n.current),n.current=null)},[l]),y=s.useCallback(()=>{n.current!==null&&(cancelAnimationFrame(n.current),n.current=null);for(const S of Array.from(t.current.keys()))l(S)},[l]),T=s.useCallback(S=>(r.current.add(S),()=>{r.current.delete(S)}),[]);return s.useEffect(()=>()=>{if(y(),e.current){try{e.current.close()}catch{}e.current=null}r.current.clear()},[y]),{attach:d,attachStream:h,detach:y,detachSlot:p,subscribe:T}}function Pi(e){const t=e==null?void 0:e.mediaStreamTrack;return t?new MediaStream([t]):null}function jr(e={}){const t=e.gateUntilAgentReady??!1,n=e.agentState??null,[r,i]=s.useState(t),[o,c]=s.useState(""),[l,u]=s.useState(null),d=s.useRef(null),h=s.useRef(null),p=s.useRef({active:t,lastAutoIntent:null}),y=s.useCallback(async E=>{var v,N;if(d.current&&h.current){try{await h.current.localParticipant.unpublishTrack(d.current)}catch{}d.current.stop(),d.current=null}h.current=E,u(null);try{const w=await Vt.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await E.localParticipant.publishTrack(w),d.current=w,p.current.active?(await E.localParticipant.setMicrophoneEnabled(!1),p.current.lastAutoIntent=!1,i(!0)):i(w.isMuted);const I=(N=(v=w.mediaStreamTrack)==null?void 0:v.getSettings)==null?void 0:N.call(v);I!=null&&I.deviceId&&c(I.deviceId)}catch(w){const I=w instanceof Error&&w.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw u(I),w}},[]),T=s.useCallback(E=>{h.current=E},[]),S=s.useCallback(async E=>{const v=h.current;if(v)try{await v.switchActiveDevice("audioinput",E),c(E)}catch(N){console.warn("[useMicrophoneState] switchDevice failed:",N)}},[]),_=s.useCallback(async()=>{const E=h.current,v=!r;if(i(v),p.current.active=!1,!!E)try{await E.localParticipant.setMicrophoneEnabled(!v)}catch(N){console.warn("[useMicrophoneState] setMicrophoneEnabled failed:",N),i(!v)}},[r]);s.useEffect(()=>{if(!p.current.active||n!=="listening")return;const E=h.current,v=E==null?void 0:E.localParticipant;if(!v){p.current.active=!1;return}v.isMicrophoneEnabled===p.current.lastAutoIntent&&(v.setMicrophoneEnabled(!0),p.current.lastAutoIntent=!0,i(!1)),p.current.active=!1},[n]);const b=s.useCallback(()=>{const E=d.current,v=h.current;if(E&&v){try{v.localParticipant.unpublishTrack(E)}catch{}E.stop()}d.current=null,h.current=null,p.current={active:t,lastAutoIntent:null},i(t),c("")},[t]),x=s.useCallback(()=>u(null),[]),A=s.useCallback(()=>Pi(d.current),[]);return{isMuted:r,activeDeviceId:o,micError:l,toggleMute:_,setupMic:y,attachRoom:T,switchDevice:S,teardownMic:b,clearError:x,getMicStream:A}}const Ni={resolution:{width:640,height:480,frameRate:24}};function Ar(){const[e,t]=s.useState(!1),[n,r]=s.useState(null),[i,o]=s.useState(null),[c,l]=s.useState(""),u=s.useRef(null),d=s.useRef(null),h=s.useCallback(x=>{u.current=x},[]),p=s.useCallback(()=>{var E;const x=u.current,A=d.current;if(A&&x){const v=x.localParticipant.getTrackPublication(Vt.Track.Source.Camera),w=(v==null?void 0:v.track)??A;try{x.localParticipant.unpublishTrack(w)}catch{}try{(E=w.stop)==null||E.call(w)}catch{}}d.current=null,o(null),t(!1)},[]),y=s.useCallback(async x=>{const A=u.current;if(A){r(null);try{const E={...Ni};x&&(E.deviceId=x);const v=await Vt.createLocalVideoTrack(E);await A.localParticipant.publishTrack(v),d.current=v;const N=v.attach();o(N),t(!0),x&&l(x);try{A.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.";r(v)}}},[]),T=s.useCallback(async()=>{e?p():await y(c||void 0)},[e,c,p,y]),S=s.useCallback(async x=>{p(),await y(x)},[p,y]),_=s.useCallback(()=>{p(),u.current=null,r(null),l("")},[p]),b=s.useCallback(()=>r(null),[]);return s.useEffect(()=>()=>{d.current&&d.current.stop()},[]),{isEnabled:e,error:n,previewEl:i,activeDeviceId:c,toggle:T,switchDevice:S,attachRoom:h,teardown:_,clearError:b}}function Tr(){const[e,t]=s.useState(!1),[n,r]=s.useState(null),[i,o]=s.useState(null),c=s.useRef(null),l=s.useCallback(y=>{c.current=y},[]),u=s.useCallback(()=>o(null),[]),d=s.useCallback(async()=>{const y=c.current;if(y){if(e){try{await y.localParticipant.setScreenShareEnabled(!1)}catch{}u(),t(!1);return}r(null);try{await y.localParticipant.setScreenShareEnabled(!0);let T=0;const S=()=>{const _=y.localParticipant.getTrackPublication(Vt.Track.Source.ScreenShare);if(_!=null&&_.track){const b=_.track.attach();o(b),t(!0);try{y.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}T++<10?setTimeout(S,100):t(!0)};S()}catch(T){const S=T instanceof Error?T.name:"";S!=="NotAllowedError"&&S!=="AbortError"&&r("Screen share unavailable. Try again."),t(!1)}}},[e,u]),h=s.useCallback(()=>{const y=c.current;if(y&&e)try{y.localParticipant.setScreenShareEnabled(!1)}catch{}u(),t(!1),r(null),c.current=null},[e,u]),p=s.useCallback(()=>r(null),[]);return{isEnabled:e,error:n,previewEl:i,toggle:d,attachRoom:l,teardown:h,clearError:p}}function Ir(){const[e,t]=s.useState([]),[n,r]=s.useState([]),i=s.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const o=await navigator.mediaDevices.enumerateDevices();t(o.filter(c=>c.kind==="audioinput")),r(o.filter(c=>c.kind==="videoinput"))}catch{}},[]);return s.useEffect(()=>{if(i(),typeof navigator>"u"||!navigator.mediaDevices)return;const o=()=>void i();return navigator.mediaDevices.addEventListener("devicechange",o),()=>navigator.mediaDevices.removeEventListener("devicechange",o)},[i]),{mics:e,cameras:n,refresh:i}}function Mr(e,t,n=!1){const[r,i]=s.useState(null),[o,c]=s.useState(null),[l,u]=s.useState(!n&&!!e);return s.useEffect(()=>{if(n||!e){u(!1);return}const d=new AbortController,h=t||"https://app.livelayer.studio";return u(!0),c(null),fetch(`${h}/api/widget/agent/${encodeURIComponent(e)}`,{signal:d.signal}).then(async p=>{if(!p.ok){const y=await p.json().catch(()=>({}));throw new Error(y.error||`HTTP ${p.status}`)}return p.json()}).then(p=>{d.signal.aborted||(i(p),u(!1))}).catch(p=>{d.signal.aborted||(c(p instanceof Error?p.message:"Agent lookup failed"),u(!1))}),()=>d.abort()},[e,t,n]),{info:r,error:o,loading:l}}function Di(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;const n=document.implementation.createHTMLDocument(),r=n.createElement("base"),i=n.createElement("a");return n.head.appendChild(r),n.body.appendChild(i),t&&(r.href=t),i.href=e,i.href}const $i=(()=>{let e=0;const t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)})();function He(e){const t=[];for(let n=0,r=e.length;n<r;n++)t.push(e[n]);return t}let lt=null;function Pr(e={}){return lt||(e.includeStyleProperties?(lt=e.includeStyleProperties,lt):(lt=He(window.getComputedStyle(document.documentElement)),lt))}function Gt(e,t){const r=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return r?parseFloat(r.replace("px","")):0}function Fi(e){const t=Gt(e,"border-left-width"),n=Gt(e,"border-right-width");return e.clientWidth+t+n}function zi(e){const t=Gt(e,"border-top-width"),n=Gt(e,"border-bottom-width");return e.clientHeight+t+n}function Nr(e,t={}){const n=t.width||Fi(e),r=t.height||zi(e);return{width:n,height:r}}function Hi(){let e,t;try{t=process}catch{}const n=t&&t.env?t.env.devicePixelRatio:null;return n&&(e=parseInt(n,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}const ge=16384;function Oi(e){(e.width>ge||e.height>ge)&&(e.width>ge&&e.height>ge?e.width>e.height?(e.height*=ge/e.width,e.width=ge):(e.width*=ge/e.height,e.height=ge):e.width>ge?(e.height*=ge/e.width,e.width=ge):(e.width*=ge/e.height,e.height=ge))}function Yt(e){return new Promise((t,n)=>{const r=new Image;r.onload=()=>{r.decode().then(()=>{requestAnimationFrame(()=>t(r))})},r.onerror=n,r.crossOrigin="anonymous",r.decoding="async",r.src=e})}async function Wi(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(t=>`data:image/svg+xml;charset=utf-8,${t}`)}async function Bi(e,t,n){const r="http://www.w3.org/2000/svg",i=document.createElementNS(r,"svg"),o=document.createElementNS(r,"foreignObject");return i.setAttribute("width",`${t}`),i.setAttribute("height",`${n}`),i.setAttribute("viewBox",`0 0 ${t} ${n}`),o.setAttribute("width","100%"),o.setAttribute("height","100%"),o.setAttribute("x","0"),o.setAttribute("y","0"),o.setAttribute("externalResourcesRequired","true"),i.appendChild(o),o.appendChild(e),Wi(i)}const pe=(e,t)=>{if(e instanceof t)return!0;const n=Object.getPrototypeOf(e);return n===null?!1:n.constructor.name===t.name||pe(n,t)};function qi(e){const t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}function Ui(e,t){return Pr(t).map(n=>{const r=e.getPropertyValue(n),i=e.getPropertyPriority(n);return`${n}: ${r}${i?" !important":""};`}).join(" ")}function Vi(e,t,n,r){const i=`.${e}:${t}`,o=n.cssText?qi(n):Ui(n,r);return document.createTextNode(`${i}{${o}}`)}function Kn(e,t,n,r){const i=window.getComputedStyle(e,n),o=i.getPropertyValue("content");if(o===""||o==="none")return;const c=$i();try{t.className=`${t.className} ${c}`}catch{return}const l=document.createElement("style");l.appendChild(Vi(c,n,i,r)),t.appendChild(l)}function Gi(e,t,n){Kn(e,t,":before",n),Kn(e,t,":after",n)}const Jn="application/font-woff",Qn="image/jpeg",Yi={woff:Jn,woff2:Jn,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:Qn,jpeg:Qn,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function Xi(e){const t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}function Sn(e){const t=Xi(e).toLowerCase();return Yi[t]||""}function Ki(e){return e.split(/,/)[1]}function bn(e){return e.search(/^(data:)/)!==-1}function Ji(e,t){return`data:${t};base64,${e}`}async function Dr(e,t,n){const r=await fetch(e,t);if(r.status===404)throw new Error(`Resource "${r.url}" not found`);const i=await r.blob();return new Promise((o,c)=>{const l=new FileReader;l.onerror=c,l.onloadend=()=>{try{o(n({res:r,result:l.result}))}catch(u){c(u)}},l.readAsDataURL(i)})}const fn={};function Qi(e,t,n){let r=e.replace(/\?.*/,"");return n&&(r=e),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,"")),t?`[${t}]${r}`:r}async function _n(e,t,n){const r=Qi(e,t,n.includeQueryParams);if(fn[r]!=null)return fn[r];n.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+new Date().getTime());let i;try{const o=await Dr(e,n.fetchRequestInit,({res:c,result:l})=>(t||(t=c.headers.get("Content-Type")||""),Ki(l)));i=Ji(o,t)}catch(o){i=n.imagePlaceholder||"";let c=`Failed to fetch resource: ${e}`;o&&(c=typeof o=="string"?o:o.message),c&&console.warn(c)}return fn[r]=i,i}async function Zi(e){const t=e.toDataURL();return t==="data:,"?e.cloneNode(!1):Yt(t)}async function eo(e,t){if(e.currentSrc){const o=document.createElement("canvas"),c=o.getContext("2d");o.width=e.clientWidth,o.height=e.clientHeight,c==null||c.drawImage(e,0,0,o.width,o.height);const l=o.toDataURL();return Yt(l)}const n=e.poster,r=Sn(n),i=await _n(n,r,t);return Yt(i)}async function to(e,t){var n;try{if(!((n=e==null?void 0:e.contentDocument)===null||n===void 0)&&n.body)return await Kt(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function no(e,t){return pe(e,HTMLCanvasElement)?Zi(e):pe(e,HTMLVideoElement)?eo(e,t):pe(e,HTMLIFrameElement)?to(e,t):e.cloneNode($r(e))}const ro=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SLOT",$r=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SVG";async function io(e,t,n){var r,i;if($r(t))return t;let o=[];return ro(e)&&e.assignedNodes?o=He(e.assignedNodes()):pe(e,HTMLIFrameElement)&&(!((r=e.contentDocument)===null||r===void 0)&&r.body)?o=He(e.contentDocument.body.childNodes):o=He(((i=e.shadowRoot)!==null&&i!==void 0?i:e).childNodes),o.length===0||pe(e,HTMLVideoElement)||await o.reduce((c,l)=>c.then(()=>Kt(l,n)).then(u=>{u&&t.appendChild(u)}),Promise.resolve()),t}function oo(e,t,n){const r=t.style;if(!r)return;const i=window.getComputedStyle(e);i.cssText?(r.cssText=i.cssText,r.transformOrigin=i.transformOrigin):Pr(n).forEach(o=>{let c=i.getPropertyValue(o);o==="font-size"&&c.endsWith("px")&&(c=`${Math.floor(parseFloat(c.substring(0,c.length-2)))-.1}px`),pe(e,HTMLIFrameElement)&&o==="display"&&c==="inline"&&(c="block"),o==="d"&&t.getAttribute("d")&&(c=`path(${t.getAttribute("d")})`),r.setProperty(o,c,i.getPropertyPriority(o))})}function so(e,t){pe(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),pe(e,HTMLInputElement)&&t.setAttribute("value",e.value)}function ao(e,t){if(pe(e,HTMLSelectElement)){const r=Array.from(t.children).find(i=>e.value===i.getAttribute("value"));r&&r.setAttribute("selected","")}}function lo(e,t,n){return pe(t,Element)&&(oo(e,t,n),Gi(e,t,n),so(e,t),ao(e,t)),t}async function co(e,t){const n=e.querySelectorAll?e.querySelectorAll("use"):[];if(n.length===0)return e;const r={};for(let o=0;o<n.length;o++){const l=n[o].getAttribute("xlink:href");if(l){const u=e.querySelector(l),d=document.querySelector(l);!u&&d&&!r[l]&&(r[l]=await Kt(d,t,!0))}}const i=Object.values(r);if(i.length){const o="http://www.w3.org/1999/xhtml",c=document.createElementNS(o,"svg");c.setAttribute("xmlns",o),c.style.position="absolute",c.style.width="0",c.style.height="0",c.style.overflow="hidden",c.style.display="none";const l=document.createElementNS(o,"defs");c.appendChild(l);for(let u=0;u<i.length;u++)l.appendChild(i[u]);e.appendChild(c)}return e}async function Kt(e,t,n){return!n&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(r=>no(r,t)).then(r=>io(e,r,t)).then(r=>lo(e,r,t)).then(r=>co(r,t))}const Fr=/url\((['"]?)([^'"]+?)\1\)/g,uo=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,fo=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function po(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}function ho(e){const t=[];return e.replace(Fr,(n,r,i)=>(t.push(i),n)),t.filter(n=>!bn(n))}async function mo(e,t,n,r,i){try{const o=n?Di(t,n):t,c=Sn(t);let l;return i||(l=await _n(o,c,r)),e.replace(po(t),`$1${l}$3`)}catch{}return e}function go(e,{preferredFontFormat:t}){return t?e.replace(fo,n=>{for(;;){const[r,,i]=uo.exec(n)||[];if(!i)return"";if(i===t)return`src: ${r};`}}):e}function zr(e){return e.search(Fr)!==-1}async function Hr(e,t,n){if(!zr(e))return e;const r=go(e,n);return ho(r).reduce((o,c)=>o.then(l=>mo(l,c,t,n)),Promise.resolve(r))}async function ct(e,t,n){var r;const i=(r=t.style)===null||r===void 0?void 0:r.getPropertyValue(e);if(i){const o=await Hr(i,null,n);return t.style.setProperty(e,o,t.style.getPropertyPriority(e)),!0}return!1}async function yo(e,t){await ct("background",e,t)||await ct("background-image",e,t),await ct("mask",e,t)||await ct("-webkit-mask",e,t)||await ct("mask-image",e,t)||await ct("-webkit-mask-image",e,t)}async function bo(e,t){const n=pe(e,HTMLImageElement);if(!(n&&!bn(e.src))&&!(pe(e,SVGImageElement)&&!bn(e.href.baseVal)))return;const r=n?e.src:e.href.baseVal,i=await _n(r,Sn(r),t);await new Promise((o,c)=>{e.onload=o,e.onerror=t.onImageErrorHandler?(...u)=>{try{o(t.onImageErrorHandler(...u))}catch(d){c(d)}}:c;const l=e;l.decode&&(l.decode=o),l.loading==="lazy"&&(l.loading="eager"),n?(e.srcset="",e.src=i):e.href.baseVal=i})}async function wo(e,t){const r=He(e.childNodes).map(i=>Or(i,t));await Promise.all(r).then(()=>e)}async function Or(e,t){pe(e,Element)&&(await yo(e,t),await bo(e,t),await wo(e,t))}function vo(e,t){const{style:n}=e;t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.width&&(n.width=`${t.width}px`),t.height&&(n.height=`${t.height}px`);const r=t.style;return r!=null&&Object.keys(r).forEach(i=>{n[i]=r[i]}),e}const Zn={};async function er(e){let t=Zn[e];if(t!=null)return t;const r=await(await fetch(e)).text();return t={url:e,cssText:r},Zn[e]=t,t}async function tr(e,t){let n=e.cssText;const r=/url\(["']?([^"')]+)["']?\)/g,o=(n.match(/url\([^)]+\)/g)||[]).map(async c=>{let l=c.replace(r,"$1");return l.startsWith("https://")||(l=new URL(l,e.url).href),Dr(l,t.fetchRequestInit,({result:u})=>(n=n.replace(c,`url(${u})`),[c,u]))});return Promise.all(o).then(()=>n)}function nr(e){if(e==null)return[];const t=[],n=/(\/\*[\s\S]*?\*\/)/gi;let r=e.replace(n,"");const i=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const u=i.exec(r);if(u===null)break;t.push(u[0])}r=r.replace(i,"");const o=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,c="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",l=new RegExp(c,"gi");for(;;){let u=o.exec(r);if(u===null){if(u=l.exec(r),u===null)break;o.lastIndex=l.lastIndex}else l.lastIndex=o.lastIndex;t.push(u[0])}return t}async function xo(e,t){const n=[],r=[];return e.forEach(i=>{if("cssRules"in i)try{He(i.cssRules||[]).forEach((o,c)=>{if(o.type===CSSRule.IMPORT_RULE){let l=c+1;const u=o.href,d=er(u).then(h=>tr(h,t)).then(h=>nr(h).forEach(p=>{try{i.insertRule(p,p.startsWith("@import")?l+=1:i.cssRules.length)}catch(y){console.error("Error inserting rule from remote css",{rule:p,error:y})}})).catch(h=>{console.error("Error loading remote css",h.toString())});r.push(d)}})}catch(o){const c=e.find(l=>l.href==null)||document.styleSheets[0];i.href!=null&&r.push(er(i.href).then(l=>tr(l,t)).then(l=>nr(l).forEach(u=>{c.insertRule(u,c.cssRules.length)})).catch(l=>{console.error("Error loading remote stylesheet",l)})),console.error("Error inlining remote css file",o)}}),Promise.all(r).then(()=>(e.forEach(i=>{if("cssRules"in i)try{He(i.cssRules||[]).forEach(o=>{n.push(o)})}catch(o){console.error(`Error while reading CSS rules from ${i.href}`,o)}}),n))}function Co(e){return e.filter(t=>t.type===CSSRule.FONT_FACE_RULE).filter(t=>zr(t.style.getPropertyValue("src")))}async function So(e,t){if(e.ownerDocument==null)throw new Error("Provided element is not within a Document");const n=He(e.ownerDocument.styleSheets),r=await xo(n,t);return Co(r)}function Wr(e){return e.trim().replace(/["']/g,"")}function _o(e){const t=new Set;function n(r){(r.style.fontFamily||getComputedStyle(r).fontFamily).split(",").forEach(o=>{t.add(Wr(o))}),Array.from(r.children).forEach(o=>{o instanceof HTMLElement&&n(o)})}return n(e),t}async function ko(e,t){const n=await So(e,t),r=_o(e);return(await Promise.all(n.filter(o=>r.has(Wr(o.style.fontFamily))).map(o=>{const c=o.parentStyleSheet?o.parentStyleSheet.href:null;return Hr(o.cssText,c,t)}))).join(`
2
+ `)}async function Eo(e,t){const n=t.fontEmbedCSS!=null?t.fontEmbedCSS:t.skipFonts?null:await ko(e,t);if(n){const r=document.createElement("style"),i=document.createTextNode(n);r.appendChild(i),e.firstChild?e.insertBefore(r,e.firstChild):e.appendChild(r)}}async function Lo(e,t={}){const{width:n,height:r}=Nr(e,t),i=await Kt(e,t,!0);return await Eo(i,t),await Or(i,t),vo(i,t),await Bi(i,n,r)}async function Ro(e,t={}){const{width:n,height:r}=Nr(e,t),i=await Lo(e,t),o=await Yt(i),c=document.createElement("canvas"),l=c.getContext("2d"),u=t.pixelRatio||Hi(),d=t.canvasWidth||n,h=t.canvasHeight||r;return c.width=d*u,c.height=h*u,t.skipAutoScale||Oi(c),c.style.width=`${d}`,c.style.height=`${h}`,t.backgroundColor&&(l.fillStyle=t.backgroundColor,l.fillRect(0,0,c.width,c.height)),l.drawImage(o,0,0,c.width,c.height),c}const ze=32,jo=8;function Ao(e){const t=new Uint8Array(ze*ze);for(let n=0;n<t.length;n++)t[n]=Math.round(.299*e[n*4]+.587*e[n*4+1]+.114*e[n*4+2]);return t}function To(e,t){if(e.length!==t.length||e.length===0)return Number.POSITIVE_INFINITY;let n=0;for(let r=0;r<e.length;r++)n+=Math.abs(e[r]-t[r]);return n/e.length}function Io(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e[n],t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}const Mo=[".ll-widget","[data-ll-private]","[data-ll-skip]","input[type='password']","iframe"].join(", ");function Po(e){return typeof e.matches=="function"&&e.matches(Mo)}function No(e){return e instanceof Element?!Po(e):!0}async function Do(e){try{const t=document.body;if(!t)return null;const n=Math.max(1,t.scrollWidth||window.innerWidth||1),r=Math.max(1,window.innerHeight||t.scrollHeight||1),i=Math.min(1,e.maxWidth/n),o=await Ro(t,{filter:No,canvasWidth:Math.round(n*i),canvasHeight:Math.round(r*i),backgroundColor:"#ffffff",skipFonts:!0,style:{transform:`translateY(-${window.scrollY||0}px)`},height:r,width:n}),c=document.createElement("canvas");c.width=ze,c.height=ze;const l=c.getContext("2d");if(!l)return null;l.drawImage(o,0,0,ze,ze);const u=l.getImageData(0,0,ze,ze).data,d=Ao(u),h=await new Promise(p=>o.toBlob(p,"image/jpeg",e.jpegQuality));return h?{blob:h,thumb:d,width:o.width,height:o.height}:null}catch(t){return console.warn("[LiveLayer] page-vision capture failed:",t),null}}class $o{constructor(t){this.deps=t,this.lastThumb=null,this.inFlight=!1,this.lastEnvelope=null,this.warnedIncompleteConfig=!1}async trigger(t,n){const{config:r}=this.deps;if(!(!r.enabled||!r.captureOn.includes(t))&&!this.inFlight){if(!r.upload.supabaseUrl||!r.upload.anonKey||!r.upload.bucket){this.warnedIncompleteConfig||(this.warnedIncompleteConfig=!0,console.warn("[LiveLayer] page-vision enabled but upload config incomplete — skipping captures"));return}this.inFlight=!0;try{const i=await this.deps.capture({maxWidth:r.maxWidth,jpegQuality:r.jpegQuality});if(!i)return;const o=Date.now();if(this.lastThumb&&To(this.lastThumb,i.thumb)<jo)return;const c=await this.deps.upload(i.blob,r.upload);if(!c)return;this.lastThumb=i.thumb;const l={type:"page_screenshot",url:c,route:n,reason:t,hash:Io(i.thumb),capturedAt:o};this.lastEnvelope=l,this.safePublish(l)}finally{this.inFlight=!1}}}republishLast(){this.lastEnvelope&&this.safePublish(this.lastEnvelope)}safePublish(t){try{this.deps.publish(t)}catch(n){console.warn("[LiveLayer] page-vision publish failed:",n)}}}async function Fo(e,t){try{const n=`${crypto.randomUUID()}.jpg`,r=await fetch(`${t.supabaseUrl}/storage/v1/object/${t.bucket}/${n}`,{method:"POST",headers:{apikey:t.anonKey,Authorization:`Bearer ${t.anonKey}`,"Content-Type":"image/jpeg"},body:e});return r.ok?`${t.supabaseUrl}/storage/v1/object/public/${t.bucket}/${n}`:(console.warn(`[LiveLayer] page-vision upload failed: HTTP ${r.status}`),null)}catch(n){return console.warn("[LiveLayer] page-vision upload error:",n),null}}function Br(e){const{config:t,connected:n,pathname:r,currentStep:i,publishData:o,agentReady:c}=e,l=s.useRef(null),u=s.useRef(o);u.current=o;const d=s.useRef(r);d.current=r,s.useEffect(()=>{if(!(t!=null&&t.enabled)){l.current=null;return}l.current=new $o({config:t,capture:Do,upload:Fo,publish:_=>u.current(_)})},[t]);const h=s.useCallback(_=>{const b=l.current;b&&requestAnimationFrame(()=>{(typeof window.requestIdleCallback=="function"?A=>window.requestIdleCallback(A,{timeout:1500}):A=>{setTimeout(A,200)})(()=>{b.trigger(_,d.current)})})},[]),p=s.useRef(!1);s.useEffect(()=>{if(!n){p.current=!1;return}l.current&&!p.current&&(p.current=!0,h("flow_start"))},[n,t,h]);const y=s.useRef(r);s.useEffect(()=>{r!==y.current&&(y.current=r,n&&h("route_change"))},[r,n,h]);const T=s.useRef(i);s.useEffect(()=>{n&&i!==void 0&&T.current!==void 0&&i!==T.current&&h("step_change"),T.current=i},[i,n,h]);const S=s.useRef(!1);s.useEffect(()=>{var _;if(!n){S.current=!1;return}c&&!S.current&&(S.current=!0,(_=l.current)==null||_.republishLast())},[c,n])}function qr(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Ur(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function zo(e){if(!(typeof window>"u"))try{window.localStorage.removeItem(e)}catch{}}function Vr({value:e,defaultValue:t="expanded",onChange:n}={}){const r=e!==void 0,[i,o]=s.useState(t),c=r?e:i,l=s.useCallback(u=>{u!==c&&(r||o(u),n==null||n(u))},[c,r,n]);return[c,l]}const Ho=["hidden","minimized","expanded"];function Oo(e){return e&&Ho.includes(e)?e:null}function Gr({value:e,defaultValue:t="expanded",onChange:n,persistKey:r="ll-widget",disablePersistence:i=!1}={}){const o=`${r}:display-mode`,c=s.useRef(!1),[l,u]=Vr({value:e,defaultValue:t,onChange:d=>{e===void 0&&!i&&Ur(o,d),n==null||n(d)}});return s.useEffect(()=>{if(c.current||(c.current=!0,i||e!==void 0))return;const d=Oo(qr(o));d&&d!==l&&u(d)},[]),[l,u]}const Wo=640;function Yr(e=Wo){const[t,n]=s.useState(!1);return s.useEffect(()=>{if(e===!1){n(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const r=`(max-width: ${e-1}px)`,i=window.matchMedia(r),o=()=>n(i.matches);return o(),typeof i.addEventListener=="function"?(i.addEventListener("change",o),()=>i.removeEventListener("change",o)):(i.addListener(o),()=>{i.removeListener(o)})},[e]),t}const Bo=280,qo=380,Uo=8,Vo=4;function pn(e){return`${e}:geometry`}function Go(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!="object"||t===null)return null;const n=t,{top:r,left:i,width:o,height:c}=n;return typeof r!="number"||typeof i!="number"||typeof o!="number"||typeof c!="number"||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(c)?null:{top:r,left:i,width:o,height:c}}function Wt(){return typeof window>"u"?{vw:0,vh:0}:{vw:window.innerWidth,vh:window.innerHeight}}function hn(e,t,n){const{minWidth:r,minHeight:i,edgeMargin:o,vw:c,vh:l}=n,u=Math.max(r,c-o*2),d=Math.max(i,l-o*2);return{width:Math.max(r,Math.min(u,e)),height:Math.max(i,Math.min(d,t))}}function mn(e,t,n,r,i){const{edgeMargin:o,vw:c,vh:l}=i,u=o,d=o,h=Math.max(u,c-n-o),p=Math.max(d,l-r-o);return{top:Math.max(d,Math.min(p,e)),left:Math.max(u,Math.min(h,t))}}function Yo(e){const{draggable:t,resizable:n,persistKey:r,disablePersistence:i,minWidth:o=Bo,minHeight:c=qo,edgeMargin:l=Uo}=e,[u,d]=s.useState(null),[h,p]=s.useState(!1),[y,T]=s.useState(!1),S=s.useRef(null),_=s.useRef(null),b=s.useRef(!1),x=s.useRef(null);x.current=u;const A=s.useCallback(m=>{i||(m===null?zo(pn(r)):Ur(pn(r),JSON.stringify(m)))},[i,r]);s.useEffect(()=>{if(b.current||(b.current=!0,i))return;const m=Go(qr(pn(r)));if(!m)return;const{vw:R,vh:M}=Wt(),H=hn(m.width,m.height,{minWidth:o,minHeight:c,edgeMargin:l,vw:R,vh:M}),V=mn(m.top,m.left,H.width,H.height,{edgeMargin:l,vw:R,vh:M});d({...V,...H})},[]),s.useEffect(()=>{if(typeof window>"u")return;const m=()=>{d(R=>{if(R===null)return null;const{vw:M,vh:H}=Wt(),V=hn(R.width,R.height,{minWidth:o,minHeight:c,edgeMargin:l,vw:M,vh:H});return{...mn(R.top,R.left,V.width,V.height,{edgeMargin:l,vw:M,vh:H}),...V}})};return window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)},[o,c,l]);const E=s.useCallback(m=>{if(!t||m.pointerType==="mouse"&&m.button!==0)return;const R=m.target;if(R&&typeof R.closest=="function"&&R.closest('button, a, input, select, textarea, [role="listbox"], [role="option"], [data-ll-no-drag]'))return;let M,H,V,Z;const F=x.current;if(F)({top:M,left:H,width:V,height:Z}=F);else{const ee=m.currentTarget.closest(".ll-widget"),ne=ee==null?void 0:ee.getBoundingClientRect();if(!ne)return;M=ne.top,H=ne.left,V=ne.width,Z=ne.height}try{m.currentTarget.setPointerCapture(m.pointerId)}catch{}S.current={startClientX:m.clientX,startClientY:m.clientY,startTop:M,startLeft:H,width:V,height:Z,moved:!1}},[t]),v=s.useCallback(m=>{const R=S.current;if(!R)return;const M=m.clientX-R.startClientX,H=m.clientY-R.startClientY;if(!R.moved&&Math.abs(M)+Math.abs(H)>Vo&&(R.moved=!0,p(!0)),!R.moved)return;const{vw:V,vh:Z}=Wt(),F=mn(R.startTop+H,R.startLeft+M,R.width,R.height,{edgeMargin:l,vw:V,vh:Z});d({...F,width:R.width,height:R.height})},[l]),N=s.useCallback(m=>{const R=S.current;if(R){try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}S.current=null,R.moved&&(p(!1),d(M=>(M&&A(M),M)))}},[A]),w=s.useCallback(()=>{S.current=null,_.current=null,p(!1),T(!1),d(null),A(null)},[A]),I=s.useCallback(m=>{if(!n||m.pointerType==="mouse"&&m.button!==0)return;m.stopPropagation();let R,M,H,V;const Z=x.current;if(Z)({top:R,left:M,width:H,height:V}=Z);else{const F=m.currentTarget.closest(".ll-widget"),ee=F==null?void 0:F.getBoundingClientRect();if(!ee)return;R=ee.top,M=ee.left,H=ee.width,V=ee.height}try{m.currentTarget.setPointerCapture(m.pointerId)}catch{}_.current={startClientX:m.clientX,startClientY:m.clientY,startWidth:H,startHeight:V,top:R,left:M},T(!0)},[n]),$=s.useCallback(m=>{const R=_.current;if(!R)return;const M=m.clientX-R.startClientX,H=m.clientY-R.startClientY,{vw:V,vh:Z}=Wt(),F=V-R.left-l,ee=Z-R.top-l,ne=hn(R.startWidth+M,R.startHeight+H,{minWidth:o,minHeight:c,edgeMargin:l,vw:Math.min(V,R.left+F+l),vh:Math.min(Z,R.top+ee+l)});d({top:R.top,left:R.left,...ne})},[l,o,c]),Y=s.useCallback(m=>{if(_.current){try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}_.current=null,T(!1),d(M=>(M&&A(M),M))}},[A]);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:h,isResizing:y,dragHandleProps:{onPointerDown:E,onPointerMove:v,onPointerUp:N,onPointerCancel:N,onDoubleClick:w,"data-ll-drag-handle":t?"":void 0},resizeHandleProps:{onPointerDown:I,onPointerMove:$,onPointerUp:Y,onPointerCancel:Y,"data-ll-resize-handle":n?"":void 0},reset:w}}const rr="__llHistoryPatched",Xt="ll:pathname";function Xo(){if(typeof window>"u"||window.history[rr])return;const e=window.history.pushState,t=window.history.replaceState;window.history.pushState=function(...n){const r=e.apply(this,n);return window.dispatchEvent(new Event(Xt)),r},window.history.replaceState=function(...n){const r=t.apply(this,n);return window.dispatchEvent(new Event(Xt)),r},window.history[rr]=!0}function ir(){return typeof window>"u"?"/":window.location.pathname||"/"}function Xr(e){const[t,n]=s.useState(()=>e??ir());return s.useEffect(()=>{if(e!==void 0)return;Xo();const r=()=>n(ir());return r(),window.addEventListener("popstate",r),window.addEventListener(Xt,r),()=>{window.removeEventListener("popstate",r),window.removeEventListener(Xt,r)}},[e]),e??t}const or=new Map,Ko=/[\\^$+?.()|{}[\]]/g;function Jo(e){return e.replace(Ko,"\\$&")}function Qo(e){const t=or.get(e);if(t)return t;const n=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,r="",i="",o=n.replace(/\*\*/g,r).replace(/\*/g,i),l=Jo(o).replace(new RegExp(`\\/${r}`,"g"),"(?:\\/.*)?").replace(new RegExp(r,"g"),".*").replace(new RegExp(i,"g"),"[^/]+"),u=new RegExp(`^${l}\\/?$`);return or.set(e,u),u}function Zo(e,t){const n=t.length>1&&t.endsWith("/")?t.slice(0,-1):t;return Qo(e).test(n)}function Kr(e,t){return typeof e=="function"?e(t):e instanceof RegExp?e.test(t):Zo(e,t)}function sr(e,t){if(!e||e.length===0)return!1;for(const n of e)if(Kr(n,t))return!0;return!1}function Jr(e,t,n){return e===void 0?!0:sr(n,e)?!1:t&&t.length>0?sr(t,e):!0}function Qr(e,t,n){return s.useMemo(()=>Jr(e,t,n),[e,t,n])}function es(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 ts(e){const t=s.useMemo(()=>es(e.config),[e.config]),n=e.baseUrl.replace(/\/+$/,""),r=s.useRef(null),i=s.useCallback(u=>{try{new Audio(`${n}${u}`).play().catch(()=>{})}catch{}},[n]),o=s.useCallback(()=>{t.navigate&&i("/audio/page-change-sound.mp3")},[t.navigate,i]),c=s.useCallback(()=>{t.action&&i("/audio/confirmation-sound.mp3")},[t.action,i]),l=s.useCallback(u=>{if(!t.thinking){if(r.current){try{r.current.pause()}catch{}r.current=null}return}if(u){if(r.current)return;try{const d=new Audio(`${n}/audio/thinking-sound.mp3`);d.loop=!0,d.volume=.3,d.play().catch(()=>{r.current=null}),r.current=d}catch{}}else if(r.current){try{r.current.pause()}catch{}r.current=null}},[n,t.thinking]);return s.useEffect(()=>()=>{if(r.current){try{r.current.pause()}catch{}r.current=null}},[]),s.useMemo(()=>({playPageChange:o,playConfirmation:c,setThinking:l}),[o,c,l])}const ar=({muted:e=!1,className:t})=>e?a.jsxs("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[a.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"}),a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):a.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:a.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"})}),lr=({className:e})=>a.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:a.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"})}),ns=({className:e})=>a.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),rs={left:180,right:0,up:-90,down:90},cr=({direction:e="right",className:t})=>a.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${rs[e]}deg)`},"aria-hidden":"true",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function is(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const Zr="ll-hidden-tab-center-y",os=5,ur=16;function ss(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(Zr);if(!e)return null;const t=Number.parseFloat(e);return Number.isFinite(t)?t:null}catch{return null}}function dr(e){if(!(typeof window>"u"))try{window.localStorage.setItem(Zr,String(e))}catch{}}const as=({position:e,isMobile:t,isSpeaking:n,onExpand:r,label:i="Open widget",avatarImageUrl:o,agentName:c,containerEl:l})=>{const u=is(e),d=u==="right"?"left":"right",h=t?80:72,p=!!o,y=!!l,[T,S]=s.useState(null),[_,b]=s.useState(!1),x=s.useRef(null),A=s.useRef(!1),E=s.useCallback(P=>{if(typeof window>"u")return P;const U=h/2,m=ur+U,R=window.innerHeight-ur-U;return R<m?Math.max(m,P):Math.max(m,Math.min(R,P))},[h]);s.useEffect(()=>{if(y){S(null);return}const P=ss();S(E(P??window.innerHeight/2));const U=()=>{S(m=>m===null?null:E(m))};return window.addEventListener("resize",U),()=>window.removeEventListener("resize",U)},[E,y]);const v=s.useCallback(P=>{if(!y&&!(P.pointerType==="mouse"&&P.button!==0)&&T!==null){try{P.currentTarget.setPointerCapture(P.pointerId)}catch{}x.current={startClientY:P.clientY,startCenterY:T,moved:!1}}},[T,y]),N=s.useCallback(P=>{const U=x.current;if(!U)return;const m=P.clientY-U.startClientY;!U.moved&&Math.abs(m)>os&&(U.moved=!0,b(!0)),U.moved&&S(E(U.startCenterY+m))},[E]),w=s.useCallback(P=>{const U=x.current;if(U){try{P.currentTarget.releasePointerCapture(P.pointerId)}catch{}x.current=null,U.moved&&(b(!1),A.current=!0,S(m=>(m!==null&&dr(m),m)))}},[]),I=s.useCallback(()=>{if(A.current){A.current=!1;return}r()},[r]),$=s.useCallback(P=>{if(P.key==="ArrowUp"||P.key==="ArrowDown"){P.preventDefault();const U=P.key==="ArrowUp"?-8:8;S(m=>{if(m===null)return m;const R=E(m+U);return dr(R),R})}},[E]),Y=["ll-hidden",`ll-hidden--${u}`,t?"ll-hidden--mobile":"ll-hidden--desktop",n?"ll-hidden--speaking":null,_?"is-dragging":null,p?"ll-hidden--with-avatar":null,y?"ll-hidden--scoped":null].filter(Boolean).join(" "),ie=T===null?void 0:{top:`${T-h/2}px`,transform:"none"};return a.jsx("button",{type:"button",className:Y,onPointerDown:v,onPointerMove:N,onPointerUp:w,onPointerCancel:w,onClick:I,onKeyDown:$,"aria-label":i,"data-position":e,style:ie,children:p?a.jsxs(a.Fragment,{children:[a.jsx(cr,{direction:d,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),a.jsx("img",{src:o,alt:c?`${c} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):a.jsx(cr,{direction:d,className:"ll-hidden__chevron"})})},ls=({audioLevel:e,bars:t=20,maxHeight:n=20,minHeight:r=4,className:i,barClassName:o})=>{const c=s.useRef(null),l=s.useRef([]),u=s.useMemo(()=>{const h=(Math.sqrt(5)-1)/2;return Array.from({length:t},(p,y)=>.5+y*h%1*.5)},[t]);s.useEffect(()=>e.subscribe(p=>{for(let y=0;y<t;y++){const T=l.current[y];if(!T)continue;const S=Math.max(r,p*n*u[y]);T.style.height=`${S}px`}}),[e,t,n,r,u]);const d=["ll-waveform",i].filter(Boolean).join(" ");return a.jsx("div",{ref:c,className:d,"aria-hidden":"true",children:Array.from({length:t},(h,p)=>a.jsx("div",{ref:y=>{l.current[p]=y},className:["ll-waveform__bar",o].filter(Boolean).join(" "),style:{height:`${r}px`}},p))})},cs=({position:e,isMobile:t,agentName:n,avatarImageUrl:r,agentState:i,isMuted:o,audioLevel:c,onExpand:l,onToggleMute:u,onClose:d})=>t?a.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${n} widget`,children:a.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:l,"aria-label":`Expand ${n} widget`,children:[r?a.jsx("img",{src:r,alt:n,className:"ll-minimized__avatar"}):a.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),a.jsx(ls,{audioLevel:c,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),a.jsx("span",{className:"ll-minimized__name",children:n}),a.jsxs("div",{className:"ll-minimized__controls",children:[a.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:h=>{h.stopPropagation(),u()},onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.stopPropagation(),h.preventDefault(),u())},"aria-label":o?"Unmute microphone":"Mute microphone",children:a.jsx(ar,{muted:o,className:"ll-minimized__icon"})}),a.jsx(lr,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):a.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${n} widget`,children:a.jsxs("div",{className:"ll-minimized__surface",children:[r?a.jsx("img",{src:r,alt:n,className:"ll-minimized__avatar"}):a.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),a.jsxs("div",{className:"ll-minimized__meta",children:[a.jsx("span",{className:"ll-minimized__name",children:n}),a.jsx("span",{className:"ll-minimized__state",children:i==="speaking"?"Speaking":i==="thinking"?"Thinking":"Listening"})]}),a.jsxs("div",{className:"ll-minimized__controls",children:[a.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:u,"aria-label":o?"Unmute microphone":"Mute microphone",children:a.jsx(ar,{muted:o,className:"ll-minimized__icon"})}),a.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:l,"aria-label":`Expand ${n} widget`,children:a.jsx(lr,{className:"ll-minimized__icon"})}),a.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:d,"aria-label":"Close widget",children:a.jsx(ns,{className:"ll-minimized__icon"})})]})]})}),us=({src:e,alt:t,preCannedPlaying:n=!1,className:r,style:i})=>{const[o,c]=s.useState(!1),l=s.useRef(e);if(s.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:n?"scale(1.02)":"scale(1)",opacity:o?1:0,...i};return a.jsx("img",{src:e,alt:t,className:r,style:u,loading:"eager",fetchPriority:"high",onLoad:()=>c(!0)})},ds="#E06540";function fs({size:e=14,className:t,fill:n=ds}){return a.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:[a.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:n}),a.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:n}),a.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:n})]})}const ps=8,fr=8,hs=({open:e,onClose:t,anchorRef:n,children:r})=>{const i=s.useRef(null),[o,c]=s.useState(null);return s.useLayoutEffect(()=>{if(!e){c(null);return}const l=n.current;if(!l)return;const u=()=>{const d=l.getBoundingClientRect(),h={top:d.top-ps,left:d.left+d.width/2},p=fr+90,y=window.innerWidth-fr-90;h.left<p&&(h.left=p),h.left>y&&(h.left=y),c(h)};return u(),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[e,n]),s.useEffect(()=>{if(!e)return;const l=d=>{const h=d.target,p=i.current,y=n.current;p&&p.contains(h)||y&&y.contains(h)||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,n]),!e||o===null||typeof document>"u"?null:Cn.createPortal(a.jsx("div",{ref:i,className:"ll-overflow-popover",role:"menu",style:{position:"fixed",top:o.top,left:o.left,transform:"translate(-50%, -100%)"},children:r}),document.body)},ms=({isMuted:e,onToggleMute:t,isCameraEnabled:n,onToggleCamera:r,allowCamera:i,isScreenShareEnabled:o,onToggleScreenShare:c,allowScreenShare:l,isSpeakerMuted:u,onToggleSpeaker:d,allowTyping:h,isTypingOpen:p,onToggleTyping:y,onDisconnect:T})=>{const[S,_]=s.useState(!1),b=s.useRef(null);return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:x=>x.stopPropagation(),children:[a.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:t,"aria-label":e?"Unmute microphone":"Mute microphone",children:a.jsx(ni,{muted:e})}),a.jsx("button",{ref:b,type:"button",className:`ll-tool ${S?"is-on":""}`,onClick:()=>_(x=>!x),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":S,children:a.jsx(gs,{})}),a.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:T,"aria-label":"End conversation",children:a.jsx(ii,{})})]}),a.jsxs(hs,{open:S,onClose:()=>_(!1),anchorRef:b,children:[i&&a.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${n?"is-on":""}`,onClick:()=>{r(),_(!1)},children:[a.jsx(ti,{}),a.jsx("span",{children:n?"Stop camera":"Start camera"})]}),l&&a.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${o?"is-on":""}`,onClick:()=>{c(),_(!1)},children:[a.jsx(ei,{}),a.jsx("span",{children:o?"Stop sharing":"Share screen"})]}),a.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${u?"is-on":""}`,onClick:()=>{d(),_(!1)},children:[a.jsx(ri,{muted:u}),a.jsx("span",{children:u?"Unmute speaker":"Mute speaker"})]}),h&&a.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${p?"is-on":""}`,onClick:()=>{y(),_(!1)},children:[a.jsx(ys,{}),a.jsx("span",{children:p?"Hide typing":"Type a message"})]}),a.jsxs("button",{type:"button",className:"ll-overflow-popover__item is-active",disabled:!0,"aria-current":"true",children:[a.jsx("span",{className:"ll-overflow-popover__lang-code",children:"EN"}),a.jsx("span",{children:"English"})]})]})]})};function gs(){return a.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[a.jsx("circle",{cx:"6",cy:"12",r:"1.5"}),a.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),a.jsx("circle",{cx:"18",cy:"12",r:"1.5"})]})}function ys(){return a.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:a.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 bs=({position:e,isMobile:t,agentName:n,avatarImageUrl:r,idleLoopUrl:i,greeting:o,branding:c,teamMembers:l,currentTeamMemberId:u,isSwitchingTeamMember:d,teamSwitcherOpen:h,onToggleTeamSwitcher:p,onSelectTeamMember:y,languageMenuOpen:T,onToggleLanguageMenu:S,connectionState:_,agentState:b,transcript:x,canResume:A,needsUserGesture:E,error:v,isMuted:N,micError:w,micDevices:I,activeMicId:$,isCameraEnabled:Y,cameraPreviewEl:ie,cameraDevices:P,activeCameraId:U,isScreenShareEnabled:m,screenPreviewEl:R,isSpeakerMuted:M,allowCamera:H,allowScreenShare:V,allowTyping:Z,showMinimize:F=!0,showClose:ee=!0,chromeless:ne=!1,compactControls:O=!1,transforming:he,transformingLabel:X,avatarVideoContainerRef:xe,agentVideoEl:te,onConnect:Te,onDisconnect:mt,onRetry:Et,onResumeAudio:Lt,onToggleMute:gt,onSwitchMicDevice:Rt,onToggleCamera:Qe,onSwitchCameraDevice:jt,onToggleScreenShare:Oe,onToggleSpeaker:We,onSendMessage:Be,onMinimize:qe,onClose:Ue,onClearMicError:Ze,dragHandleProps:Ve,resizeHandleProps:Le})=>{var ot;const D=((l==null?void 0:l.length)??0)>1,et=_==="connecting"||_==="connected",Ce=_==="connected",Qt=_==="idle"||_==="disconnected"||_==="error",[yt,Ie]=s.useState(!1);s.useEffect(()=>{if(!te){Ie(!1);return}if(!te.paused&&te.readyState>=2){Ie(!0);return}Ie(!1);const k=()=>Ie(!0);return te.addEventListener("playing",k),te.addEventListener("loadeddata",k),()=>{te.removeEventListener("playing",k),te.removeEventListener("loadeddata",k)}},[te]);const[Ge,At]=s.useState(!1);s.useEffect(()=>{b==="speaking"&&At(!0)},[b]),s.useEffect(()=>{(_==="disconnected"||_==="idle")&&At(!1)},[_]);const[Zt,Me]=s.useState(!1);s.useEffect(()=>{if(!Ce){Me(!1);return}if(Ge)return;const k=setTimeout(()=>Me(!0),12e3);return()=>clearTimeout(k)},[Ce,Ge]);const ue=_==="connecting"||Ce&&!Ge&&!Zt,bt=s.useRef(null),le=s.useRef(null);s.useEffect(()=>{const k=bt.current;k&&(k.innerHTML="",ie&&(ie.style.width="100%",ie.style.height="100%",ie.style.objectFit="cover",ie.style.transform="scaleX(-1)",k.appendChild(ie)))},[ie]),s.useEffect(()=>{const k=le.current;k&&(k.innerHTML="",R&&(R.style.width="100%",R.style.height="100%",R.style.objectFit="contain",k.appendChild(R)))},[R]);const[de,tt]=s.useState(!1),[nt,fe]=s.useState(!1),Se=s.useRef(null),Tt=s.useRef(null);s.useEffect(()=>{if(!de&&!nt&&!T&&!h)return;const k=()=>{tt(!1),fe(!1),T&&S(),h&&p()};return document.addEventListener("click",k),()=>document.removeEventListener("click",k)},[de,nt,T,h,S,p]);const[It,en]=s.useState(!1),kn=s.useCallback(()=>en(k=>!k),[]),[wt,Re]=s.useState(""),Ye=s.useCallback(k=>{k.preventDefault();const re=wt.trim();re&&(Be(re),Re(""))},[wt,Be]),_e=c.productName||"Live Layer",Xe=!c.hideBranding&&!c.productName;let ke=null,Pe=null;for(let k=x.length-1;k>=0;k--){const re=x[k];if(!ke&&re.role==="agent"?ke=re:!Pe&&re.role==="user"&&(Pe=re),ke&&Pe)break}const rt=Ce?(ke==null?void 0:ke.text)||null:o||null,it=Ce&&(Pe==null?void 0:Pe.text)||null,Mt=["ll-expanded",t?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return a.jsxs("div",{className:Mt,"data-position":e,"data-state":Ce?"connected":et?"connecting":"idle",role:"dialog","aria-label":`${n} widget`,children:[a.jsxs("div",{className:"ll-expanded__bg",children:[r?a.jsx(us,{src:r,alt:n,className:"ll-expanded__bg-img"}):a.jsx("div",{className:"ll-expanded__bg-fallback",children:a.jsx("span",{className:"ll-expanded__bg-initial",children:((ot=n==null?void 0:n.charAt(0))==null?void 0:ot.toUpperCase())||"A"})}),i&&!Ce&&a.jsx("video",{className:"ll-expanded__bg-idle",src:i,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),a.jsx("div",{ref:xe,className:"ll-expanded__video","data-ready":yt}),ue&&a.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--connecting",children:[a.jsx("div",{className:"ll-expanded__spinner"}),a.jsx("p",{className:"ll-expanded__overlay-text",children:d?"Switching...":"Connecting..."})]}),E&&Ce&&a.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:Lt,children:[a.jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:a.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"})}),a.jsx("p",{className:"ll-expanded__overlay-text",children:"Tap to enable audio"})]}),he&&a.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":X,children:[a.jsx("div",{className:"ll-expanded__spinner"}),a.jsx("p",{className:"ll-expanded__overlay-text",children:X})]}),et?a.jsxs(a.Fragment,{children:[!O&&a.jsxs("div",{className:"ll-expanded__topbar",...Ve,children:[!ne&&a.jsxs("div",{className:"ll-expanded__topbar-left",children:[a.jsxs("div",{className:"ll-expanded__pill-wrap",children:[a.jsxs("button",{type:"button",className:"ll-hpill",onClick:k=>{D&&(k.stopPropagation(),p())},"aria-haspopup":D?"listbox":void 0,"aria-expanded":D?h:void 0,children:[a.jsx("span",{className:"ll-hpill__label",children:n}),D&&a.jsx(Bt,{})]}),D&&h&&a.jsx("div",{className:"ll-hmenu",onClick:k=>k.stopPropagation(),role:"listbox",children:l==null?void 0:l.map(k=>a.jsxs("button",{type:"button",className:`ll-hmenu__item ${k.id===u?"is-active":""}`,onClick:()=>y(k.id),role:"option","aria-selected":k.id===u,children:[k.avatarImageUrl&&a.jsx("img",{src:k.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),a.jsx("span",{className:"ll-hmenu__name",children:k.name}),k.role&&a.jsx("span",{className:"ll-hmenu__role",children:k.role})]},k.id))})]}),a.jsxs("div",{className:"ll-expanded__pill-wrap",children:[a.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:k=>{k.stopPropagation(),S()},"aria-haspopup":"listbox","aria-expanded":T,"aria-label":"Language: English",title:"Language: English",children:[a.jsx("span",{className:"ll-hpill__label",children:"EN"}),a.jsx(Bt,{})]}),T&&a.jsx("div",{className:"ll-hmenu",onClick:k=>k.stopPropagation(),role:"listbox",children:a.jsx("button",{type:"button",className:"ll-hmenu__item is-active",role:"option","aria-selected":!0,children:a.jsx("span",{className:"ll-hmenu__name",children:"English"})})})]}),a.jsx("span",{className:`ll-expanded__state ll-expanded__state--${b}`,children:b})]}),a.jsxs("div",{className:"ll-expanded__header-actions",children:[F!==!1&&a.jsx("button",{type:"button",className:"ll-hbtn",onClick:qe,"aria-label":"Minimize widget",title:"Minimize",children:a.jsx(hr,{})}),ee!==!1&&a.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Ue,"aria-label":"End call",title:"End call",children:a.jsx(pr,{})})]})]}),O&&a.jsxs("div",{className:"ll-compact-status","data-state":b,children:[a.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),a.jsx("span",{className:"ll-compact-status__label",children:b})]})]}):a.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",...Ve,children:[!O&&(Xe?a.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:[a.jsx(fs,{size:14,className:"ll-expanded__brand-mark"}),a.jsx("span",{children:_e})]}):a.jsx("span",{className:"ll-expanded__brand",children:_e})),a.jsxs("div",{className:"ll-expanded__header-actions",children:[!O&&F!==!1&&a.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:qe,"aria-label":"Minimize widget",children:a.jsx(hr,{})}),ee!==!1&&a.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Ue,"aria-label":"Close widget",children:a.jsx(pr,{})})]})]}),Qt&&(()=>{const k=A?"Resume session":_==="disconnected"?"Reconnect to agent":"Start video call",re=!v;return a.jsxs(a.Fragment,{children:[re&&a.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:Te,"aria-label":k,children:[a.jsx("div",{className:"ll-expanded__play-circle",children:a.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:a.jsx("polygon",{points:"6 3 20 12 6 21 6 3"})})}),O&&a.jsx("span",{className:"ll-expanded__play-label",children:k})]}),!O&&a.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[o&&a.jsx("div",{className:"ll-expanded__transcript",children:a.jsx("p",{className:"ll-expanded__transcript-text",children:o})}),a.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:Te,"aria-label":k,children:k})]})]})})(),a.jsxs("div",{className:`ll-expanded__pip ${et&&(Y||m)?"is-visible":""}`,children:[a.jsx("div",{ref:le,className:m?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),a.jsx("div",{ref:bt,className:!m&&Y?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),et?a.jsxs("div",{className:"ll-expanded__bottom",children:[!O&&rt&&a.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:a.jsx("p",{className:"ll-expanded__transcript-text",children:rt})}),!O&&it&&a.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:a.jsx("p",{className:"ll-expanded__transcript-text",children:it})}),!ne&&!O&&a.jsxs("div",{className:"ll-toolbar",onClick:k=>k.stopPropagation(),children:[V&&a.jsx("button",{type:"button",className:`ll-tool ${m?"is-on":""}`,onClick:Oe,"aria-label":m?"Stop sharing screen":"Share screen",title:m?"Stop sharing":"Share screen",children:a.jsx(ei,{})}),H&&a.jsxs("div",{className:"ll-tool-split",children:[a.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${Y?"is-on":""}`,onClick:Qe,"aria-label":Y?"Turn off camera":"Turn on camera",title:Y?"Stop camera":"Start camera",children:a.jsx(ti,{})}),a.jsx("button",{ref:Tt,type:"button",className:`ll-tool ll-tool--right ${Y?"is-on":""}`,onClick:k=>{k.stopPropagation(),fe(re=>!re),tt(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":nt,children:a.jsx(Bt,{})}),nt&&P.length>0&&a.jsx(mr,{label:"Camera",devices:P,activeId:U,anchorRef:Tt,onPick:k=>{fe(!1),jt(k)}})]}),a.jsxs("div",{className:"ll-tool-split",children:[a.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${N?"is-muted":""}`,onClick:gt,"aria-label":N?"Unmute microphone":"Mute microphone",title:N?"Unmute":"Mute",children:a.jsx(ni,{muted:N})}),a.jsx("button",{ref:Se,type:"button",className:`ll-tool ll-tool--right ${N?"is-muted":""}`,onClick:k=>{k.stopPropagation(),tt(re=>!re),fe(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":de,children:a.jsx(Bt,{})}),de&&I.length>0&&a.jsx(mr,{label:"Microphone",devices:I,activeId:$,anchorRef:Se,onPick:k=>{tt(!1),Rt(k)}})]}),a.jsx("button",{type:"button",className:`ll-tool ${M?"is-muted":""}`,onClick:We,"aria-label":M?"Unmute speaker":"Mute speaker",title:M?"Unmute speaker":"Mute speaker",children:a.jsx(ri,{muted:M})}),a.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:mt,"aria-label":"End conversation",title:"End conversation",children:a.jsx(ii,{})})]}),!ne&&O&&a.jsx(ms,{isMuted:N,onToggleMute:gt,isCameraEnabled:Y,onToggleCamera:Qe,allowCamera:H,isScreenShareEnabled:m,onToggleScreenShare:Oe,allowScreenShare:V,isSpeakerMuted:M,onToggleSpeaker:We,allowTyping:Z,isTypingOpen:It,onToggleTyping:kn,onDisconnect:mt}),!ne&&Z&&(O?It:!0)&&a.jsxs("form",{className:"ll-message-input",onSubmit:Ye,children:[a.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:wt,onChange:k=>Re(k.target.value),"aria-label":"Message the agent"}),wt.trim()&&a.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:a.jsx(ws,{})})]})]}):null,(()=>{if(w&&_!=="error")return a.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[a.jsx("span",{children:w}),a.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:Ze,"aria-label":"Dismiss",children:"×"})]});if(!v||_!=="error")return null;let k="Failed to connect",re="Try again";return v==="MIC_PERMISSION_DENIED"?k="Microphone blocked. Allow access to talk.":v==="MIC_NOT_FOUND"?k="No microphone found. Plug one in + retry.":v==="MIC_UNAVAILABLE"?k="Mic unavailable. Check other apps using it.":v==="AGENT_TIMEOUT"?k="Agent didn't pick up. Try again.":v==="CONNECT_FAILED"?k="Connection failed. Check your network.":v.length<80&&(k=v),a.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[a.jsx("span",{children:k}),a.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:Et,children:re})]})})(),(Le==null?void 0:Le["data-ll-resize-handle"])!==void 0&&a.jsx("div",{className:"ll-expanded__resize-grip",...Le,"aria-hidden":!0,children:a.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[a.jsx("line",{x1:"11",y1:"4",x2:"4",y2:"11"}),a.jsx("line",{x1:"11",y1:"8",x2:"8",y2:"11"})]})})]})};function Bt(){return a.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":!0,children:a.jsx("polyline",{points:"6 9 12 15 18 9"})})}function pr(){return a.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:[a.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),a.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function hr(){return a.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:a.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function ei(){return a.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:[a.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),a.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),a.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function ti(){return a.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:[a.jsx("path",{d:"M23 7l-7 5 7 5V7z"}),a.jsx("rect",{x:"1",y:"5",width:"15",height:"14",rx:"2"})]})}function ni({muted:e}){return a.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:[a.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),a.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),a.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),e&&a.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function ri({muted:e}){return a.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:[a.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e?a.jsx("line",{x1:"23",y1:"9",x2:"17",y2:"15"}):a.jsxs(a.Fragment,{children:[a.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"}),a.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]})]})}function ws(){return a.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:[a.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),a.jsx("polyline",{points:"12 5 19 12 12 19"})]})}function ii(){return a.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:a.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 mr=({label:e,devices:t,activeId:n,onPick:r,anchorRef:i})=>{const[o,c]=s.useState(null);return s.useLayoutEffect(()=>{const l=()=>{const u=i.current;if(!u)return;const d=u.getBoundingClientRect(),h=126,p=window.innerWidth-16-110,y=d.left+d.width/2;c({top:d.top-8,left:Math.max(h,Math.min(p,y))})};return l(),window.addEventListener("scroll",l,!0),window.addEventListener("resize",l),()=>{window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l)}},[i]),o===null||typeof document>"u"?null:Cn.createPortal(a.jsxs("div",{className:"ll-device-menu ll-device-menu--floating",onClick:l=>l.stopPropagation(),role:"listbox",style:{position:"fixed",top:o.top,left:o.left,transform:"translate(-50%, -100%)"},children:[a.jsx("p",{className:"ll-device-menu__label",children:e}),t.map((l,u)=>{const d=n===l.deviceId;return a.jsxs("button",{type:"button",className:`ll-device-menu__item ${d?"is-active":""}`,onClick:()=>r(l.deviceId),role:"option","aria-selected":d,children:[d&&a.jsx("span",{className:"ll-device-menu__dot",children:"●"}),a.jsx("span",{className:"ll-device-menu__name",children:l.label||`${e} ${u+1}`})]},l.deviceId||u)})]}),document.body)},vs=["[data-ll-private]","[data-ll-skip]",".ll-widget"];function Jt(e){let t=e;for(;t;){for(const n of vs)if(t.matches(n))return!0;t=t.parentElement}return!1}function wn(e){if(Jt(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 xs=/\b(continue|next|proceed|move\s*on|forward)\b|→|›/i,gr=/\b(back|previous|prev|go\s*back)\b|←|‹/i,Cs=/\b(submit|finish|done|complete|send)\b/i,kt=new Map;function yr(e){const t=kt.get(e);return t&&t.isConnected?t:null}function dt(e){if(Jt(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 Ss(e){return!!(e.disabled||e.getAttribute("aria-disabled")==="true")}function _s(e){return(e.innerText||e.textContent||e.getAttribute("aria-label")||e.value||"").trim()}function ks(e){return Array.from(e.querySelectorAll('button, [role="button"], input[type="submit"], input[type="button"]')).filter(n=>!dt(n)&&!Ss(n))}function oi(e){kt.clear();const t=ks(e);let n,r,i;for(const l of t){const u=_s(l);if(!u||u.length>40)continue;const d=l.getAttribute("type")==="submit"||l.tagName==="BUTTON"&&!l.getAttribute("type")&&!!l.closest("form");!n&&xs.test(u)&&!gr.test(u)?(n={id:"ll-advance",label:u},kt.set("ll-advance",l)):!r&&gr.test(u)?(r={id:"ll-back",label:u},kt.set("ll-back",l)):!i&&(Cs.test(u)||d)&&(i={id:"ll-submit",label:u},kt.set("ll-submit",l))}const o=Is(e);return{kind:n||o.totalSteps?"multi-step":"single-page",advance:n,back:r,submit:i,...o}}const Es=60;function si(e){return e.replace(/^\s*(step\s+)?\d{1,2}(?:[.):\-]+\s*|\s+)/i,"").replace(/\s+/g," ").trim().slice(0,Es)}function Ls(e){const t=e.getAttribute("class");return t?t.toLowerCase():""}const Rs=/stepper|wizard|ant-steps|step-indicator/;function js(e){return Rs.test(Ls(e))}function br(e){const t=e.getAttribute("aria-current");return t==="step"||t==="true"?!0:Array.from(e.classList).some(n=>/(^|[-_])(active|current|selected)([-_]|$)/i.test(n))}const As='[aria-current="step"],[aria-current="true"],[class*="active"],[class*="Active"],[class*="current"],[class*="Current"],[class*="selected"],[class*="Selected"]';function Ts(e){return br(e)?!0:Array.from(e.querySelectorAll(As)).some(br)}function wr(e,t){const n=si(e[t].innerText||e[t].textContent||"");return{totalSteps:e.length,currentStep:t+1,...n?{stepLabel:n}:{}}}function Is(e){const t=e.querySelector('[aria-current="step"]');if(t&&t.parentElement&&!dt(t)){const i=Array.from(t.parentElement.children).filter(c=>c.tagName===t.tagName&&!dt(c)),o=i.indexOf(t);if(o>=0&&i.length>=2)return wr(i,o)}const n=e.querySelector('[role="progressbar"]');if(n&&!dt(n)){const i=Number(n.getAttribute("aria-valuenow")),o=Number(n.getAttribute("aria-valuemax"));if(Number.isFinite(i)&&Number.isFinite(o)&&o>=2){const c=(n.getAttribute("aria-valuetext")||"").trim();return{totalSteps:o,currentStep:i,...c?{stepLabel:si(c)}:{}}}}const r=Array.from(e.querySelectorAll('[class*="step"], [class*="Step"], [class*="wizard"], [class*="Wizard"]')).filter(i=>!dt(i)&&js(i));for(const i of r){const o=Array.from(i.children).filter(l=>!dt(l)&&(l.textContent||"").trim().length>0);if(o.length<2||o.length>12)continue;const c=o.findIndex(Ts);if(!(c<0))return wr(o,c)}return{}}const qt=4096,Ms=20,Ps=20,Ns=10,Ds=10,$s=30,Fs=20,vr=500,zs=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function St(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let t=e;for(;t;){for(const n of zs)if(t.matches(n))return!0;t=t.parentElement}return!1}function _t(e){if(typeof window>"u")return!0;const t=e.getBoundingClientRect();if(t.width<=0||t.height<=0)return!1;const n=window.innerHeight||document.documentElement.clientHeight,r=window.innerWidth||document.documentElement.clientWidth;return t.bottom>0&&t.right>0&&t.top<n&&t.left<r}function xr(e){const t=e.getAttribute("id");if(t){const o=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(t):t.replace(/"/g,'\\"'),c=document.querySelector(`label[for="${o}"]`);if(c!=null&&c.textContent)return c.textContent.trim()}const n=e.getAttribute("aria-label");if(n)return n.trim();const r=e.closest("label");if(r){const o=[];for(const l of Array.from(r.childNodes))if(l.nodeType===Node.TEXT_NODE){const u=(l.textContent||"").trim();u&&o.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&&o.push(u)}const c=o.join(" ").trim();if(c)return c}const i=e.getAttribute("placeholder");return i?i.trim():""}function ae(e,t){return e.length<=t?e:e.slice(0,t-1)+"…"}function Hs(e){return e&&e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function Os(e){const t=e.getAttribute("aria-label");if(t)return t.trim().slice(0,80);const n=e.getAttribute("aria-labelledby");if(n){const o=document.getElementById(n);if(o!=null&&o.textContent)return o.textContent.trim().slice(0,80)}const r=e.querySelector('button[type="submit"], input[type="submit"], button:not([type])');if(r){const o=r instanceof HTMLInputElement?r.value:(r.textContent??"").trim();if(o&&o.length<60&&!/^(submit|ok|continue)$/i.test(o))return o}let i=e.parentElement;for(let o=0;i&&o<4;o++,i=i.parentElement){const c=i.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 ut(e){return e.length}function ai(e,t={}){const n=t.doc??(typeof document<"u"?document:null);if(!n)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const r=typeof window<"u"&&window.location.href||"",i=typeof window<"u"&&window.location.pathname||"/",o=n.title||"",c=Array.from(n.querySelectorAll("[data-ll-region]")),l=[];for(const w of c){if(l.length>=Ns)break;if(St(w)||!_t(w))continue;const I=w.getAttribute("data-ll-region")??"",$=w.getAttribute("data-ll-intent")??void 0,Y=ae((w.innerText||w.textContent||"").trim(),vr*2);!I||!Y||l.push({id:I,intent:$,text:Y})}const u=[],d=["H1","H2","H3","H4","H5","H6"],h=Array.from(n.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const w of h){if(St(w)||!_t(w))continue;const I=(w.textContent||"").trim();I&&u.push(`${w.tagName}: ${ae(I,200)}`)}const p=Array.from(n.querySelectorAll("p, li"));for(const w of p){if(St(w)||!_t(w)||d.includes(w.tagName))continue;const I=(w.textContent||"").trim();I.length>10&&u.push(ae(I,vr))}const y=u.join(`
3
+ `),T=[],S=Array.from(n.querySelectorAll("a[href]"));for(const w of S){if(T.length>=Ms)break;if(St(w)||!_t(w))continue;const I=w.getAttribute("href")||"",$=(w.textContent||"").trim();!I||!$||T.push({href:I,text:ae($,100)})}const _=[],b=Array.from(n.querySelectorAll("input, textarea, select"));for(const w of b){if(_.length>=Ps)break;if(St(w)||!wn(w)||!_t(w))continue;const I=xr(w),$=w instanceof HTMLInputElement?w.type:w.tagName.toLowerCase();I&&_.push({label:ae(I,100),type:$})}const x=Array.from(n.querySelectorAll("form")),A=[];let E=0;for(const w of x){if(A.length>=Ds)break;if(Jt(w)||w.matches(".ll-widget *, .ll-widget"))continue;const I=w.getAttribute("id")||w.getAttribute("name")||Hs(w.getAttribute("data-ll-intent"))||`form_${E++}`,$=w.getAttribute("data-ll-intent")||Os(w)||void 0,Y=Array.from(w.querySelectorAll("input, textarea, select")),ie=[];let P=0;const U=new Set;for(const m of Y){if(ie.length>=$s)break;if(!wn(m))continue;if(m instanceof HTMLInputElement){const O=m.type;if(O==="submit"||O==="button"||O==="reset"||O==="hidden"||O==="image"||O==="file")continue}const R=m.getAttribute("name")||"",M=m.getAttribute("id")||"";let H=R||M||`field_${P}`;U.has(H)&&(H=`${H}__${P}`),U.add(H),P++;const V=xr(m)||H,Z=m instanceof HTMLInputElement?m.type:m.tagName.toLowerCase(),F={name:H,label:ae(V,100),type:Z};m.required===!0&&(F.required=!0);const ee=m.getAttribute("placeholder");if(ee&&(F.placeholder=ae(ee.trim(),100)),m instanceof HTMLInputElement||m instanceof HTMLTextAreaElement){const O=m.getAttribute("minlength");if(O!==null){const X=parseInt(O,10);!Number.isNaN(X)&&X>=0&&(F.minLength=X)}const he=m.getAttribute("maxlength");if(he!==null){const X=parseInt(he,10);!Number.isNaN(X)&&X>=0&&(F.maxLength=X)}}if(m instanceof HTMLInputElement){const O=m.getAttribute("min");O!==null&&(F.min=ae(O,50));const he=m.getAttribute("max");he!==null&&(F.max=ae(he,50));const X=m.getAttribute("step");X!==null&&(F.step=ae(X,20));const xe=m.getAttribute("pattern");xe!==null&&(F.pattern=ae(xe,200));const te=(m.getAttribute("autocomplete")||"").toLowerCase();te&&te!=="off"&&!te.startsWith("cc-")&&(F.autocomplete=ae(te,50))}if(m instanceof HTMLSelectElement){const O=[];for(let he=0;he<m.options.length;he++){const X=m.options[he];if(!X)continue;if(X.value===""||X.disabled){const Te=(X.textContent||"").trim();if(Te&&!F.placeholderOption&&(F.placeholderOption=ae(Te,60)),F.hasEmptyOption=!0,X.disabled)continue}if(O.length>=Fs)break;const xe=X.value||"",te=(X.textContent||"").trim()||xe;!xe&&!te||O.push({value:xe,label:ae(te,60)})}O.length>0&&(F.options=O)}const ne=typeof m.validationMessage=="string"?m.validationMessage:"";ne&&(F.validationMessage=ae(ne,200)),ie.push(F)}A.push({id:I,intent:$,fields:ie})}const v={url:r,title:o,pathname:i,regions:l,visibleText:y,visibleLinks:T,visibleFields:_,forms:A,flow:oi(n),extras:e};let N=ut(JSON.stringify(v.regions))+ut(v.visibleText)+ut(JSON.stringify(v.visibleLinks))+ut(JSON.stringify(v.visibleFields));for(;N>qt&&v.visibleFields.length>0;)v.visibleFields.pop(),N=ut(JSON.stringify(v.visibleFields));for(;N>qt&&v.visibleLinks.length>0;)v.visibleLinks.pop(),N-=80;return ut(v.visibleText)>qt&&(v.visibleText=ae(v.visibleText,qt-100)),v}let ft=null;function Ws(e){const t=e.querySelectorAll("form");let n=`f${t.length}`;return t.forEach(r=>{n+=`|${r.id||r.getAttribute("name")||""}:${r.querySelectorAll("input,select,textarea").length}`}),n}function vn(e,t={}){const n=Date.now(),r=t.doc??(typeof document<"u"?document:null),i=typeof window<"u"&&window.location.pathname||"/",o=typeof window<"u"?window.scrollY:0,c=`${i}::${o}::${r?Ws(r):""}`;if(ft&&ft.key===c&&n-ft.at<1e3)return ft.ctx;const l=ai(e,t);return ft={key:c,at:n,ctx:l},l}function li(){ft=null}const Bs=200;function ci(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 qs(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function ui(e){const t=e??(typeof document<"u"?document:null);if(!t)return[];const n=typeof window<"u"&&window.location.origin||"",r=new Set,i=[],o=Array.from(t.querySelectorAll("a[href]"));for(const c of o){if(i.length>=Bs)break;if(Jt(c))continue;const l=c.getAttribute("href")||"";if(!qs(l))continue;let u=l,d=!0;try{if(typeof window<"u"){const p=new URL(l,n);d=p.origin===n,d&&l.startsWith("http")&&(u=p.pathname+p.search+p.hash)}}catch{continue}if(r.has(u))continue;r.add(u);const h=(c.textContent||"").trim().slice(0,120);i.push({href:u,text:h,internal:d})}return i}let pt=null;const Us=5e3;function Ut(){const e=Date.now(),t=typeof window<"u"&&window.location.pathname||"/";if(pt&&pt.pathname===t&&e-pt.at<Us)return pt.routes;const n=ui();return pt={at:e,pathname:t,routes:n},n}function di(){pt=null}function xn(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 Vs(e,t){return e.getAttribute("name")||e.getAttribute("id")||`field_${t}`}function Fe(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"")}function gn(e){const t=e.lastIndexOf(".");return t>=0?e.slice(t+1):e}function Gs(e){var r;const t=e.getAttribute("id");if(t)try{const i=(r=e.ownerDocument)==null?void 0:r.querySelector(`label[for="${t.replace(/"/g,'\\"')}"]`);if(i!=null&&i.textContent)return i.textContent}catch{}const n=e.closest("label");return n!=null&&n.textContent?n.textContent:e.getAttribute("aria-label")||e.getAttribute("placeholder")||""}function Ys(e,t){const n=Fe(t);if(n.length<2)return null;let r=null,i=0;for(const o of Array.from(e.querySelectorAll("input, textarea, select"))){if(!xn(o))continue;const c=o.getAttribute("name")||"",l=o.getAttribute("id")||"",u=[Fe(gn(c)),Fe(gn(l)),Fe(c),Fe(l)];let d=0;u.some(h=>h.length>=2&&h===n)?d=4:[Fe(c),Fe(gn(c)),Fe(Gs(o))].some(p=>p.length>=3&&(p.includes(n)||n.includes(p)))&&(d=2),d>i&&(i=d,r=o)}return i>=2?r:null}function Xs(e,t){if(!t)return null;try{const o=e.querySelector(`[name="${t.replace(/"/g,'\\"')}"]`);if(o&&xn(o))return o}catch{}const n=Array.from(e.querySelectorAll("input, textarea, select"));let r=0;const i=new Map;for(const o of n){if(!xn(o))continue;const c=Vs(o,r);let l=c;if(i.has(c)&&(l=`${c}__${r}`),l===t)return o;i.set(c,o),r++}return Ys(e,t)}function Cr(e,t){const n=Xs(e,t);return n?wn(n)?{el:n}:{el:null,reason:"private"}:{el:null,reason:"not_found"}}function Ks(e,t){const n=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,r=Object.getOwnPropertyDescriptor(n,"value"),i=r==null?void 0:r.set;i?i.call(e,t):e.value=t}function Js(e,t,n={}){const r=n.triggerInput??!0,i=n.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const o=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),c=o==null?void 0:o.set,l=t==="true"||t==="1"||t==="on";c?c.call(e,l):e.checked=l,r&&e.dispatchEvent(new Event("input",{bubbles:!0})),i&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}Ks(e,t),r&&e.dispatchEvent(new Event("input",{bubbles:!0})),i&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function Sr(e,t){if(!t)return null;const n=t.replace(/"/g,'\\"'),r=l=>l.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')!==null;try{const l=e.querySelector(`form#${CSS.escape(t)}`);if(l&&!r(l))return l}catch{}const i=e.querySelector(`form[name="${n}"]`);if(i&&!r(i))return i;const o=e.querySelector(`form[data-ll-intent="${n}"]`);if(o&&!r(o))return o;const c=Array.from(e.querySelectorAll("form")).filter(l=>!r(l));for(const l of c){const u=l.getAttribute("data-ll-intent");if(u&&Qs(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 Qs(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function Zs(){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 ea(e){if(!(e instanceof HTMLElement))return!1;const n=window.getComputedStyle(e).overflowY;return!(n!=="auto"&&n!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function ta(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let t=null,n=0;for(const r of e){if(!ea(r))continue;const i=r.getBoundingClientRect();if(i.bottom<=0||i.top>=window.innerHeight||i.right<=0||i.left>=window.innerWidth||i.width<=0||i.height<=0||r.closest(".ll-widget"))continue;const o=i.width*i.height;o>n&&(n=o,t=r)}return t}function na(){if(typeof window>"u")return null;if(Zs())return window;const e=ta();return e||window}function _r(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function ra(e){var t,n;return e instanceof Window?typeof document>"u"?0:Math.max(((t=document.body)==null?void 0:t.scrollHeight)??0,((n=document.documentElement)==null?void 0:n.scrollHeight)??0):e.scrollHeight-e.clientHeight}const ia=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"]),fi=s.forwardRef(function(t,n){var Dn,$n,Fn,zn,Hn,On,Wn,Bn,qn;const{agentId:r,apiKey:i,baseUrl:o="https://app.livelayer.studio",sessionEndpoint:c,sessionBody:l,soundEffects:u,experienceMode:d="WIDGET",autoConnect:h=!1,displayMode:p,defaultDisplayMode:y="expanded",onDisplayModeChange:T,position:S="bottom-right",mobileBreakpoint:_=640,draggable:b,resizable:x,persistKey:A="ll-widget",disablePersistence:E=!1,teamMembers:v,currentTeamMemberId:N,onTeamMemberChange:w,idleLoopUrl:I,greeting:$,avatarImageUrl:Y,agentName:ie,branding:P={},allowCamera:U=!0,allowScreenShare:m=!0,allowTyping:R=!0,blurUntilFirstSpeech:M=!0,showMinimize:H,showClose:V,chromeless:Z=!1,floatingChromeContainer:F=null,compactControls:ee=!1,transforming:ne=!1,transformingLabel:O="Transforming…",showOn:he,hideOn:X,pathname:xe,onNavigate:te,onScrollToSelector:Te,getPageContext:mt,pageContextExtras:Et,getRoutes:Lt,onScrollPage:gt,onClick:Rt,capabilities:Qe,pageVision:jt,onConnect:Oe,onDisconnect:We,onTranscript:Be,onAgentState:qe,onConnectionStateChange:Ue,onAgentEvent:Ze,onAgentCommand:Ve,onCollect:Le,controlledSession:D,className:et,style:Ce,zIndex:Qt=2147483647}=t,yt=Xr(xe),Ie=Qr(yt,he,X);s.useEffect(()=>{li(),di()},[yt]);const Ge=N!==void 0,[At,Zt]=s.useState(()=>{var g;return N??((g=v==null?void 0:v[0])==null?void 0:g.id)}),Me=Ge?N:At,ue=s.useMemo(()=>(v==null?void 0:v.find(g=>g.id===Me))??null,[v,Me]),bt=(ue==null?void 0:ue.agentId)??r,le=d==="EMBEDDED",de=Yr(_),[tt,nt]=Gr({value:p,defaultValue:y,onChange:T,persistKey:A,disablePersistence:le||E}),fe=le?"expanded":tt,Se=le?()=>{}:nt,Tt=H??!le,It=V??!le,en=ee||!le&&de,Re=Yo({draggable:!le&&(b??!de),resizable:!le&&(x??!de),persistKey:A,disablePersistence:le||E}),Ye=Rr(),_e=Ar(),Xe=Tr(),ke=Ir(),[Pe,rt]=s.useState(!1),[it,Mt]=s.useState(!1),[ot,k]=s.useState(!1),[re,mi]=s.useState(!1),[tn,gi]=s.useState(!1),[yi,bi]=s.useState(void 0),Pt=ts({baseUrl:o,config:u}),Nt=s.useRef(Pt);Nt.current=Pt;const nn=s.useRef(te),rn=s.useRef(Te),on=s.useRef(gt),sn=s.useRef(Rt),En=s.useRef(mt),Ln=s.useRef(Et),Rn=s.useRef(Lt),an=s.useRef(Qe),Ee=s.useRef(null);nn.current=te,rn.current=Te,on.current=gt,sn.current=Rt,En.current=mt,Ln.current=Et,Rn.current=Lt,an.current=Qe;function we(g){const f=an.current;return f?f.includes(g):!0}function ve(g,f){console.warn(`[LiveLayer] Agent command "${g}" blocked — capability "${f}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const vt=s.useCallback(g=>{var K,ce,je,xt,Ne,Un,Vn;const f=g;if(!(!f.type||typeof f.type!="string")){if(Ze==null||Ze({eventName:f.type,data:g}),f.type==="navigate"){if(!we("navigate")){ve("navigate","navigate");return}const L=typeof f.href=="string"?f.href:null;if(!L){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(Nt.current.playPageChange(),nn.current){try{nn.current(L)}catch(j){console.warn(`[LiveLayer] onNavigate threw for "${L}". Falling back. Error:`,j)}return}if(typeof document<"u"){const j=document.querySelector(`a[href="${L.replace(/"/g,'\\"')}"]`);if(j){j.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",L),window.dispatchEvent(new PopStateEvent("popstate"))}catch(j){console.warn(`[LiveLayer] history.pushState fallback failed for "${L}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,j)}return}if(f.type==="scroll_to"){if(!we("scroll")){ve("scroll_to","scroll");return}const L=typeof f.selector=="string"?f.selector:null;if(!L)return;const j=f.behavior==="instant"?"instant":"smooth";if(rn.current){try{rn.current(L,j)}catch(B){console.warn("[LiveLayer] onScrollToSelector threw.",B)}return}if(typeof document<"u"){let B=null;try{B=document.querySelector(L)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${L}".`);return}if(!B){console.warn(`[LiveLayer] scroll_to: no element matched "${L}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}B.scrollIntoView({behavior:j,block:"start"})}return}if(f.type==="request_page_context"){if(!we("read_page")){ve("request_page_context","read_page");return}const L=typeof f.requestId=="string"?f.requestId:void 0,j=(K=Ee.current)==null?void 0:K.call(Ee),B=J=>{var be,Ct;if(J.type==="page_context"){const Ae=(Ct=(be=J.context)==null?void 0:be.flow)==null?void 0:Ct.currentStep;bi(typeof Ae=="number"?Ae:void 0)}const z=j,me=z==null?void 0:z.localParticipant;if(me!=null&&me.publishData)try{const Ae=L?{...J,requestId:L}:J,un=new TextEncoder().encode(JSON.stringify(Ae));me.publishData(un,{reliable:!0})}catch(Ae){console.warn("[LiveLayer] publishData failed.",Ae)}},W=Ln.current,Q=En.current;try{if(Q){const J=Q(W);if(J instanceof Promise){B({type:"page_context_pending"}),J.then(z=>B({type:"page_context",context:z})).catch(z=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",z),B({type:"page_context",context:vn(W)})});return}B({type:"page_context",context:J});return}B({type:"page_context",context:vn(W)})}catch(J){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",J),B({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:W}})}return}if(f.type==="scroll_page"){if(!we("scroll")){ve("scroll_page","scroll");return}const L=f.direction;if(L!=="up"&&L!=="down"&&L!=="top"&&L!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(L)}". Expected up | down | top | bottom.`);return}const j=f.behavior==="instant"?"instant":"smooth";if(on.current){try{on.current(L,j)}catch(z){console.warn("[LiveLayer] onScrollPage threw.",z)}return}if(typeof window>"u")return;const B={behavior:j},W=na(),Q=z=>{W instanceof Window?W.scrollBy({top:z,...B}):W.scrollBy({top:z,...B})},J=z=>{W instanceof Window?W.scrollTo({top:z,...B}):W.scrollTo({top:z,...B})};L==="up"?Q(-_r(W)):L==="down"?Q(_r(W)):J(L==="top"?0:ra(W));return}if(f.type==="click"){if(!we("click")){ve("click","click");return}const L=typeof f.selector=="string"?f.selector:null;if(!L){console.warn("[LiveLayer] click: missing selector.");return}if(sn.current){try{sn.current(L)}catch(B){console.warn("[LiveLayer] onClick threw.",B)}return}if(typeof document>"u")return;let j=null;try{j=document.querySelector(L)}catch{console.warn(`[LiveLayer] click: invalid selector "${L}".`);return}if(!j){console.warn(`[LiveLayer] click: no element matched "${L}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(j.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(ce=j.click)==null||ce.call(j);return}if(f.type==="advance_step"||f.type==="go_back"||f.type==="submit_flow"){if(!we("click")){ve(f.type,"click");return}if(typeof document>"u")return;const L=f.type==="advance_step"?"ll-advance":f.type==="go_back"?"ll-back":"ll-submit";let j=yr(L);if(j||(oi(document),j=yr(L)),!j){console.warn(`[LiveLayer] ${f.type}: no "${L}" control found.`);return}(je=j.click)==null||je.call(j);return}if(f.type==="fill_form"||f.type==="focus_field"){if(!we("fill_forms")){ve(f.type,"fill_forms");return}if(typeof document>"u")return;f.type==="fill_form"&&Nt.current.playConfirmation();const L=typeof f.formId=="string"?f.formId:null;if(!L){console.warn(`[LiveLayer] ${f.type}: missing formId.`);return}const j=Sr(document,L);if(!j){console.warn(`[LiveLayer] ${f.type}: no <form> matched id="${L}" (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(j.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 W=typeof f.fieldName=="string"?f.fieldName:null;if(!W){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const Q=Cr(j,W);if(Q.el===null){Q.reason==="private"?console.warn(`[LiveLayer] focus_field: field "${W}" is privacy-protected and not focusable.`):console.warn(`[LiveLayer] focus_field: no input matching key="${W}" in form "${L}". The agent should use the field.name it observed in PageContext.forms[].fields[].`);return}Q.el.focus();return}const B=f.values&&typeof f.values=="object"?f.values:null;if(!B){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[W,Q]of Object.entries(B)){if(typeof Q!="string")continue;const J=Cr(j,W);if(J.el===null){J.reason==="private"?console.warn(`[LiveLayer] fill_form: field "${W}" is privacy-protected (password / cc-* / data-ll-private). Skipping.`):console.warn(`[LiveLayer] fill_form: no input matching key="${W}" in form "${L}". The agent should use the field.name it observed in PageContext.forms[].fields[]. Skipping.`);continue}try{Js(J.el,Q)}catch(z){console.warn(`[LiveLayer] fill_form: failed to set "${W}".`,z)}}return}if(f.type==="submit_form"){if(!we("submit_forms")){ve("submit_form","submit_forms");return}if(typeof document>"u")return;const L=typeof f.formId=="string"?f.formId:null;if(!L){console.warn("[LiveLayer] submit_form: missing formId.");return}Nt.current.playConfirmation();const j=Sr(document,L);if(!j){console.warn(`[LiveLayer] submit_form: no <form> matched id="${L}" (or matching name / data-ll-intent slug).`);return}if(j.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 B=typeof f.requestId=="string"?f.requestId:void 0,W=(xt=Ee.current)==null?void 0:xt.call(Ee),Q=q=>{const G=W,se=G==null?void 0:G.localParticipant;if(se!=null&&se.publishData)try{const $e=B?{...q,requestId:B}:q,Je=new TextEncoder().encode(JSON.stringify($e));se.publishData(Je,{reliable:!0})}catch{}},J=q=>{var Je,Ht,Yn,Xn;const G=q,se=(Je=G.getAttribute)==null?void 0:Je.call(G,"aria-label");if(se)return se;const $e=G.id;if($e){const Ot=(Ht=j.ownerDocument)==null?void 0:Ht.querySelector(`label[for="${$e}"]`);if((Yn=Ot==null?void 0:Ot.textContent)!=null&&Yn.trim())return Ot.textContent.trim()}return((Xn=G.getAttribute)==null?void 0:Xn.call(G,"name"))||G.id||G.type||"field"},z=()=>{try{return Array.from(j.elements).filter(q=>"willValidate"in q&&q.willValidate&&!q.checkValidity()).map(q=>`${J(q)}: ${q.validationMessage}`)}catch{return[]}};if(typeof j.checkValidity=="function"&&!j.checkValidity()){try{(Ne=j.reportValidity)==null||Ne.call(j)}catch{}Q({type:"form_submit_blocked",formId:L,reason:"validation",invalidFields:z()});return}const me=q=>{var se;const G=(se=q.tagName)==null?void 0:se.toLowerCase();if(G==="textarea"||G==="select")return!0;if(G==="input"){const $e=(q.type||"text").toLowerCase();return!["hidden","submit","button","reset","file","image"].includes($e)}return!1},be=q=>{var se;const G=q;return((se=q.tagName)==null?void 0:se.toLowerCase())==="input"&&(G.type==="checkbox"||G.type==="radio")?G.checked?"on":"":(G.value||"").trim()},Ct=Array.from(j.elements).filter(q=>me(q)&&be(q).length>0),Ae=/(thank you|thanks|we'?ll be in touch|message sent|message has been sent|successfully|submission received|got your message|we received|talk soon|be in touch)/i,un=(((Un=j.parentElement)==null?void 0:Un.textContent)||"").toLowerCase();let Gn=!1,zt=!1;const De=q=>{zt||(zt=!0,Q(q))},Mi=()=>{const q=Date.now(),G=()=>{var Je;if(zt)return;const se=z();if(se.length>0){De({type:"form_submit_blocked",formId:L,reason:"validation",invalidFields:se});return}if(!j.isConnected){De({type:"form_submitted",formId:L,reason:"form_removed"});return}if(Ct.length>0&&Ct.every(Ht=>be(Ht).length===0)){De({type:"form_submitted",formId:L,reason:"form_reset"});return}const $e=(((Je=j.parentElement)==null?void 0:Je.textContent)||"").toLowerCase();if(Ae.test($e)&&!Ae.test(un)){De({type:"form_submitted",formId:L,reason:"success_text"});return}Date.now()-q<2e3?setTimeout(G,250):De({type:"form_submit_uncertain",formId:L,reason:"spa_prevented"})};setTimeout(G,200)},dn=q=>{Gn=!0,queueMicrotask(()=>{q.defaultPrevented?Mi():De({type:"form_submitted",formId:L})})};j.addEventListener("submit",dn,{once:!0});try{typeof j.requestSubmit=="function"?j.requestSubmit():j.submit()}catch(q){console.warn("[LiveLayer] submit_form: requestSubmit threw.",q),j.removeEventListener("submit",dn),De({type:"form_submit_blocked",formId:L,reason:"exception"});return}setTimeout(()=>{!Gn&&!zt&&(j.removeEventListener("submit",dn),De({type:"form_submit_blocked",formId:L,reason:"validation",invalidFields:z()}))},500);return}if(f.type==="request_routes"){if(!we("read_page")){ve("request_routes","read_page");return}const L=typeof f.requestId=="string"?f.requestId:void 0,B=(Vn=Ee.current)==null?void 0:Vn.call(Ee),W=B==null?void 0:B.localParticipant;if(!(W!=null&&W.publishData))return;const Q=z=>{try{const me=L?{type:"routes",routes:z,requestId:L}:{type:"routes",routes:z},be=new TextEncoder().encode(JSON.stringify(me));W.publishData(be,{reliable:!0})}catch(me){console.warn("[LiveLayer] request_routes: publishData failed.",me)}},J=Rn.current;if(J){try{const z=J(),me=be=>{if(!Array.isArray(be)){Q([]);return}Q(be.map(ci).slice(0,200))};z instanceof Promise?z.then(me).catch(be=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",be),Q(Ut())}):me(z)}catch(z){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",z),Q(Ut())}return}try{Q(Ut())}catch(z){console.warn("[LiveLayer] request_routes: extractRoutes threw.",z)}return}if(f.type==="task_field_updated"){if(!we("collect_data")){ve("task_field_updated","collect_data");return}const L={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:L}))}catch{}return}if(f.type==="task_completed"){if(!we("collect_data")){ve("task_completed","collect_data");return}const L=f.result;if(!L||typeof L!="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:L}}))}catch{}try{Le==null||Le(L)}catch(j){console.warn("[LiveLayer] onCollect threw.",j)}return}ia.has(f.type)||Ve==null||Ve(f)}},[Ve,Ze,Le]),oe=Lr({agentId:D?"__controlled__":bt,baseUrl:o,apiKey:i,sessionEndpoint:c,sessionBody:l,onDataMessage:D?void 0:vt});s.useEffect(()=>{if(D!=null&&D.subscribeToDataMessages)return D.subscribeToDataMessages(vt)},[D,vt]),Ee.current=()=>{var g;return(g=oe.getRoom)==null?void 0:g.call(oe)},s.useEffect(()=>{var K;if(typeof window>"u")return;const g=((K=window.location)==null?void 0:K.hostname)||"";if(g==="localhost"||g==="127.0.0.1"||g==="0.0.0.0"||g.endsWith(".local")||g.endsWith(".test"))return window.__livelayerSimulateCommand=ce=>{try{vt(ce)}catch(je){console.warn("[LiveLayer] simulate-command threw:",je)}},()=>{delete window.__livelayerSimulateCommand}},[vt]);const C=s.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:oe.getRoom,isControlled:!0}:{connectionState:oe.connectionState,agentState:oe.agentState,transcript:oe.transcript,videoElement:oe.videoElement,audioElement:oe.audioElement,canResume:oe.canResume,error:oe.error,agentConfig:oe.agentConfig,connect:oe.connect,disconnect:oe.disconnect,getRoom:oe.getRoom,isControlled:!1},[D,oe]),jn=s.useRef(C);jn.current=C;const An=s.useRef(D);An.current=D;const ln=s.useCallback(async g=>{var je,xt;const f=An.current;if(f!=null&&f.publishData){try{await f.publishData(g)}catch(Ne){console.warn("[AvatarWidget] sendData (controlled) failed:",Ne)}return}const K=(xt=(je=jn.current)==null?void 0:je.getRoom)==null?void 0:xt.call(je),ce=K==null?void 0:K.localParticipant;if(ce!=null&&ce.publishData)try{const Ne=new TextEncoder().encode(JSON.stringify(g));await ce.publishData(Ne,{reliable:!0})}catch(Ne){console.warn("[AvatarWidget] sendData failed:",Ne)}},[]);s.useImperativeHandle(n,()=>({sendData:async g=>ln(g)}),[ln]);const Tn=s.useRef(null);s.useEffect(()=>{const g=C.videoElement,f=Tn.current;if(!(!g||!f))return f.appendChild(g),()=>{g.parentNode===f&&f.removeChild(g)}},[C.videoElement]);const[st,Dt]=s.useState(!1);s.useEffect(()=>{if(!M){Dt(!0);return}C.agentState==="speaking"&&!st&&Dt(!0)},[M,C.agentState,st]),s.useEffect(()=>{if(!M)return;const g=C.connectionState;(g==="disconnected"||g==="idle")&&Dt(!1)},[M,C.connectionState]),s.useEffect(()=>{if(!M||!C.videoElement||st)return;const g=setTimeout(()=>Dt(!0),5e3);return()=>clearTimeout(g)},[M,C.videoElement,st]),s.useEffect(()=>{const g=C.videoElement;if(g){if(!M){g.style.filter="";return}g.style.transition="filter 500ms ease-out",g.style.filter=st?"":"blur(8px)"}},[M,C.videoElement,st]);const $t=s.useRef(new Map);s.useEffect(()=>{const g=C.audioElement;if(!g||$t.current.has(g))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(g),document.body.appendChild(f),$t.current.set(g,f),Ye.attach(g);const K=g.play();K&&typeof K.catch=="function"&&K.catch(ce=>{(ce==null?void 0:ce.name)==="NotAllowedError"&&rt(!0)})},[C.audioElement]),s.useEffect(()=>{const g=C.connectionState;if(!(g!=="disconnected"&&g!=="idle"&&g!=="error")){Ye.detach();for(const[f,K]of $t.current)f.parentNode===K&&K.removeChild(f),K.parentNode===document.body&&document.body.removeChild(K);$t.current.clear()}},[C.connectionState]);const ye=jr({gateUntilAgentReady:!0,agentState:C.agentState});s.useEffect(()=>{if(C.isControlled||C.connectionState!=="connected")return;const g=C.getRoom();if(g)return ye.setupMic(g).then(()=>{const f=ye.getMicStream();f&&Ye.attachStream(f,"mic")}).catch(()=>{}),()=>{Ye.detachSlot("mic"),ye.teardownMic()}},[C.isControlled,C.connectionState]),s.useEffect(()=>{var f;if(C.connectionState!=="connected")return;const g=C.isControlled?(f=D==null?void 0:D.getRoom)==null?void 0:f.call(D):C.getRoom();if(g)return _e.attachRoom(g),Xe.attachRoom(g),C.isControlled&&ye.attachRoom(g),ke.refresh(),()=>{_e.teardown(),Xe.teardown()}},[C.isControlled,C.connectionState,D]),s.useEffect(()=>{const g=C.audioElement;g&&(g.muted=tn)},[C.audioElement,tn]);const wi=s.useCallback(g=>{const f={type:"user_message",text:g};if(D!=null&&D.publishData){try{D.publishData(f)}catch{}return}const K=C.getRoom();if(K)try{const ce=new TextEncoder().encode(JSON.stringify(f));K.localParticipant.publishData(ce,{reliable:!0})}catch{}},[C,D]),vi=s.useCallback(()=>{gi(g=>!g)},[]);s.useEffect(()=>{Ue==null||Ue(C.connectionState),C.connectionState==="connected"?Oe==null||Oe():C.connectionState==="disconnected"&&(We==null||We())},[C.connectionState,Oe,We,Ue]),s.useEffect(()=>{Be==null||Be(C.transcript)},[C.transcript,Be]),s.useEffect(()=>{qe==null||qe(C.agentState)},[C.agentState,qe]),s.useEffect(()=>{Pt.setThinking(C.agentState==="thinking")},[C.agentState,Pt]);const In=s.useRef(!1);s.useEffect(()=>{!h||In.current||Ie&&C.connectionState==="idle"&&(In.current=!0,C.connect())},[h,C.connectionState,C,Ie]);const xi=s.useCallback(g=>{const f=v==null?void 0:v.find(K=>K.id===g);f&&(k(!1),g!==Me&&(Mt(!0),C.disconnect(),Ge||Zt(g),w==null||w(f)))},[v,Me,C,Ge,w]);s.useEffect(()=>{it&&C.connectionState==="connected"&&Mt(!1)},[C.connectionState,it]),s.useEffect(()=>{if(!ot)return;const g=f=>{f.key==="Escape"&&k(!1)};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[ot]);const Ci=!!Y||!!(ue!=null&&ue.avatarImageUrl)||C.isControlled,Ke=Mr(bt,o,Ci);Qe===void 0&&((Dn=Ke.info)!=null&&Dn.capabilities)&&(an.current=Ke.info.capabilities);const Si=C.agentState==="listening"||C.agentState==="speaking";Br({config:jt!==void 0?jt:(($n=Ke.info)==null?void 0:$n.pageVision)??null,connected:C.connectionState==="connected",pathname:yt,currentStep:yi,agentReady:Si,publishData:ln});const Ft=(ue==null?void 0:ue.name)??ie??((Fn=C.agentConfig)==null?void 0:Fn.name)??((zn=Ke.info)==null?void 0:zn.name)??"Live Layer",cn=(ue==null?void 0:ue.avatarImageUrl)??Y??((Hn=C.agentConfig)==null?void 0:Hn.avatarImageUrl)??((On=Ke.info)==null?void 0:On.avatarImageUrl)??null,_i=I??((Wn=C.agentConfig)==null?void 0:Wn.idleLoopUrl)??((Bn=Ke.info)==null?void 0:Bn.idleLoopUrl)??null,ki=$??null,Ei=s.useCallback(()=>Se("expanded"),[Se]),Li=s.useCallback(()=>Se("minimized"),[Se]),Mn=s.useCallback(()=>{C.disconnect(),Se("hidden")},[C,Se]),Ri=s.useCallback(()=>{const g=C.audioElement;g&&g.play().then(()=>rt(!1)).catch(()=>{})},[C.audioElement]),ji=s.useCallback(()=>{rt(!1),C.connect()},[C]),at={...Ce,...le?{}:{zIndex:Qt}};P.primaryColor&&(at["--ll-color-primary"]=P.primaryColor),P.accentColor&&(at["--ll-color-accent"]=P.accentColor),P.backgroundColor&&(at["--ll-color-bg"]=P.backgroundColor),P.textColor&&(at["--ll-color-fg"]=P.textColor);const Ai={...at,...Re.style},Ti=["ll-widget",`ll-widget--${fe}`,`ll-widget--${de?"mobile":"desktop"}`,Re.hasGeometry?"ll-widget--has-geometry":null,Re.isDragging?"is-dragging":null,Re.isResizing?"is-resizing":null,et].filter(Boolean).join(" ");if(!Ie)return null;const Ii=a.jsx("div",{className:Ti,style:Ai,"data-display-mode":fe,"data-position":S,"data-experience-mode":d==="EMBEDDED"?"embedded":"widget",children:fe==="expanded"&&a.jsx(bs,{position:S,isMobile:de,agentName:Ft,avatarImageUrl:cn,idleLoopUrl:_i,greeting:ki,branding:{...P,hideBranding:P.hideBranding??((qn=Ke.info)==null?void 0:qn.hideBranding)},teamMembers:v,currentTeamMemberId:Me,isSwitchingTeamMember:it,teamSwitcherOpen:ot,onToggleTeamSwitcher:()=>k(g=>!g),onSelectTeamMember:xi,connectionState:C.connectionState,agentState:C.agentState,transcript:C.transcript,isMuted:ye.isMuted,micDevices:ke.mics,activeMicId:ye.activeDeviceId,isCameraEnabled:_e.isEnabled,cameraPreviewEl:_e.previewEl,cameraDevices:ke.cameras,activeCameraId:_e.activeDeviceId,isScreenShareEnabled:Xe.isEnabled,screenPreviewEl:Xe.previewEl,isSpeakerMuted:tn,allowCamera:U,allowScreenShare:m,allowTyping:R,showMinimize:de&&!le?!1:Tt,showClose:It,chromeless:Z,compactControls:en,transforming:ne,transformingLabel:O,languageMenuOpen:re,onToggleLanguageMenu:()=>mi(g=>!g),needsUserGesture:Pe,canResume:C.canResume,micError:ye.micError,error:C.error,avatarVideoContainerRef:Tn,agentVideoEl:C.videoElement,onConnect:()=>{Promise.resolve(C.connect()).then(()=>{var f;const g=(f=C.getRoom)==null?void 0:f.call(C);g!=null&&g.startAudio&&g.canPlaybackAudio===!1&&g.startAudio().catch(()=>{})})},onDisconnect:()=>C.disconnect(),onRetry:ji,onResumeAudio:Ri,onToggleMute:ye.toggleMute,onSwitchMicDevice:g=>void ye.switchDevice(g),onToggleCamera:()=>void _e.toggle(),onSwitchCameraDevice:g=>void _e.switchDevice(g),onToggleScreenShare:()=>void Xe.toggle(),onToggleSpeaker:vi,onSendMessage:wi,onMinimize:Li,onClose:Mn,onClearMicError:ye.clearError,dragHandleProps:Re.dragHandleProps,resizeHandleProps:Re.resizeHandleProps})}),Pn=!le&&(fe==="hidden"||fe==="minimized")?a.jsxs("div",{className:["ll-widget","ll-widget--floating",`ll-widget--${fe}`,`ll-widget--${de?"mobile":"desktop"}`].join(" "),style:at,"data-display-mode":fe,"data-position":S,children:[fe==="hidden"&&a.jsx(as,{position:S,isMobile:de,isSpeaking:C.agentState==="speaking",onExpand:()=>Se("expanded"),label:`Open ${Ft} widget`,avatarImageUrl:cn,agentName:Ft,containerEl:F}),fe==="minimized"&&a.jsx(cs,{position:S,isMobile:de,agentName:Ft,avatarImageUrl:cn,agentState:C.agentState,isMuted:ye.isMuted,audioLevel:Ye,onExpand:Ei,onToggleMute:ye.toggleMute,onClose:Mn})]}):null,Nn=F??(typeof document<"u"?document.body:null);return a.jsxs(a.Fragment,{children:[Ii,Pn&&Nn&&Cn.createPortal(Pn,Nn)]})});fi.displayName="AvatarWidgetInner";const pi=s.forwardRef(function(t,n){return a.jsx(Er,{children:a.jsx(fi,{...t,ref:n})})});pi.displayName="AvatarWidget";const oa=({agentId:e,baseUrl:t,apiKey:n,mode:r,onAgentEvent:i,className:o,style:c})=>{const l=s.useRef(null),u=s.useRef(null),d=s.useRef(i);d.current=i;const h=s.useCallback(p=>{var T;const y=p.detail;(T=d.current)==null||T.call(d,y)},[]);return s.useEffect(()=>{const p=l.current;if(!p)return;const y=document.createElement("livelayer-widget");return y.setAttribute("agent-id",e),t&&y.setAttribute("base-url",t),n&&y.setAttribute("api-key",n),r&&y.setAttribute("mode",r),y.addEventListener("agent-event",h),p.appendChild(y),u.current=y,()=>{y.removeEventListener("agent-event",h),p.removeChild(y),u.current=null}},[e]),s.useEffect(()=>{u.current&&(r?u.current.setAttribute("mode",r):u.current.removeAttribute("mode"))},[r]),a.jsx("div",{ref:l,className:o,style:c})},sa=s.forwardRef(function({id:t,intent:n,as:r="div",className:i,style:o,children:c},l){return s.createElement(r,{ref:l,"data-ll-region":t,"data-ll-intent":n,className:i,style:o},c)});function aa(e={}){const{onFieldUpdate:t,onComplete:n,source:r="all"}=e,[i,o]=s.useState({}),[c,l]=s.useState(!1),[u,d]=s.useState(null),h=s.useRef(t),p=s.useRef(n),y=s.useRef(r);s.useEffect(()=>{h.current=t,p.current=n,y.current=r},[t,n,r]);const T=s.useCallback(()=>{o({}),l(!1)},[]);return s.useEffect(()=>{if(typeof window>"u")return;const S=_=>{var x,A;const b=_.detail;if(b){if(b.phase==="field"){if(y.current!=="all"&&b.source!==y.current)return;l(!0),o(E=>E[b.fieldName]===b.value?E:{...E,[b.fieldName]:b.value});try{(x=h.current)==null||x.call(h,b)}catch(E){console.warn("[LiveLayer] useCollect onFieldUpdate threw.",E)}return}if(b.phase==="complete"){const E=b.result;if(y.current!=="all"&&E.source!==y.current)return;d(E),l(!1);try{(A=p.current)==null||A.call(p,E)}catch(v){console.warn("[LiveLayer] useCollect onComplete threw.",v)}}}};return document.addEventListener("ll-collected",S),()=>document.removeEventListener("ll-collected",S)},[]),{fields:i,isCollecting:c,lastResult:u,reset:T}}let kr=1;function la({onMount:e,defaultOpen:t=!1,storageKey:n="ll-debug-open"}){const[r,i]=s.useState(t),[o,c]=s.useState([]),[l,u]=s.useState(""),[d,h]=s.useState(!1),p=s.useRef(new Set),y=s.useRef([]),T=s.useRef(d);T.current=d,s.useEffect(()=>{try{const b=localStorage.getItem(n);b==="1"&&i(!0),b==="0"&&i(!1)}catch{}},[n]),s.useEffect(()=>{try{localStorage.setItem(n,r?"1":"0")}catch{}},[r,n]),s.useEffect(()=>{const b=x=>{(x.metaKey||x.ctrlKey)&&x.shiftKey&&x.key.toLowerCase()==="l"&&(x.preventDefault(),i(A=>!A))};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[]),s.useEffect(()=>{const b=setInterval(()=>{if(y.current.length===0||T.current)return;const x=y.current.splice(0,y.current.length);c(A=>[...x.reverse(),...A].slice(0,200))},100);return()=>clearInterval(b)},[]);const S=s.useRef(!1);if(s.useEffect(()=>{!e||S.current||(S.current=!0,e(b=>{y.current.push({id:kr++,ts:Date.now(),kind:"event",type:b.eventName,data:b.data})}))},[e]),s.useEffect(()=>{const b=console.warn,x=console.log,A=(E,v)=>function(...N){try{const w=typeof N[0]=="string"?N[0]:"";w.startsWith("[LiveLayer]")&&y.current.push({id:kr++,ts:Date.now(),kind:E,type:w.slice(0,120),data:{args:N.slice(1).map(I=>ua(I))}})}catch{}return v.apply(this,N)};return console.warn=A("warn",b),console.log=A("log",x),()=>{console.warn=b,console.log=x}},[]),!r)return a.jsx("button",{type:"button",onClick:()=>i(!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 _=o.filter(b=>{if(!l)return!0;const x=l.toLowerCase();return b.type.toLowerCase().includes(x)||JSON.stringify(b.data||{}).toLowerCase().includes(x)});return a.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:[a.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:[a.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),a.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[o.length," event",o.length===1?"":"s"]}),a.jsx("span",{style:{flex:1}}),a.jsx("button",{type:"button",onClick:()=>h(b=>!b),style:yn(d?"#f59e0b":"transparent"),title:"Pause / resume capture",children:d?"▶ resume":"⏸ pause"}),a.jsx("button",{type:"button",onClick:()=>{c([]),y.current=[]},style:yn("transparent"),title:"Clear buffer",children:"clear"}),a.jsx("button",{type:"button",onClick:()=>i(!1),style:yn("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),a.jsx("input",{type:"text",value:l,onChange:b=>u(b.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"}}),a.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 8px 8px"},children:_.length===0?a.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:",a.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
4
  type: "navigate",
4
5
  href: "/about"
5
- })`})]}):S.map(b=>n.jsx(So,{entry:b,expanded:h.current.has(b.id),onToggle:()=>{h.current.has(b.id)?h.current.delete(b.id):h.current.add(b.id),c(w=>[...w])}},b.id))})]})}function So({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 nn(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 Eo(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Pr(e){const t=JSON.stringify(e);r.useEffect(()=>st.registerFields(e),[t])}function Lo({fields:e,children:t}){return Pr(e),n.jsx(n.Fragment,{children:t})}function jo(){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:()=>st.clearFieldRegistry});Object.defineProperty(exports,"getRegisteredFields",{enumerable:!0,get:()=>st.getRegisteredFields});Object.defineProperty(exports,"registerFields",{enumerable:!0,get:()=>st.registerFields});Object.defineProperty(exports,"setFieldValue",{enumerable:!0,get:()=>st.setFieldValue});exports.AvatarWidget=Tr;exports.ErrorBoundary=rr;exports.FieldProvider=Lo;exports.LiveLayerDebugPanel=ko;exports.LiveLayerRegion=_o;exports.LiveLayerWidget=wo;exports.clearPageContextCache=Ar;exports.clearRoutesCache=Mr;exports.extractPageContext=jr;exports.extractRoutes=Nr;exports.getCachedPageContext=on;exports.getCachedRoutes=Ft;exports.matchesPattern=yr;exports.normalizeRouteInput=Rr;exports.shouldRenderAtPath=br;exports.useAgentInfo=ur;exports.useAudioLevel=or;exports.useCameraState=ar;exports.useCollect=Co;exports.useDisplayMode=pr;exports.useDisplayModePersistence=hr;exports.useIsMobile=mr;exports.useLiveKitSession=ir;exports.useMediaDevices=cr;exports.useMicrophoneState=sr;exports.usePathname=gr;exports.useRegisterFields=Pr;exports.useRouteMatch=vr;exports.useScreenShareState=lr;exports.useTranscript=jo;
6
+ })`})]}):_.map(b=>a.jsx(ca,{entry:b,expanded:p.current.has(b.id),onToggle:()=>{p.current.has(b.id)?p.current.delete(b.id):p.current.add(b.id),c(x=>[...x])}},b.id))})]})}function ca({entry:e,expanded:t,onToggle:n}){const r=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",i=new Date(e.ts).toLocaleTimeString("en-US",{hour12:!1});return a.jsxs("button",{type:"button",onClick:n,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:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[a.jsx("span",{style:{color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums",fontSize:10},children:i}),a.jsx("span",{style:{color:r,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),t&&e.data&&a.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 yn(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 ua(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function hi(e){const t=JSON.stringify(e);s.useEffect(()=>ht.registerFields(e),[t])}function da({fields:e,children:t}){return hi(e),a.jsx(a.Fragment,{children:t})}function fa(){const[e,t]=s.useState([]),n=s.useCallback(i=>{t(o=>{const c=o.findIndex(l=>l.id===i.id);if(c>=0){const l=o.slice();return l[c]=i,l}return[...o,i]})},[]),r=s.useCallback(()=>t([]),[]);return{entries:e,pushSegment:n,clear:r,latest:e.length>0?e[e.length-1]:null}}Object.defineProperty(exports,"clearFieldRegistry",{enumerable:!0,get:()=>ht.clearFieldRegistry});Object.defineProperty(exports,"getRegisteredFields",{enumerable:!0,get:()=>ht.getRegisteredFields});Object.defineProperty(exports,"registerFields",{enumerable:!0,get:()=>ht.registerFields});Object.defineProperty(exports,"setFieldValue",{enumerable:!0,get:()=>ht.setFieldValue});exports.AvatarWidget=pi;exports.ErrorBoundary=Er;exports.FieldProvider=da;exports.LiveLayerDebugPanel=la;exports.LiveLayerRegion=sa;exports.LiveLayerWidget=oa;exports.clearPageContextCache=li;exports.clearRoutesCache=di;exports.extractPageContext=ai;exports.extractRoutes=ui;exports.getCachedPageContext=vn;exports.getCachedRoutes=Ut;exports.matchesPattern=Kr;exports.normalizeRouteInput=ci;exports.shouldRenderAtPath=Jr;exports.useAgentInfo=Mr;exports.useAudioLevel=Rr;exports.useCameraState=Ar;exports.useCollect=aa;exports.useDisplayMode=Vr;exports.useDisplayModePersistence=Gr;exports.useIsMobile=Yr;exports.useLiveKitSession=Lr;exports.useMediaDevices=Ir;exports.useMicrophoneState=jr;exports.usePageVision=Br;exports.usePathname=Xr;exports.useRegisterFields=hi;exports.useRouteMatch=Qr;exports.useScreenShareState=Tr;exports.useTranscript=fa;