@livelayer/react 0.23.4 → 0.24.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.d.ts CHANGED
@@ -82,6 +82,13 @@ export declare interface AgentInfo {
82
82
  * does the work).
83
83
  */
84
84
  autoPageContext?: boolean;
85
+ /**
86
+ * When true, hide the "Powered by LiveLayer" badge for this agent — set
87
+ * server-side for premium / white-label customers (e.g. derived from the
88
+ * owning organization's plan). The widget folds this into
89
+ * `branding.hideBranding`.
90
+ */
91
+ hideBranding?: boolean;
85
92
  }
86
93
 
87
94
  export declare interface AgentInfoHandle {
@@ -459,6 +466,12 @@ export declare interface BrandingConfig {
459
466
  accentColor?: string;
460
467
  backgroundColor?: string;
461
468
  textColor?: string;
469
+ /**
470
+ * Hide the "Powered by LiveLayer" badge (premium / white-label). The host may
471
+ * set this directly, or it's folded in from the server-derived
472
+ * `AgentInfo.hideBranding` (e.g. the owning org's plan) — see AvatarWidget.
473
+ */
474
+ hideBranding?: boolean;
462
475
  }
463
476
 
464
477
  export declare interface CameraStateHandle {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("react"),an=require("react-dom"),ot=require("@livelayer/sdk"),Ot=require("livekit-client");class nr 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 rr(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 ot.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 ir(){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 Jr(e){const t=e==null?void 0:e.mediaStreamTrack;return t?new MediaStream([t]):null}function or(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(()=>Jr(f.current),[]);return{isMuted:o,activeDeviceId:s,micError:l,toggleMute:S,setupMic:g,attachRoom:N,switchDevice:C,teardownMic:b,clearError:w,getMicStream:R}}const Zr={resolution:{width:640,height:480,frameRate:24}};function sr(){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={...Zr};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 ar(){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 lr(){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 cr(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 ur(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function dr(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function Qr(e){if(!(typeof window>"u"))try{window.localStorage.removeItem(e)}catch{}}function fr({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 ei=["hidden","minimized","expanded"];function ti(e){return e&&ei.includes(e)?e:null}function pr({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]=fr({value:e,defaultValue:t,onChange:f=>{e===void 0&&!a&&dr(s,f),i==null||i(f)}});return r.useEffect(()=>{if(c.current||(c.current=!0,a||e!==void 0))return;const f=ti(ur(s));f&&f!==l&&u(f)},[]),[l,u]}const ni=640;function hr(e=ni){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 ri=280,ii=380,oi=8,si=4;function Zt(e){return`${e}:geometry`}function ai(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 li(e){const{draggable:t,resizable:i,persistKey:o,disablePersistence:a,minWidth:s=ri,minHeight:c=ii,edgeMargin:l=oi}=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?Qr(Zt(o)):dr(Zt(o),JSON.stringify(p)))},[a,o]);r.useEffect(()=>{if(b.current||(b.current=!0,a))return;const p=ai(ur(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)>si&&(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 In="__llHistoryPatched",Bt="ll:pathname";function ci(){if(typeof window>"u"||window.history[In])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[In]=!0}function Tn(){return typeof window>"u"?"/":window.location.pathname||"/"}function mr(e){const[t,i]=r.useState(()=>e??Tn());return r.useEffect(()=>{if(e!==void 0)return;ci();const o=()=>i(Tn());return o(),window.addEventListener("popstate",o),window.addEventListener(Bt,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(Bt,o)}},[e]),e??t}const Pn=new Map,ui=/[\\^$+?.()|{}[\]]/g;function di(e){return e.replace(ui,"\\$&")}function fi(e){const t=Pn.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=di(s).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(a,"g"),"[^/]+"),u=new RegExp(`^${l}\\/?$`);return Pn.set(e,u),u}function pi(e,t){const i=t.length>1&&t.endsWith("/")?t.slice(0,-1):t;return fi(e).test(i)}function gr(e,t){return typeof e=="function"?e(t):e instanceof RegExp?e.test(t):pi(e,t)}function Dn(e,t){if(!e||e.length===0)return!1;for(const i of e)if(gr(i,t))return!0;return!1}function yr(e,t,i){return e===void 0?!0:Dn(i,e)?!1:t&&t.length>0?Dn(t,e):!0}function br(e,t,i){return r.useMemo(()=>yr(e,t,i),[e,t,i])}function hi(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 mi(e){const t=r.useMemo(()=>hi(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 zn=({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"})}),$n=({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"})}),gi=({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"})}),yi={left:180,right:0,up:-90,down:90},Hn=({direction:e="right",className:t})=>n.jsx("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${yi[e]}deg)`},"aria-hidden":"true",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function bi(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const vr="ll-hidden-tab-center-y",vi=5,Fn=16;function xi(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(vr);if(!e)return null;const t=Number.parseFloat(e);return Number.isFinite(t)?t:null}catch{return null}}function On(e){if(!(typeof window>"u"))try{window.localStorage.setItem(vr,String(e))}catch{}}const wi=({position:e,isMobile:t,isSpeaking:i,onExpand:o,label:a="Open widget",avatarImageUrl:s,agentName:c,containerEl:l})=>{const u=bi(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=Fn+U,j=window.innerHeight-Fn-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=xi();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)>vi&&(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&&On(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 On(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(Hn,{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(Hn,{direction:f,className:"ll-hidden__chevron"})})},_i=({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))})},Ci=({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(_i,{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(zn,{muted:s,className:"ll-minimized__icon"})}),n.jsx($n,{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(zn,{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($n,{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(gi,{className:"ll-minimized__icon"})})]})]})}),ki=({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)})},Si="#E06540";function Ei({size:e=14,className:t,fill:i=Si}){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 Li=8,Bn=8,ji=({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-Li,left:f.left+f.width/2},h=Bn+90,g=window.innerWidth-Bn-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)},Ai=({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(_r,{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(Ri,{})}),n.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:N,"aria-label":"End conversation",children:n.jsx(kr,{})})]}),n.jsxs(ji,{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(wr,{}),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(xr,{}),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(Cr,{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(Ni,{}),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 Ri(){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 Ni(){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 Mi=({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:st,onRetry:vt,onResumeAudio:xt,onToggleMute:at,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",[lt,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[ct,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(ct)return;const k=setTimeout(()=>le(!0),12e3);return()=>clearTimeout(k)},[_e,ct]);const kt=S==="connecting"||_e&&!ct&&!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",ut=!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,dt=_e&&(Ce==null?void 0:Ce.text)||null,ft=["ll-expanded",t?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return n.jsxs("div",{className:ft,"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(ki,{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":lt}),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(qn,{})}),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(Wn,{})})]})]}),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&&(ut?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(Ei,{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(qn,{})}),ee!==!1&&n.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Fe,"aria-label":"Close widget",children:n.jsx(Wn,{})})]})]}),_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&&dt&&n.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:n.jsx("p",{className:"ll-expanded__transcript-text",children:dt})}),!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(xr,{})}),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(wr,{})}),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(Un,{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:at,"aria-label":P?"Unmute microphone":"Mute microphone",title:P?"Unmute":"Mute",children:n.jsx(_r,{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(Un,{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(Cr,{muted:I})}),n.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:st,"aria-label":"End conversation",title:"End conversation",children:n.jsx(kr,{})})]}),!ne&&O&&n.jsx(Ai,{isMuted:P,onToggleMute:at,isCameraEnabled:G,onToggleCamera:Ue,allowCamera:F,isScreenShareEnabled:p,onToggleScreenShare:De,allowScreenShare:V,isSpeakerMuted:I,onToggleSpeaker:ze,allowTyping:Q,isTypingOpen:Lt,onToggleTyping:cn,onDisconnect:st}),!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(Ii,{})})]})]}):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 Wn(){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 qn(){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 xr(){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 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("path",{d:"M23 7l-7 5 7 5V7z"}),n.jsx("rect",{x:"1",y:"5",width:"15",height:"14",rx:"2"})]})}function _r({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 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("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 Ii(){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 kr(){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 Un=({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)},Ti=["[data-ll-private]","[data-ll-skip]",".ll-widget"];function Wt(e){let t=e;for(;t;){for(const i of Ti)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 Pi=/\b(continue|next|proceed|move\s*on|forward)\b|→|›/i,Vn=/\b(back|previous|prev|go\s*back)\b|←|‹/i,Di=/\b(submit|finish|done|complete|send)\b/i,bt=new Map;function Yn(e){const t=bt.get(e);return t&&t.isConnected?t:null}function nt(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 zi(e){return!!(e.disabled||e.getAttribute("aria-disabled")==="true")}function $i(e){return(e.innerText||e.textContent||e.getAttribute("aria-label")||e.value||"").trim()}function Hi(e){return Array.from(e.querySelectorAll('button, [role="button"], input[type="submit"], input[type="button"]')).filter(i=>!nt(i)&&!zi(i))}function Sr(e){bt.clear();const t=Hi(e);let i,o,a;for(const l of t){const u=$i(l);if(!u||u.length>40)continue;const f=l.getAttribute("type")==="submit"||l.tagName==="BUTTON"&&!l.getAttribute("type")&&!!l.closest("form");!i&&Pi.test(u)&&!Vn.test(u)?(i={id:"ll-advance",label:u},bt.set("ll-advance",l)):!o&&Vn.test(u)?(o={id:"ll-back",label:u},bt.set("ll-back",l)):!a&&(Di.test(u)||f)&&(a={id:"ll-submit",label:u},bt.set("ll-submit",l))}const s=Vi(e);return{kind:i||s.totalSteps?"multi-step":"single-page",advance:i,back:o,submit:a,...s}}const Fi=60;function Er(e){return e.replace(/^\s*(step\s+)?\d{1,2}(?:[.):\-]+\s*|\s+)/i,"").replace(/\s+/g," ").trim().slice(0,Fi)}function Oi(e){const t=e.getAttribute("class");return t?t.toLowerCase():""}const Bi=/stepper|wizard|ant-steps|step-indicator/;function Wi(e){return Bi.test(Oi(e))}function Gn(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 qi='[aria-current="step"],[aria-current="true"],[class*="active"],[class*="Active"],[class*="current"],[class*="Current"],[class*="selected"],[class*="Selected"]';function Ui(e){return Gn(e)?!0:Array.from(e.querySelectorAll(qi)).some(Gn)}function Xn(e,t){const i=Er(e[t].innerText||e[t].textContent||"");return{totalSteps:e.length,currentStep:t+1,...i?{stepLabel:i}:{}}}function Vi(e){const t=e.querySelector('[aria-current="step"]');if(t&&t.parentElement&&!nt(t)){const a=Array.from(t.parentElement.children).filter(c=>c.tagName===t.tagName&&!nt(c)),s=a.indexOf(t);if(s>=0&&a.length>=2)return Xn(a,s)}const i=e.querySelector('[role="progressbar"]');if(i&&!nt(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:Er(c)}:{}}}}const o=Array.from(e.querySelectorAll('[class*="step"], [class*="Step"], [class*="wizard"], [class*="Wizard"]')).filter(a=>!nt(a)&&Wi(a));for(const a of o){const s=Array.from(a.children).filter(l=>!nt(l)&&(l.textContent||"").trim().length>0);if(s.length<2||s.length>12)continue;const c=s.findIndex(Ui);if(!(c<0))return Xn(s,c)}return{}}const Ht=4096,Yi=20,Gi=20,Xi=10,Ki=10,Ji=30,Zi=20,Kn=500,Qi=['[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 Qi)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 Jn(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 eo(e){return e&&e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function to(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 tt(e){return e.length}function Lr(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>=Xi)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(),Kn*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,Kn))}const g=u.join(`
2
- `),N=[],C=Array.from(i.querySelectorAll("a[href]"));for(const v of C){if(N.length>=Yi)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>=Gi)break;if(gt(v)||!rn(v)||!yt(v))continue;const M=Jn(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>=Ki)break;if(Wt(v)||v.matches(".ll-widget *, .ll-widget"))continue;const M=v.getAttribute("id")||v.getAttribute("name")||eo(v.getAttribute("data-ll-intent"))||`form_${E++}`,z=v.getAttribute("data-ll-intent")||to(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>=Ji)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=Jn(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>=Zi)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:Sr(i),extras:e};let P=tt(JSON.stringify(x.regions))+tt(x.visibleText)+tt(JSON.stringify(x.visibleLinks))+tt(JSON.stringify(x.visibleFields));for(;P>Ht&&x.visibleFields.length>0;)x.visibleFields.pop(),P=tt(JSON.stringify(x.visibleFields));for(;P>Ht&&x.visibleLinks.length>0;)x.visibleLinks.pop(),P-=80;return tt(x.visibleText)>Ht&&(x.visibleText=ae(x.visibleText,Ht-100)),x}let rt=null;function no(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?no(o):""}`;if(rt&&rt.key===c&&i-rt.at<1e3)return rt.ctx;const l=Lr(e,t);return rt={key:c,at:i,ctx:l},l}function jr(){rt=null}const ro=200;function Ar(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 io(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function Rr(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>=ro)break;if(Wt(c))continue;const l=c.getAttribute("href")||"";if(!io(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 it=null;const oo=5e3;function Ft(){const e=Date.now(),t=typeof window<"u"&&window.location.pathname||"/";if(it&&it.pathname===t&&e-it.at<oo)return it.routes;const i=Rr();return it={at:e,pathname:t,routes:i},i}function Nr(){it=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 so(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 ao(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 lo(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(ao(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 co(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=so(s,o);let l=c;if(a.has(c)&&(l=`${c}__${o}`),l===t)return s;a.set(c,s),o++}return lo(e,t)}function Zn(e,t){const i=co(e,t);return i?rn(i)?{el:i}:{el:null,reason:"private"}:{el:null,reason:"not_found"}}function uo(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 fo(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}uo(e,t),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),a&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function Qn(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&&po(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 po(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function ho(){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 mo(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function go(){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(!mo(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 yo(){if(typeof window>"u")return null;if(ho())return window;const e=go();return e||window}function er(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function bo(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 vo=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"]),Mr=r.forwardRef(function(t,i){var xn,wn,_n,Cn,kn,Sn,En;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:st,pageContextExtras:vt,getRoutes:xt,onScrollPage:at,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=mr(we),lt=br(_t,fe,X);r.useEffect(()=>{jr(),Nr()},[_t]);const je=P!==void 0,[ct,Ct]=r.useState(()=>{var m;return P??((m=x==null?void 0:x[0])==null?void 0:m.id)}),We=je?P:ct,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=hr(S),[Xe,Ke]=pr({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=li({draggable:!ce&&(b??!me),resizable:!ce&&(w??!me),persistKey:R,disablePersistence:ce||E}),Ae=ir(),Se=sr(),Re=ar(),ut=lr(),[Ne,Ce]=r.useState(!1),[Je,dt]=r.useState(!1),[ft,Ze]=r.useState(!1),[k,re]=r.useState(!1),[qt,Pr]=r.useState(!1),jt=mi({baseUrl:s,config:u}),At=r.useRef(jt);At.current=jt;const Ut=r.useRef(te),Vt=r.useRef(Le),Yt=r.useRef(at),Gt=r.useRef(wt),un=r.useRef(st),dn=r.useRef(vt),fn=r.useRef(xt),Xt=r.useRef(Ue),ke=r.useRef(null);Ut.current=te,Vt.current=Le,Yt.current=at,Gt.current=wt,un.current=st,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 pt=r.useCallback(m=>{var K,ue,Ee,mt,Me,Ln,jn;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=yo(),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(-er(B)):L==="down"?J(er(B)):Z(L==="top"?0:bo(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=Yn(L);if(A||(Sr(document),A=Yn(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=Qn(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=Zn(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=Zn(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{fo(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=Qn(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,Nn,Mn;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((Nn=Dt==null?void 0:Dt.textContent)!=null&&Nn.trim())return Dt.textContent.trim()}return((Mn=Y.getAttribute)==null?void 0:Mn.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),An=/(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,Xr=(((Ln=A.parentElement)==null?void 0:Ln.textContent)||"").toLowerCase();let Rn=!1,Tt=!1;const Ie=q=>{Tt||(Tt=!0,J(q))},Kr=()=>{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(An.test(Te)&&!An.test(Xr)){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=>{Rn=!0,queueMicrotask(()=>{q.defaultPrevented?Kr():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(()=>{!Rn&&!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=(jn=ke.current)==null?void 0:jn.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(Ar).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}vo.has(d.type)||Ye==null||Ye(d)}},[Ye,Fe,Oe]),oe=rr({agentId:D?"__controlled__":kt,baseUrl:s,apiKey:a,sessionEndpoint:c,sessionBody:l,onDataMessage:D?void 0:pt});r.useEffect(()=>{if(D!=null&&D.subscribeToDataMessages)return D.subscribeToDataMessages(pt)},[D,pt]),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{pt(ue)}catch(Ee){console.warn("[LiveLayer] simulate-command threw:",Ee)}},()=>{delete window.__livelayerSimulateCommand}},[pt]);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=or({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),ut.refresh(),()=>{Se.teardown(),Re.teardown()}},[_.isControlled,_.connectionState,D]),r.useEffect(()=>{const m=_.audioElement;m&&(m.muted=qt)},[_.audioElement,qt]);const Dr=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]),zr=r.useCallback(()=>{Pr(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||lt&&_.connectionState==="idle"&&(gn.current=!0,_.connect())},[y,_.connectionState,_,lt]);const $r=r.useCallback(m=>{const d=x==null?void 0:x.find(K=>K.id===m);d&&(Ze(!1),m!==We&&(dt(!0),_.disconnect(),je||Ct(m),v==null||v(d)))},[x,We,_,je,v]);r.useEffect(()=>{Je&&_.connectionState==="connected"&&dt(!1)},[_.connectionState,Je]),r.useEffect(()=>{if(!ft)return;const m=d=>{d.key==="Escape"&&Ze(!1)};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[ft]);const Hr=!!G||!!(le!=null&&le.avatarImageUrl)||_.isControlled,ht=cr(kt,s,Hr);Ue===void 0&&((xn=ht.info)!=null&&xn.capabilities)&&(Xt.current=ht.info.capabilities);const Mt=(le==null?void 0:le.name)??ie??((wn=_.agentConfig)==null?void 0:wn.name)??((_n=ht.info)==null?void 0:_n.name)??"Live Layer",Kt=(le==null?void 0:le.avatarImageUrl)??G??((Cn=_.agentConfig)==null?void 0:Cn.avatarImageUrl)??((kn=ht.info)==null?void 0:kn.avatarImageUrl)??null,Fr=M??((Sn=_.agentConfig)==null?void 0:Sn.idleLoopUrl)??((En=ht.info)==null?void 0:En.idleLoopUrl)??null,Or=z??null,Br=r.useCallback(()=>ge("expanded"),[ge]),Wr=r.useCallback(()=>ge("minimized"),[ge]),yn=r.useCallback(()=>{_.disconnect(),ge("hidden")},[_,ge]),qr=r.useCallback(()=>{const m=_.audioElement;m&&m.play().then(()=>Ce(!1)).catch(()=>{})},[_.audioElement]),Ur=r.useCallback(()=>{Ce(!1),_.connect()},[_]),et={...Ge,...ce?{}:{zIndex:_e}};T.primaryColor&&(et["--ll-color-primary"]=T.primaryColor),T.accentColor&&(et["--ll-color-accent"]=T.accentColor),T.backgroundColor&&(et["--ll-color-bg"]=T.backgroundColor),T.textColor&&(et["--ll-color-fg"]=T.textColor);const Vr={...et,...be.style},Yr=["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(!lt)return null;const Gr=n.jsx("div",{className:Yr,style:Vr,"data-display-mode":de,"data-position":C,"data-experience-mode":f==="EMBEDDED"?"embedded":"widget",children:de==="expanded"&&n.jsx(Mi,{position:C,isMobile:me,agentName:Mt,avatarImageUrl:Kt,idleLoopUrl:Fr,greeting:Or,branding:T,teamMembers:x,currentTeamMemberId:We,isSwitchingTeamMember:Je,teamSwitcherOpen:ft,onToggleTeamSwitcher:()=>Ze(m=>!m),onSelectTeamMember:$r,connectionState:_.connectionState,agentState:_.agentState,transcript:_.transcript,isMuted:ye.isMuted,micDevices:ut.mics,activeMicId:ye.activeDeviceId,isCameraEnabled:Se.isEnabled,cameraPreviewEl:Se.previewEl,cameraDevices:ut.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:Ur,onResumeAudio:qr,onToggleMute:ye.toggleMute,onSwitchMicDevice:m=>void ye.switchDevice(m),onToggleCamera:()=>void Se.toggle(),onSwitchCameraDevice:m=>void Se.switchDevice(m),onToggleScreenShare:()=>void Re.toggle(),onToggleSpeaker:zr,onSendMessage:Dr,onMinimize:Wr,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:et,"data-display-mode":de,"data-position":C,children:[de==="hidden"&&n.jsx(wi,{position:C,isMobile:me,isSpeaking:_.agentState==="speaking",onExpand:()=>ge("expanded"),label:`Open ${Mt} widget`,avatarImageUrl:Kt,agentName:Mt,containerEl:$}),de==="minimized"&&n.jsx(Ci,{position:C,isMobile:me,agentName:Mt,avatarImageUrl:Kt,agentState:_.agentState,isMuted:ye.isMuted,audioLevel:Ae,onExpand:Br,onToggleMute:ye.toggleMute,onClose:yn})]}):null,vn=$??(typeof document<"u"?document.body:null);return n.jsxs(n.Fragment,{children:[Gr,bn&&vn&&an.createPortal(bn,vn)]})});Mr.displayName="AvatarWidgetInner";const Ir=r.forwardRef(function(t,i){return n.jsx(nr,{children:n.jsx(Mr,{...t,ref:i})})});Ir.displayName="AvatarWidget";const xo=({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})},wo=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 _o(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 tr=1;function Co({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:tr++,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:tr++,ts:Date.now(),kind:E,type:v.slice(0,120),data:{args:P.slice(1).map(M=>So(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 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({
3
3
  type: "navigate",
4
4
  href: "/about"
5
- })`})]}):S.map(b=>n.jsx(ko,{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 ko({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 So(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Tr(e){const t=JSON.stringify(e);r.useEffect(()=>ot.registerFields(e),[t])}function Eo({fields:e,children:t}){return Tr(e),n.jsx(n.Fragment,{children:t})}function Lo(){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:()=>ot.clearFieldRegistry});Object.defineProperty(exports,"getRegisteredFields",{enumerable:!0,get:()=>ot.getRegisteredFields});Object.defineProperty(exports,"registerFields",{enumerable:!0,get:()=>ot.registerFields});Object.defineProperty(exports,"setFieldValue",{enumerable:!0,get:()=>ot.setFieldValue});exports.AvatarWidget=Ir;exports.ErrorBoundary=nr;exports.FieldProvider=Eo;exports.LiveLayerDebugPanel=Co;exports.LiveLayerRegion=wo;exports.LiveLayerWidget=xo;exports.clearPageContextCache=jr;exports.clearRoutesCache=Nr;exports.extractPageContext=Lr;exports.extractRoutes=Rr;exports.getCachedPageContext=on;exports.getCachedRoutes=Ft;exports.matchesPattern=gr;exports.normalizeRouteInput=Ar;exports.shouldRenderAtPath=yr;exports.useAgentInfo=cr;exports.useAudioLevel=ir;exports.useCameraState=sr;exports.useCollect=_o;exports.useDisplayMode=fr;exports.useDisplayModePersistence=pr;exports.useIsMobile=hr;exports.useLiveKitSession=rr;exports.useMediaDevices=lr;exports.useMicrophoneState=or;exports.usePathname=mr;exports.useRegisterFields=Tr;exports.useRouteMatch=br;exports.useScreenShareState=ar;exports.useTranscript=Lo;
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;