@livelayer/react 0.5.7 → 0.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),r=require("react"),kn=require("@livelayer/sdk"),Ge=require("livekit-client");class Ht extends r.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,i){var o,s;(s=(o=this.props).onError)==null||s.call(o,n,i)}render(){var n;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[t.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),t.jsx("p",{className:"ll-error-boundary__message",children:((n=this.state.error)==null?void 0:n.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function Ot(e){const[n,i]=r.useState("idle"),[o,s]=r.useState("idle"),[l,u]=r.useState([]),[d,p]=r.useState(null),[y,g]=r.useState(null),[a,c]=r.useState(null),[j,S]=r.useState(!1),[k,x]=r.useState(null),v=r.useRef(null),I=r.useRef(e.onDataMessage);I.current=e.onDataMessage,r.useEffect(()=>{const C={onConnectionStateChange:A=>{i(A),A==="connected"&&x(null)},onAgentStateChange:s,onTranscript:A=>u([...A]),onAgentConfig:p,onAudioTrack:A=>c(A),onVideoTrack:A=>g(A),onVideoTrackRemoved:()=>g(null),onError:A=>x(A),onDataMessage:A=>{var L;(L=I.current)==null||L.call(I,A)},onResumabilityChange:S},$=new kn.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},C);return v.current=$,i("idle"),s("idle"),u([]),p(null),g(null),c(null),S(!1),x(null),()=>{var A;(A=$.destroy)==null||A.call($),v.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=r.useCallback(async()=>{const C=v.current;if(C)try{await C.connect()}catch($){throw x($ instanceof Error?$.message:String($)),$}},[]),T=r.useCallback(()=>{const C=v.current;C&&C.disconnect()},[]),h=r.useCallback(()=>{var C;return((C=v.current)==null?void 0:C.getRoom())??null},[]);return{connectionState:n,agentState:o,transcript:l,agentConfig:d,videoElement:y,audioElement:a,canResume:j,error:k,connect:E,disconnect:T,getRoom:h,session:v.current}}function qt(){const e=r.useRef(null),n=r.useRef(null),i=r.useRef(null),o=r.useRef(null),s=r.useRef(new Set),l=r.useRef(null),u=r.useCallback(()=>{const a=n.current;if(!a){o.current=null;return}(!l.current||l.current.length!==a.frequencyBinCount)&&(l.current=new Uint8Array(new ArrayBuffer(a.frequencyBinCount)));const c=l.current;a.getByteFrequencyData(c);let j=0;for(let k=0;k<c.length;k++)j+=c[k];const S=j/c.length/255;for(const k of s.current)try{k(S)}catch(x){console.error("[useAudioLevel] subscriber threw:",x)}o.current=requestAnimationFrame(u)},[]),d=r.useCallback(()=>{if(e.current||typeof window>"u"||typeof AudioContext>"u")return;const a=new AudioContext,c=a.createAnalyser();c.fftSize=64,c.connect(a.destination),e.current=a,n.current=c},[]),p=r.useCallback(a=>{if(d(),!(!e.current||!n.current)){if(i.current){try{i.current.disconnect()}catch{}i.current=null}try{const c=e.current.createMediaElementSource(a);c.connect(n.current),i.current=c}catch(c){console.warn("[useAudioLevel] createMediaElementSource failed:",c);return}o.current===null&&(o.current=requestAnimationFrame(u))}},[d,u]),y=r.useCallback(()=>{if(o.current!==null&&(cancelAnimationFrame(o.current),o.current=null),i.current){try{i.current.disconnect()}catch{}i.current=null}},[]),g=r.useCallback(a=>(s.current.add(a),()=>{s.current.delete(a)}),[]);return r.useEffect(()=>()=>{if(y(),n.current){try{n.current.disconnect()}catch{}n.current=null}if(e.current){try{e.current.close()}catch{}e.current=null}s.current.clear(),l.current=null},[y]),{attach:p,detach:y,subscribe:g}}function Bt(){const[e,n]=r.useState(!1),[i,o]=r.useState(null),s=r.useRef(null),l=r.useRef(null),u=r.useCallback(async g=>{if(s.current&&l.current){try{await l.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}l.current=g,o(null);try{const a=await Ge.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await g.localParticipant.publishTrack(a),s.current=a,n(a.isMuted)}catch(a){const c=a instanceof Error&&a.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw o(c),a}},[]),d=r.useCallback(()=>{const g=s.current;g&&(g.isMuted?(g.unmute(),n(!1)):(g.mute(),n(!0)))},[]),p=r.useCallback(()=>{const g=s.current,a=l.current;if(g&&a){try{a.localParticipant.unpublishTrack(g)}catch{}g.stop()}s.current=null,l.current=null,n(!1)},[]),y=r.useCallback(()=>o(null),[]);return{isMuted:e,micError:i,toggleMute:d,setupMic:u,teardownMic:p,clearError:y}}const Sn={resolution:{width:640,height:480,frameRate:24}};function Wt(){const[e,n]=r.useState(!1),[i,o]=r.useState(null),[s,l]=r.useState(null),[u,d]=r.useState(""),p=r.useRef(null),y=r.useRef(null),g=r.useCallback(v=>{p.current=v},[]),a=r.useCallback(()=>{const v=p.current,I=y.current;if(I&&v){const E=v.localParticipant.getTrackPublication(Ge.Track.Source.Camera);if(E!=null&&E.track){try{v.localParticipant.unpublishTrack(E.track)}catch{}E.track.stop()}else I.stop()}y.current=null,l(null),n(!1)},[]),c=r.useCallback(async v=>{const I=p.current;if(I){o(null);try{const E={...Sn};v&&(E.deviceId=v);const T=await Ge.createLocalVideoTrack(E);await I.localParticipant.publishTrack(T),y.current=T;const h=T.attach();l(h),n(!0),v&&d(v);try{I.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const T=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";o(T)}}},[]),j=r.useCallback(async()=>{e?a():await c(u||void 0)},[e,u,a,c]),S=r.useCallback(async v=>{a(),await c(v)},[a,c]),k=r.useCallback(()=>{a(),p.current=null,o(null),d("")},[a]),x=r.useCallback(()=>o(null),[]);return r.useEffect(()=>()=>{y.current&&y.current.stop()},[]),{isEnabled:e,error:i,previewEl:s,activeDeviceId:u,toggle:j,switchDevice:S,attachRoom:g,teardown:k,clearError:x}}function Ft(){const[e,n]=r.useState(!1),[i,o]=r.useState(null),[s,l]=r.useState(null),u=r.useRef(null),d=r.useCallback(c=>{u.current=c},[]),p=r.useCallback(()=>l(null),[]),y=r.useCallback(async()=>{const c=u.current;if(c){if(e){try{await c.localParticipant.setScreenShareEnabled(!1)}catch{}p(),n(!1);return}o(null);try{await c.localParticipant.setScreenShareEnabled(!0);let j=0;const S=()=>{const k=c.localParticipant.getTrackPublication(Ge.Track.Source.ScreenShare);if(k!=null&&k.track){const x=k.track.attach();l(x),n(!0);try{c.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}j++<10?setTimeout(S,100):n(!0)};S()}catch(j){const S=j instanceof Error?j.name:"";S!=="NotAllowedError"&&S!=="AbortError"&&o("Screen share unavailable. Try again."),n(!1)}}},[e,p]),g=r.useCallback(()=>{const c=u.current;if(c&&e)try{c.localParticipant.setScreenShareEnabled(!1)}catch{}p(),n(!1),o(null),u.current=null},[e,p]),a=r.useCallback(()=>o(null),[]);return{isEnabled:e,error:i,previewEl:s,toggle:y,attachRoom:d,teardown:g,clearError:a}}function Ut(){const[e,n]=r.useState([]),[i,o]=r.useState([]),s=r.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const l=await navigator.mediaDevices.enumerateDevices();n(l.filter(u=>u.kind==="audioinput")),o(l.filter(u=>u.kind==="videoinput"))}catch{}},[]);return r.useEffect(()=>{if(s(),typeof navigator>"u"||!navigator.mediaDevices)return;const l=()=>void s();return navigator.mediaDevices.addEventListener("devicechange",l),()=>navigator.mediaDevices.removeEventListener("devicechange",l)},[s]),{mics:e,cameras:i,refresh:s}}function Vt(e,n,i=!1){const[o,s]=r.useState(null),[l,u]=r.useState(null),[d,p]=r.useState(!i&&!!e);return r.useEffect(()=>{if(i||!e){p(!1);return}const y=new AbortController,g=n||"https://app.livelayer.studio";return p(!0),u(null),fetch(`${g}/api/widget/agent/${encodeURIComponent(e)}`,{signal:y.signal}).then(async a=>{if(!a.ok){const c=await a.json().catch(()=>({}));throw new Error(c.error||`HTTP ${a.status}`)}return a.json()}).then(a=>{y.signal.aborted||(s(a),p(!1))}).catch(a=>{y.signal.aborted||(u(a instanceof Error?a.message:"Agent lookup failed"),p(!1))}),()=>y.abort()},[e,n,i]),{info:o,error:l,loading:d}}function Cn(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Ln(e,n){if(!(typeof window>"u"))try{window.localStorage.setItem(e,n)}catch{}}function Yt({value:e,defaultValue:n="expanded",onChange:i}={}){const o=e!==void 0,[s,l]=r.useState(n),u=o?e:s,d=r.useCallback(p=>{p!==u&&(o||l(p),i==null||i(p))},[u,o,i]);return[u,d]}const jn=["hidden","minimized","expanded"];function En(e){return e&&jn.includes(e)?e:null}function Jt({value:e,defaultValue:n="expanded",onChange:i,persistKey:o="ll-widget",disablePersistence:s=!1}={}){const l=`${o}:display-mode`,u=r.useRef(!1),[d,p]=Yt({value:e,defaultValue:n,onChange:y=>{e===void 0&&!s&&Ln(l,y),i==null||i(y)}});return r.useEffect(()=>{if(u.current||(u.current=!0,s||e!==void 0))return;const y=En(Cn(l));y&&y!==d&&p(y)},[]),[d,p]}const Rn=640;function Kt(e=Rn){const[n,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)`,s=window.matchMedia(o),l=()=>i(s.matches);return l(),typeof s.addEventListener=="function"?(s.addEventListener("change",l),()=>s.removeEventListener("change",l)):(s.addListener(l),()=>{s.removeListener(l)})},[e]),n}const kt="__llHistoryPatched",Xe="ll:pathname";function Nn(){if(typeof window>"u"||window.history[kt])return;const e=window.history.pushState,n=window.history.replaceState;window.history.pushState=function(...i){const o=e.apply(this,i);return window.dispatchEvent(new Event(Xe)),o},window.history.replaceState=function(...i){const o=n.apply(this,i);return window.dispatchEvent(new Event(Xe)),o},window.history[kt]=!0}function St(){return typeof window>"u"?"/":window.location.pathname||"/"}function Gt(e){const[n,i]=r.useState(()=>e??St());return r.useEffect(()=>{if(e!==void 0)return;Nn();const o=()=>i(St());return o(),window.addEventListener("popstate",o),window.addEventListener(Xe,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(Xe,o)}},[e]),e??n}const Ct=new Map,An=/[\\^$+?.()|{}[\]]/g;function Mn(e){return e.replace(An,"\\$&")}function In(e){const n=Ct.get(e);if(n)return n;const i=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,o="",s="",l=i.replace(/\*\*/g,o).replace(/\*/g,s),d=Mn(l).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),p=new RegExp(`^${d}\\/?$`);return Ct.set(e,p),p}function Tn(e,n){const i=n.length>1&&n.endsWith("/")?n.slice(0,-1):n;return In(e).test(i)}function Xt(e,n){return typeof e=="function"?e(n):e instanceof RegExp?e.test(n):Tn(e,n)}function Lt(e,n){if(!e||e.length===0)return!1;for(const i of e)if(Xt(i,n))return!0;return!1}function Qt(e,n,i){return e===void 0?!0:Lt(i,e)?!1:n&&n.length>0?Lt(n,e):!0}function Zt(e,n,i){return r.useMemo(()=>Qt(e,n,i),[e,n,i])}const jt=({muted:e=!1,className:n})=>e?t.jsxs("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):t.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"})}),Et=({className:e})=>t.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})}),Pn=({className:e})=>t.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),Dn={left:180,right:0,up:-90,down:90},Rt=({direction:e="right",className:n})=>t.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${Dn[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function $n(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const en="ll-hidden-tab-center-y",zn=5,Nt=16;function Hn(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(en);if(!e)return null;const n=Number.parseFloat(e);return Number.isFinite(n)?n:null}catch{return null}}function At(e){if(!(typeof window>"u"))try{window.localStorage.setItem(en,String(e))}catch{}}const On=({position:e,isMobile:n,isSpeaking:i,onExpand:o,label:s="Open widget",avatarImageUrl:l,agentName:u})=>{const d=$n(e),p=d==="right"?"left":"right",y=n?80:72,g=!!l,[a,c]=r.useState(null),[j,S]=r.useState(!1),k=r.useRef(null),x=r.useRef(!1),v=r.useCallback(L=>{if(typeof window>"u")return L;const P=y/2,z=Nt+P,W=window.innerHeight-Nt-P;return W<z?Math.max(z,L):Math.max(z,Math.min(W,L))},[y]);r.useEffect(()=>{const L=Hn();c(v(L??window.innerHeight/2));const P=()=>{c(z=>z===null?null:v(z))};return window.addEventListener("resize",P),()=>window.removeEventListener("resize",P)},[v]);const I=r.useCallback(L=>{if(!(L.pointerType==="mouse"&&L.button!==0)&&a!==null){try{L.currentTarget.setPointerCapture(L.pointerId)}catch{}k.current={startClientY:L.clientY,startCenterY:a,moved:!1}}},[a]),E=r.useCallback(L=>{const P=k.current;if(!P)return;const z=L.clientY-P.startClientY;!P.moved&&Math.abs(z)>zn&&(P.moved=!0,S(!0)),P.moved&&c(v(P.startCenterY+z))},[v]),T=r.useCallback(L=>{const P=k.current;if(P){try{L.currentTarget.releasePointerCapture(L.pointerId)}catch{}k.current=null,P.moved&&(S(!1),x.current=!0,c(z=>(z!==null&&At(z),z)))}},[]),h=r.useCallback(()=>{if(x.current){x.current=!1;return}o()},[o]),C=r.useCallback(L=>{if(L.key==="ArrowUp"||L.key==="ArrowDown"){L.preventDefault();const P=L.key==="ArrowUp"?-8:8;c(z=>{if(z===null)return z;const W=v(z+P);return At(W),W})}},[v]),$=["ll-hidden",`ll-hidden--${d}`,n?"ll-hidden--mobile":"ll-hidden--desktop",i?"ll-hidden--speaking":null,j?"is-dragging":null,g?"ll-hidden--with-avatar":null].filter(Boolean).join(" "),A=a===null?void 0:{top:`${a-y/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:$,onPointerDown:I,onPointerMove:E,onPointerUp:T,onPointerCancel:T,onClick:h,onKeyDown:C,"aria-label":s,"data-position":e,style:A,children:g?t.jsxs(t.Fragment,{children:[t.jsx(Rt,{direction:p,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:l,alt:u?`${u} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Rt,{direction:p,className:"ll-hidden__chevron"})})},qn=({audioLevel:e,bars:n=20,maxHeight:i=20,minHeight:o=4,className:s,barClassName:l})=>{const u=r.useRef(null),d=r.useRef([]),p=r.useMemo(()=>{const g=(Math.sqrt(5)-1)/2;return Array.from({length:n},(a,c)=>.5+c*g%1*.5)},[n]);r.useEffect(()=>e.subscribe(a=>{for(let c=0;c<n;c++){const j=d.current[c];if(!j)continue;const S=Math.max(o,a*i*p[c]);j.style.height=`${S}px`}}),[e,n,i,o,p]);const y=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:u,className:y,"aria-hidden":"true",children:Array.from({length:n},(g,a)=>t.jsx("div",{ref:c=>{d.current[a]=c},className:["ll-waveform__bar",l].filter(Boolean).join(" "),style:{height:`${o}px`}},a))})},Bn=({position:e,isMobile:n,agentName:i,avatarImageUrl:o,agentState:s,isMuted:l,audioLevel:u,onExpand:d,onToggleMute:p,onClose:y})=>n?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${i} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:d,"aria-label":`Expand ${i} widget`,children:[o?t.jsx("img",{src:o,alt:i,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsx(qn,{audioLevel:u,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),t.jsx("span",{className:"ll-minimized__name",children:i}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:g=>{g.stopPropagation(),p()},onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.stopPropagation(),g.preventDefault(),p())},"aria-label":l?"Unmute microphone":"Mute microphone",children:t.jsx(jt,{muted:l,className:"ll-minimized__icon"})}),t.jsx(Et,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):t.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${i} widget`,children:t.jsxs("div",{className:"ll-minimized__surface",children:[o?t.jsx("img",{src:o,alt:i,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsxs("div",{className:"ll-minimized__meta",children:[t.jsx("span",{className:"ll-minimized__name",children:i}),t.jsx("span",{className:"ll-minimized__state",children:s==="speaking"?"Speaking":s==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:p,"aria-label":l?"Unmute microphone":"Mute microphone",children:t.jsx(jt,{muted:l,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:d,"aria-label":`Expand ${i} widget`,children:t.jsx(Et,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:y,"aria-label":"Close widget",children:t.jsx(Pn,{className:"ll-minimized__icon"})})]})]})}),Wn=({src:e,alt:n,preCannedPlaying:i=!1,className:o,style:s})=>{const[l,u]=r.useState(!1),d=r.useRef(e);if(r.useEffect(()=>{d.current!==e&&(d.current=e,u(!1))},[e]),!e)return null;const p={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:l?1:0,...s};return t.jsx("img",{src:e,alt:n,className:o,style:p,loading:"eager",fetchPriority:"high",onLoad:()=>u(!0)})},Fn=({position:e,isMobile:n,agentName:i,avatarImageUrl:o,idleLoopUrl:s,greeting:l,branding:u,teamMembers:d,currentTeamMemberId:p,isSwitchingTeamMember:y,teamSwitcherOpen:g,onToggleTeamSwitcher:a,onSelectTeamMember:c,languageMenuOpen:j,onToggleLanguageMenu:S,connectionState:k,agentState:x,transcript:v,canResume:I,needsUserGesture:E,error:T,isMuted:h,micError:C,micDevices:$,isCameraEnabled:A,cameraPreviewEl:L,cameraDevices:P,activeCameraId:z,isScreenShareEnabled:W,screenPreviewEl:X,isSpeakerMuted:le,allowCamera:$e,allowScreenShare:ze,allowTyping:He,avatarVideoContainerRef:Oe,onConnect:fe,onDisconnect:pe,onRetry:he,onResumeAudio:me,onToggleMute:ge,onToggleCamera:ye,onSwitchCameraDevice:be,onToggleScreenShare:xe,onToggleSpeaker:B,onSendMessage:qe,onMinimize:Be,onClose:We,onClearMicError:ae})=>{var _e;const re=v.length>0?v[v.length-1]:null,te=((d==null?void 0:d.length)??0)>1,ve=k==="connecting"||k==="connected",we=k==="connected",ce=k==="idle"||k==="disconnected"||k==="error",V=r.useRef(null),Ee=r.useRef(null);r.useEffect(()=>{const b=V.current;b&&(b.innerHTML="",L&&(L.style.width="100%",L.style.height="100%",L.style.objectFit="cover",L.style.transform="scaleX(-1)",b.appendChild(L)))},[L]),r.useEffect(()=>{const b=Ee.current;b&&(b.innerHTML="",X&&(X.style.width="100%",X.style.height="100%",X.style.objectFit="contain",b.appendChild(X)))},[X]);const[Q,G]=r.useState(!1),[ne,ie]=r.useState(!1);r.useEffect(()=>{if(!Q&&!ne&&!j&&!g)return;const b=()=>{G(!1),ie(!1),j&&S(),g&&a()};return document.addEventListener("click",b),()=>document.removeEventListener("click",b)},[Q,ne,j,g,S,a]);const[K,Z]=r.useState(""),ue=r.useCallback(b=>{b.preventDefault();const Y=K.trim();Y&&(qe(Y),Z(""))},[K,qe]),Re=u.productName||"Live Layer",Fe=we&&(re!=null&&re.text)?re.text:l||"",Ne=["ll-expanded",n?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:Ne,"data-position":e,"data-state":we?"connected":ve?"connecting":"idle",role:"dialog","aria-label":`${i} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[o?t.jsx(Wn,{src:o,alt:i,className:"ll-expanded__bg-img"}):t.jsx("div",{className:"ll-expanded__bg-fallback",children:t.jsx("span",{className:"ll-expanded__bg-initial",children:((_e=i==null?void 0:i.charAt(0))==null?void 0:_e.toUpperCase())||"A"})}),s&&!we&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:Oe,className:"ll-expanded__video"}),k==="connecting"&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--connecting",children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:y?"Switching...":"Connecting..."})]}),E&&we&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:me,children:[t.jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:t.jsx("path",{d:"M3 9v6h4l5 5V4L7 9H3zm13.54.12a5 5 0 0 1 0 5.76l-1.41-1.41a3 3 0 0 0 0-2.94L16.54 9.12z"})}),t.jsx("p",{className:"ll-expanded__overlay-text",children:"Tap to enable audio"})]}),ve?t.jsxs("div",{className:"ll-expanded__topbar",children:[t.jsxs("div",{className:"ll-expanded__topbar-left",children:[t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill",onClick:b=>{te&&(b.stopPropagation(),a())},"aria-haspopup":te?"listbox":void 0,"aria-expanded":te?g:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:i}),te&&t.jsx(Ye,{})]}),te&&g&&t.jsx("div",{className:"ll-hmenu",onClick:b=>b.stopPropagation(),role:"listbox",children:d==null?void 0:d.map(b=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${b.id===p?"is-active":""}`,onClick:()=>c(b.id),role:"option","aria-selected":b.id===p,children:[b.avatarImageUrl&&t.jsx("img",{src:b.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:b.name}),b.role&&t.jsx("span",{className:"ll-hmenu__role",children:b.role})]},b.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:b=>{b.stopPropagation(),S()},"aria-haspopup":"listbox","aria-expanded":j,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(Ye,{})]}),j&&t.jsx("div",{className:"ll-hmenu",onClick:b=>b.stopPropagation(),role:"listbox",children:t.jsx("button",{type:"button",className:"ll-hmenu__item is-active",role:"option","aria-selected":!0,children:t.jsx("span",{className:"ll-hmenu__name",children:"English"})})})]}),t.jsx("span",{className:`ll-expanded__state ll-expanded__state--${x}`,children:x})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn",onClick:Be,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(It,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:We,"aria-label":"End call",title:"End call",children:t.jsx(Mt,{})})]})]}):t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:Re}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:Be,"aria-label":"Minimize widget",children:t.jsx(It,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:We,"aria-label":"Close widget",children:t.jsx(Mt,{})})]})]}),ce&&(()=>{const b=I?"Restart paused session":k==="disconnected"?"Reconnect to agent":"Start video call",Y=I?"Pick up where you left off":null,Ae=k==="idle"&&!I&&!T;return t.jsxs(t.Fragment,{children:[Ae&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:fe,"aria-label":b,children:[t.jsx("div",{className:"ll-expanded__play-circle",children:t.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:t.jsx("polygon",{points:"6 3 20 12 6 21 6 3"})})}),t.jsx("span",{className:"ll-expanded__play-label",children:b})]}),t.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[l&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:l})}),Y&&t.jsx("p",{className:"ll-expanded__cta-sublabel",children:Y}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:fe,"aria-label":b,children:b})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${ve&&(A||W)?"is-visible":""}`,children:[t.jsx("div",{ref:Ee,className:W?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:V,className:!W&&A?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),ve?t.jsxs("div",{className:"ll-expanded__bottom",children:[Fe&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Fe})}),t.jsxs("div",{className:"ll-toolbar",onClick:b=>b.stopPropagation(),children:[ze&&t.jsx("button",{type:"button",className:`ll-tool ${W?"is-on":""}`,onClick:xe,"aria-label":W?"Stop sharing screen":"Share screen",title:W?"Stop sharing":"Share screen",children:t.jsx(Un,{})}),$e&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${A?"is-on":""}`,onClick:ye,"aria-label":A?"Turn off camera":"Turn on camera",title:A?"Stop camera":"Start camera",children:t.jsx(Vn,{})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${A?"is-on":""}`,onClick:b=>{b.stopPropagation(),ie(Y=>!Y),G(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":ne,children:t.jsx(Ye,{})}),ne&&P.length>0&&t.jsx(Tt,{label:"Camera",devices:P,activeId:z,onPick:b=>{ie(!1),be(b)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${h?"is-muted":""}`,onClick:ge,"aria-label":h?"Unmute microphone":"Mute microphone",title:h?"Unmute":"Mute",children:t.jsx(Yn,{muted:h})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${h?"is-muted":""}`,onClick:b=>{b.stopPropagation(),G(Y=>!Y),ie(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":Q,children:t.jsx(Ye,{})}),Q&&$.length>0&&t.jsx(Tt,{label:"Microphone",devices:$,activeId:"",onPick:()=>G(!1)})]}),t.jsx("button",{type:"button",className:`ll-tool ${le?"is-muted":""}`,onClick:B,"aria-label":le?"Unmute speaker":"Mute speaker",title:le?"Unmute speaker":"Mute speaker",children:t.jsx(Jn,{muted:le})})]}),He&&t.jsxs("form",{className:"ll-message-input",onSubmit:ue,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:K,onChange:b=>Z(b.target.value),"aria-label":"Message the agent"}),K.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(Kn,{})})]}),t.jsx("button",{type:"button",className:"ll-expanded__end",onClick:pe,children:"End conversation"})]}):null,(()=>{if(C&&k!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:C}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:ae,"aria-label":"Dismiss",children:"×"})]});if(!T||k!=="error")return null;let b="Failed to connect",Y="Try again";return T==="MIC_PERMISSION_DENIED"?b="Microphone blocked. Allow access to talk.":T==="MIC_NOT_FOUND"?b="No microphone found. Plug one in + retry.":T==="MIC_UNAVAILABLE"?b="Mic unavailable. Check other apps using it.":T==="AGENT_TIMEOUT"?b="Agent didn't pick up. Try again.":T==="CONNECT_FAILED"?b="Connection failed. Check your network.":T.length<80&&(b=T),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:b}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:he,children:Y})]})})()]})};function Ye(){return t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":!0,children:t.jsx("polyline",{points:"6 9 12 15 18 9"})})}function Mt(){return t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function It(){return t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function Un(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),t.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),t.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function Vn(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M23 7l-7 5 7 5V7z"}),t.jsx("rect",{x:"1",y:"5",width:"15",height:"14",rx:"2"})]})}function Yn({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),t.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),t.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),e&&t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Jn({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e?t.jsx("line",{x1:"23",y1:"9",x2:"17",y2:"15"}):t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"}),t.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]})]})}function Kn(){return t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),t.jsx("polyline",{points:"12 5 19 12 12 19"})]})}const Tt=({label:e,devices:n,activeId:i,onPick:o})=>t.jsxs("div",{className:"ll-device-menu",onClick:s=>s.stopPropagation(),role:"listbox",children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),n.map((s,l)=>{const u=i===s.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${u?"is-active":""}`,onClick:()=>o(s.deviceId),role:"option","aria-selected":u,children:[u&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:s.label||`${e} ${l+1}`})]},s.deviceId||l)})]}),Gn=['[data-ll-private="true"]',".ll-widget"];function at(e){let n=e;for(;n;){for(const i of Gn)if(n.matches(i))return!0;n=n.parentElement}return!1}function Qe(e){if(at(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const n=(e.getAttribute("autocomplete")||"").toLowerCase();if(n==="off"||n.startsWith("cc-"))return!1}return!0}const Je=4096,Xn=20,Qn=20,Zn=10,er=10,tr=30,Pt=500,nr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function Pe(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let n=e;for(;n;){for(const i of nr)if(n.matches(i))return!0;n=n.parentElement}return!1}function De(e){if(typeof window>"u")return!0;const n=e.getBoundingClientRect();if(n.width<=0||n.height<=0)return!1;const i=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth;return n.bottom>0&&n.right>0&&n.top<i&&n.left<o}function Dt(e){const n=e.getAttribute("id");if(n){const l=document.querySelector(`label[for="${CSS.escape(n)}"]`);if(l!=null&&l.textContent)return l.textContent.trim()}const i=e.getAttribute("aria-label");if(i)return i.trim();const o=e.getAttribute("placeholder");if(o)return o.trim();const s=e.closest("label");return s!=null&&s.textContent?s.textContent.trim():""}function de(e,n){return e.length<=n?e:e.slice(0,n-1)+"…"}function Ce(e){return e.length}function tn(e,n={}){const i=n.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||"",s=typeof window<"u"&&window.location.pathname||"/",l=i.title||"",u=Array.from(i.querySelectorAll("[data-ll-region]")),d=[];for(const h of u){if(d.length>=Zn)break;if(Pe(h)||!De(h))continue;const C=h.getAttribute("data-ll-region")??"",$=h.getAttribute("data-ll-intent")??void 0,A=de((h.innerText||h.textContent||"").trim(),Pt*2);!C||!A||d.push({id:C,intent:$,text:A})}const p=[],y=["H1","H2","H3","H4","H5","H6"],g=Array.from(i.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const h of g){if(Pe(h)||!De(h))continue;const C=(h.textContent||"").trim();C&&p.push(`${h.tagName}: ${de(C,200)}`)}const a=Array.from(i.querySelectorAll("p, li"));for(const h of a){if(Pe(h)||!De(h)||y.includes(h.tagName))continue;const C=(h.textContent||"").trim();C.length>10&&p.push(de(C,Pt))}const c=p.join(`
2
- `),j=[],S=Array.from(i.querySelectorAll("a[href]"));for(const h of S){if(j.length>=Xn)break;if(Pe(h)||!De(h))continue;const C=h.getAttribute("href")||"",$=(h.textContent||"").trim();!C||!$||j.push({href:C,text:de($,100)})}const k=[],x=Array.from(i.querySelectorAll("input, textarea, select"));for(const h of x){if(k.length>=Qn)break;if(Pe(h)||!Qe(h)||!De(h))continue;const C=Dt(h),$=h instanceof HTMLInputElement?h.type:h.tagName.toLowerCase();C&&k.push({label:de(C,100),type:$})}const v=Array.from(i.querySelectorAll("[data-ll-form]")),I=[];for(const h of v){if(I.length>=er)break;if(at(h))continue;const C=h.getAttribute("data-ll-form")||"";if(!C)continue;const $=h.getAttribute("data-ll-intent")||void 0,A=Array.from(h.querySelectorAll("[data-ll-field]")),L=[];for(const P of A){if(L.length>=tr)break;if(!Qe(P))continue;const z=P.getAttribute("data-ll-field")||"";if(!z)continue;const W=Dt(P)||z,X=P instanceof HTMLInputElement?P.type:P.tagName.toLowerCase();L.push({name:z,label:de(W,100),type:X})}I.push({id:C,intent:$,fields:L})}const E={url:o,title:l,pathname:s,regions:d,visibleText:c,visibleLinks:j,visibleFields:k,forms:I,extras:e};let T=Ce(JSON.stringify(E.regions))+Ce(E.visibleText)+Ce(JSON.stringify(E.visibleLinks))+Ce(JSON.stringify(E.visibleFields));for(;T>Je&&E.visibleFields.length>0;)E.visibleFields.pop(),T=Ce(JSON.stringify(E.visibleFields));for(;T>Je&&E.visibleLinks.length>0;)E.visibleLinks.pop(),T-=80;return Ce(E.visibleText)>Je&&(E.visibleText=de(E.visibleText,Je-100)),E}let Le=null;function lt(e,n={}){const i=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(Le&&Le.key===s&&i-Le.at<1e3)return Le.ctx;const l=tn(e,n);return Le={key:s,at:i,ctx:l},l}function nn(){Le=null}const rr=200;function rn(e){const n=String(e.href||"");return{href:n,text:String(e.text??e.title??n),internal:e.internal??!0,title:e.title,description:e.description}}function ir(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function on(e){const n=e??(typeof document<"u"?document:null);if(!n)return[];const i=typeof window<"u"&&window.location.origin||"",o=new Set,s=[],l=Array.from(n.querySelectorAll("a[href]"));for(const u of l){if(s.length>=rr)break;if(at(u))continue;const d=u.getAttribute("href")||"";if(!ir(d))continue;let p=d,y=!0;try{if(typeof window<"u"){const a=new URL(d,i);y=a.origin===i,y&&d.startsWith("http")&&(p=a.pathname+a.search+a.hash)}}catch{continue}if(o.has(p))continue;o.add(p);const g=(u.textContent||"").trim().slice(0,120);s.push({href:p,text:g,internal:y})}return s}let je=null;const or=5e3;function Ke(){const e=Date.now(),n=typeof window<"u"&&window.location.pathname||"/";if(je&&je.pathname===n&&e-je.at<or)return je.routes;const i=on();return je={at:e,pathname:n,routes:i},i}function sn(){je=null}function sr(e,n){const i=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,o=Object.getOwnPropertyDescriptor(i,"value"),s=o==null?void 0:o.set;s?s.call(e,n):e.value=n}function lr(e,n,i={}){const o=i.triggerInput??!0,s=i.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const l=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),u=l==null?void 0:l.set,d=n==="true"||n==="1"||n==="on";u?u.call(e,d):e.checked=d,o&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}sr(e,n),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function ar(){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 n=window.getComputedStyle(e);return!(n.overflowY==="hidden"||n.overflowY==="clip")}function cr(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function ur(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let n=null,i=0;for(const o of e){if(!cr(o))continue;const s=o.getBoundingClientRect();if(s.bottom<=0||s.top>=window.innerHeight||s.right<=0||s.left>=window.innerWidth||s.width<=0||s.height<=0||o.closest(".ll-widget"))continue;const l=s.width*s.height;l>i&&(i=l,n=o)}return n}function dr(){if(typeof window>"u")return null;if(ar())return window;const e=ur();return e||window}function $t(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function fr(e){var n,i;return e instanceof Window?typeof document>"u"?0:Math.max(((n=document.body)==null?void 0:n.scrollHeight)??0,((i=document.documentElement)==null?void 0:i.scrollHeight)??0):e.scrollHeight-e.clientHeight}const pr=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"]);function hr(e){var mt,gt,yt,bt,xt,vt,wt;const{agentId:n,apiKey:i,baseUrl:o="https://app.livelayer.studio",sessionEndpoint:s,sessionBody:l,autoConnect:u=!1,displayMode:d,defaultDisplayMode:p="expanded",onDisplayModeChange:y,position:g="bottom-right",mobileBreakpoint:a=640,persistKey:c="ll-widget",disablePersistence:j=!1,teamMembers:S,currentTeamMemberId:k,onTeamMemberChange:x,idleLoopUrl:v,greeting:I,avatarImageUrl:E,agentName:T,branding:h={},allowCamera:C=!0,allowScreenShare:$=!0,allowTyping:A=!0,showOn:L,hideOn:P,pathname:z,onNavigate:W,onScrollToSelector:X,getPageContext:le,pageContextExtras:$e,getRoutes:ze,onScrollPage:He,onClick:Oe,capabilities:fe,onConnect:pe,onDisconnect:he,onTranscript:me,onAgentState:ge,onConnectionStateChange:ye,onAgentEvent:be,onAgentCommand:xe,controlledSession:B,className:qe,style:Be,zIndex:We=2147483647}=e,ae=Gt(z),re=Zt(ae,L,P);r.useEffect(()=>{nn(),sn()},[ae]);const te=k!==void 0,[ve,we]=r.useState(()=>{var m;return k??((m=S==null?void 0:S[0])==null?void 0:m.id)}),ce=te?k:ve,V=r.useMemo(()=>(S==null?void 0:S.find(m=>m.id===ce))??null,[S,ce]),Ee=(V==null?void 0:V.agentId)??n,[Q,G]=Jt({value:d,defaultValue:p,onChange:y,persistKey:c,disablePersistence:j}),ne=Kt(a),ie=qt(),K=Bt(),Z=Wt(),ue=Ft(),Re=Ut(),[Fe,Ne]=r.useState(!1),[_e,b]=r.useState(!1),[Y,Ae]=r.useState(!1),[ln,an]=r.useState(!1),[Ze,cn]=r.useState(!1),et=r.useRef(W),tt=r.useRef(X),nt=r.useRef(He),rt=r.useRef(Oe),ct=r.useRef(le),ut=r.useRef($e),dt=r.useRef(ze),it=r.useRef(fe),ee=r.useRef(null);et.current=W,tt.current=X,nt.current=He,rt.current=Oe,ct.current=le,ut.current=$e,dt.current=ze,it.current=fe;function oe(m){const f=it.current;return f?f.includes(m):!0}function se(m,f){console.warn(`[LiveLayer] Agent command "${m}" blocked — capability "${f}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const Me=r.useCallback(m=>{var F,ke,Ve,_t;const f=m;if(!(!f.type||typeof f.type!="string")){if(be==null||be({eventName:f.type,data:m}),f.type==="navigate"){if(!oe("navigate")){se("navigate","navigate");return}const _=typeof f.href=="string"?f.href:null;if(!_){console.warn(`[LiveLayer] Agent emitted "navigate" without href. Skipping. Check your agent's tool schema. See https://livelayer.studio/docs/errors/navigate-missing-href`);return}if(et.current){try{et.current(_)}catch(R){console.warn(`[LiveLayer] onNavigate threw for "${_}". Falling back. Error:`,R)}return}if(typeof document<"u"){const R=document.querySelector(`a[href="${_.replace(/"/g,'\\"')}"]`);if(R){R.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",_),window.dispatchEvent(new PopStateEvent("popstate"))}catch(R){console.warn(`[LiveLayer] history.pushState fallback failed for "${_}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,R)}return}if(f.type==="scroll_to"){if(!oe("scroll")){se("scroll_to","scroll");return}const _=typeof f.selector=="string"?f.selector:null;if(!_)return;const R=f.behavior==="instant"?"instant":"smooth";if(tt.current){try{tt.current(_,R)}catch(D){console.warn("[LiveLayer] onScrollToSelector threw.",D)}return}if(typeof document<"u"){let D=null;try{D=document.querySelector(_)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${_}".`);return}if(!D){console.warn(`[LiveLayer] scroll_to: no element matched "${_}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}D.scrollIntoView({behavior:R,block:"start"})}return}if(f.type==="request_page_context"){if(!oe("read_page")){se("request_page_context","read_page");return}const _=typeof f.requestId=="string"?f.requestId:void 0,R=(F=ee.current)==null?void 0:F.call(ee),D=q=>{const N=R,U=N==null?void 0:N.localParticipant;if(U!=null&&U.publishData)try{const J=_?{...q,requestId:_}:q,Se=new TextEncoder().encode(JSON.stringify(J));U.publishData(Se,{reliable:!0})}catch(J){console.warn("[LiveLayer] publishData failed.",J)}},M=ut.current,H=ct.current;try{if(H){const q=H(M);if(q instanceof Promise){D({type:"page_context_pending"}),q.then(N=>D({type:"page_context",context:N})).catch(N=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",N),D({type:"page_context",context:lt(M)})});return}D({type:"page_context",context:q});return}D({type:"page_context",context:lt(M)})}catch(q){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",q),D({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:M}})}return}if(f.type==="scroll_page"){if(!oe("scroll")){se("scroll_page","scroll");return}const _=f.direction;if(_!=="up"&&_!=="down"&&_!=="top"&&_!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(_)}". Expected up | down | top | bottom.`);return}const R=f.behavior==="instant"?"instant":"smooth";if(nt.current){try{nt.current(_,R)}catch(N){console.warn("[LiveLayer] onScrollPage threw.",N)}return}if(typeof window>"u")return;const D={behavior:R},M=dr(),H=N=>{M instanceof Window?M.scrollBy({top:N,...D}):M.scrollBy({top:N,...D})},q=N=>{M instanceof Window?M.scrollTo({top:N,...D}):M.scrollTo({top:N,...D})};_==="up"?H(-$t(M)):_==="down"?H($t(M)):q(_==="top"?0:fr(M));return}if(f.type==="click"){if(!oe("click")){se("click","click");return}const _=typeof f.selector=="string"?f.selector:null;if(!_){console.warn("[LiveLayer] click: missing selector.");return}if(rt.current){try{rt.current(_)}catch(D){console.warn("[LiveLayer] onClick threw.",D)}return}if(typeof document>"u")return;let R=null;try{R=document.querySelector(_)}catch{console.warn(`[LiveLayer] click: invalid selector "${_}".`);return}if(!R){console.warn(`[LiveLayer] click: no element matched "${_}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(ke=R.click)==null||ke.call(R);return}if(f.type==="fill_form"||f.type==="focus_field"){if(!oe("fill_forms")){se(f.type,"fill_forms");return}if(typeof document>"u")return;const _=typeof f.formId=="string"?f.formId:null;if(!_){console.warn(`[LiveLayer] ${f.type}: missing formId.`);return}const R=document.querySelector(`[data-ll-form="${_.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] ${f.type}: no form with data-ll-form="${_}". Tag your form with <LiveLayerForm id> or data-ll-form. See https://livelayer.studio/docs/react/forms`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn(`[LiveLayer] ${f.type}: refusing to touch a form in a private subtree.`);return}if(f.type==="focus_field"){const M=typeof f.fieldName=="string"?f.fieldName:null;if(!M){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const H=R.querySelector(`[data-ll-field="${M.replace(/"/g,'\\"')}"]`);if(!H){console.warn(`[LiveLayer] focus_field: no field "${M}" in form "${_}".`);return}if(!Qe(H)){console.warn(`[LiveLayer] focus_field: field "${M}" is privacy-protected and not focusable.`);return}H.focus();return}const D=f.values&&typeof f.values=="object"?f.values:null;if(!D){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[M,H]of Object.entries(D)){if(typeof H!="string")continue;const q=R.querySelector(`[data-ll-field="${M.replace(/"/g,'\\"')}"]`);if(!q){console.warn(`[LiveLayer] fill_form: no field "${M}" in form "${_}". Skipping.`);continue}if(!Qe(q)){console.warn(`[LiveLayer] fill_form: field "${M}" is privacy-protected (password / cc-* / private). Skipping.`);continue}try{lr(q,H)}catch(N){console.warn(`[LiveLayer] fill_form: failed to set "${M}".`,N)}}return}if(f.type==="submit_form"){if(!oe("submit_forms")){se("submit_form","submit_forms");return}if(typeof document>"u")return;const _=typeof f.formId=="string"?f.formId:null;if(!_){console.warn("[LiveLayer] submit_form: missing formId.");return}const R=document.querySelector(`[data-ll-form="${_.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${_}".`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private subtree.");return}const D=typeof f.requestId=="string"?f.requestId:void 0,M=(Ve=ee.current)==null?void 0:Ve.call(ee),H=U=>{const J=M,Se=J==null?void 0:J.localParticipant;if(Se!=null&&Se.publishData)try{const wn=D?{...U,requestId:D}:U,_n=new TextEncoder().encode(JSON.stringify(wn));Se.publishData(_n,{reliable:!0})}catch{}};let q=!1;const N=()=>{q=!0,H({type:"form_submitted",formId:_})};R.addEventListener("submit",N,{once:!0});try{typeof R.requestSubmit=="function"?R.requestSubmit():R.submit()}catch(U){console.warn("[LiveLayer] submit_form: requestSubmit threw.",U),R.removeEventListener("submit",N),H({type:"form_submit_blocked",formId:_,reason:"exception"});return}setTimeout(()=>{q||(R.removeEventListener("submit",N),H({type:"form_submit_blocked",formId:_,reason:"validation"}))},500);return}if(f.type==="request_routes"){if(!oe("read_page")){se("request_routes","read_page");return}const _=typeof f.requestId=="string"?f.requestId:void 0,D=(_t=ee.current)==null?void 0:_t.call(ee),M=D==null?void 0:D.localParticipant;if(!(M!=null&&M.publishData))return;const H=N=>{try{const U=_?{type:"routes",routes:N,requestId:_}:{type:"routes",routes:N},J=new TextEncoder().encode(JSON.stringify(U));M.publishData(J,{reliable:!0})}catch(U){console.warn("[LiveLayer] request_routes: publishData failed.",U)}},q=dt.current;if(q){try{const N=q(),U=J=>{if(!Array.isArray(J)){H([]);return}H(J.map(rn).slice(0,200))};N instanceof Promise?N.then(U).catch(J=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",J),H(Ke())}):U(N)}catch(N){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",N),H(Ke())}return}try{H(Ke())}catch(N){console.warn("[LiveLayer] request_routes: extractRoutes threw.",N)}return}pr.has(f.type)||xe==null||xe(f)}},[xe,be]),O=Ot({agentId:B?"__controlled__":Ee,baseUrl:o,apiKey:i,sessionEndpoint:s,sessionBody:l,onDataMessage:B?void 0:Me});r.useEffect(()=>{if(B!=null&&B.subscribeToDataMessages)return B.subscribeToDataMessages(Me)},[B,Me]),ee.current=()=>{var m;return(m=O.getRoom)==null?void 0:m.call(O)},r.useEffect(()=>{var F;if(!ae)return;const m=(F=O.getRoom)==null?void 0:F.call(O),f=m==null?void 0:m.localParticipant;if(f!=null&&f.publishData)try{const ke=new TextEncoder().encode(JSON.stringify({type:"pathname",pathname:ae}));f.publishData(ke,{reliable:!0})}catch{}},[ae,O,O.connectionState]),r.useEffect(()=>{var F;if(typeof window>"u")return;const m=((F=window.location)==null?void 0:F.hostname)||"";if(m==="localhost"||m==="127.0.0.1"||m==="0.0.0.0"||m.endsWith(".local")||m.endsWith(".test"))return window.__livelayerSimulateCommand=ke=>{try{Me(ke)}catch(Ve){console.warn("[LiveLayer] simulate-command threw:",Ve)}},()=>{delete window.__livelayerSimulateCommand}},[Me]);const w=r.useMemo(()=>B?{connectionState:B.connectionState,agentState:B.agentState,transcript:B.transcript,videoElement:B.videoElement,audioElement:B.audioElement,canResume:B.canResume,error:B.error,agentConfig:null,connect:async()=>{await B.onConnect()},disconnect:()=>B.onDisconnect(),getRoom:O.getRoom,isControlled:!0}:{connectionState:O.connectionState,agentState:O.agentState,transcript:O.transcript,videoElement:O.videoElement,audioElement:O.audioElement,canResume:O.canResume,error:O.error,agentConfig:O.agentConfig,connect:O.connect,disconnect:O.disconnect,getRoom:O.getRoom,isControlled:!1},[B,O]),ft=r.useRef(null);r.useEffect(()=>{const m=w.videoElement,f=ft.current;if(!(!m||!f))return f.appendChild(m),()=>{m.parentNode===f&&f.removeChild(m)}},[w.videoElement]),r.useEffect(()=>{const m=w.audioElement;if(!m)return;ie.attach(m);const f=m.play();return f&&typeof f.catch=="function"&&f.catch(F=>{(F==null?void 0:F.name)==="NotAllowedError"&&Ne(!0)}),()=>{ie.detach()}},[w.audioElement]),r.useEffect(()=>{if(w.isControlled||w.connectionState!=="connected")return;const m=w.getRoom();if(m)return K.setupMic(m).catch(()=>{}),Z.attachRoom(m),ue.attachRoom(m),Re.refresh(),()=>{K.teardownMic(),Z.teardown(),ue.teardown()}},[w.isControlled,w.connectionState]),r.useEffect(()=>{const m=w.audioElement;m&&(m.muted=Ze)},[w.audioElement,Ze]);const un=r.useCallback(m=>{const f=w.getRoom();if(f)try{const F=new TextEncoder().encode(JSON.stringify({type:"user_message",text:m}));f.localParticipant.publishData(F,{reliable:!0})}catch{}},[w]),dn=r.useCallback(()=>{cn(m=>!m)},[]);r.useEffect(()=>{ye==null||ye(w.connectionState),w.connectionState==="connected"?pe==null||pe():w.connectionState==="disconnected"&&(he==null||he())},[w.connectionState,pe,he,ye]),r.useEffect(()=>{me==null||me(w.transcript)},[w.transcript,me]),r.useEffect(()=>{ge==null||ge(w.agentState)},[w.agentState,ge]);const pt=r.useRef(!1);r.useEffect(()=>{w.isControlled||!u||pt.current||re&&w.connectionState==="idle"&&(pt.current=!0,w.connect())},[u,w.connectionState,w,re]);const fn=r.useCallback(m=>{const f=S==null?void 0:S.find(F=>F.id===m);f&&(Ae(!1),m!==ce&&(b(!0),w.disconnect(),te||we(m),x==null||x(f)))},[S,ce,w,te,x]);r.useEffect(()=>{_e&&w.connectionState==="connected"&&b(!1)},[w.connectionState,_e]),r.useEffect(()=>{if(!Y)return;const m=f=>{f.key==="Escape"&&Ae(!1)};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[Y]);const pn=!!E||!!(V!=null&&V.avatarImageUrl)||w.isControlled,Ie=Vt(Ee,o,pn);fe===void 0&&((mt=Ie.info)!=null&&mt.capabilities)&&(it.current=Ie.info.capabilities);const Ue=(V==null?void 0:V.name)??T??((gt=w.agentConfig)==null?void 0:gt.name)??((yt=Ie.info)==null?void 0:yt.name)??"Live Layer",ot=(V==null?void 0:V.avatarImageUrl)??E??((bt=w.agentConfig)==null?void 0:bt.avatarImageUrl)??((xt=Ie.info)==null?void 0:xt.avatarImageUrl)??null,hn=v??((vt=w.agentConfig)==null?void 0:vt.idleLoopUrl)??((wt=Ie.info)==null?void 0:wt.idleLoopUrl)??null,mn=I??null,gn=r.useCallback(()=>G("expanded"),[G]),yn=r.useCallback(()=>G("minimized"),[G]),ht=r.useCallback(()=>{w.disconnect(),G("hidden")},[w,G]),bn=r.useCallback(()=>{const m=w.audioElement;m&&m.play().then(()=>Ne(!1)).catch(()=>{})},[w.audioElement]),xn=r.useCallback(()=>{Ne(!1),w.connect()},[w]),Te={...Be,zIndex:We};h.primaryColor&&(Te["--ll-color-primary"]=h.primaryColor),h.accentColor&&(Te["--ll-color-accent"]=h.accentColor),h.backgroundColor&&(Te["--ll-color-bg"]=h.backgroundColor),h.textColor&&(Te["--ll-color-fg"]=h.textColor);const vn=["ll-widget",`ll-widget--${Q}`,`ll-widget--${ne?"mobile":"desktop"}`,qe].filter(Boolean).join(" ");return re?t.jsxs("div",{className:vn,style:Te,"data-display-mode":Q,"data-position":g,children:[Q==="hidden"&&t.jsx(On,{position:g,isMobile:ne,isSpeaking:w.agentState==="speaking",onExpand:()=>G("expanded"),label:`Open ${Ue} widget`,avatarImageUrl:ot,agentName:Ue}),Q==="minimized"&&t.jsx(Bn,{position:g,isMobile:ne,agentName:Ue,avatarImageUrl:ot,agentState:w.agentState,isMuted:K.isMuted,audioLevel:ie,onExpand:gn,onToggleMute:K.toggleMute,onClose:ht}),Q==="expanded"&&t.jsx(Fn,{position:g,isMobile:ne,agentName:Ue,avatarImageUrl:ot,idleLoopUrl:hn,greeting:mn,branding:h,teamMembers:S,currentTeamMemberId:ce,isSwitchingTeamMember:_e,teamSwitcherOpen:Y,onToggleTeamSwitcher:()=>Ae(m=>!m),onSelectTeamMember:fn,connectionState:w.connectionState,agentState:w.agentState,transcript:w.transcript,isMuted:K.isMuted,micDevices:Re.mics,isCameraEnabled:Z.isEnabled,cameraPreviewEl:Z.previewEl,cameraDevices:Re.cameras,activeCameraId:Z.activeDeviceId,isScreenShareEnabled:ue.isEnabled,screenPreviewEl:ue.previewEl,isSpeakerMuted:Ze,allowCamera:C,allowScreenShare:$,allowTyping:A,languageMenuOpen:ln,onToggleLanguageMenu:()=>an(m=>!m),needsUserGesture:Fe,canResume:w.canResume,micError:K.micError,error:w.error,avatarVideoContainerRef:ft,onConnect:()=>void w.connect(),onDisconnect:()=>w.disconnect(),onRetry:xn,onResumeAudio:bn,onToggleMute:K.toggleMute,onToggleCamera:()=>void Z.toggle(),onSwitchCameraDevice:m=>void Z.switchDevice(m),onToggleScreenShare:()=>void ue.toggle(),onToggleSpeaker:dn,onSendMessage:un,onMinimize:yn,onClose:ht,onClearMicError:K.clearError})]}):null}function mr(e){return t.jsx(Ht,{children:t.jsx(hr,{...e})})}const gr=({agentId:e,baseUrl:n,apiKey:i,mode:o,onAgentEvent:s,className:l,style:u})=>{const d=r.useRef(null),p=r.useRef(null),y=r.useRef(s);y.current=s;const g=r.useCallback(a=>{var j;const c=a.detail;(j=y.current)==null||j.call(y,c)},[]);return r.useEffect(()=>{const a=d.current;if(!a)return;const c=document.createElement("livelayer-widget");return c.setAttribute("agent-id",e),n&&c.setAttribute("base-url",n),i&&c.setAttribute("api-key",i),o&&c.setAttribute("mode",o),c.addEventListener("agent-event",g),a.appendChild(c),p.current=c,()=>{c.removeEventListener("agent-event",g),a.removeChild(c),p.current=null}},[e]),r.useEffect(()=>{p.current&&(o?p.current.setAttribute("mode",o):p.current.removeAttribute("mode"))},[o]),t.jsx("div",{ref:d,className:l,style:u})},yr=r.forwardRef(function({id:n,intent:i,as:o="div",className:s,style:l,children:u},d){return r.createElement(o,{ref:d,"data-ll-region":n,"data-ll-intent":i,className:s,style:l},u)}),br=r.forwardRef(function({id:n,intent:i,children:o,...s},l){return t.jsx("form",{ref:l,"data-ll-form":n,"data-ll-intent":i,...s,children:o})}),xr=r.forwardRef(function(n,i){const{name:o,label:s,labelClassName:l}=n,u={name:o,"data-ll-field":o};let d;if("as"in n&&n.as==="textarea"){const{name:p,label:y,labelClassName:g,as:a,...c}=n;d=t.jsx("textarea",{ref:i,...u,...c})}else if("as"in n&&n.as==="select"){const{name:p,label:y,labelClassName:g,as:a,children:c,...j}=n;d=t.jsx("select",{ref:i,...u,...j,children:c})}else{const{name:p,label:y,labelClassName:g,as:a,...c}=n;d=t.jsx("input",{ref:i,...u,...c})}return s===void 0?d:t.jsxs("label",{className:l,children:[s,d]})});let zt=1;function vr({onMount:e,defaultOpen:n=!1,storageKey:i="ll-debug-open"}){const[o,s]=r.useState(n),[l,u]=r.useState([]),[d,p]=r.useState(""),[y,g]=r.useState(!1),a=r.useRef(new Set),c=r.useRef([]),j=r.useRef(y);j.current=y,r.useEffect(()=>{try{const x=localStorage.getItem(i);x==="1"&&s(!0),x==="0"&&s(!1)}catch{}},[i]),r.useEffect(()=>{try{localStorage.setItem(i,o?"1":"0")}catch{}},[o,i]),r.useEffect(()=>{const x=v=>{(v.metaKey||v.ctrlKey)&&v.shiftKey&&v.key.toLowerCase()==="l"&&(v.preventDefault(),s(I=>!I))};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[]),r.useEffect(()=>{const x=setInterval(()=>{if(c.current.length===0||j.current)return;const v=c.current.splice(0,c.current.length);u(I=>[...v.reverse(),...I].slice(0,200))},100);return()=>clearInterval(x)},[]);const S=r.useRef(!1);if(r.useEffect(()=>{!e||S.current||(S.current=!0,e(x=>{c.current.push({id:zt++,ts:Date.now(),kind:"event",type:x.eventName,data:x.data})}))},[e]),r.useEffect(()=>{const x=console.warn,v=console.log,I=(E,T)=>function(...h){try{const C=typeof h[0]=="string"?h[0]:"";C.startsWith("[LiveLayer]")&&c.current.push({id:zt++,ts:Date.now(),kind:E,type:C.slice(0,120),data:{args:h.slice(1).map($=>_r($))}})}catch{}return T.apply(this,h)};return console.warn=I("warn",x),console.log=I("log",v),()=>{console.warn=x,console.log=v}},[]),!o)return t.jsx("button",{type:"button",onClick:()=>s(!0),title:"Open LiveLayer debug panel (Cmd/Ctrl + Shift + L)","aria-label":"Open LiveLayer debug panel",style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.18)",borderRadius:999,padding:"6px 10px",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",cursor:"pointer",boxShadow:"0 4px 12px rgba(0,0,0,0.35)",opacity:.85},children:"🛰 LL debug"});const k=l.filter(x=>{if(!d)return!0;const v=d.toLowerCase();return x.type.toLowerCase().includes(v)||JSON.stringify(x.data||{}).toLowerCase().includes(v)});return t.jsxs("div",{style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,width:380,maxHeight:"60vh",background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:12,boxShadow:"0 16px 48px rgba(0,0,0,0.5)",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"8px 10px",background:"rgba(255,255,255,0.04)",borderBottom:"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),t.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[l.length," event",l.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>g(x=>!x),style:st(y?"#f59e0b":"transparent"),title:"Pause / resume capture",children:y?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{u([]),c.current=[]},style:st("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:st("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:d,onChange:x=>p(x.target.value),placeholder:"filter by type or data…",style:{margin:8,padding:"6px 8px",background:"rgba(255,255,255,0.06)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:"#fff",fontSize:11,outline:"none"}}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 8px 8px"},children:k.length===0?t.jsxs("div",{style:{padding:14,fontSize:11,color:"rgba(255,255,255,0.4)",lineHeight:1.5},children:["No events yet. Connect to the agent and trigger a tool call — the events will stream in here. You can also dispatch commands manually in DevTools:",t.jsx("pre",{style:{marginTop:6,background:"rgba(255,255,255,0.04)",padding:6,borderRadius:4,fontSize:10,whiteSpace:"pre-wrap"},children:`window.__livelayerSimulateCommand({
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),r=require("react"),kn=require("@livelayer/sdk"),Ke=require("livekit-client");class Ht extends r.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,o){var i,s;(s=(i=this.props).onError)==null||s.call(i,n,o)}render(){var n;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[t.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),t.jsx("p",{className:"ll-error-boundary__message",children:((n=this.state.error)==null?void 0:n.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function Ot(e){const[n,o]=r.useState("idle"),[i,s]=r.useState("idle"),[l,u]=r.useState([]),[d,p]=r.useState(null),[y,g]=r.useState(null),[a,c]=r.useState(null),[j,S]=r.useState(!1),[k,x]=r.useState(null),v=r.useRef(null),I=r.useRef(e.onDataMessage);I.current=e.onDataMessage,r.useEffect(()=>{const C={onConnectionStateChange:A=>{o(A),A==="connected"&&x(null)},onAgentStateChange:s,onTranscript:A=>u([...A]),onAgentConfig:p,onAudioTrack:A=>c(A),onVideoTrack:A=>g(A),onVideoTrackRemoved:()=>g(null),onError:A=>x(A),onDataMessage:A=>{var L;(L=I.current)==null||L.call(I,A)},onResumabilityChange:S},$=new kn.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},C);return v.current=$,o("idle"),s("idle"),u([]),p(null),g(null),c(null),S(!1),x(null),()=>{var A;(A=$.destroy)==null||A.call($),v.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=r.useCallback(async()=>{const C=v.current;if(C)try{await C.connect()}catch($){throw x($ instanceof Error?$.message:String($)),$}},[]),T=r.useCallback(()=>{const C=v.current;C&&C.disconnect()},[]),h=r.useCallback(()=>{var C;return((C=v.current)==null?void 0:C.getRoom())??null},[]);return{connectionState:n,agentState:i,transcript:l,agentConfig:d,videoElement:y,audioElement:a,canResume:j,error:k,connect:E,disconnect:T,getRoom:h,session:v.current}}function qt(){const e=r.useRef(null),n=r.useRef(null),o=r.useRef(null),i=r.useRef(null),s=r.useRef(new Set),l=r.useRef(null),u=r.useCallback(()=>{const a=n.current;if(!a){i.current=null;return}(!l.current||l.current.length!==a.frequencyBinCount)&&(l.current=new Uint8Array(new ArrayBuffer(a.frequencyBinCount)));const c=l.current;a.getByteFrequencyData(c);let j=0;for(let k=0;k<c.length;k++)j+=c[k];const S=j/c.length/255;for(const k of s.current)try{k(S)}catch(x){console.error("[useAudioLevel] subscriber threw:",x)}i.current=requestAnimationFrame(u)},[]),d=r.useCallback(()=>{if(e.current||typeof window>"u"||typeof AudioContext>"u")return;const a=new AudioContext,c=a.createAnalyser();c.fftSize=64,c.connect(a.destination),e.current=a,n.current=c},[]),p=r.useCallback(a=>{if(d(),!(!e.current||!n.current)){if(o.current){try{o.current.disconnect()}catch{}o.current=null}try{const c=e.current.createMediaElementSource(a);c.connect(n.current),o.current=c}catch(c){console.warn("[useAudioLevel] createMediaElementSource failed:",c);return}i.current===null&&(i.current=requestAnimationFrame(u))}},[d,u]),y=r.useCallback(()=>{if(i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),o.current){try{o.current.disconnect()}catch{}o.current=null}},[]),g=r.useCallback(a=>(s.current.add(a),()=>{s.current.delete(a)}),[]);return r.useEffect(()=>()=>{if(y(),n.current){try{n.current.disconnect()}catch{}n.current=null}if(e.current){try{e.current.close()}catch{}e.current=null}s.current.clear(),l.current=null},[y]),{attach:p,detach:y,subscribe:g}}function Bt(){const[e,n]=r.useState(!1),[o,i]=r.useState(null),s=r.useRef(null),l=r.useRef(null),u=r.useCallback(async g=>{if(s.current&&l.current){try{await l.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}l.current=g,i(null);try{const a=await Ke.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await g.localParticipant.publishTrack(a),s.current=a,n(a.isMuted)}catch(a){const c=a instanceof Error&&a.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw i(c),a}},[]),d=r.useCallback(()=>{const g=s.current;g&&(g.isMuted?(g.unmute(),n(!1)):(g.mute(),n(!0)))},[]),p=r.useCallback(()=>{const g=s.current,a=l.current;if(g&&a){try{a.localParticipant.unpublishTrack(g)}catch{}g.stop()}s.current=null,l.current=null,n(!1)},[]),y=r.useCallback(()=>i(null),[]);return{isMuted:e,micError:o,toggleMute:d,setupMic:u,teardownMic:p,clearError:y}}const Sn={resolution:{width:640,height:480,frameRate:24}};function Wt(){const[e,n]=r.useState(!1),[o,i]=r.useState(null),[s,l]=r.useState(null),[u,d]=r.useState(""),p=r.useRef(null),y=r.useRef(null),g=r.useCallback(v=>{p.current=v},[]),a=r.useCallback(()=>{const v=p.current,I=y.current;if(I&&v){const E=v.localParticipant.getTrackPublication(Ke.Track.Source.Camera);if(E!=null&&E.track){try{v.localParticipant.unpublishTrack(E.track)}catch{}E.track.stop()}else I.stop()}y.current=null,l(null),n(!1)},[]),c=r.useCallback(async v=>{const I=p.current;if(I){i(null);try{const E={...Sn};v&&(E.deviceId=v);const T=await Ke.createLocalVideoTrack(E);await I.localParticipant.publishTrack(T),y.current=T;const h=T.attach();l(h),n(!0),v&&d(v);try{I.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const T=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";i(T)}}},[]),j=r.useCallback(async()=>{e?a():await c(u||void 0)},[e,u,a,c]),S=r.useCallback(async v=>{a(),await c(v)},[a,c]),k=r.useCallback(()=>{a(),p.current=null,i(null),d("")},[a]),x=r.useCallback(()=>i(null),[]);return r.useEffect(()=>()=>{y.current&&y.current.stop()},[]),{isEnabled:e,error:o,previewEl:s,activeDeviceId:u,toggle:j,switchDevice:S,attachRoom:g,teardown:k,clearError:x}}function Ft(){const[e,n]=r.useState(!1),[o,i]=r.useState(null),[s,l]=r.useState(null),u=r.useRef(null),d=r.useCallback(c=>{u.current=c},[]),p=r.useCallback(()=>l(null),[]),y=r.useCallback(async()=>{const c=u.current;if(c){if(e){try{await c.localParticipant.setScreenShareEnabled(!1)}catch{}p(),n(!1);return}i(null);try{await c.localParticipant.setScreenShareEnabled(!0);let j=0;const S=()=>{const k=c.localParticipant.getTrackPublication(Ke.Track.Source.ScreenShare);if(k!=null&&k.track){const x=k.track.attach();l(x),n(!0);try{c.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}j++<10?setTimeout(S,100):n(!0)};S()}catch(j){const S=j instanceof Error?j.name:"";S!=="NotAllowedError"&&S!=="AbortError"&&i("Screen share unavailable. Try again."),n(!1)}}},[e,p]),g=r.useCallback(()=>{const c=u.current;if(c&&e)try{c.localParticipant.setScreenShareEnabled(!1)}catch{}p(),n(!1),i(null),u.current=null},[e,p]),a=r.useCallback(()=>i(null),[]);return{isEnabled:e,error:o,previewEl:s,toggle:y,attachRoom:d,teardown:g,clearError:a}}function Ut(){const[e,n]=r.useState([]),[o,i]=r.useState([]),s=r.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const l=await navigator.mediaDevices.enumerateDevices();n(l.filter(u=>u.kind==="audioinput")),i(l.filter(u=>u.kind==="videoinput"))}catch{}},[]);return r.useEffect(()=>{if(s(),typeof navigator>"u"||!navigator.mediaDevices)return;const l=()=>void s();return navigator.mediaDevices.addEventListener("devicechange",l),()=>navigator.mediaDevices.removeEventListener("devicechange",l)},[s]),{mics:e,cameras:o,refresh:s}}function Vt(e,n,o=!1){const[i,s]=r.useState(null),[l,u]=r.useState(null),[d,p]=r.useState(!o&&!!e);return r.useEffect(()=>{if(o||!e){p(!1);return}const y=new AbortController,g=n||"https://app.livelayer.studio";return p(!0),u(null),fetch(`${g}/api/widget/agent/${encodeURIComponent(e)}`,{signal:y.signal}).then(async a=>{if(!a.ok){const c=await a.json().catch(()=>({}));throw new Error(c.error||`HTTP ${a.status}`)}return a.json()}).then(a=>{y.signal.aborted||(s(a),p(!1))}).catch(a=>{y.signal.aborted||(u(a instanceof Error?a.message:"Agent lookup failed"),p(!1))}),()=>y.abort()},[e,n,o]),{info:i,error:l,loading:d}}function Cn(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Ln(e,n){if(!(typeof window>"u"))try{window.localStorage.setItem(e,n)}catch{}}function Yt({value:e,defaultValue:n="expanded",onChange:o}={}){const i=e!==void 0,[s,l]=r.useState(n),u=i?e:s,d=r.useCallback(p=>{p!==u&&(i||l(p),o==null||o(p))},[u,i,o]);return[u,d]}const jn=["hidden","minimized","expanded"];function En(e){return e&&jn.includes(e)?e:null}function Gt({value:e,defaultValue:n="expanded",onChange:o,persistKey:i="ll-widget",disablePersistence:s=!1}={}){const l=`${i}:display-mode`,u=r.useRef(!1),[d,p]=Yt({value:e,defaultValue:n,onChange:y=>{e===void 0&&!s&&Ln(l,y),o==null||o(y)}});return r.useEffect(()=>{if(u.current||(u.current=!0,s||e!==void 0))return;const y=En(Cn(l));y&&y!==d&&p(y)},[]),[d,p]}const Rn=640;function Jt(e=Rn){const[n,o]=r.useState(!1);return r.useEffect(()=>{if(e===!1){o(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const i=`(max-width: ${e-1}px)`,s=window.matchMedia(i),l=()=>o(s.matches);return l(),typeof s.addEventListener=="function"?(s.addEventListener("change",l),()=>s.removeEventListener("change",l)):(s.addListener(l),()=>{s.removeListener(l)})},[e]),n}const kt="__llHistoryPatched",Xe="ll:pathname";function Nn(){if(typeof window>"u"||window.history[kt])return;const e=window.history.pushState,n=window.history.replaceState;window.history.pushState=function(...o){const i=e.apply(this,o);return window.dispatchEvent(new Event(Xe)),i},window.history.replaceState=function(...o){const i=n.apply(this,o);return window.dispatchEvent(new Event(Xe)),i},window.history[kt]=!0}function St(){return typeof window>"u"?"/":window.location.pathname||"/"}function Kt(e){const[n,o]=r.useState(()=>e??St());return r.useEffect(()=>{if(e!==void 0)return;Nn();const i=()=>o(St());return i(),window.addEventListener("popstate",i),window.addEventListener(Xe,i),()=>{window.removeEventListener("popstate",i),window.removeEventListener(Xe,i)}},[e]),e??n}const Ct=new Map,An=/[\\^$+?.()|{}[\]]/g;function Mn(e){return e.replace(An,"\\$&")}function In(e){const n=Ct.get(e);if(n)return n;const o=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,i="",s="",l=o.replace(/\*\*/g,i).replace(/\*/g,s),d=Mn(l).replace(new RegExp(`\\/${i}`,"g"),"(?:\\/.*)?").replace(new RegExp(i,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),p=new RegExp(`^${d}\\/?$`);return Ct.set(e,p),p}function Tn(e,n){const o=n.length>1&&n.endsWith("/")?n.slice(0,-1):n;return In(e).test(o)}function Xt(e,n){return typeof e=="function"?e(n):e instanceof RegExp?e.test(n):Tn(e,n)}function Lt(e,n){if(!e||e.length===0)return!1;for(const o of e)if(Xt(o,n))return!0;return!1}function Qt(e,n,o){return e===void 0?!0:Lt(o,e)?!1:n&&n.length>0?Lt(n,e):!0}function Zt(e,n,o){return r.useMemo(()=>Qt(e,n,o),[e,n,o])}const jt=({muted:e=!1,className:n})=>e?t.jsxs("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):t.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"})}),Et=({className:e})=>t.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})}),Pn=({className:e})=>t.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),Dn={left:180,right:0,up:-90,down:90},Rt=({direction:e="right",className:n})=>t.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${Dn[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function $n(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const en="ll-hidden-tab-center-y",zn=5,Nt=16;function Hn(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(en);if(!e)return null;const n=Number.parseFloat(e);return Number.isFinite(n)?n:null}catch{return null}}function At(e){if(!(typeof window>"u"))try{window.localStorage.setItem(en,String(e))}catch{}}const On=({position:e,isMobile:n,isSpeaking:o,onExpand:i,label:s="Open widget",avatarImageUrl:l,agentName:u})=>{const d=$n(e),p=d==="right"?"left":"right",y=n?80:72,g=!!l,[a,c]=r.useState(null),[j,S]=r.useState(!1),k=r.useRef(null),x=r.useRef(!1),v=r.useCallback(L=>{if(typeof window>"u")return L;const P=y/2,z=Nt+P,W=window.innerHeight-Nt-P;return W<z?Math.max(z,L):Math.max(z,Math.min(W,L))},[y]);r.useEffect(()=>{const L=Hn();c(v(L??window.innerHeight/2));const P=()=>{c(z=>z===null?null:v(z))};return window.addEventListener("resize",P),()=>window.removeEventListener("resize",P)},[v]);const I=r.useCallback(L=>{if(!(L.pointerType==="mouse"&&L.button!==0)&&a!==null){try{L.currentTarget.setPointerCapture(L.pointerId)}catch{}k.current={startClientY:L.clientY,startCenterY:a,moved:!1}}},[a]),E=r.useCallback(L=>{const P=k.current;if(!P)return;const z=L.clientY-P.startClientY;!P.moved&&Math.abs(z)>zn&&(P.moved=!0,S(!0)),P.moved&&c(v(P.startCenterY+z))},[v]),T=r.useCallback(L=>{const P=k.current;if(P){try{L.currentTarget.releasePointerCapture(L.pointerId)}catch{}k.current=null,P.moved&&(S(!1),x.current=!0,c(z=>(z!==null&&At(z),z)))}},[]),h=r.useCallback(()=>{if(x.current){x.current=!1;return}i()},[i]),C=r.useCallback(L=>{if(L.key==="ArrowUp"||L.key==="ArrowDown"){L.preventDefault();const P=L.key==="ArrowUp"?-8:8;c(z=>{if(z===null)return z;const W=v(z+P);return At(W),W})}},[v]),$=["ll-hidden",`ll-hidden--${d}`,n?"ll-hidden--mobile":"ll-hidden--desktop",o?"ll-hidden--speaking":null,j?"is-dragging":null,g?"ll-hidden--with-avatar":null].filter(Boolean).join(" "),A=a===null?void 0:{top:`${a-y/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:$,onPointerDown:I,onPointerMove:E,onPointerUp:T,onPointerCancel:T,onClick:h,onKeyDown:C,"aria-label":s,"data-position":e,style:A,children:g?t.jsxs(t.Fragment,{children:[t.jsx(Rt,{direction:p,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:l,alt:u?`${u} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Rt,{direction:p,className:"ll-hidden__chevron"})})},qn=({audioLevel:e,bars:n=20,maxHeight:o=20,minHeight:i=4,className:s,barClassName:l})=>{const u=r.useRef(null),d=r.useRef([]),p=r.useMemo(()=>{const g=(Math.sqrt(5)-1)/2;return Array.from({length:n},(a,c)=>.5+c*g%1*.5)},[n]);r.useEffect(()=>e.subscribe(a=>{for(let c=0;c<n;c++){const j=d.current[c];if(!j)continue;const S=Math.max(i,a*o*p[c]);j.style.height=`${S}px`}}),[e,n,o,i,p]);const y=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:u,className:y,"aria-hidden":"true",children:Array.from({length:n},(g,a)=>t.jsx("div",{ref:c=>{d.current[a]=c},className:["ll-waveform__bar",l].filter(Boolean).join(" "),style:{height:`${i}px`}},a))})},Bn=({position:e,isMobile:n,agentName:o,avatarImageUrl:i,agentState:s,isMuted:l,audioLevel:u,onExpand:d,onToggleMute:p,onClose:y})=>n?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${o} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:d,"aria-label":`Expand ${o} widget`,children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsx(qn,{audioLevel:u,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:g=>{g.stopPropagation(),p()},onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.stopPropagation(),g.preventDefault(),p())},"aria-label":l?"Unmute microphone":"Mute microphone",children:t.jsx(jt,{muted:l,className:"ll-minimized__icon"})}),t.jsx(Et,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):t.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${o} widget`,children:t.jsxs("div",{className:"ll-minimized__surface",children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsxs("div",{className:"ll-minimized__meta",children:[t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsx("span",{className:"ll-minimized__state",children:s==="speaking"?"Speaking":s==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:p,"aria-label":l?"Unmute microphone":"Mute microphone",children:t.jsx(jt,{muted:l,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:d,"aria-label":`Expand ${o} widget`,children:t.jsx(Et,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:y,"aria-label":"Close widget",children:t.jsx(Pn,{className:"ll-minimized__icon"})})]})]})}),Wn=({src:e,alt:n,preCannedPlaying:o=!1,className:i,style:s})=>{const[l,u]=r.useState(!1),d=r.useRef(e);if(r.useEffect(()=>{d.current!==e&&(d.current=e,u(!1))},[e]),!e)return null;const p={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:o?"scale(1.02)":"scale(1)",opacity:l?1:0,...s};return t.jsx("img",{src:e,alt:n,className:i,style:p,loading:"eager",fetchPriority:"high",onLoad:()=>u(!0)})},Fn=({position:e,isMobile:n,agentName:o,avatarImageUrl:i,idleLoopUrl:s,greeting:l,branding:u,teamMembers:d,currentTeamMemberId:p,isSwitchingTeamMember:y,teamSwitcherOpen:g,onToggleTeamSwitcher:a,onSelectTeamMember:c,languageMenuOpen:j,onToggleLanguageMenu:S,connectionState:k,agentState:x,transcript:v,canResume:I,needsUserGesture:E,error:T,isMuted:h,micError:C,micDevices:$,isCameraEnabled:A,cameraPreviewEl:L,cameraDevices:P,activeCameraId:z,isScreenShareEnabled:W,screenPreviewEl:X,isSpeakerMuted:le,allowCamera:$e,allowScreenShare:ze,allowTyping:He,avatarVideoContainerRef:Oe,onConnect:fe,onDisconnect:pe,onRetry:he,onResumeAudio:me,onToggleMute:ge,onToggleCamera:ye,onSwitchCameraDevice:be,onToggleScreenShare:xe,onToggleSpeaker:B,onSendMessage:qe,onMinimize:Be,onClose:We,onClearMicError:ae})=>{var _e;const re=v.length>0?v[v.length-1]:null,te=((d==null?void 0:d.length)??0)>1,ve=k==="connecting"||k==="connected",we=k==="connected",ce=k==="idle"||k==="disconnected"||k==="error",V=r.useRef(null),Ee=r.useRef(null);r.useEffect(()=>{const b=V.current;b&&(b.innerHTML="",L&&(L.style.width="100%",L.style.height="100%",L.style.objectFit="cover",L.style.transform="scaleX(-1)",b.appendChild(L)))},[L]),r.useEffect(()=>{const b=Ee.current;b&&(b.innerHTML="",X&&(X.style.width="100%",X.style.height="100%",X.style.objectFit="contain",b.appendChild(X)))},[X]);const[Q,K]=r.useState(!1),[ne,oe]=r.useState(!1);r.useEffect(()=>{if(!Q&&!ne&&!j&&!g)return;const b=()=>{K(!1),oe(!1),j&&S(),g&&a()};return document.addEventListener("click",b),()=>document.removeEventListener("click",b)},[Q,ne,j,g,S,a]);const[J,Z]=r.useState(""),ue=r.useCallback(b=>{b.preventDefault();const Y=J.trim();Y&&(qe(Y),Z(""))},[J,qe]),Re=u.productName||"Live Layer",Fe=we&&(re!=null&&re.text)?re.text:l||"",Ne=["ll-expanded",n?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:Ne,"data-position":e,"data-state":we?"connected":ve?"connecting":"idle",role:"dialog","aria-label":`${o} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[i?t.jsx(Wn,{src:i,alt:o,className:"ll-expanded__bg-img"}):t.jsx("div",{className:"ll-expanded__bg-fallback",children:t.jsx("span",{className:"ll-expanded__bg-initial",children:((_e=o==null?void 0:o.charAt(0))==null?void 0:_e.toUpperCase())||"A"})}),s&&!we&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:Oe,className:"ll-expanded__video"}),k==="connecting"&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--connecting",children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:y?"Switching...":"Connecting..."})]}),E&&we&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:me,children:[t.jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:t.jsx("path",{d:"M3 9v6h4l5 5V4L7 9H3zm13.54.12a5 5 0 0 1 0 5.76l-1.41-1.41a3 3 0 0 0 0-2.94L16.54 9.12z"})}),t.jsx("p",{className:"ll-expanded__overlay-text",children:"Tap to enable audio"})]}),ve?t.jsxs("div",{className:"ll-expanded__topbar",children:[t.jsxs("div",{className:"ll-expanded__topbar-left",children:[t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill",onClick:b=>{te&&(b.stopPropagation(),a())},"aria-haspopup":te?"listbox":void 0,"aria-expanded":te?g:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:o}),te&&t.jsx(Ye,{})]}),te&&g&&t.jsx("div",{className:"ll-hmenu",onClick:b=>b.stopPropagation(),role:"listbox",children:d==null?void 0:d.map(b=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${b.id===p?"is-active":""}`,onClick:()=>c(b.id),role:"option","aria-selected":b.id===p,children:[b.avatarImageUrl&&t.jsx("img",{src:b.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:b.name}),b.role&&t.jsx("span",{className:"ll-hmenu__role",children:b.role})]},b.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:b=>{b.stopPropagation(),S()},"aria-haspopup":"listbox","aria-expanded":j,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(Ye,{})]}),j&&t.jsx("div",{className:"ll-hmenu",onClick:b=>b.stopPropagation(),role:"listbox",children:t.jsx("button",{type:"button",className:"ll-hmenu__item is-active",role:"option","aria-selected":!0,children:t.jsx("span",{className:"ll-hmenu__name",children:"English"})})})]}),t.jsx("span",{className:`ll-expanded__state ll-expanded__state--${x}`,children:x})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn",onClick:Be,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(It,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:We,"aria-label":"End call",title:"End call",children:t.jsx(Mt,{})})]})]}):t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:Re}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:Be,"aria-label":"Minimize widget",children:t.jsx(It,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:We,"aria-label":"Close widget",children:t.jsx(Mt,{})})]})]}),ce&&(()=>{const b=I?"Restart paused session":k==="disconnected"?"Reconnect to agent":"Start video call",Y=I?"Pick up where you left off":null,Ae=k==="idle"&&!I&&!T;return t.jsxs(t.Fragment,{children:[Ae&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:fe,"aria-label":b,children:[t.jsx("div",{className:"ll-expanded__play-circle",children:t.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:t.jsx("polygon",{points:"6 3 20 12 6 21 6 3"})})}),t.jsx("span",{className:"ll-expanded__play-label",children:b})]}),t.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[l&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:l})}),Y&&t.jsx("p",{className:"ll-expanded__cta-sublabel",children:Y}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:fe,"aria-label":b,children:b})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${ve&&(A||W)?"is-visible":""}`,children:[t.jsx("div",{ref:Ee,className:W?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:V,className:!W&&A?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),ve?t.jsxs("div",{className:"ll-expanded__bottom",children:[Fe&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Fe})}),t.jsxs("div",{className:"ll-toolbar",onClick:b=>b.stopPropagation(),children:[ze&&t.jsx("button",{type:"button",className:`ll-tool ${W?"is-on":""}`,onClick:xe,"aria-label":W?"Stop sharing screen":"Share screen",title:W?"Stop sharing":"Share screen",children:t.jsx(Un,{})}),$e&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${A?"is-on":""}`,onClick:ye,"aria-label":A?"Turn off camera":"Turn on camera",title:A?"Stop camera":"Start camera",children:t.jsx(Vn,{})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${A?"is-on":""}`,onClick:b=>{b.stopPropagation(),oe(Y=>!Y),K(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":ne,children:t.jsx(Ye,{})}),ne&&P.length>0&&t.jsx(Tt,{label:"Camera",devices:P,activeId:z,onPick:b=>{oe(!1),be(b)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${h?"is-muted":""}`,onClick:ge,"aria-label":h?"Unmute microphone":"Mute microphone",title:h?"Unmute":"Mute",children:t.jsx(Yn,{muted:h})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${h?"is-muted":""}`,onClick:b=>{b.stopPropagation(),K(Y=>!Y),oe(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":Q,children:t.jsx(Ye,{})}),Q&&$.length>0&&t.jsx(Tt,{label:"Microphone",devices:$,activeId:"",onPick:()=>K(!1)})]}),t.jsx("button",{type:"button",className:`ll-tool ${le?"is-muted":""}`,onClick:B,"aria-label":le?"Unmute speaker":"Mute speaker",title:le?"Unmute speaker":"Mute speaker",children:t.jsx(Gn,{muted:le})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:pe,"aria-label":"End conversation",title:"End conversation",children:t.jsx(Kn,{})})]}),He&&t.jsxs("form",{className:"ll-message-input",onSubmit:ue,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:J,onChange:b=>Z(b.target.value),"aria-label":"Message the agent"}),J.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(Jn,{})})]})]}):null,(()=>{if(C&&k!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:C}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:ae,"aria-label":"Dismiss",children:"×"})]});if(!T||k!=="error")return null;let b="Failed to connect",Y="Try again";return T==="MIC_PERMISSION_DENIED"?b="Microphone blocked. Allow access to talk.":T==="MIC_NOT_FOUND"?b="No microphone found. Plug one in + retry.":T==="MIC_UNAVAILABLE"?b="Mic unavailable. Check other apps using it.":T==="AGENT_TIMEOUT"?b="Agent didn't pick up. Try again.":T==="CONNECT_FAILED"?b="Connection failed. Check your network.":T.length<80&&(b=T),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:b}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:he,children:Y})]})})()]})};function Ye(){return t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":!0,children:t.jsx("polyline",{points:"6 9 12 15 18 9"})})}function Mt(){return t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function It(){return t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function Un(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),t.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),t.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function Vn(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M23 7l-7 5 7 5V7z"}),t.jsx("rect",{x:"1",y:"5",width:"15",height:"14",rx:"2"})]})}function Yn({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),t.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),t.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),e&&t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Gn({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e?t.jsx("line",{x1:"23",y1:"9",x2:"17",y2:"15"}):t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"}),t.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]})]})}function Jn(){return t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),t.jsx("polyline",{points:"12 5 19 12 12 19"})]})}function Kn(){return t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.93.37 1.84.71 2.7a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.38-1.38a2 2 0 0 1 2.11-.45c.86.34 1.77.58 2.7.71A2 2 0 0 1 22 16.92z",transform:"rotate(135 12 12)"})})}const Tt=({label:e,devices:n,activeId:o,onPick:i})=>t.jsxs("div",{className:"ll-device-menu",onClick:s=>s.stopPropagation(),role:"listbox",children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),n.map((s,l)=>{const u=o===s.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${u?"is-active":""}`,onClick:()=>i(s.deviceId),role:"option","aria-selected":u,children:[u&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:s.label||`${e} ${l+1}`})]},s.deviceId||l)})]}),Xn=['[data-ll-private="true"]',".ll-widget"];function at(e){let n=e;for(;n;){for(const o of Xn)if(n.matches(o))return!0;n=n.parentElement}return!1}function Qe(e){if(at(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const n=(e.getAttribute("autocomplete")||"").toLowerCase();if(n==="off"||n.startsWith("cc-"))return!1}return!0}const Ge=4096,Qn=20,Zn=20,er=10,tr=10,nr=30,Pt=500,rr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function Pe(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let n=e;for(;n;){for(const o of rr)if(n.matches(o))return!0;n=n.parentElement}return!1}function De(e){if(typeof window>"u")return!0;const n=e.getBoundingClientRect();if(n.width<=0||n.height<=0)return!1;const o=window.innerHeight||document.documentElement.clientHeight,i=window.innerWidth||document.documentElement.clientWidth;return n.bottom>0&&n.right>0&&n.top<o&&n.left<i}function Dt(e){const n=e.getAttribute("id");if(n){const l=document.querySelector(`label[for="${CSS.escape(n)}"]`);if(l!=null&&l.textContent)return l.textContent.trim()}const o=e.getAttribute("aria-label");if(o)return o.trim();const i=e.getAttribute("placeholder");if(i)return i.trim();const s=e.closest("label");return s!=null&&s.textContent?s.textContent.trim():""}function de(e,n){return e.length<=n?e:e.slice(0,n-1)+"…"}function Ce(e){return e.length}function tn(e,n={}){const o=n.doc??(typeof document<"u"?document:null);if(!o)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const i=typeof window<"u"&&window.location.href||"",s=typeof window<"u"&&window.location.pathname||"/",l=o.title||"",u=Array.from(o.querySelectorAll("[data-ll-region]")),d=[];for(const h of u){if(d.length>=er)break;if(Pe(h)||!De(h))continue;const C=h.getAttribute("data-ll-region")??"",$=h.getAttribute("data-ll-intent")??void 0,A=de((h.innerText||h.textContent||"").trim(),Pt*2);!C||!A||d.push({id:C,intent:$,text:A})}const p=[],y=["H1","H2","H3","H4","H5","H6"],g=Array.from(o.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const h of g){if(Pe(h)||!De(h))continue;const C=(h.textContent||"").trim();C&&p.push(`${h.tagName}: ${de(C,200)}`)}const a=Array.from(o.querySelectorAll("p, li"));for(const h of a){if(Pe(h)||!De(h)||y.includes(h.tagName))continue;const C=(h.textContent||"").trim();C.length>10&&p.push(de(C,Pt))}const c=p.join(`
2
+ `),j=[],S=Array.from(o.querySelectorAll("a[href]"));for(const h of S){if(j.length>=Qn)break;if(Pe(h)||!De(h))continue;const C=h.getAttribute("href")||"",$=(h.textContent||"").trim();!C||!$||j.push({href:C,text:de($,100)})}const k=[],x=Array.from(o.querySelectorAll("input, textarea, select"));for(const h of x){if(k.length>=Zn)break;if(Pe(h)||!Qe(h)||!De(h))continue;const C=Dt(h),$=h instanceof HTMLInputElement?h.type:h.tagName.toLowerCase();C&&k.push({label:de(C,100),type:$})}const v=Array.from(o.querySelectorAll("[data-ll-form]")),I=[];for(const h of v){if(I.length>=tr)break;if(at(h))continue;const C=h.getAttribute("data-ll-form")||"";if(!C)continue;const $=h.getAttribute("data-ll-intent")||void 0,A=Array.from(h.querySelectorAll("[data-ll-field]")),L=[];for(const P of A){if(L.length>=nr)break;if(!Qe(P))continue;const z=P.getAttribute("data-ll-field")||"";if(!z)continue;const W=Dt(P)||z,X=P instanceof HTMLInputElement?P.type:P.tagName.toLowerCase();L.push({name:z,label:de(W,100),type:X})}I.push({id:C,intent:$,fields:L})}const E={url:i,title:l,pathname:s,regions:d,visibleText:c,visibleLinks:j,visibleFields:k,forms:I,extras:e};let T=Ce(JSON.stringify(E.regions))+Ce(E.visibleText)+Ce(JSON.stringify(E.visibleLinks))+Ce(JSON.stringify(E.visibleFields));for(;T>Ge&&E.visibleFields.length>0;)E.visibleFields.pop(),T=Ce(JSON.stringify(E.visibleFields));for(;T>Ge&&E.visibleLinks.length>0;)E.visibleLinks.pop(),T-=80;return Ce(E.visibleText)>Ge&&(E.visibleText=de(E.visibleText,Ge-100)),E}let Le=null;function lt(e,n={}){const o=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(Le&&Le.key===s&&o-Le.at<1e3)return Le.ctx;const l=tn(e,n);return Le={key:s,at:o,ctx:l},l}function nn(){Le=null}const or=200;function rn(e){const n=String(e.href||"");return{href:n,text:String(e.text??e.title??n),internal:e.internal??!0,title:e.title,description:e.description}}function ir(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function on(e){const n=e??(typeof document<"u"?document:null);if(!n)return[];const o=typeof window<"u"&&window.location.origin||"",i=new Set,s=[],l=Array.from(n.querySelectorAll("a[href]"));for(const u of l){if(s.length>=or)break;if(at(u))continue;const d=u.getAttribute("href")||"";if(!ir(d))continue;let p=d,y=!0;try{if(typeof window<"u"){const a=new URL(d,o);y=a.origin===o,y&&d.startsWith("http")&&(p=a.pathname+a.search+a.hash)}}catch{continue}if(i.has(p))continue;i.add(p);const g=(u.textContent||"").trim().slice(0,120);s.push({href:p,text:g,internal:y})}return s}let je=null;const sr=5e3;function Je(){const e=Date.now(),n=typeof window<"u"&&window.location.pathname||"/";if(je&&je.pathname===n&&e-je.at<sr)return je.routes;const o=on();return je={at:e,pathname:n,routes:o},o}function sn(){je=null}function lr(e,n){const o=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,i=Object.getOwnPropertyDescriptor(o,"value"),s=i==null?void 0:i.set;s?s.call(e,n):e.value=n}function ar(e,n,o={}){const i=o.triggerInput??!0,s=o.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const l=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),u=l==null?void 0:l.set,d=n==="true"||n==="1"||n==="on";u?u.call(e,d):e.checked=d,i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}lr(e,n),i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function cr(){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 n=window.getComputedStyle(e);return!(n.overflowY==="hidden"||n.overflowY==="clip")}function ur(e){if(!(e instanceof HTMLElement))return!1;const o=window.getComputedStyle(e).overflowY;return!(o!=="auto"&&o!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function dr(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let n=null,o=0;for(const i of e){if(!ur(i))continue;const s=i.getBoundingClientRect();if(s.bottom<=0||s.top>=window.innerHeight||s.right<=0||s.left>=window.innerWidth||s.width<=0||s.height<=0||i.closest(".ll-widget"))continue;const l=s.width*s.height;l>o&&(o=l,n=i)}return n}function fr(){if(typeof window>"u")return null;if(cr())return window;const e=dr();return e||window}function $t(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function pr(e){var n,o;return e instanceof Window?typeof document>"u"?0:Math.max(((n=document.body)==null?void 0:n.scrollHeight)??0,((o=document.documentElement)==null?void 0:o.scrollHeight)??0):e.scrollHeight-e.clientHeight}const hr=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"]);function mr(e){var mt,gt,yt,bt,xt,vt,wt;const{agentId:n,apiKey:o,baseUrl:i="https://app.livelayer.studio",sessionEndpoint:s,sessionBody:l,autoConnect:u=!1,displayMode:d,defaultDisplayMode:p="expanded",onDisplayModeChange:y,position:g="bottom-right",mobileBreakpoint:a=640,persistKey:c="ll-widget",disablePersistence:j=!1,teamMembers:S,currentTeamMemberId:k,onTeamMemberChange:x,idleLoopUrl:v,greeting:I,avatarImageUrl:E,agentName:T,branding:h={},allowCamera:C=!0,allowScreenShare:$=!0,allowTyping:A=!0,showOn:L,hideOn:P,pathname:z,onNavigate:W,onScrollToSelector:X,getPageContext:le,pageContextExtras:$e,getRoutes:ze,onScrollPage:He,onClick:Oe,capabilities:fe,onConnect:pe,onDisconnect:he,onTranscript:me,onAgentState:ge,onConnectionStateChange:ye,onAgentEvent:be,onAgentCommand:xe,controlledSession:B,className:qe,style:Be,zIndex:We=2147483647}=e,ae=Kt(z),re=Zt(ae,L,P);r.useEffect(()=>{nn(),sn()},[ae]);const te=k!==void 0,[ve,we]=r.useState(()=>{var m;return k??((m=S==null?void 0:S[0])==null?void 0:m.id)}),ce=te?k:ve,V=r.useMemo(()=>(S==null?void 0:S.find(m=>m.id===ce))??null,[S,ce]),Ee=(V==null?void 0:V.agentId)??n,[Q,K]=Gt({value:d,defaultValue:p,onChange:y,persistKey:c,disablePersistence:j}),ne=Jt(a),oe=qt(),J=Bt(),Z=Wt(),ue=Ft(),Re=Ut(),[Fe,Ne]=r.useState(!1),[_e,b]=r.useState(!1),[Y,Ae]=r.useState(!1),[ln,an]=r.useState(!1),[Ze,cn]=r.useState(!1),et=r.useRef(W),tt=r.useRef(X),nt=r.useRef(He),rt=r.useRef(Oe),ct=r.useRef(le),ut=r.useRef($e),dt=r.useRef(ze),ot=r.useRef(fe),ee=r.useRef(null);et.current=W,tt.current=X,nt.current=He,rt.current=Oe,ct.current=le,ut.current=$e,dt.current=ze,ot.current=fe;function ie(m){const f=ot.current;return f?f.includes(m):!0}function se(m,f){console.warn(`[LiveLayer] Agent command "${m}" blocked — capability "${f}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const Me=r.useCallback(m=>{var F,ke,Ve,_t;const f=m;if(!(!f.type||typeof f.type!="string")){if(be==null||be({eventName:f.type,data:m}),f.type==="navigate"){if(!ie("navigate")){se("navigate","navigate");return}const _=typeof f.href=="string"?f.href:null;if(!_){console.warn(`[LiveLayer] Agent emitted "navigate" without href. Skipping. Check your agent's tool schema. See https://livelayer.studio/docs/errors/navigate-missing-href`);return}if(et.current){try{et.current(_)}catch(R){console.warn(`[LiveLayer] onNavigate threw for "${_}". Falling back. Error:`,R)}return}if(typeof document<"u"){const R=document.querySelector(`a[href="${_.replace(/"/g,'\\"')}"]`);if(R){R.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",_),window.dispatchEvent(new PopStateEvent("popstate"))}catch(R){console.warn(`[LiveLayer] history.pushState fallback failed for "${_}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,R)}return}if(f.type==="scroll_to"){if(!ie("scroll")){se("scroll_to","scroll");return}const _=typeof f.selector=="string"?f.selector:null;if(!_)return;const R=f.behavior==="instant"?"instant":"smooth";if(tt.current){try{tt.current(_,R)}catch(D){console.warn("[LiveLayer] onScrollToSelector threw.",D)}return}if(typeof document<"u"){let D=null;try{D=document.querySelector(_)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${_}".`);return}if(!D){console.warn(`[LiveLayer] scroll_to: no element matched "${_}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}D.scrollIntoView({behavior:R,block:"start"})}return}if(f.type==="request_page_context"){if(!ie("read_page")){se("request_page_context","read_page");return}const _=typeof f.requestId=="string"?f.requestId:void 0,R=(F=ee.current)==null?void 0:F.call(ee),D=q=>{const N=R,U=N==null?void 0:N.localParticipant;if(U!=null&&U.publishData)try{const G=_?{...q,requestId:_}:q,Se=new TextEncoder().encode(JSON.stringify(G));U.publishData(Se,{reliable:!0})}catch(G){console.warn("[LiveLayer] publishData failed.",G)}},M=ut.current,H=ct.current;try{if(H){const q=H(M);if(q instanceof Promise){D({type:"page_context_pending"}),q.then(N=>D({type:"page_context",context:N})).catch(N=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",N),D({type:"page_context",context:lt(M)})});return}D({type:"page_context",context:q});return}D({type:"page_context",context:lt(M)})}catch(q){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",q),D({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:M}})}return}if(f.type==="scroll_page"){if(!ie("scroll")){se("scroll_page","scroll");return}const _=f.direction;if(_!=="up"&&_!=="down"&&_!=="top"&&_!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(_)}". Expected up | down | top | bottom.`);return}const R=f.behavior==="instant"?"instant":"smooth";if(nt.current){try{nt.current(_,R)}catch(N){console.warn("[LiveLayer] onScrollPage threw.",N)}return}if(typeof window>"u")return;const D={behavior:R},M=fr(),H=N=>{M instanceof Window?M.scrollBy({top:N,...D}):M.scrollBy({top:N,...D})},q=N=>{M instanceof Window?M.scrollTo({top:N,...D}):M.scrollTo({top:N,...D})};_==="up"?H(-$t(M)):_==="down"?H($t(M)):q(_==="top"?0:pr(M));return}if(f.type==="click"){if(!ie("click")){se("click","click");return}const _=typeof f.selector=="string"?f.selector:null;if(!_){console.warn("[LiveLayer] click: missing selector.");return}if(rt.current){try{rt.current(_)}catch(D){console.warn("[LiveLayer] onClick threw.",D)}return}if(typeof document>"u")return;let R=null;try{R=document.querySelector(_)}catch{console.warn(`[LiveLayer] click: invalid selector "${_}".`);return}if(!R){console.warn(`[LiveLayer] click: no element matched "${_}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(ke=R.click)==null||ke.call(R);return}if(f.type==="fill_form"||f.type==="focus_field"){if(!ie("fill_forms")){se(f.type,"fill_forms");return}if(typeof document>"u")return;const _=typeof f.formId=="string"?f.formId:null;if(!_){console.warn(`[LiveLayer] ${f.type}: missing formId.`);return}const R=document.querySelector(`[data-ll-form="${_.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] ${f.type}: no form with data-ll-form="${_}". Tag your form with <LiveLayerForm id> or data-ll-form. See https://livelayer.studio/docs/react/forms`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn(`[LiveLayer] ${f.type}: refusing to touch a form in a private subtree.`);return}if(f.type==="focus_field"){const M=typeof f.fieldName=="string"?f.fieldName:null;if(!M){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const H=R.querySelector(`[data-ll-field="${M.replace(/"/g,'\\"')}"]`);if(!H){console.warn(`[LiveLayer] focus_field: no field "${M}" in form "${_}".`);return}if(!Qe(H)){console.warn(`[LiveLayer] focus_field: field "${M}" is privacy-protected and not focusable.`);return}H.focus();return}const D=f.values&&typeof f.values=="object"?f.values:null;if(!D){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[M,H]of Object.entries(D)){if(typeof H!="string")continue;const q=R.querySelector(`[data-ll-field="${M.replace(/"/g,'\\"')}"]`);if(!q){console.warn(`[LiveLayer] fill_form: no field "${M}" in form "${_}". Skipping.`);continue}if(!Qe(q)){console.warn(`[LiveLayer] fill_form: field "${M}" is privacy-protected (password / cc-* / private). Skipping.`);continue}try{ar(q,H)}catch(N){console.warn(`[LiveLayer] fill_form: failed to set "${M}".`,N)}}return}if(f.type==="submit_form"){if(!ie("submit_forms")){se("submit_form","submit_forms");return}if(typeof document>"u")return;const _=typeof f.formId=="string"?f.formId:null;if(!_){console.warn("[LiveLayer] submit_form: missing formId.");return}const R=document.querySelector(`[data-ll-form="${_.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${_}".`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private subtree.");return}const D=typeof f.requestId=="string"?f.requestId:void 0,M=(Ve=ee.current)==null?void 0:Ve.call(ee),H=U=>{const G=M,Se=G==null?void 0:G.localParticipant;if(Se!=null&&Se.publishData)try{const wn=D?{...U,requestId:D}:U,_n=new TextEncoder().encode(JSON.stringify(wn));Se.publishData(_n,{reliable:!0})}catch{}};let q=!1;const N=()=>{q=!0,H({type:"form_submitted",formId:_})};R.addEventListener("submit",N,{once:!0});try{typeof R.requestSubmit=="function"?R.requestSubmit():R.submit()}catch(U){console.warn("[LiveLayer] submit_form: requestSubmit threw.",U),R.removeEventListener("submit",N),H({type:"form_submit_blocked",formId:_,reason:"exception"});return}setTimeout(()=>{q||(R.removeEventListener("submit",N),H({type:"form_submit_blocked",formId:_,reason:"validation"}))},500);return}if(f.type==="request_routes"){if(!ie("read_page")){se("request_routes","read_page");return}const _=typeof f.requestId=="string"?f.requestId:void 0,D=(_t=ee.current)==null?void 0:_t.call(ee),M=D==null?void 0:D.localParticipant;if(!(M!=null&&M.publishData))return;const H=N=>{try{const U=_?{type:"routes",routes:N,requestId:_}:{type:"routes",routes:N},G=new TextEncoder().encode(JSON.stringify(U));M.publishData(G,{reliable:!0})}catch(U){console.warn("[LiveLayer] request_routes: publishData failed.",U)}},q=dt.current;if(q){try{const N=q(),U=G=>{if(!Array.isArray(G)){H([]);return}H(G.map(rn).slice(0,200))};N instanceof Promise?N.then(U).catch(G=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",G),H(Je())}):U(N)}catch(N){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",N),H(Je())}return}try{H(Je())}catch(N){console.warn("[LiveLayer] request_routes: extractRoutes threw.",N)}return}hr.has(f.type)||xe==null||xe(f)}},[xe,be]),O=Ot({agentId:B?"__controlled__":Ee,baseUrl:i,apiKey:o,sessionEndpoint:s,sessionBody:l,onDataMessage:B?void 0:Me});r.useEffect(()=>{if(B!=null&&B.subscribeToDataMessages)return B.subscribeToDataMessages(Me)},[B,Me]),ee.current=()=>{var m;return(m=O.getRoom)==null?void 0:m.call(O)},r.useEffect(()=>{var F;if(!ae)return;const m=(F=O.getRoom)==null?void 0:F.call(O),f=m==null?void 0:m.localParticipant;if(f!=null&&f.publishData)try{const ke=new TextEncoder().encode(JSON.stringify({type:"pathname",pathname:ae}));f.publishData(ke,{reliable:!0})}catch{}},[ae,O,O.connectionState]),r.useEffect(()=>{var F;if(typeof window>"u")return;const m=((F=window.location)==null?void 0:F.hostname)||"";if(m==="localhost"||m==="127.0.0.1"||m==="0.0.0.0"||m.endsWith(".local")||m.endsWith(".test"))return window.__livelayerSimulateCommand=ke=>{try{Me(ke)}catch(Ve){console.warn("[LiveLayer] simulate-command threw:",Ve)}},()=>{delete window.__livelayerSimulateCommand}},[Me]);const w=r.useMemo(()=>B?{connectionState:B.connectionState,agentState:B.agentState,transcript:B.transcript,videoElement:B.videoElement,audioElement:B.audioElement,canResume:B.canResume,error:B.error,agentConfig:null,connect:async()=>{await B.onConnect()},disconnect:()=>B.onDisconnect(),getRoom:O.getRoom,isControlled:!0}:{connectionState:O.connectionState,agentState:O.agentState,transcript:O.transcript,videoElement:O.videoElement,audioElement:O.audioElement,canResume:O.canResume,error:O.error,agentConfig:O.agentConfig,connect:O.connect,disconnect:O.disconnect,getRoom:O.getRoom,isControlled:!1},[B,O]),ft=r.useRef(null);r.useEffect(()=>{const m=w.videoElement,f=ft.current;if(!(!m||!f))return f.appendChild(m),()=>{m.parentNode===f&&f.removeChild(m)}},[w.videoElement]),r.useEffect(()=>{const m=w.audioElement;if(!m)return;oe.attach(m);const f=m.play();return f&&typeof f.catch=="function"&&f.catch(F=>{(F==null?void 0:F.name)==="NotAllowedError"&&Ne(!0)}),()=>{oe.detach()}},[w.audioElement]),r.useEffect(()=>{if(w.isControlled||w.connectionState!=="connected")return;const m=w.getRoom();if(m)return J.setupMic(m).catch(()=>{}),Z.attachRoom(m),ue.attachRoom(m),Re.refresh(),()=>{J.teardownMic(),Z.teardown(),ue.teardown()}},[w.isControlled,w.connectionState]),r.useEffect(()=>{const m=w.audioElement;m&&(m.muted=Ze)},[w.audioElement,Ze]);const un=r.useCallback(m=>{const f=w.getRoom();if(f)try{const F=new TextEncoder().encode(JSON.stringify({type:"user_message",text:m}));f.localParticipant.publishData(F,{reliable:!0})}catch{}},[w]),dn=r.useCallback(()=>{cn(m=>!m)},[]);r.useEffect(()=>{ye==null||ye(w.connectionState),w.connectionState==="connected"?pe==null||pe():w.connectionState==="disconnected"&&(he==null||he())},[w.connectionState,pe,he,ye]),r.useEffect(()=>{me==null||me(w.transcript)},[w.transcript,me]),r.useEffect(()=>{ge==null||ge(w.agentState)},[w.agentState,ge]);const pt=r.useRef(!1);r.useEffect(()=>{w.isControlled||!u||pt.current||re&&w.connectionState==="idle"&&(pt.current=!0,w.connect())},[u,w.connectionState,w,re]);const fn=r.useCallback(m=>{const f=S==null?void 0:S.find(F=>F.id===m);f&&(Ae(!1),m!==ce&&(b(!0),w.disconnect(),te||we(m),x==null||x(f)))},[S,ce,w,te,x]);r.useEffect(()=>{_e&&w.connectionState==="connected"&&b(!1)},[w.connectionState,_e]),r.useEffect(()=>{if(!Y)return;const m=f=>{f.key==="Escape"&&Ae(!1)};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[Y]);const pn=!!E||!!(V!=null&&V.avatarImageUrl)||w.isControlled,Ie=Vt(Ee,i,pn);fe===void 0&&((mt=Ie.info)!=null&&mt.capabilities)&&(ot.current=Ie.info.capabilities);const Ue=(V==null?void 0:V.name)??T??((gt=w.agentConfig)==null?void 0:gt.name)??((yt=Ie.info)==null?void 0:yt.name)??"Live Layer",it=(V==null?void 0:V.avatarImageUrl)??E??((bt=w.agentConfig)==null?void 0:bt.avatarImageUrl)??((xt=Ie.info)==null?void 0:xt.avatarImageUrl)??null,hn=v??((vt=w.agentConfig)==null?void 0:vt.idleLoopUrl)??((wt=Ie.info)==null?void 0:wt.idleLoopUrl)??null,mn=I??null,gn=r.useCallback(()=>K("expanded"),[K]),yn=r.useCallback(()=>K("minimized"),[K]),ht=r.useCallback(()=>{w.disconnect(),K("hidden")},[w,K]),bn=r.useCallback(()=>{const m=w.audioElement;m&&m.play().then(()=>Ne(!1)).catch(()=>{})},[w.audioElement]),xn=r.useCallback(()=>{Ne(!1),w.connect()},[w]),Te={...Be,zIndex:We};h.primaryColor&&(Te["--ll-color-primary"]=h.primaryColor),h.accentColor&&(Te["--ll-color-accent"]=h.accentColor),h.backgroundColor&&(Te["--ll-color-bg"]=h.backgroundColor),h.textColor&&(Te["--ll-color-fg"]=h.textColor);const vn=["ll-widget",`ll-widget--${Q}`,`ll-widget--${ne?"mobile":"desktop"}`,qe].filter(Boolean).join(" ");return re?t.jsxs("div",{className:vn,style:Te,"data-display-mode":Q,"data-position":g,children:[Q==="hidden"&&t.jsx(On,{position:g,isMobile:ne,isSpeaking:w.agentState==="speaking",onExpand:()=>K("expanded"),label:`Open ${Ue} widget`,avatarImageUrl:it,agentName:Ue}),Q==="minimized"&&t.jsx(Bn,{position:g,isMobile:ne,agentName:Ue,avatarImageUrl:it,agentState:w.agentState,isMuted:J.isMuted,audioLevel:oe,onExpand:gn,onToggleMute:J.toggleMute,onClose:ht}),Q==="expanded"&&t.jsx(Fn,{position:g,isMobile:ne,agentName:Ue,avatarImageUrl:it,idleLoopUrl:hn,greeting:mn,branding:h,teamMembers:S,currentTeamMemberId:ce,isSwitchingTeamMember:_e,teamSwitcherOpen:Y,onToggleTeamSwitcher:()=>Ae(m=>!m),onSelectTeamMember:fn,connectionState:w.connectionState,agentState:w.agentState,transcript:w.transcript,isMuted:J.isMuted,micDevices:Re.mics,isCameraEnabled:Z.isEnabled,cameraPreviewEl:Z.previewEl,cameraDevices:Re.cameras,activeCameraId:Z.activeDeviceId,isScreenShareEnabled:ue.isEnabled,screenPreviewEl:ue.previewEl,isSpeakerMuted:Ze,allowCamera:C,allowScreenShare:$,allowTyping:A,languageMenuOpen:ln,onToggleLanguageMenu:()=>an(m=>!m),needsUserGesture:Fe,canResume:w.canResume,micError:J.micError,error:w.error,avatarVideoContainerRef:ft,onConnect:()=>void w.connect(),onDisconnect:()=>w.disconnect(),onRetry:xn,onResumeAudio:bn,onToggleMute:J.toggleMute,onToggleCamera:()=>void Z.toggle(),onSwitchCameraDevice:m=>void Z.switchDevice(m),onToggleScreenShare:()=>void ue.toggle(),onToggleSpeaker:dn,onSendMessage:un,onMinimize:yn,onClose:ht,onClearMicError:J.clearError})]}):null}function gr(e){return t.jsx(Ht,{children:t.jsx(mr,{...e})})}const yr=({agentId:e,baseUrl:n,apiKey:o,mode:i,onAgentEvent:s,className:l,style:u})=>{const d=r.useRef(null),p=r.useRef(null),y=r.useRef(s);y.current=s;const g=r.useCallback(a=>{var j;const c=a.detail;(j=y.current)==null||j.call(y,c)},[]);return r.useEffect(()=>{const a=d.current;if(!a)return;const c=document.createElement("livelayer-widget");return c.setAttribute("agent-id",e),n&&c.setAttribute("base-url",n),o&&c.setAttribute("api-key",o),i&&c.setAttribute("mode",i),c.addEventListener("agent-event",g),a.appendChild(c),p.current=c,()=>{c.removeEventListener("agent-event",g),a.removeChild(c),p.current=null}},[e]),r.useEffect(()=>{p.current&&(i?p.current.setAttribute("mode",i):p.current.removeAttribute("mode"))},[i]),t.jsx("div",{ref:d,className:l,style:u})},br=r.forwardRef(function({id:n,intent:o,as:i="div",className:s,style:l,children:u},d){return r.createElement(i,{ref:d,"data-ll-region":n,"data-ll-intent":o,className:s,style:l},u)}),xr=r.forwardRef(function({id:n,intent:o,children:i,...s},l){return t.jsx("form",{ref:l,"data-ll-form":n,"data-ll-intent":o,...s,children:i})}),vr=r.forwardRef(function(n,o){const{name:i,label:s,labelClassName:l}=n,u={name:i,"data-ll-field":i};let d;if("as"in n&&n.as==="textarea"){const{name:p,label:y,labelClassName:g,as:a,...c}=n;d=t.jsx("textarea",{ref:o,...u,...c})}else if("as"in n&&n.as==="select"){const{name:p,label:y,labelClassName:g,as:a,children:c,...j}=n;d=t.jsx("select",{ref:o,...u,...j,children:c})}else{const{name:p,label:y,labelClassName:g,as:a,...c}=n;d=t.jsx("input",{ref:o,...u,...c})}return s===void 0?d:t.jsxs("label",{className:l,children:[s,d]})});let zt=1;function wr({onMount:e,defaultOpen:n=!1,storageKey:o="ll-debug-open"}){const[i,s]=r.useState(n),[l,u]=r.useState([]),[d,p]=r.useState(""),[y,g]=r.useState(!1),a=r.useRef(new Set),c=r.useRef([]),j=r.useRef(y);j.current=y,r.useEffect(()=>{try{const x=localStorage.getItem(o);x==="1"&&s(!0),x==="0"&&s(!1)}catch{}},[o]),r.useEffect(()=>{try{localStorage.setItem(o,i?"1":"0")}catch{}},[i,o]),r.useEffect(()=>{const x=v=>{(v.metaKey||v.ctrlKey)&&v.shiftKey&&v.key.toLowerCase()==="l"&&(v.preventDefault(),s(I=>!I))};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[]),r.useEffect(()=>{const x=setInterval(()=>{if(c.current.length===0||j.current)return;const v=c.current.splice(0,c.current.length);u(I=>[...v.reverse(),...I].slice(0,200))},100);return()=>clearInterval(x)},[]);const S=r.useRef(!1);if(r.useEffect(()=>{!e||S.current||(S.current=!0,e(x=>{c.current.push({id:zt++,ts:Date.now(),kind:"event",type:x.eventName,data:x.data})}))},[e]),r.useEffect(()=>{const x=console.warn,v=console.log,I=(E,T)=>function(...h){try{const C=typeof h[0]=="string"?h[0]:"";C.startsWith("[LiveLayer]")&&c.current.push({id:zt++,ts:Date.now(),kind:E,type:C.slice(0,120),data:{args:h.slice(1).map($=>kr($))}})}catch{}return T.apply(this,h)};return console.warn=I("warn",x),console.log=I("log",v),()=>{console.warn=x,console.log=v}},[]),!i)return t.jsx("button",{type:"button",onClick:()=>s(!0),title:"Open LiveLayer debug panel (Cmd/Ctrl + Shift + L)","aria-label":"Open LiveLayer debug panel",style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.18)",borderRadius:999,padding:"6px 10px",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",cursor:"pointer",boxShadow:"0 4px 12px rgba(0,0,0,0.35)",opacity:.85},children:"🛰 LL debug"});const k=l.filter(x=>{if(!d)return!0;const v=d.toLowerCase();return x.type.toLowerCase().includes(v)||JSON.stringify(x.data||{}).toLowerCase().includes(v)});return t.jsxs("div",{style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,width:380,maxHeight:"60vh",background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:12,boxShadow:"0 16px 48px rgba(0,0,0,0.5)",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"8px 10px",background:"rgba(255,255,255,0.04)",borderBottom:"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),t.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[l.length," event",l.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>g(x=>!x),style:st(y?"#f59e0b":"transparent"),title:"Pause / resume capture",children:y?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{u([]),c.current=[]},style:st("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:st("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:d,onChange:x=>p(x.target.value),placeholder:"filter by type or data…",style:{margin:8,padding:"6px 8px",background:"rgba(255,255,255,0.06)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:"#fff",fontSize:11,outline:"none"}}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 8px 8px"},children:k.length===0?t.jsxs("div",{style:{padding:14,fontSize:11,color:"rgba(255,255,255,0.4)",lineHeight:1.5},children:["No events yet. Connect to the agent and trigger a tool call — the events will stream in here. You can also dispatch commands manually in DevTools:",t.jsx("pre",{style:{marginTop:6,background:"rgba(255,255,255,0.04)",padding:6,borderRadius:4,fontSize:10,whiteSpace:"pre-wrap"},children:`window.__livelayerSimulateCommand({
3
3
  type: "navigate",
4
4
  href: "/about"
5
- })`})]}):k.map(x=>t.jsx(wr,{entry:x,expanded:a.current.has(x.id),onToggle:()=>{a.current.has(x.id)?a.current.delete(x.id):a.current.add(x.id),u(v=>[...v])}},x.id))})]})}function wr({entry:e,expanded:n,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",s=new Date(e.ts).toLocaleTimeString("en-US",{hour12:!1});return t.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:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums",fontSize:10},children:s}),t.jsx("span",{style:{color:o,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),n&&e.data&&t.jsx("pre",{style:{marginTop:6,padding:6,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:10,overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(e.data,null,2)})]})}function st(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 _r(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function kr(){const[e,n]=r.useState([]),i=r.useCallback(s=>{n(l=>{const u=l.findIndex(d=>d.id===s.id);if(u>=0){const d=l.slice();return d[u]=s,d}return[...l,s]})},[]),o=r.useCallback(()=>n([]),[]);return{entries:e,pushSegment:i,clear:o,latest:e.length>0?e[e.length-1]:null}}exports.AvatarWidget=mr;exports.ErrorBoundary=Ht;exports.LiveLayerDebugPanel=vr;exports.LiveLayerField=xr;exports.LiveLayerForm=br;exports.LiveLayerRegion=yr;exports.LiveLayerWidget=gr;exports.clearPageContextCache=nn;exports.clearRoutesCache=sn;exports.extractPageContext=tn;exports.extractRoutes=on;exports.getCachedPageContext=lt;exports.getCachedRoutes=Ke;exports.matchesPattern=Xt;exports.normalizeRouteInput=rn;exports.shouldRenderAtPath=Qt;exports.useAgentInfo=Vt;exports.useAudioLevel=qt;exports.useCameraState=Wt;exports.useDisplayMode=Yt;exports.useDisplayModePersistence=Jt;exports.useIsMobile=Kt;exports.useLiveKitSession=Ot;exports.useMediaDevices=Ut;exports.useMicrophoneState=Bt;exports.usePathname=Gt;exports.useRouteMatch=Zt;exports.useScreenShareState=Ft;exports.useTranscript=kr;
5
+ })`})]}):k.map(x=>t.jsx(_r,{entry:x,expanded:a.current.has(x.id),onToggle:()=>{a.current.has(x.id)?a.current.delete(x.id):a.current.add(x.id),u(v=>[...v])}},x.id))})]})}function _r({entry:e,expanded:n,onToggle:o}){const i=e.kind==="warn"?"#f59e0b":e.type.startsWith("[LiveLayer]")?"#94a3b8":e.type==="navigate"||e.type==="scroll_page"||e.type==="scroll_to"||e.type==="click"?"#22c55e":e.type==="fill_form"||e.type==="submit_form"||e.type==="focus_field"?"#a78bfa":e.type==="request_page_context"||e.type==="request_routes"?"#38bdf8":e.type==="agent_state"?"#facc15":"#cbd5e1",s=new Date(e.ts).toLocaleTimeString("en-US",{hour12:!1});return t.jsxs("button",{type:"button",onClick:o,style:{textAlign:"left",background:"transparent",border:0,color:"#fff",width:"100%",padding:"6px 4px",cursor:"pointer",borderBottom:"1px solid rgba(255,255,255,0.04)",fontSize:11,lineHeight:1.4},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums",fontSize:10},children:s}),t.jsx("span",{style:{color:i,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),n&&e.data&&t.jsx("pre",{style:{marginTop:6,padding:6,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:10,overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(e.data,null,2)})]})}function st(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 kr(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Sr(){const[e,n]=r.useState([]),o=r.useCallback(s=>{n(l=>{const u=l.findIndex(d=>d.id===s.id);if(u>=0){const d=l.slice();return d[u]=s,d}return[...l,s]})},[]),i=r.useCallback(()=>n([]),[]);return{entries:e,pushSegment:o,clear:i,latest:e.length>0?e[e.length-1]:null}}exports.AvatarWidget=gr;exports.ErrorBoundary=Ht;exports.LiveLayerDebugPanel=wr;exports.LiveLayerField=vr;exports.LiveLayerForm=xr;exports.LiveLayerRegion=br;exports.LiveLayerWidget=yr;exports.clearPageContextCache=nn;exports.clearRoutesCache=sn;exports.extractPageContext=tn;exports.extractRoutes=on;exports.getCachedPageContext=lt;exports.getCachedRoutes=Je;exports.matchesPattern=Xt;exports.normalizeRouteInput=rn;exports.shouldRenderAtPath=Qt;exports.useAgentInfo=Vt;exports.useAudioLevel=qt;exports.useCameraState=Wt;exports.useDisplayMode=Yt;exports.useDisplayModePersistence=Gt;exports.useIsMobile=Jt;exports.useLiveKitSession=Ot;exports.useMediaDevices=Ut;exports.useMicrophoneState=Bt;exports.usePathname=Kt;exports.useRouteMatch=Zt;exports.useScreenShareState=Ft;exports.useTranscript=Sr;
package/dist/index.mjs CHANGED
@@ -781,7 +781,7 @@ const Vn = ({
781
781
  },
782
782
  a
783
783
  )) });
784
- }, Jn = ({
784
+ }, Gn = ({
785
785
  position: e,
786
786
  isMobile: t,
787
787
  agentName: r,
@@ -907,7 +907,7 @@ const Vn = ({
907
907
  ] })
908
908
  ] })
909
909
  }
910
- ), Gn = ({
910
+ ), Jn = ({
911
911
  src: e,
912
912
  alt: t,
913
913
  preCannedPlaying: r = !1,
@@ -1041,7 +1041,7 @@ const Vn = ({
1041
1041
  children: [
1042
1042
  /* @__PURE__ */ w("div", { className: "ll-expanded__bg", children: [
1043
1043
  o ? /* @__PURE__ */ n(
1044
- Gn,
1044
+ Jn,
1045
1045
  {
1046
1046
  src: o,
1047
1047
  alt: r,
@@ -1378,6 +1378,17 @@ const Vn = ({
1378
1378
  title: ue ? "Unmute speaker" : "Mute speaker",
1379
1379
  children: /* @__PURE__ */ n(er, { muted: ue })
1380
1380
  }
1381
+ ),
1382
+ /* @__PURE__ */ n(
1383
+ "button",
1384
+ {
1385
+ type: "button",
1386
+ className: "ll-tool ll-tool--danger",
1387
+ onClick: ye,
1388
+ "aria-label": "End conversation",
1389
+ title: "End conversation",
1390
+ children: /* @__PURE__ */ n(nr, {})
1391
+ }
1381
1392
  )
1382
1393
  ] }),
1383
1394
  We && /* @__PURE__ */ w("form", { className: "ll-message-input", onSubmit: he, children: [
@@ -1401,16 +1412,7 @@ const Vn = ({
1401
1412
  children: /* @__PURE__ */ n(tr, {})
1402
1413
  }
1403
1414
  )
1404
- ] }),
1405
- /* @__PURE__ */ n(
1406
- "button",
1407
- {
1408
- type: "button",
1409
- className: "ll-expanded__end",
1410
- onClick: ye,
1411
- children: "End conversation"
1412
- }
1413
- )
1415
+ ] })
1414
1416
  ] }) : null,
1415
1417
  (() => {
1416
1418
  if (N && L !== "error")
@@ -1494,6 +1496,15 @@ function tr() {
1494
1496
  /* @__PURE__ */ n("polyline", { points: "12 5 19 12 12 19" })
1495
1497
  ] });
1496
1498
  }
1499
+ function nr() {
1500
+ return /* @__PURE__ */ n("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": !0, children: /* @__PURE__ */ n(
1501
+ "path",
1502
+ {
1503
+ 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",
1504
+ transform: "rotate(135 12 12)"
1505
+ }
1506
+ ) });
1507
+ }
1497
1508
  const Ot = ({ label: e, devices: t, activeId: r, onPick: o }) => /* @__PURE__ */ w(
1498
1509
  "div",
1499
1510
  {
@@ -1522,14 +1533,14 @@ const Ot = ({ label: e, devices: t, activeId: r, onPick: o }) => /* @__PURE__ */
1522
1533
  })
1523
1534
  ]
1524
1535
  }
1525
- ), nr = [
1536
+ ), rr = [
1526
1537
  '[data-ll-private="true"]',
1527
1538
  ".ll-widget"
1528
1539
  ];
1529
1540
  function pt(e) {
1530
1541
  let t = e;
1531
1542
  for (; t; ) {
1532
- for (const r of nr)
1543
+ for (const r of rr)
1533
1544
  if (t.matches(r)) return !0;
1534
1545
  t = t.parentElement;
1535
1546
  }
@@ -1544,7 +1555,7 @@ function tt(e) {
1544
1555
  }
1545
1556
  return !0;
1546
1557
  }
1547
- const Qe = 4096, rr = 20, or = 20, ir = 10, lr = 10, ar = 30, qt = 500, cr = [
1558
+ const Qe = 4096, or = 20, ir = 20, lr = 10, ar = 10, cr = 30, qt = 500, sr = [
1548
1559
  '[data-ll-private="true"]',
1549
1560
  ".ll-widget",
1550
1561
  "script",
@@ -1556,7 +1567,7 @@ function He(e) {
1556
1567
  if (e.getAttribute("aria-hidden") === "true" || e.hasAttribute("hidden")) return !0;
1557
1568
  let t = e;
1558
1569
  for (; t; ) {
1559
- for (const r of cr)
1570
+ for (const r of sr)
1560
1571
  if (t.matches(r)) return !0;
1561
1572
  t = t.parentElement;
1562
1573
  }
@@ -1588,7 +1599,7 @@ function me(e, t) {
1588
1599
  function Ae(e) {
1589
1600
  return e.length;
1590
1601
  }
1591
- function sr(e, t = {}) {
1602
+ function dr(e, t = {}) {
1592
1603
  const r = t.doc ?? (typeof document < "u" ? document : null);
1593
1604
  if (!r)
1594
1605
  return {
@@ -1606,7 +1617,7 @@ function sr(e, t = {}) {
1606
1617
  r.querySelectorAll("[data-ll-region]")
1607
1618
  ), d = [];
1608
1619
  for (const p of s) {
1609
- if (d.length >= ir) break;
1620
+ if (d.length >= lr) break;
1610
1621
  if (He(p) || !Oe(p)) continue;
1611
1622
  const N = p.getAttribute("data-ll-region") ?? "", B = p.getAttribute("data-ll-intent") ?? void 0, D = me(
1612
1623
  (p.innerText || p.textContent || "").trim(),
@@ -1631,7 +1642,7 @@ function sr(e, t = {}) {
1631
1642
  const c = f.join(`
1632
1643
  `), R = [], C = Array.from(r.querySelectorAll("a[href]"));
1633
1644
  for (const p of C) {
1634
- if (R.length >= rr) break;
1645
+ if (R.length >= or) break;
1635
1646
  if (He(p) || !Oe(p)) continue;
1636
1647
  const N = p.getAttribute("href") || "", B = (p.textContent || "").trim();
1637
1648
  !N || !B || R.push({ href: N, text: me(B, 100) });
@@ -1642,7 +1653,7 @@ function sr(e, t = {}) {
1642
1653
  )
1643
1654
  );
1644
1655
  for (const p of v) {
1645
- if (L.length >= or) break;
1656
+ if (L.length >= ir) break;
1646
1657
  if (He(p) || !tt(p) || !Oe(p)) continue;
1647
1658
  const N = Bt(p), B = p instanceof HTMLInputElement ? p.type : p.tagName.toLowerCase();
1648
1659
  N && L.push({ label: me(N, 100), type: B });
@@ -1651,7 +1662,7 @@ function sr(e, t = {}) {
1651
1662
  r.querySelectorAll("[data-ll-form]")
1652
1663
  ), z = [];
1653
1664
  for (const p of b) {
1654
- if (z.length >= lr) break;
1665
+ if (z.length >= ar) break;
1655
1666
  if (pt(p)) continue;
1656
1667
  const N = p.getAttribute("data-ll-form") || "";
1657
1668
  if (!N) continue;
@@ -1661,7 +1672,7 @@ function sr(e, t = {}) {
1661
1672
  )
1662
1673
  ), A = [];
1663
1674
  for (const O of D) {
1664
- if (A.length >= ar) break;
1675
+ if (A.length >= cr) break;
1665
1676
  if (!tt(O)) continue;
1666
1677
  const W = O.getAttribute("data-ll-field") || "";
1667
1678
  if (!W) continue;
@@ -1693,14 +1704,14 @@ function Wt(e, t = {}) {
1693
1704
  const r = Date.now(), i = `${typeof window < "u" && window.location.pathname || "/"}::${typeof window < "u" ? window.scrollY : 0}`;
1694
1705
  if (Re && Re.key === i && r - Re.at < 1e3)
1695
1706
  return Re.ctx;
1696
- const l = sr(e, t);
1707
+ const l = dr(e, t);
1697
1708
  return Re = { key: i, at: r, ctx: l }, l;
1698
1709
  }
1699
- function dr() {
1710
+ function ur() {
1700
1711
  Re = null;
1701
1712
  }
1702
- const ur = 200;
1703
- function fr(e) {
1713
+ const fr = 200;
1714
+ function pr(e) {
1704
1715
  const t = String(e.href || "");
1705
1716
  return {
1706
1717
  href: t,
@@ -1710,18 +1721,18 @@ function fr(e) {
1710
1721
  description: e.description
1711
1722
  };
1712
1723
  }
1713
- function pr(e) {
1724
+ function hr(e) {
1714
1725
  return !(!e || e.startsWith("#") || e.startsWith("javascript:") || e.startsWith("mailto:") || e.startsWith("tel:"));
1715
1726
  }
1716
- function hr(e) {
1727
+ function mr(e) {
1717
1728
  const t = e ?? (typeof document < "u" ? document : null);
1718
1729
  if (!t) return [];
1719
1730
  const r = typeof window < "u" && window.location.origin || "", o = /* @__PURE__ */ new Set(), i = [], l = Array.from(t.querySelectorAll("a[href]"));
1720
1731
  for (const s of l) {
1721
- if (i.length >= ur) break;
1732
+ if (i.length >= fr) break;
1722
1733
  if (pt(s)) continue;
1723
1734
  const d = s.getAttribute("href") || "";
1724
- if (!pr(d)) continue;
1735
+ if (!hr(d)) continue;
1725
1736
  let f = d, g = !0;
1726
1737
  try {
1727
1738
  if (typeof window < "u") {
@@ -1739,22 +1750,22 @@ function hr(e) {
1739
1750
  return i;
1740
1751
  }
1741
1752
  let Ie = null;
1742
- const mr = 5e3;
1753
+ const gr = 5e3;
1743
1754
  function st() {
1744
1755
  const e = Date.now(), t = typeof window < "u" && window.location.pathname || "/";
1745
- if (Ie && Ie.pathname === t && e - Ie.at < mr)
1756
+ if (Ie && Ie.pathname === t && e - Ie.at < gr)
1746
1757
  return Ie.routes;
1747
- const r = hr();
1758
+ const r = mr();
1748
1759
  return Ie = { at: e, pathname: t, routes: r }, r;
1749
1760
  }
1750
- function gr() {
1761
+ function yr() {
1751
1762
  Ie = null;
1752
1763
  }
1753
- function yr(e, t) {
1764
+ function vr(e, t) {
1754
1765
  const r = e instanceof HTMLInputElement ? HTMLInputElement.prototype : e instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLSelectElement.prototype, o = Object.getOwnPropertyDescriptor(r, "value"), i = o == null ? void 0 : o.set;
1755
1766
  i ? i.call(e, t) : e.value = t;
1756
1767
  }
1757
- function vr(e, t, r = {}) {
1768
+ function br(e, t, r = {}) {
1758
1769
  const o = r.triggerInput ?? !0, i = r.triggerChange ?? !0;
1759
1770
  if (e instanceof HTMLInputElement && (e.type === "checkbox" || e.type === "radio")) {
1760
1771
  const l = Object.getOwnPropertyDescriptor(
@@ -1764,9 +1775,9 @@ function vr(e, t, r = {}) {
1764
1775
  s ? s.call(e, d) : e.checked = d, o && e.dispatchEvent(new Event("input", { bubbles: !0 })), i && e.dispatchEvent(new Event("change", { bubbles: !0 }));
1765
1776
  return;
1766
1777
  }
1767
- yr(e, t), o && e.dispatchEvent(new Event("input", { bubbles: !0 })), i && e.dispatchEvent(new Event("change", { bubbles: !0 }));
1778
+ vr(e, t), o && e.dispatchEvent(new Event("input", { bubbles: !0 })), i && e.dispatchEvent(new Event("change", { bubbles: !0 }));
1768
1779
  }
1769
- function br() {
1780
+ function wr() {
1770
1781
  if (typeof window > "u" || typeof document > "u")
1771
1782
  return !1;
1772
1783
  const e = document.scrollingElement || document.documentElement;
@@ -1774,19 +1785,19 @@ function br() {
1774
1785
  const t = window.getComputedStyle(e);
1775
1786
  return !(t.overflowY === "hidden" || t.overflowY === "clip");
1776
1787
  }
1777
- function wr(e) {
1788
+ function _r(e) {
1778
1789
  if (!(e instanceof HTMLElement)) return !1;
1779
1790
  const r = window.getComputedStyle(e).overflowY;
1780
1791
  return !(r !== "auto" && r !== "scroll" || e.scrollHeight <= e.clientHeight + 2);
1781
1792
  }
1782
- function _r() {
1793
+ function xr() {
1783
1794
  if (typeof document > "u") return null;
1784
1795
  const e = Array.from(
1785
1796
  document.querySelectorAll("body, body *")
1786
1797
  );
1787
1798
  let t = null, r = 0;
1788
1799
  for (const o of e) {
1789
- if (!wr(o)) continue;
1800
+ if (!_r(o)) continue;
1790
1801
  const i = o.getBoundingClientRect();
1791
1802
  if (i.bottom <= 0 || i.top >= window.innerHeight || i.right <= 0 || i.left >= window.innerWidth || i.width <= 0 || i.height <= 0 || o.closest(".ll-widget")) continue;
1792
1803
  const l = i.width * i.height;
@@ -1794,24 +1805,24 @@ function _r() {
1794
1805
  }
1795
1806
  return t;
1796
1807
  }
1797
- function xr() {
1808
+ function kr() {
1798
1809
  if (typeof window > "u")
1799
1810
  return null;
1800
- if (br()) return window;
1801
- const e = _r();
1811
+ if (wr()) return window;
1812
+ const e = xr();
1802
1813
  return e || window;
1803
1814
  }
1804
1815
  function Ft(e) {
1805
1816
  return e instanceof Window ? e.innerHeight || 0 : e.clientHeight || 0;
1806
1817
  }
1807
- function kr(e) {
1818
+ function Lr(e) {
1808
1819
  var t, r;
1809
1820
  return e instanceof Window ? typeof document > "u" ? 0 : Math.max(
1810
1821
  ((t = document.body) == null ? void 0 : t.scrollHeight) ?? 0,
1811
1822
  ((r = document.documentElement) == null ? void 0 : r.scrollHeight) ?? 0
1812
1823
  ) : e.scrollHeight - e.clientHeight;
1813
1824
  }
1814
- const Lr = /* @__PURE__ */ new Set([
1825
+ const Sr = /* @__PURE__ */ new Set([
1815
1826
  "agent_state",
1816
1827
  "avatar_stream_ready",
1817
1828
  "avatar_active",
@@ -1834,7 +1845,7 @@ const Lr = /* @__PURE__ */ new Set([
1834
1845
  "submit_form",
1835
1846
  "request_routes"
1836
1847
  ]);
1837
- function Sr(e) {
1848
+ function Cr(e) {
1838
1849
  var wt, _t, xt, kt, Lt, St, Ct;
1839
1850
  const {
1840
1851
  agentId: t,
@@ -1885,7 +1896,7 @@ function Sr(e) {
1885
1896
  zIndex: Ve = 2147483647
1886
1897
  } = e, fe = Tn(W), ae = qn(fe, A, O);
1887
1898
  T(() => {
1888
- dr(), gr();
1899
+ ur(), yr();
1889
1900
  }, [fe]);
1890
1901
  const ie = L !== void 0, [Le, Se] = S(() => {
1891
1902
  var h;
@@ -1899,7 +1910,7 @@ function Sr(e) {
1899
1910
  onChange: g,
1900
1911
  persistKey: c,
1901
1912
  disablePersistence: R
1902
- }), le = In(a), ce = yn(), Z = vn(), re = wn(), he = _n(), Te = xn(), [Ye, Pe] = S(!1), [Ce, y] = S(!1), [X, Je] = S(!1), [Yt, Jt] = S(!1), [nt, Gt] = S(!1), rt = E(Y), ot = E(te), it = E(We), lt = E(Fe), ht = E(ue), mt = E(qe), gt = E(Be), at = E(ge), oe = E(null);
1913
+ }), le = In(a), ce = yn(), Z = vn(), re = wn(), he = _n(), Te = xn(), [Ye, Pe] = S(!1), [Ce, y] = S(!1), [X, Ge] = S(!1), [Yt, Gt] = S(!1), [nt, Jt] = S(!1), rt = E(Y), ot = E(te), it = E(We), lt = E(Fe), ht = E(ue), mt = E(qe), gt = E(Be), at = E(ge), oe = E(null);
1903
1914
  rt.current = Y, ot.current = te, it.current = We, lt.current = Fe, ht.current = ue, mt.current = qe, gt.current = Be, at.current = ge;
1904
1915
  function se(h) {
1905
1916
  const u = at.current;
@@ -1912,7 +1923,7 @@ function Sr(e) {
1912
1923
  }
1913
1924
  const De = k(
1914
1925
  (h) => {
1915
- var J, Ee, Ke, Et;
1926
+ var G, Ee, Ke, Et;
1916
1927
  const u = h;
1917
1928
  if (!(!u.type || typeof u.type != "string")) {
1918
1929
  if (xe == null || xe({ eventName: u.type, data: h }), u.type === "navigate") {
@@ -2005,12 +2016,12 @@ function Sr(e) {
2005
2016
  de("request_page_context", "read_page");
2006
2017
  return;
2007
2018
  }
2008
- const x = typeof u.requestId == "string" ? u.requestId : void 0, M = (J = oe.current) == null ? void 0 : J.call(oe), q = (j) => {
2009
- const P = M, G = P == null ? void 0 : P.localParticipant;
2010
- if (G != null && G.publishData)
2019
+ const x = typeof u.requestId == "string" ? u.requestId : void 0, M = (G = oe.current) == null ? void 0 : G.call(oe), q = (j) => {
2020
+ const P = M, J = P == null ? void 0 : P.localParticipant;
2021
+ if (J != null && J.publishData)
2011
2022
  try {
2012
2023
  const Q = x ? { ...j, requestId: x } : j, Ne = new TextEncoder().encode(JSON.stringify(Q));
2013
- G.publishData(Ne, { reliable: !0 });
2024
+ J.publishData(Ne, { reliable: !0 });
2014
2025
  } catch (Q) {
2015
2026
  console.warn("[LiveLayer] publishData failed.", Q);
2016
2027
  }
@@ -2073,12 +2084,12 @@ function Sr(e) {
2073
2084
  return;
2074
2085
  }
2075
2086
  if (typeof window > "u") return;
2076
- const q = { behavior: M }, $ = xr(), F = (P) => {
2087
+ const q = { behavior: M }, $ = kr(), F = (P) => {
2077
2088
  $ instanceof Window ? $.scrollBy({ top: P, ...q }) : $.scrollBy({ top: P, ...q });
2078
2089
  }, j = (P) => {
2079
2090
  $ instanceof Window ? $.scrollTo({ top: P, ...q }) : $.scrollTo({ top: P, ...q });
2080
2091
  };
2081
- x === "up" ? F(-Ft($)) : x === "down" ? F(Ft($)) : j(x === "top" ? 0 : kr($));
2092
+ x === "up" ? F(-Ft($)) : x === "down" ? F(Ft($)) : j(x === "top" ? 0 : Lr($));
2082
2093
  return;
2083
2094
  }
2084
2095
  if (u.type === "click") {
@@ -2193,7 +2204,7 @@ function Sr(e) {
2193
2204
  continue;
2194
2205
  }
2195
2206
  try {
2196
- vr(j, F);
2207
+ br(j, F);
2197
2208
  } catch (P) {
2198
2209
  console.warn(
2199
2210
  `[LiveLayer] fill_form: failed to set "${$}".`,
@@ -2229,11 +2240,11 @@ function Sr(e) {
2229
2240
  );
2230
2241
  return;
2231
2242
  }
2232
- const q = typeof u.requestId == "string" ? u.requestId : void 0, $ = (Ke = oe.current) == null ? void 0 : Ke.call(oe), F = (G) => {
2243
+ const q = typeof u.requestId == "string" ? u.requestId : void 0, $ = (Ke = oe.current) == null ? void 0 : Ke.call(oe), F = (J) => {
2233
2244
  const Q = $, Ne = Q == null ? void 0 : Q.localParticipant;
2234
2245
  if (Ne != null && Ne.publishData)
2235
2246
  try {
2236
- const cn = q ? { ...G, requestId: q } : G, sn = new TextEncoder().encode(JSON.stringify(cn));
2247
+ const cn = q ? { ...J, requestId: q } : J, sn = new TextEncoder().encode(JSON.stringify(cn));
2237
2248
  Ne.publishData(sn, { reliable: !0 });
2238
2249
  } catch {
2239
2250
  }
@@ -2245,8 +2256,8 @@ function Sr(e) {
2245
2256
  M.addEventListener("submit", P, { once: !0 });
2246
2257
  try {
2247
2258
  typeof M.requestSubmit == "function" ? M.requestSubmit() : M.submit();
2248
- } catch (G) {
2249
- console.warn("[LiveLayer] submit_form: requestSubmit threw.", G), M.removeEventListener("submit", P), F({
2259
+ } catch (J) {
2260
+ console.warn("[LiveLayer] submit_form: requestSubmit threw.", J), M.removeEventListener("submit", P), F({
2250
2261
  type: "form_submit_blocked",
2251
2262
  formId: x,
2252
2263
  reason: "exception"
@@ -2271,27 +2282,27 @@ function Sr(e) {
2271
2282
  if (!($ != null && $.publishData)) return;
2272
2283
  const F = (P) => {
2273
2284
  try {
2274
- const G = x ? { type: "routes", routes: P, requestId: x } : { type: "routes", routes: P }, Q = new TextEncoder().encode(JSON.stringify(G));
2285
+ const J = x ? { type: "routes", routes: P, requestId: x } : { type: "routes", routes: P }, Q = new TextEncoder().encode(JSON.stringify(J));
2275
2286
  $.publishData(Q, { reliable: !0 });
2276
- } catch (G) {
2277
- console.warn("[LiveLayer] request_routes: publishData failed.", G);
2287
+ } catch (J) {
2288
+ console.warn("[LiveLayer] request_routes: publishData failed.", J);
2278
2289
  }
2279
2290
  }, j = gt.current;
2280
2291
  if (j) {
2281
2292
  try {
2282
- const P = j(), G = (Q) => {
2293
+ const P = j(), J = (Q) => {
2283
2294
  if (!Array.isArray(Q)) {
2284
2295
  F([]);
2285
2296
  return;
2286
2297
  }
2287
- F(Q.map(fr).slice(0, 200));
2298
+ F(Q.map(pr).slice(0, 200));
2288
2299
  };
2289
- P instanceof Promise ? P.then(G).catch((Q) => {
2300
+ P instanceof Promise ? P.then(J).catch((Q) => {
2290
2301
  console.warn(
2291
2302
  "[LiveLayer] getRoutes rejected; falling back to DOM walker.",
2292
2303
  Q
2293
2304
  ), F(st());
2294
- }) : G(P);
2305
+ }) : J(P);
2295
2306
  } catch (P) {
2296
2307
  console.warn(
2297
2308
  "[LiveLayer] getRoutes threw; falling back to DOM walker.",
@@ -2307,7 +2318,7 @@ function Sr(e) {
2307
2318
  }
2308
2319
  return;
2309
2320
  }
2310
- Lr.has(u.type) || ke == null || ke(u);
2321
+ Sr.has(u.type) || ke == null || ke(u);
2311
2322
  }
2312
2323
  },
2313
2324
  [ke, xe]
@@ -2326,9 +2337,9 @@ function Sr(e) {
2326
2337
  var h;
2327
2338
  return (h = U.getRoom) == null ? void 0 : h.call(U);
2328
2339
  }, T(() => {
2329
- var J;
2340
+ var G;
2330
2341
  if (!fe) return;
2331
- const h = (J = U.getRoom) == null ? void 0 : J.call(U), u = h == null ? void 0 : h.localParticipant;
2342
+ const h = (G = U.getRoom) == null ? void 0 : G.call(U), u = h == null ? void 0 : h.localParticipant;
2332
2343
  if (u != null && u.publishData)
2333
2344
  try {
2334
2345
  const Ee = new TextEncoder().encode(
@@ -2338,9 +2349,9 @@ function Sr(e) {
2338
2349
  } catch {
2339
2350
  }
2340
2351
  }, [fe, U, U.connectionState]), T(() => {
2341
- var J;
2352
+ var G;
2342
2353
  if (typeof window > "u") return;
2343
- const h = ((J = window.location) == null ? void 0 : J.hostname) || "";
2354
+ const h = ((G = window.location) == null ? void 0 : G.hostname) || "";
2344
2355
  if (h === "localhost" || h === "127.0.0.1" || h === "0.0.0.0" || h.endsWith(".local") || h.endsWith(".test"))
2345
2356
  return window.__livelayerSimulateCommand = (Ee) => {
2346
2357
  try {
@@ -2395,8 +2406,8 @@ function Sr(e) {
2395
2406
  if (!h) return;
2396
2407
  ce.attach(h);
2397
2408
  const u = h.play();
2398
- return u && typeof u.catch == "function" && u.catch((J) => {
2399
- (J == null ? void 0 : J.name) === "NotAllowedError" && Pe(!0);
2409
+ return u && typeof u.catch == "function" && u.catch((G) => {
2410
+ (G == null ? void 0 : G.name) === "NotAllowedError" && Pe(!0);
2400
2411
  }), () => {
2401
2412
  ce.detach();
2402
2413
  };
@@ -2416,14 +2427,14 @@ function Sr(e) {
2416
2427
  const u = _.getRoom();
2417
2428
  if (u)
2418
2429
  try {
2419
- const J = new TextEncoder().encode(
2430
+ const G = new TextEncoder().encode(
2420
2431
  JSON.stringify({ type: "user_message", text: h })
2421
2432
  );
2422
- u.localParticipant.publishData(J, { reliable: !0 });
2433
+ u.localParticipant.publishData(G, { reliable: !0 });
2423
2434
  } catch {
2424
2435
  }
2425
2436
  }, [_]), Xt = k(() => {
2426
- Gt((h) => !h);
2437
+ Jt((h) => !h);
2427
2438
  }, []);
2428
2439
  T(() => {
2429
2440
  _e == null || _e(_.connectionState), _.connectionState === "connected" ? ye == null || ye() : _.connectionState === "disconnected" && (ve == null || ve());
@@ -2438,8 +2449,8 @@ function Sr(e) {
2438
2449
  }, [s, _.connectionState, _, ae]);
2439
2450
  const Qt = k(
2440
2451
  (h) => {
2441
- const u = C == null ? void 0 : C.find((J) => J.id === h);
2442
- u && (Je(!1), h !== pe && (y(!0), _.disconnect(), ie || Se(h), v == null || v(u)));
2452
+ const u = C == null ? void 0 : C.find((G) => G.id === h);
2453
+ u && (Ge(!1), h !== pe && (y(!0), _.disconnect(), ie || Se(h), v == null || v(u)));
2443
2454
  },
2444
2455
  [
2445
2456
  C,
@@ -2454,13 +2465,13 @@ function Sr(e) {
2454
2465
  }, [_.connectionState, Ce]), T(() => {
2455
2466
  if (!X) return;
2456
2467
  const h = (u) => {
2457
- u.key === "Escape" && Je(!1);
2468
+ u.key === "Escape" && Ge(!1);
2458
2469
  };
2459
2470
  return window.addEventListener("keydown", h), () => window.removeEventListener("keydown", h);
2460
2471
  }, [X]);
2461
2472
  const Zt = !!I || !!(K != null && K.avatarImageUrl) || _.isControlled, $e = kn(Me, o, Zt);
2462
2473
  ge === void 0 && ((wt = $e.info) != null && wt.capabilities) && (at.current = $e.info.capabilities);
2463
- const Ge = (K == null ? void 0 : K.name) ?? H ?? ((_t = _.agentConfig) == null ? void 0 : _t.name) ?? ((xt = $e.info) == null ? void 0 : xt.name) ?? "Live Layer", ct = (K == null ? void 0 : K.avatarImageUrl) ?? I ?? ((kt = _.agentConfig) == null ? void 0 : kt.avatarImageUrl) ?? ((Lt = $e.info) == null ? void 0 : Lt.avatarImageUrl) ?? null, en = b ?? ((St = _.agentConfig) == null ? void 0 : St.idleLoopUrl) ?? ((Ct = $e.info) == null ? void 0 : Ct.idleLoopUrl) ?? null, tn = z ?? null, nn = k(() => ee("expanded"), [ee]), rn = k(
2474
+ const Je = (K == null ? void 0 : K.name) ?? H ?? ((_t = _.agentConfig) == null ? void 0 : _t.name) ?? ((xt = $e.info) == null ? void 0 : xt.name) ?? "Live Layer", ct = (K == null ? void 0 : K.avatarImageUrl) ?? I ?? ((kt = _.agentConfig) == null ? void 0 : kt.avatarImageUrl) ?? ((Lt = $e.info) == null ? void 0 : Lt.avatarImageUrl) ?? null, en = b ?? ((St = _.agentConfig) == null ? void 0 : St.idleLoopUrl) ?? ((Ct = $e.info) == null ? void 0 : Ct.idleLoopUrl) ?? null, tn = z ?? null, nn = k(() => ee("expanded"), [ee]), rn = k(
2464
2475
  () => ee("minimized"),
2465
2476
  [ee]
2466
2477
  ), bt = k(() => {
@@ -2497,17 +2508,17 @@ function Sr(e) {
2497
2508
  isMobile: le,
2498
2509
  isSpeaking: _.agentState === "speaking",
2499
2510
  onExpand: () => ee("expanded"),
2500
- label: `Open ${Ge} widget`,
2511
+ label: `Open ${Je} widget`,
2501
2512
  avatarImageUrl: ct,
2502
- agentName: Ge
2513
+ agentName: Je
2503
2514
  }
2504
2515
  ),
2505
2516
  ne === "minimized" && /* @__PURE__ */ n(
2506
- Jn,
2517
+ Gn,
2507
2518
  {
2508
2519
  position: m,
2509
2520
  isMobile: le,
2510
- agentName: Ge,
2521
+ agentName: Je,
2511
2522
  avatarImageUrl: ct,
2512
2523
  agentState: _.agentState,
2513
2524
  isMuted: Z.isMuted,
@@ -2522,7 +2533,7 @@ function Sr(e) {
2522
2533
  {
2523
2534
  position: m,
2524
2535
  isMobile: le,
2525
- agentName: Ge,
2536
+ agentName: Je,
2526
2537
  avatarImageUrl: ct,
2527
2538
  idleLoopUrl: en,
2528
2539
  greeting: tn,
@@ -2531,7 +2542,7 @@ function Sr(e) {
2531
2542
  currentTeamMemberId: pe,
2532
2543
  isSwitchingTeamMember: Ce,
2533
2544
  teamSwitcherOpen: X,
2534
- onToggleTeamSwitcher: () => Je((h) => !h),
2545
+ onToggleTeamSwitcher: () => Ge((h) => !h),
2535
2546
  onSelectTeamMember: Qt,
2536
2547
  connectionState: _.connectionState,
2537
2548
  agentState: _.agentState,
@@ -2549,7 +2560,7 @@ function Sr(e) {
2549
2560
  allowScreenShare: B,
2550
2561
  allowTyping: D,
2551
2562
  languageMenuOpen: Yt,
2552
- onToggleLanguageMenu: () => Jt((h) => !h),
2563
+ onToggleLanguageMenu: () => Gt((h) => !h),
2553
2564
  needsUserGesture: Ye,
2554
2565
  canResume: _.canResume,
2555
2566
  micError: Z.micError,
@@ -2574,10 +2585,10 @@ function Sr(e) {
2574
2585
  }
2575
2586
  ) : null;
2576
2587
  }
2577
- function Tr(e) {
2578
- return /* @__PURE__ */ n(mn, { children: /* @__PURE__ */ n(Sr, { ...e }) });
2588
+ function Pr(e) {
2589
+ return /* @__PURE__ */ n(mn, { children: /* @__PURE__ */ n(Cr, { ...e }) });
2579
2590
  }
2580
- const Pr = ({
2591
+ const Dr = ({
2581
2592
  agentId: e,
2582
2593
  baseUrl: t,
2583
2594
  apiKey: r,
@@ -2603,7 +2614,7 @@ const Pr = ({
2603
2614
  }, [e]), T(() => {
2604
2615
  f.current && (o ? f.current.setAttribute("mode", o) : f.current.removeAttribute("mode"));
2605
2616
  }, [o]), /* @__PURE__ */ n("div", { ref: d, className: l, style: s });
2606
- }, Dr = ft(
2617
+ }, $r = ft(
2607
2618
  function({ id: t, intent: r, as: o = "div", className: i, style: l, children: s }, d) {
2608
2619
  return un(
2609
2620
  o,
@@ -2617,7 +2628,7 @@ const Pr = ({
2617
2628
  s
2618
2629
  );
2619
2630
  }
2620
- ), $r = ft(
2631
+ ), zr = ft(
2621
2632
  function({ id: t, intent: r, children: o, ...i }, l) {
2622
2633
  return /* @__PURE__ */ n(
2623
2634
  "form",
@@ -2630,7 +2641,7 @@ const Pr = ({
2630
2641
  }
2631
2642
  );
2632
2643
  }
2633
- ), zr = ft(
2644
+ ), Hr = ft(
2634
2645
  function(t, r) {
2635
2646
  const { name: o, label: i, labelClassName: l } = t, s = { name: o, "data-ll-field": o };
2636
2647
  let d;
@@ -2673,7 +2684,7 @@ const Pr = ({
2673
2684
  }
2674
2685
  );
2675
2686
  let Ut = 1;
2676
- function Hr({
2687
+ function Or({
2677
2688
  onMount: e,
2678
2689
  defaultOpen: t = !1,
2679
2690
  storageKey: r = "ll-debug-open"
@@ -2725,7 +2736,7 @@ function Hr({
2725
2736
  ts: Date.now(),
2726
2737
  kind: I,
2727
2738
  type: N.slice(0, 120),
2728
- data: { args: p.slice(1).map((B) => Er(B)) }
2739
+ data: { args: p.slice(1).map((B) => Nr(B)) }
2729
2740
  });
2730
2741
  } catch {
2731
2742
  }
@@ -2901,7 +2912,7 @@ function Hr({
2901
2912
  ]
2902
2913
  }
2903
2914
  ) : L.map((v) => /* @__PURE__ */ n(
2904
- Cr,
2915
+ Er,
2905
2916
  {
2906
2917
  entry: v,
2907
2918
  expanded: a.current.has(v.id),
@@ -2917,7 +2928,7 @@ function Hr({
2917
2928
  }
2918
2929
  );
2919
2930
  }
2920
- function Cr({
2931
+ function Er({
2921
2932
  entry: e,
2922
2933
  expanded: t,
2923
2934
  onToggle: r
@@ -2998,14 +3009,14 @@ function dt(e) {
2998
3009
  cursor: "pointer"
2999
3010
  };
3000
3011
  }
3001
- function Er(e) {
3012
+ function Nr(e) {
3002
3013
  try {
3003
3014
  return e instanceof Error ? { message: e.message, stack: e.stack } : (JSON.stringify(e), e);
3004
3015
  } catch {
3005
3016
  return String(e);
3006
3017
  }
3007
3018
  }
3008
- function Or() {
3019
+ function qr() {
3009
3020
  const [e, t] = S([]), r = k((i) => {
3010
3021
  t((l) => {
3011
3022
  const s = l.findIndex((d) => d.id === i.id);
@@ -3024,21 +3035,21 @@ function Or() {
3024
3035
  };
3025
3036
  }
3026
3037
  export {
3027
- Tr as AvatarWidget,
3038
+ Pr as AvatarWidget,
3028
3039
  mn as ErrorBoundary,
3029
- Hr as LiveLayerDebugPanel,
3030
- zr as LiveLayerField,
3031
- $r as LiveLayerForm,
3032
- Dr as LiveLayerRegion,
3033
- Pr as LiveLayerWidget,
3034
- dr as clearPageContextCache,
3035
- gr as clearRoutesCache,
3036
- sr as extractPageContext,
3037
- hr as extractRoutes,
3040
+ Or as LiveLayerDebugPanel,
3041
+ Hr as LiveLayerField,
3042
+ zr as LiveLayerForm,
3043
+ $r as LiveLayerRegion,
3044
+ Dr as LiveLayerWidget,
3045
+ ur as clearPageContextCache,
3046
+ yr as clearRoutesCache,
3047
+ dr as extractPageContext,
3048
+ mr as extractRoutes,
3038
3049
  Wt as getCachedPageContext,
3039
3050
  st as getCachedRoutes,
3040
3051
  Hn as matchesPattern,
3041
- fr as normalizeRouteInput,
3052
+ pr as normalizeRouteInput,
3042
3053
  On as shouldRenderAtPath,
3043
3054
  kn as useAgentInfo,
3044
3055
  yn as useAudioLevel,
@@ -3052,5 +3063,5 @@ export {
3052
3063
  Tn as usePathname,
3053
3064
  qn as useRouteMatch,
3054
3065
  _n as useScreenShareState,
3055
- Or as useTranscript
3066
+ qr as useTranscript
3056
3067
  };
package/dist/styles.css CHANGED
@@ -683,12 +683,13 @@
683
683
  background: rgba(0, 0, 0, 0.55);
684
684
  }
685
685
 
686
- /* Compact pill — used for short codes like "EN". Tightens horizontal
687
- padding and slightly shrinks the type so it reads as an icon-style
688
- chip next to the full-size agent name pill. */
686
+ /* Compact pill — used for short codes like "EN". Same height as the
687
+ sibling pills/buttons in the topbar (40px) so the row is uniform.
688
+ Compact horizontal padding + uppercase / tracked type so it reads
689
+ as an icon-style chip next to the full-size agent name pill. */
689
690
  .ll-hpill--compact {
690
- height: 32px;
691
- padding: 0 10px;
691
+ height: 40px;
692
+ padding: 0 12px;
692
693
  font-size: 12px;
693
694
  font-weight: 600;
694
695
  letter-spacing: 0.04em;
@@ -1000,6 +1001,24 @@
1000
1001
  color: #fff;
1001
1002
  }
1002
1003
 
1004
+ /* Danger variant — used for End conversation in the toolbar row.
1005
+ Same shape/size as a regular tool; red tint signals "this ends the
1006
+ call." Sits at the right edge of the toolbar so eye flow is L→R:
1007
+ share → camera → mic → speaker → END. */
1008
+ .ll-tool--danger {
1009
+ background: rgba(239, 68, 68, 0.78);
1010
+ border-color: rgba(255, 120, 120, 0.55);
1011
+ color: #fff;
1012
+ /* Pull slightly away from the speaker so it visually groups as
1013
+ "exit", not "yet another media control." */
1014
+ margin-left: 6px;
1015
+ }
1016
+
1017
+ .ll-tool--danger:hover {
1018
+ background: rgba(220, 38, 38, 0.92);
1019
+ border-color: rgba(255, 140, 140, 0.7);
1020
+ }
1021
+
1003
1022
  /* Split button: left = toggle, right = device menu */
1004
1023
  .ll-tool-split {
1005
1024
  position: relative;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livelayer/react",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
4
4
  "description": "LiveLayer agent widget for React — avatar video, team switching, responsive layouts, full-fidelity embed",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",