@livelayer/react 0.5.20 → 0.5.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),n=require("react"),Nn=require("@livelayer/sdk"),at=require("livekit-client");class Xt extends n.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,i){var o,s;(s=(o=this.props).onError)==null||s.call(o,r,i)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[t.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),t.jsx("p",{className:"ll-error-boundary__message",children:((r=this.state.error)==null?void 0:r.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function Gt(e){const[r,i]=n.useState("idle"),[o,s]=n.useState("idle"),[a,u]=n.useState([]),[f,p]=n.useState(null),[b,v]=n.useState(null),[c,l]=n.useState(null),[_,C]=n.useState(!1),[S,x]=n.useState(null),w=n.useRef(null),P=n.useRef(e.onDataMessage);P.current=e.onDataMessage,n.useEffect(()=>{const L={onConnectionStateChange:I=>{i(I),I==="connected"&&x(null)},onAgentStateChange:s,onTranscript:I=>u([...I]),onAgentConfig:p,onAudioTrack:I=>l(I),onVideoTrack:I=>v(I),onVideoTrackRemoved:()=>v(null),onError:I=>x(I),onDataMessage:I=>{var j;(j=P.current)==null||j.call(P,I)},onResumabilityChange:C},z=new Nn.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},L);return w.current=z,i("idle"),s("idle"),u([]),p(null),v(null),l(null),C(!1),x(null),()=>{var I;(I=z.destroy)==null||I.call(z),w.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=n.useCallback(async()=>{const L=w.current;if(L)try{await L.connect()}catch(z){throw x(z instanceof Error?z.message:String(z)),z}},[]),D=n.useCallback(()=>{const L=w.current;L&&L.disconnect()},[]),g=n.useCallback(()=>{var L;return((L=w.current)==null?void 0:L.getRoom())??null},[]);return{connectionState:r,agentState:o,transcript:a,agentConfig:f,videoElement:b,audioElement:c,canResume:_,error:S,connect:E,disconnect:D,getRoom:g,session:w.current}}function Qt(){const e=n.useRef(null),r=n.useRef(null),i=n.useRef(null),o=n.useRef(null),s=n.useRef(new Set),a=n.useRef(null),u=n.useCallback(()=>{const c=r.current;if(!c){o.current=null;return}(!a.current||a.current.length!==c.frequencyBinCount)&&(a.current=new Uint8Array(new ArrayBuffer(c.frequencyBinCount)));const l=a.current;c.getByteFrequencyData(l);let _=0;for(let S=0;S<l.length;S++)_+=l[S];const C=_/l.length/255;for(const S of s.current)try{S(C)}catch(x){console.error("[useAudioLevel] subscriber threw:",x)}o.current=requestAnimationFrame(u)},[]),f=n.useCallback(()=>{if(e.current||typeof window>"u"||typeof AudioContext>"u")return;const c=new AudioContext,l=c.createAnalyser();l.fftSize=64,l.connect(c.destination),e.current=c,r.current=l},[]),p=n.useCallback(c=>{if(f(),!(!e.current||!r.current)){if(i.current){try{i.current.disconnect()}catch{}i.current=null}try{const l=e.current.createMediaElementSource(c);l.connect(r.current),i.current=l}catch(l){console.warn("[useAudioLevel] createMediaElementSource failed:",l);return}o.current===null&&(o.current=requestAnimationFrame(u))}},[f,u]),b=n.useCallback(()=>{if(o.current!==null&&(cancelAnimationFrame(o.current),o.current=null),i.current){try{i.current.disconnect()}catch{}i.current=null}},[]),v=n.useCallback(c=>(s.current.add(c),()=>{s.current.delete(c)}),[]);return n.useEffect(()=>()=>{if(b(),r.current){try{r.current.disconnect()}catch{}r.current=null}if(e.current){try{e.current.close()}catch{}e.current=null}s.current.clear(),a.current=null},[b]),{attach:p,detach:b,subscribe:v}}function Zt(){const[e,r]=n.useState(!1),[i,o]=n.useState(null),s=n.useRef(null),a=n.useRef(null),u=n.useCallback(async(c,l)=>{if(s.current&&a.current){try{await a.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}a.current=c,o(null);try{const _=await at.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});l!=null&&l.startMuted&&await _.mute(),await c.localParticipant.publishTrack(_),s.current=_,r(_.isMuted)}catch(_){const C=_ instanceof Error&&_.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw o(C),_}},[]),f=n.useCallback(()=>{const c=s.current;c&&(c.isMuted?(c.unmute(),r(!1)):(c.mute(),r(!0)))},[]),p=n.useCallback(c=>{const l=s.current;l&&(c&&!l.isMuted?(l.mute(),r(!0)):!c&&l.isMuted&&(l.unmute(),r(!1)))},[]),b=n.useCallback(()=>{const c=s.current,l=a.current;if(c&&l){try{l.localParticipant.unpublishTrack(c)}catch{}c.stop()}s.current=null,a.current=null,r(!1)},[]),v=n.useCallback(()=>o(null),[]);return{isMuted:e,micError:i,toggleMute:f,setMuted:p,setupMic:u,teardownMic:b,clearError:v}}const An={resolution:{width:640,height:480,frameRate:24}};function en(){const[e,r]=n.useState(!1),[i,o]=n.useState(null),[s,a]=n.useState(null),[u,f]=n.useState(""),p=n.useRef(null),b=n.useRef(null),v=n.useCallback(w=>{p.current=w},[]),c=n.useCallback(()=>{const w=p.current,P=b.current;if(P&&w){const E=w.localParticipant.getTrackPublication(at.Track.Source.Camera);if(E!=null&&E.track){try{w.localParticipant.unpublishTrack(E.track)}catch{}E.track.stop()}else P.stop()}b.current=null,a(null),r(!1)},[]),l=n.useCallback(async w=>{const P=p.current;if(P){o(null);try{const E={...An};w&&(E.deviceId=w);const D=await at.createLocalVideoTrack(E);await P.localParticipant.publishTrack(D),b.current=D;const g=D.attach();a(g),r(!0),w&&f(w);try{P.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const D=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";o(D)}}},[]),_=n.useCallback(async()=>{e?c():await l(u||void 0)},[e,u,c,l]),C=n.useCallback(async w=>{c(),await l(w)},[c,l]),S=n.useCallback(()=>{c(),p.current=null,o(null),f("")},[c]),x=n.useCallback(()=>o(null),[]);return n.useEffect(()=>()=>{b.current&&b.current.stop()},[]),{isEnabled:e,error:i,previewEl:s,activeDeviceId:u,toggle:_,switchDevice:C,attachRoom:v,teardown:S,clearError:x}}function tn(){const[e,r]=n.useState(!1),[i,o]=n.useState(null),[s,a]=n.useState(null),u=n.useRef(null),f=n.useCallback(l=>{u.current=l},[]),p=n.useCallback(()=>a(null),[]),b=n.useCallback(async()=>{const l=u.current;if(l){if(e){try{await l.localParticipant.setScreenShareEnabled(!1)}catch{}p(),r(!1);return}o(null);try{await l.localParticipant.setScreenShareEnabled(!0);let _=0;const C=()=>{const S=l.localParticipant.getTrackPublication(at.Track.Source.ScreenShare);if(S!=null&&S.track){const x=S.track.attach();a(x),r(!0);try{l.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}_++<10?setTimeout(C,100):r(!0)};C()}catch(_){const C=_ instanceof Error?_.name:"";C!=="NotAllowedError"&&C!=="AbortError"&&o("Screen share unavailable. Try again."),r(!1)}}},[e,p]),v=n.useCallback(()=>{const l=u.current;if(l&&e)try{l.localParticipant.setScreenShareEnabled(!1)}catch{}p(),r(!1),o(null),u.current=null},[e,p]),c=n.useCallback(()=>o(null),[]);return{isEnabled:e,error:i,previewEl:s,toggle:b,attachRoom:f,teardown:v,clearError:c}}function nn(){const[e,r]=n.useState([]),[i,o]=n.useState([]),s=n.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const a=await navigator.mediaDevices.enumerateDevices();r(a.filter(u=>u.kind==="audioinput")),o(a.filter(u=>u.kind==="videoinput"))}catch{}},[]);return n.useEffect(()=>{if(s(),typeof navigator>"u"||!navigator.mediaDevices)return;const a=()=>void s();return navigator.mediaDevices.addEventListener("devicechange",a),()=>navigator.mediaDevices.removeEventListener("devicechange",a)},[s]),{mics:e,cameras:i,refresh:s}}function rn(e,r,i=!1){const[o,s]=n.useState(null),[a,u]=n.useState(null),[f,p]=n.useState(!i&&!!e);return n.useEffect(()=>{if(i||!e){p(!1);return}const b=new AbortController,v=r||"https://app.livelayer.studio";return p(!0),u(null),fetch(`${v}/api/widget/agent/${encodeURIComponent(e)}`,{signal:b.signal}).then(async c=>{if(!c.ok){const l=await c.json().catch(()=>({}));throw new Error(l.error||`HTTP ${c.status}`)}return c.json()}).then(c=>{b.signal.aborted||(s(c),p(!1))}).catch(c=>{b.signal.aborted||(u(c instanceof Error?c.message:"Agent lookup failed"),p(!1))}),()=>b.abort()},[e,r,i]),{info:o,error:a,loading:f}}function Mn(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function In(e,r){if(!(typeof window>"u"))try{window.localStorage.setItem(e,r)}catch{}}function on({value:e,defaultValue:r="expanded",onChange:i}={}){const o=e!==void 0,[s,a]=n.useState(r),u=o?e:s,f=n.useCallback(p=>{p!==u&&(o||a(p),i==null||i(p))},[u,o,i]);return[u,f]}const Tn=["hidden","minimized","expanded"];function Pn(e){return e&&Tn.includes(e)?e:null}function sn({value:e,defaultValue:r="expanded",onChange:i,persistKey:o="ll-widget",disablePersistence:s=!1}={}){const a=`${o}:display-mode`,u=n.useRef(!1),[f,p]=on({value:e,defaultValue:r,onChange:b=>{e===void 0&&!s&&In(a,b),i==null||i(b)}});return n.useEffect(()=>{if(u.current||(u.current=!0,s||e!==void 0))return;const b=Pn(Mn(a));b&&b!==f&&p(b)},[]),[f,p]}const Dn=640;function an(e=Dn){const[r,i]=n.useState(!1);return n.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),a=()=>i(s.matches);return a(),typeof s.addEventListener=="function"?(s.addEventListener("change",a),()=>s.removeEventListener("change",a)):(s.addListener(a),()=>{s.removeListener(a)})},[e]),r}const Tt="__llHistoryPatched",lt="ll:pathname";function $n(){if(typeof window>"u"||window.history[Tt])return;const e=window.history.pushState,r=window.history.replaceState;window.history.pushState=function(...i){const o=e.apply(this,i);return window.dispatchEvent(new Event(lt)),o},window.history.replaceState=function(...i){const o=r.apply(this,i);return window.dispatchEvent(new Event(lt)),o},window.history[Tt]=!0}function Pt(){return typeof window>"u"?"/":window.location.pathname||"/"}function ln(e){const[r,i]=n.useState(()=>e??Pt());return n.useEffect(()=>{if(e!==void 0)return;$n();const o=()=>i(Pt());return o(),window.addEventListener("popstate",o),window.addEventListener(lt,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(lt,o)}},[e]),e??r}const Dt=new Map,zn=/[\\^$+?.()|{}[\]]/g;function Hn(e){return e.replace(zn,"\\$&")}function On(e){const r=Dt.get(e);if(r)return r;const i=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,o="",s="",a=i.replace(/\*\*/g,o).replace(/\*/g,s),f=Hn(a).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),p=new RegExp(`^${f}\\/?$`);return Dt.set(e,p),p}function qn(e,r){const i=r.length>1&&r.endsWith("/")?r.slice(0,-1):r;return On(e).test(i)}function cn(e,r){return typeof e=="function"?e(r):e instanceof RegExp?e.test(r):qn(e,r)}function $t(e,r){if(!e||e.length===0)return!1;for(const i of e)if(cn(i,r))return!0;return!1}function un(e,r,i){return e===void 0?!0:$t(i,e)?!1:r&&r.length>0?$t(r,e):!0}function dn(e,r,i){return n.useMemo(()=>un(e,r,i),[e,r,i])}const zt=({muted:e=!1,className:r})=>e?t.jsxs("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"})}),Ht=({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"})}),Bn=({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"})}),Wn={left:180,right:0,up:-90,down:90},Ot=({direction:e="right",className:r})=>t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${Wn[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function Fn(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const fn="ll-hidden-tab-center-y",Un=5,qt=16;function Vn(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(fn);if(!e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null}catch{return null}}function Bt(e){if(!(typeof window>"u"))try{window.localStorage.setItem(fn,String(e))}catch{}}const Yn=({position:e,isMobile:r,isSpeaking:i,onExpand:o,label:s="Open widget",avatarImageUrl:a,agentName:u})=>{const f=Fn(e),p=f==="right"?"left":"right",b=r?80:72,v=!!a,[c,l]=n.useState(null),[_,C]=n.useState(!1),S=n.useRef(null),x=n.useRef(!1),w=n.useCallback(j=>{if(typeof window>"u")return j;const $=b/2,H=qt+$,Y=window.innerHeight-qt-$;return Y<H?Math.max(H,j):Math.max(H,Math.min(Y,j))},[b]);n.useEffect(()=>{const j=Vn();l(w(j??window.innerHeight/2));const $=()=>{l(H=>H===null?null:w(H))};return window.addEventListener("resize",$),()=>window.removeEventListener("resize",$)},[w]);const P=n.useCallback(j=>{if(!(j.pointerType==="mouse"&&j.button!==0)&&c!==null){try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}S.current={startClientY:j.clientY,startCenterY:c,moved:!1}}},[c]),E=n.useCallback(j=>{const $=S.current;if(!$)return;const H=j.clientY-$.startClientY;!$.moved&&Math.abs(H)>Un&&($.moved=!0,C(!0)),$.moved&&l(w($.startCenterY+H))},[w]),D=n.useCallback(j=>{const $=S.current;if($){try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}S.current=null,$.moved&&(C(!1),x.current=!0,l(H=>(H!==null&&Bt(H),H)))}},[]),g=n.useCallback(()=>{if(x.current){x.current=!1;return}o()},[o]),L=n.useCallback(j=>{if(j.key==="ArrowUp"||j.key==="ArrowDown"){j.preventDefault();const $=j.key==="ArrowUp"?-8:8;l(H=>{if(H===null)return H;const Y=w(H+$);return Bt(Y),Y})}},[w]),z=["ll-hidden",`ll-hidden--${f}`,r?"ll-hidden--mobile":"ll-hidden--desktop",i?"ll-hidden--speaking":null,_?"is-dragging":null,v?"ll-hidden--with-avatar":null].filter(Boolean).join(" "),I=c===null?void 0:{top:`${c-b/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:z,onPointerDown:P,onPointerMove:E,onPointerUp:D,onPointerCancel:D,onClick:g,onKeyDown:L,"aria-label":s,"data-position":e,style:I,children:v?t.jsxs(t.Fragment,{children:[t.jsx(Ot,{direction:p,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:a,alt:u?`${u} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Ot,{direction:p,className:"ll-hidden__chevron"})})},Jn=({audioLevel:e,bars:r=20,maxHeight:i=20,minHeight:o=4,className:s,barClassName:a})=>{const u=n.useRef(null),f=n.useRef([]),p=n.useMemo(()=>{const v=(Math.sqrt(5)-1)/2;return Array.from({length:r},(c,l)=>.5+l*v%1*.5)},[r]);n.useEffect(()=>e.subscribe(c=>{for(let l=0;l<r;l++){const _=f.current[l];if(!_)continue;const C=Math.max(o,c*i*p[l]);_.style.height=`${C}px`}}),[e,r,i,o,p]);const b=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:u,className:b,"aria-hidden":"true",children:Array.from({length:r},(v,c)=>t.jsx("div",{ref:l=>{f.current[c]=l},className:["ll-waveform__bar",a].filter(Boolean).join(" "),style:{height:`${o}px`}},c))})},Kn=({position:e,isMobile:r,agentName:i,avatarImageUrl:o,agentState:s,isMuted:a,audioLevel:u,onExpand:f,onToggleMute:p,onClose:b})=>r?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:f,"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(Jn,{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:v=>{v.stopPropagation(),p()},onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.stopPropagation(),v.preventDefault(),p())},"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(zt,{muted:a,className:"ll-minimized__icon"})}),t.jsx(Ht,{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":a?"Unmute microphone":"Mute microphone",children:t.jsx(zt,{muted:a,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:f,"aria-label":`Expand ${i} widget`,children:t.jsx(Ht,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:b,"aria-label":"Close widget",children:t.jsx(Bn,{className:"ll-minimized__icon"})})]})]})}),Xn=({src:e,alt:r,preCannedPlaying:i=!1,className:o,style:s})=>{const[a,u]=n.useState(!1),f=n.useRef(e);if(n.useEffect(()=>{f.current!==e&&(f.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:a?1:0,...s};return t.jsx("img",{src:e,alt:r,className:o,style:p,loading:"eager",fetchPriority:"high",onLoad:()=>u(!0)})},Gn=({position:e,isMobile:r,agentName:i,avatarImageUrl:o,idleLoopUrl:s,greeting:a,branding:u,teamMembers:f,currentTeamMemberId:p,isSwitchingTeamMember:b,teamSwitcherOpen:v,onToggleTeamSwitcher:c,onSelectTeamMember:l,languageMenuOpen:_,onToggleLanguageMenu:C,connectionState:S,agentState:x,transcript:w,canResume:P,needsUserGesture:E,error:D,isMuted:g,micError:L,micDevices:z,isCameraEnabled:I,cameraPreviewEl:j,cameraDevices:$,activeCameraId:H,isScreenShareEnabled:Y,screenPreviewEl:ee,isSpeakerMuted:me,allowCamera:Je,allowScreenShare:Ke,allowTyping:Xe,avatarVideoContainerRef:Ge,agentVideoEl:Z,micGateOpen:oe,onConnect:ge,onDisconnect:_e,onRetry:ke,onResumeAudio:Se,onToggleMute:Ce,onToggleCamera:Le,onSwitchCameraDevice:B,onToggleScreenShare:ut,onToggleSpeaker:dt,onSendMessage:Qe,onMinimize:ae,onClose:je,onClearMicError:$e})=>{var Me;const ye=((f==null?void 0:f.length)??0)>1,Ee=S==="connecting"||S==="connected",V=S==="connected",G=S==="idle"||S==="disconnected"||S==="error",[Re,te]=n.useState(!1);n.useEffect(()=>{if(!Z){te(!1);return}if(!Z.paused&&Z.readyState>=2){te(!0);return}te(!1);const h=()=>te(!0);return Z.addEventListener("playing",h),Z.addEventListener("loadeddata",h),()=>{Z.removeEventListener("playing",h),Z.removeEventListener("loadeddata",h)}},[Z]);const[se,be]=n.useState(!1);n.useEffect(()=>{if(!V){be(!1);return}if(Re)return;const h=setTimeout(()=>be(!0),8e3);return()=>clearTimeout(h)},[V,Re]);const ze=S==="connecting"||V&&!!o&&!Re&&!se,K=n.useRef(null),ne=n.useRef(null);n.useEffect(()=>{const h=K.current;h&&(h.innerHTML="",j&&(j.style.width="100%",j.style.height="100%",j.style.objectFit="cover",j.style.transform="scaleX(-1)",h.appendChild(j)))},[j]),n.useEffect(()=>{const h=ne.current;h&&(h.innerHTML="",ee&&(ee.style.width="100%",ee.style.height="100%",ee.style.objectFit="contain",h.appendChild(ee)))},[ee]);const[re,le]=n.useState(!1),[Ne,ce]=n.useState(!1);n.useEffect(()=>{if(!re&&!Ne&&!_&&!v)return;const h=()=>{le(!1),ce(!1),_&&C(),v&&c()};return document.addEventListener("click",h),()=>document.removeEventListener("click",h)},[re,Ne,_,v,C,c]);const[ue,He]=n.useState(""),Oe=n.useCallback(h=>{h.preventDefault();const W=ue.trim();W&&(Qe(W),He(""))},[ue,Qe]),qe=u.productName||"Live Layer";let de=null,fe=null;for(let h=w.length-1;h>=0;h--){const W=w[h];if(!de&&W.role==="agent"?de=W:!fe&&W.role==="user"&&(fe=W),de&&fe)break}const Ae=V?(de==null?void 0:de.text)||null:a||null,Ze=V&&(fe==null?void 0:fe.text)||null,Be=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:Be,"data-position":e,"data-state":V?"connected":Ee?"connecting":"idle",role:"dialog","aria-label":`${i} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[o?t.jsx(Xn,{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:((Me=i==null?void 0:i.charAt(0))==null?void 0:Me.toUpperCase())||"A"})}),s&&!V&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:Ge,className:"ll-expanded__video"}),ze&&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:b?"Switching...":"Connecting..."})]}),E&&V&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:Se,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"})]}),Ee?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:h=>{ye&&(h.stopPropagation(),c())},"aria-haspopup":ye?"listbox":void 0,"aria-expanded":ye?v:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:i}),ye&&t.jsx(it,{})]}),ye&&v&&t.jsx("div",{className:"ll-hmenu",onClick:h=>h.stopPropagation(),role:"listbox",children:f==null?void 0:f.map(h=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${h.id===p?"is-active":""}`,onClick:()=>l(h.id),role:"option","aria-selected":h.id===p,children:[h.avatarImageUrl&&t.jsx("img",{src:h.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:h.name}),h.role&&t.jsx("span",{className:"ll-hmenu__role",children:h.role})]},h.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:h=>{h.stopPropagation(),C()},"aria-haspopup":"listbox","aria-expanded":_,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(it,{})]}),_&&t.jsx("div",{className:"ll-hmenu",onClick:h=>h.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:ae,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(Ft,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:je,"aria-label":"End call",title:"End call",children:t.jsx(Wt,{})})]})]}):t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:qe}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:ae,"aria-label":"Minimize widget",children:t.jsx(Ft,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:je,"aria-label":"Close widget",children:t.jsx(Wt,{})})]})]}),G&&(()=>{const h=P?"Restart paused session":S==="disconnected"?"Reconnect to agent":"Start video call",W=P?"Pick up where you left off":null,et=S==="idle"&&!P&&!D;return t.jsxs(t.Fragment,{children:[et&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:ge,"aria-label":h,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:h})]}),t.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[a&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:a})}),W&&t.jsx("p",{className:"ll-expanded__cta-sublabel",children:W}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:ge,"aria-label":h,children:h})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${Ee&&(I||Y)?"is-visible":""}`,children:[t.jsx("div",{ref:ne,className:Y?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:K,className:!Y&&I?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Ee?t.jsxs("div",{className:"ll-expanded__bottom",children:[Ae&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Ae})}),Ze&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Ze})}),t.jsxs("div",{className:"ll-toolbar",onClick:h=>h.stopPropagation(),children:[Ke&&t.jsx("button",{type:"button",className:`ll-tool ${Y?"is-on":""}`,onClick:ut,"aria-label":Y?"Stop sharing screen":"Share screen",title:Y?"Stop sharing":"Share screen",children:t.jsx(Qn,{})}),Je&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${I?"is-on":""}`,onClick:Le,"aria-label":I?"Turn off camera":"Turn on camera",title:I?"Stop camera":"Start camera",children:t.jsx(Zn,{})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${I?"is-on":""}`,onClick:h=>{h.stopPropagation(),ce(W=>!W),le(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":Ne,children:t.jsx(it,{})}),Ne&&$.length>0&&t.jsx(Ut,{label:"Camera",devices:$,activeId:H,onPick:h=>{ce(!1),B(h)}})]}),t.jsxs("div",{className:`ll-tool-split${!oe&&V?" ll-tool-split--gated":""}`,children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${g?"is-muted":""}`,onClick:Ce,disabled:!oe&&V,"aria-label":!oe&&V?"Microphone enables once the agent finishes its greeting":g?"Unmute microphone":"Mute microphone",title:!oe&&V?"Mic enables after greeting":g?"Unmute":"Mute",children:t.jsx(er,{muted:g})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${g?"is-muted":""}`,onClick:h=>{h.stopPropagation(),le(W=>!W),ce(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":re,children:t.jsx(it,{})}),re&&z.length>0&&t.jsx(Ut,{label:"Microphone",devices:z,activeId:"",onPick:()=>le(!1)})]}),t.jsx("button",{type:"button",className:`ll-tool ${me?"is-muted":""}`,onClick:dt,"aria-label":me?"Unmute speaker":"Mute speaker",title:me?"Unmute speaker":"Mute speaker",children:t.jsx(tr,{muted:me})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:_e,"aria-label":"End conversation",title:"End conversation",children:t.jsx(rr,{})})]}),Xe&&t.jsxs("form",{className:"ll-message-input",onSubmit:Oe,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:ue,onChange:h=>He(h.target.value),"aria-label":"Message the agent"}),ue.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(nr,{})})]})]}):null,(()=>{if(L&&S!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:L}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:$e,"aria-label":"Dismiss",children:"×"})]});if(!D||S!=="error")return null;let h="Failed to connect",W="Try again";return D==="MIC_PERMISSION_DENIED"?h="Microphone blocked. Allow access to talk.":D==="MIC_NOT_FOUND"?h="No microphone found. Plug one in + retry.":D==="MIC_UNAVAILABLE"?h="Mic unavailable. Check other apps using it.":D==="AGENT_TIMEOUT"?h="Agent didn't pick up. Try again.":D==="CONNECT_FAILED"?h="Connection failed. Check your network.":D.length<80&&(h=D),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:h}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:ke,children:W})]})})()]})};function it(){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 Wt(){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 Ft(){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 Qn(){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 Zn(){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 er({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 tr({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 nr(){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 rr(){return t.jsx("svg",{width:"16",height:"16",viewBox:"-4 -4 32 32",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.93.37 1.84.71 2.7a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.38-1.38a2 2 0 0 1 2.11-.45c.86.34 1.77.58 2.7.71A2 2 0 0 1 22 16.92z",transform:"rotate(135 12 12)"})})}const Ut=({label:e,devices:r,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}),r.map((s,a)=>{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} ${a+1}`})]},s.deviceId||a)})]}),ir=['[data-ll-private="true"]',".ll-widget"];function bt(e){let r=e;for(;r;){for(const i of ir)if(r.matches(i))return!0;r=r.parentElement}return!1}function ct(e){if(bt(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const r=(e.getAttribute("autocomplete")||"").toLowerCase();if(r==="off"||r.startsWith("cc-"))return!1}return!0}const ot=4096,or=20,sr=20,ar=10,lr=10,cr=30,Vt=500,ur=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function Ve(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let r=e;for(;r;){for(const i of ur)if(r.matches(i))return!0;r=r.parentElement}return!1}function Ye(e){if(typeof window>"u")return!0;const r=e.getBoundingClientRect();if(r.width<=0||r.height<=0)return!1;const i=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth;return r.bottom>0&&r.right>0&&r.top<i&&r.left<o}function Yt(e){const r=e.getAttribute("id");if(r){const a=document.querySelector(`label[for="${CSS.escape(r)}"]`);if(a!=null&&a.textContent)return a.textContent.trim()}const 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 we(e,r){return e.length<=r?e:e.slice(0,r-1)+"…"}function Te(e){return e.length}function pn(e,r={}){const i=r.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||"/",a=i.title||"",u=Array.from(i.querySelectorAll("[data-ll-region]")),f=[];for(const g of u){if(f.length>=ar)break;if(Ve(g)||!Ye(g))continue;const L=g.getAttribute("data-ll-region")??"",z=g.getAttribute("data-ll-intent")??void 0,I=we((g.innerText||g.textContent||"").trim(),Vt*2);!L||!I||f.push({id:L,intent:z,text:I})}const p=[],b=["H1","H2","H3","H4","H5","H6"],v=Array.from(i.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const g of v){if(Ve(g)||!Ye(g))continue;const L=(g.textContent||"").trim();L&&p.push(`${g.tagName}: ${we(L,200)}`)}const c=Array.from(i.querySelectorAll("p, li"));for(const g of c){if(Ve(g)||!Ye(g)||b.includes(g.tagName))continue;const L=(g.textContent||"").trim();L.length>10&&p.push(we(L,Vt))}const l=p.join(`
2
- `),_=[],C=Array.from(i.querySelectorAll("a[href]"));for(const g of C){if(_.length>=or)break;if(Ve(g)||!Ye(g))continue;const L=g.getAttribute("href")||"",z=(g.textContent||"").trim();!L||!z||_.push({href:L,text:we(z,100)})}const S=[],x=Array.from(i.querySelectorAll("input, textarea, select"));for(const g of x){if(S.length>=sr)break;if(Ve(g)||!ct(g)||!Ye(g))continue;const L=Yt(g),z=g instanceof HTMLInputElement?g.type:g.tagName.toLowerCase();L&&S.push({label:we(L,100),type:z})}const w=Array.from(i.querySelectorAll("[data-ll-form]")),P=[];for(const g of w){if(P.length>=lr)break;if(bt(g))continue;const L=g.getAttribute("data-ll-form")||"";if(!L)continue;const z=g.getAttribute("data-ll-intent")||void 0,I=Array.from(g.querySelectorAll("[data-ll-field]")),j=[];for(const $ of I){if(j.length>=cr)break;if(!ct($))continue;const H=$.getAttribute("data-ll-field")||"";if(!H)continue;const Y=Yt($)||H,ee=$ instanceof HTMLInputElement?$.type:$.tagName.toLowerCase();j.push({name:H,label:we(Y,100),type:ee})}P.push({id:L,intent:z,fields:j})}const E={url:o,title:a,pathname:s,regions:f,visibleText:l,visibleLinks:_,visibleFields:S,forms:P,extras:e};let D=Te(JSON.stringify(E.regions))+Te(E.visibleText)+Te(JSON.stringify(E.visibleLinks))+Te(JSON.stringify(E.visibleFields));for(;D>ot&&E.visibleFields.length>0;)E.visibleFields.pop(),D=Te(JSON.stringify(E.visibleFields));for(;D>ot&&E.visibleLinks.length>0;)E.visibleLinks.pop(),D-=80;return Te(E.visibleText)>ot&&(E.visibleText=we(E.visibleText,ot-100)),E}let Pe=null;function yt(e,r={}){const i=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(Pe&&Pe.key===s&&i-Pe.at<1e3)return Pe.ctx;const a=pn(e,r);return Pe={key:s,at:i,ctx:a},a}function hn(){Pe=null}const dr=200;function mn(e){const r=String(e.href||"");return{href:r,text:String(e.text??e.title??r),internal:e.internal??!0,title:e.title,description:e.description}}function fr(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function gn(e){const r=e??(typeof document<"u"?document:null);if(!r)return[];const i=typeof window<"u"&&window.location.origin||"",o=new Set,s=[],a=Array.from(r.querySelectorAll("a[href]"));for(const u of a){if(s.length>=dr)break;if(bt(u))continue;const f=u.getAttribute("href")||"";if(!fr(f))continue;let p=f,b=!0;try{if(typeof window<"u"){const c=new URL(f,i);b=c.origin===i,b&&f.startsWith("http")&&(p=c.pathname+c.search+c.hash)}}catch{continue}if(o.has(p))continue;o.add(p);const v=(u.textContent||"").trim().slice(0,120);s.push({href:p,text:v,internal:b})}return s}let De=null;const pr=5e3;function st(){const e=Date.now(),r=typeof window<"u"&&window.location.pathname||"/";if(De&&De.pathname===r&&e-De.at<pr)return De.routes;const i=gn();return De={at:e,pathname:r,routes:i},i}function yn(){De=null}function hr(e,r){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,r):e.value=r}function mr(e,r,i={}){const o=i.triggerInput??!0,s=i.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const a=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),u=a==null?void 0:a.set,f=r==="true"||r==="1"||r==="on";u?u.call(e,f):e.checked=f,o&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}hr(e,r),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function gr(){if(typeof window>"u"||typeof document>"u")return!1;const e=document.scrollingElement||document.documentElement;if(!e||e.scrollHeight<=e.clientHeight+2)return!1;const r=window.getComputedStyle(e);return!(r.overflowY==="hidden"||r.overflowY==="clip")}function yr(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function br(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let r=null,i=0;for(const o of e){if(!yr(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 a=s.width*s.height;a>i&&(i=a,r=o)}return r}function xr(){if(typeof window>"u")return null;if(gr())return window;const e=br();return e||window}function Jt(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function vr(e){var r,i;return e instanceof Window?typeof document>"u"?0:Math.max(((r=document.body)==null?void 0:r.scrollHeight)??0,((i=document.documentElement)==null?void 0:i.scrollHeight)??0):e.scrollHeight-e.clientHeight}const wr=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 _r(e){var Ct,Lt,jt,Et,Rt,Nt,At;const{agentId:r,apiKey:i,baseUrl:o="https://app.livelayer.studio",sessionEndpoint:s,sessionBody:a,autoConnect:u=!1,displayMode:f,defaultDisplayMode:p="expanded",onDisplayModeChange:b,position:v="bottom-right",mobileBreakpoint:c=640,persistKey:l="ll-widget",disablePersistence:_=!1,teamMembers:C,currentTeamMemberId:S,onTeamMemberChange:x,idleLoopUrl:w,greeting:P,avatarImageUrl:E,agentName:D,branding:g={},allowCamera:L=!0,allowScreenShare:z=!0,allowTyping:I=!0,showOn:j,hideOn:$,pathname:H,onNavigate:Y,onScrollToSelector:ee,getPageContext:me,pageContextExtras:Je,getRoutes:Ke,onScrollPage:Xe,onClick:Ge,capabilities:Z,onConnect:oe,onDisconnect:ge,onTranscript:_e,onAgentState:ke,onConnectionStateChange:Se,onAgentEvent:Ce,onAgentCommand:Le,controlledSession:B,className:ut,style:dt,zIndex:Qe=2147483647}=e,ae=ln(H),je=dn(ae,j,$);n.useEffect(()=>{hn(),yn()},[ae]);const $e=S!==void 0,[ye,Ee]=n.useState(()=>{var m;return S??((m=C==null?void 0:C[0])==null?void 0:m.id)}),V=$e?S:ye,G=n.useMemo(()=>(C==null?void 0:C.find(m=>m.id===V))??null,[C,V]),Re=(G==null?void 0:G.agentId)??r,[te,se]=sn({value:f,defaultValue:p,onChange:b,persistKey:l,disablePersistence:_}),be=an(c),ze=Qt(),K=Zt(),ne=en(),re=tn(),le=nn(),[Ne,ce]=n.useState(!1),[ue,He]=n.useState(!1),[Oe,qe]=n.useState(!1),[de,fe]=n.useState(!1),[Ae,Ze]=n.useState(!1),Be=n.useRef(Y),Me=n.useRef(ee),h=n.useRef(Xe),W=n.useRef(Ge),et=n.useRef(me),xt=n.useRef(Je),vt=n.useRef(Ke),ft=n.useRef(Z),Q=n.useRef(null);Be.current=Y,Me.current=ee,h.current=Xe,W.current=Ge,et.current=me,xt.current=Je,vt.current=Ke,ft.current=Z;function pe(m){const d=ft.current;return d?d.includes(m):!0}function he(m,d){console.warn(`[LiveLayer] Agent command "${m}" blocked — capability "${d}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const We=n.useCallback(m=>{var X,Ie,rt,Mt,It;const d=m;if(!(!d.type||typeof d.type!="string")){if(Ce==null||Ce({eventName:d.type,data:m}),d.type==="navigate"){if(!pe("navigate")){he("navigate","navigate");return}const k=typeof d.href=="string"?d.href:null;if(!k){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(Be.current){try{Be.current(k)}catch(N){console.warn(`[LiveLayer] onNavigate threw for "${k}". Falling back. Error:`,N)}return}if(typeof document<"u"){const N=document.querySelector(`a[href="${k.replace(/"/g,'\\"')}"]`);if(N){N.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",k),window.dispatchEvent(new PopStateEvent("popstate"))}catch(N){console.warn(`[LiveLayer] history.pushState fallback failed for "${k}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,N)}return}if(d.type==="scroll_to"){if(!pe("scroll")){he("scroll_to","scroll");return}const k=typeof d.selector=="string"?d.selector:null;if(!k)return;const N=d.behavior==="instant"?"instant":"smooth";if(Me.current){try{Me.current(k,N)}catch(A){console.warn("[LiveLayer] onScrollToSelector threw.",A)}return}if(typeof document<"u"){let A=null;try{A=document.querySelector(k)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${k}".`);return}if(!A){console.warn(`[LiveLayer] scroll_to: no element matched "${k}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}A.scrollIntoView({behavior:N,block:"start"})}return}if(d.type==="request_page_context"){if(!pe("read_page")){he("request_page_context","read_page");return}const k=typeof d.requestId=="string"?d.requestId:void 0,N=(X=Q.current)==null?void 0:X.call(Q),A=U=>{const R=N,O=R==null?void 0:R.localParticipant;if(O!=null&&O.publishData)try{const T=k?{...U,requestId:k}:U,J=new TextEncoder().encode(JSON.stringify(T));O.publishData(J,{reliable:!0})}catch(T){console.warn("[LiveLayer] publishData failed.",T)}},M=xt.current,F=et.current;try{if(F){const U=F(M);if(U instanceof Promise){A({type:"page_context_pending"}),U.then(R=>A({type:"page_context",context:R})).catch(R=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",R),A({type:"page_context",context:yt(M)})});return}A({type:"page_context",context:U});return}A({type:"page_context",context:yt(M)})}catch(U){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",U),A({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:M}})}return}if(d.type==="scroll_page"){if(!pe("scroll")){he("scroll_page","scroll");return}const k=d.direction;if(k!=="up"&&k!=="down"&&k!=="top"&&k!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(k)}". Expected up | down | top | bottom.`);return}const N=d.behavior==="instant"?"instant":"smooth";if(h.current){try{h.current(k,N)}catch(R){console.warn("[LiveLayer] onScrollPage threw.",R)}return}if(typeof window>"u")return;const A={behavior:N},M=xr(),F=R=>{M instanceof Window?M.scrollBy({top:R,...A}):M.scrollBy({top:R,...A})},U=R=>{M instanceof Window?M.scrollTo({top:R,...A}):M.scrollTo({top:R,...A})};k==="up"?F(-Jt(M)):k==="down"?F(Jt(M)):U(k==="top"?0:vr(M));return}if(d.type==="click"){if(!pe("click")){he("click","click");return}const k=typeof d.selector=="string"?d.selector:null;if(!k){console.warn("[LiveLayer] click: missing selector.");return}if(W.current){try{W.current(k)}catch(A){console.warn("[LiveLayer] onClick threw.",A)}return}if(typeof document>"u")return;let N=null;try{N=document.querySelector(k)}catch{console.warn(`[LiveLayer] click: invalid selector "${k}".`);return}if(!N){console.warn(`[LiveLayer] click: no element matched "${k}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(N.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(Ie=N.click)==null||Ie.call(N);return}if(d.type==="fill_form"||d.type==="focus_field"){if(!pe("fill_forms")){he(d.type,"fill_forms");return}if(typeof document>"u")return;const k=typeof d.requestId=="string"?d.requestId:void 0,N=(rt=Q.current)==null?void 0:rt.call(Q),A=T=>{if(d.type!=="fill_form")return;const J=N,ie=J==null?void 0:J.localParticipant;if(ie!=null&&ie.publishData)try{const ve=k?{...T,requestId:k}:T,Rn=new TextEncoder().encode(JSON.stringify(ve));ie.publishData(Rn,{reliable:!0})}catch(ve){console.warn("[LiveLayer] publishData failed.",ve)}},M=typeof d.formId=="string"?d.formId:null;if(!M){console.warn(`[LiveLayer] ${d.type}: missing formId.`),A({type:"fill_form_result",ok:!1,reason:"missing formId"});return}const F=document.querySelector(`[data-ll-form="${M.replace(/"/g,'\\"')}"]`);if(!F){console.warn(`[LiveLayer] ${d.type}: no form with data-ll-form="${M}". Tag your form with <LiveLayerForm id> or data-ll-form. See https://livelayer.studio/docs/react/forms`),A({type:"fill_form_result",ok:!1,reason:`no form with data-ll-form="${M}" on this page`,formId:M});return}if(F.closest('[data-ll-private="true"], .ll-widget')){console.warn(`[LiveLayer] ${d.type}: refusing to touch a form in a private subtree.`),A({type:"fill_form_result",ok:!1,reason:"form is in a private subtree (data-ll-private)",formId:M});return}if(d.type==="focus_field"){const T=typeof d.fieldName=="string"?d.fieldName:null;if(!T){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const J=F.querySelector(`[data-ll-field="${T.replace(/"/g,'\\"')}"]`);if(!J){console.warn(`[LiveLayer] focus_field: no field "${T}" in form "${M}".`);return}if(!ct(J)){console.warn(`[LiveLayer] focus_field: field "${T}" is privacy-protected and not focusable.`);return}J.focus();return}const U=d.values&&typeof d.values=="object"?d.values:null;if(!U){console.warn("[LiveLayer] fill_form: missing or invalid values."),A({type:"fill_form_result",ok:!1,reason:"missing or invalid values",formId:M});return}const R=[],O=[];for(const[T,J]of Object.entries(U)){if(typeof J!="string")continue;const ie=F.querySelector(`[data-ll-field="${T.replace(/"/g,'\\"')}"]`);if(!ie){console.warn(`[LiveLayer] fill_form: no field "${T}" in form "${M}". Skipping.`),O.push(T);continue}if(!ct(ie)){console.warn(`[LiveLayer] fill_form: field "${T}" is privacy-protected (password / cc-* / private). Skipping.`),O.push(T);continue}try{mr(ie,J),R.push(T)}catch(ve){console.warn(`[LiveLayer] fill_form: failed to set "${T}".`,ve),O.push(T)}}A({type:"fill_form_result",ok:R.length>0,formId:M,filled:R,skipped:O,reason:R.length===0?`none of the requested fields exist on this form (skipped: ${O.join(", ")})`:void 0});return}if(d.type==="submit_form"){if(!pe("submit_forms")){he("submit_form","submit_forms");return}if(typeof document>"u")return;const k=typeof d.formId=="string"?d.formId:null;if(!k){console.warn("[LiveLayer] submit_form: missing formId.");return}const N=document.querySelector(`[data-ll-form="${k.replace(/"/g,'\\"')}"]`);if(!N){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${k}".`);return}if(N.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private subtree.");return}const A=typeof d.requestId=="string"?d.requestId:void 0,M=(Mt=Q.current)==null?void 0:Mt.call(Q),F=O=>{const T=M,J=T==null?void 0:T.localParticipant;if(J!=null&&J.publishData)try{const ie=A?{...O,requestId:A}:O,ve=new TextEncoder().encode(JSON.stringify(ie));J.publishData(ve,{reliable:!0})}catch{}};let U=!1;const R=()=>{U=!0,F({type:"form_submitted",formId:k})};N.addEventListener("submit",R,{once:!0});try{typeof N.requestSubmit=="function"?N.requestSubmit():N.submit()}catch(O){console.warn("[LiveLayer] submit_form: requestSubmit threw.",O),N.removeEventListener("submit",R),F({type:"form_submit_blocked",formId:k,reason:"exception"});return}setTimeout(()=>{U||(N.removeEventListener("submit",R),F({type:"form_submit_blocked",formId:k,reason:"validation"}))},500);return}if(d.type==="request_routes"){if(!pe("read_page")){he("request_routes","read_page");return}const k=typeof d.requestId=="string"?d.requestId:void 0,A=(It=Q.current)==null?void 0:It.call(Q),M=A==null?void 0:A.localParticipant;if(!(M!=null&&M.publishData))return;const F=R=>{try{const O=k?{type:"routes",routes:R,requestId:k}:{type:"routes",routes:R},T=new TextEncoder().encode(JSON.stringify(O));M.publishData(T,{reliable:!0})}catch(O){console.warn("[LiveLayer] request_routes: publishData failed.",O)}},U=vt.current;if(U){try{const R=U(),O=T=>{if(!Array.isArray(T)){F([]);return}F(T.map(mn).slice(0,200))};R instanceof Promise?R.then(O).catch(T=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",T),F(st())}):O(R)}catch(R){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",R),F(st())}return}try{F(st())}catch(R){console.warn("[LiveLayer] request_routes: extractRoutes threw.",R)}return}wr.has(d.type)||Le==null||Le(d)}},[Le,Ce]),q=Gt({agentId:B?"__controlled__":Re,baseUrl:o,apiKey:i,sessionEndpoint:s,sessionBody:a,onDataMessage:B?void 0:We});n.useEffect(()=>{if(B!=null&&B.subscribeToDataMessages)return B.subscribeToDataMessages(We)},[B,We]),Q.current=()=>{var m;return(m=q.getRoom)==null?void 0:m.call(q)},n.useEffect(()=>{var X;if(!ae)return;const m=(X=q.getRoom)==null?void 0:X.call(q),d=m==null?void 0:m.localParticipant;if(d!=null&&d.publishData)try{const Ie=new TextEncoder().encode(JSON.stringify({type:"pathname",pathname:ae}));d.publishData(Ie,{reliable:!0})}catch{}},[ae,q,q.connectionState]),n.useEffect(()=>{var X;if(typeof window>"u")return;const m=((X=window.location)==null?void 0:X.hostname)||"";if(m==="localhost"||m==="127.0.0.1"||m==="0.0.0.0"||m.endsWith(".local")||m.endsWith(".test"))return window.__livelayerSimulateCommand=Ie=>{try{We(Ie)}catch(rt){console.warn("[LiveLayer] simulate-command threw:",rt)}},()=>{delete window.__livelayerSimulateCommand}},[We]);const y=n.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:q.getRoom,isControlled:!0}:{connectionState:q.connectionState,agentState:q.agentState,transcript:q.transcript,videoElement:q.videoElement,audioElement:q.audioElement,canResume:q.canResume,error:q.error,agentConfig:q.agentConfig,connect:q.connect,disconnect:q.disconnect,getRoom:q.getRoom,isControlled:!1},[B,q]),wt=n.useRef(null);n.useEffect(()=>{const m=y.videoElement,d=wt.current;if(!(!m||!d))return d.appendChild(m),()=>{m.parentNode===d&&d.removeChild(m)}},[y.videoElement]),n.useEffect(()=>{const m=y.audioElement;if(!m)return;ze.attach(m);const d=m.play();return d&&typeof d.catch=="function"&&d.catch(X=>{(X==null?void 0:X.name)==="NotAllowedError"&&ce(!0)}),()=>{ze.detach()}},[y.audioElement]),n.useEffect(()=>{if(y.isControlled||y.connectionState!=="connected")return;const m=y.getRoom();if(m)return K.setupMic(m,{startMuted:!0}).catch(()=>{}),ne.attachRoom(m),re.attachRoom(m),le.refresh(),()=>{K.teardownMic(),ne.teardown(),re.teardown()}},[y.isControlled,y.connectionState]);const[xe,pt]=n.useState(!1),ht=n.useRef("idle");n.useEffect(()=>{if(y.connectionState==="idle"||y.connectionState==="disconnected"){pt(!1),ht.current="idle";return}!xe&&ht.current==="speaking"&&y.agentState!=="speaking"&&(pt(!0),K.setMuted(!1)),ht.current=y.agentState},[y.agentState,y.connectionState,xe]),n.useEffect(()=>{if(y.connectionState!=="connected"||xe)return;const m=setTimeout(()=>{pt(!0),K.setMuted(!1)},4e3);return()=>clearTimeout(m)},[y.connectionState,xe]);const _t=n.useRef(!1),tt=n.useRef(!1);n.useEffect(()=>{if(!xe)return;const m=y.agentState;!tt.current&&(m==="speaking"||m==="thinking")?(_t.current=K.isMuted,tt.current=!0,K.setMuted(!0)):tt.current&&m==="listening"&&(tt.current=!1,K.setMuted(_t.current))},[y.agentState,xe]),n.useEffect(()=>{const m=y.audioElement;m&&(m.muted=Ae)},[y.audioElement,Ae]);const bn=n.useCallback(m=>{const d=y.getRoom();if(d)try{const X=new TextEncoder().encode(JSON.stringify({type:"user_message",text:m}));d.localParticipant.publishData(X,{reliable:!0})}catch{}},[y]),xn=n.useCallback(()=>{Ze(m=>!m)},[]);n.useEffect(()=>{Se==null||Se(y.connectionState),y.connectionState==="connected"?oe==null||oe():y.connectionState==="disconnected"&&(ge==null||ge())},[y.connectionState,oe,ge,Se]),n.useEffect(()=>{_e==null||_e(y.transcript)},[y.transcript,_e]),n.useEffect(()=>{ke==null||ke(y.agentState)},[y.agentState,ke]);const kt=n.useRef(!1);n.useEffect(()=>{y.isControlled||!u||kt.current||je&&y.connectionState==="idle"&&(kt.current=!0,y.connect())},[u,y.connectionState,y,je]);const vn=n.useCallback(m=>{const d=C==null?void 0:C.find(X=>X.id===m);d&&(qe(!1),m!==V&&(He(!0),y.disconnect(),$e||Ee(m),x==null||x(d)))},[C,V,y,$e,x]);n.useEffect(()=>{ue&&y.connectionState==="connected"&&He(!1)},[y.connectionState,ue]),n.useEffect(()=>{if(!Oe)return;const m=d=>{d.key==="Escape"&&qe(!1)};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[Oe]);const wn=!!E||!!(G!=null&&G.avatarImageUrl)||y.isControlled,Fe=rn(Re,o,wn);Z===void 0&&((Ct=Fe.info)!=null&&Ct.capabilities)&&(ft.current=Fe.info.capabilities);const nt=(G==null?void 0:G.name)??D??((Lt=y.agentConfig)==null?void 0:Lt.name)??((jt=Fe.info)==null?void 0:jt.name)??"Live Layer",mt=(G==null?void 0:G.avatarImageUrl)??E??((Et=y.agentConfig)==null?void 0:Et.avatarImageUrl)??((Rt=Fe.info)==null?void 0:Rt.avatarImageUrl)??null,_n=w??((Nt=y.agentConfig)==null?void 0:Nt.idleLoopUrl)??((At=Fe.info)==null?void 0:At.idleLoopUrl)??null,kn=P??null,Sn=n.useCallback(()=>se("expanded"),[se]),Cn=n.useCallback(()=>se("minimized"),[se]),St=n.useCallback(()=>{y.disconnect(),se("hidden")},[y,se]),Ln=n.useCallback(()=>{const m=y.audioElement;m&&m.play().then(()=>ce(!1)).catch(()=>{})},[y.audioElement]),jn=n.useCallback(()=>{ce(!1),y.connect()},[y]),Ue={...dt,zIndex:Qe};g.primaryColor&&(Ue["--ll-color-primary"]=g.primaryColor),g.accentColor&&(Ue["--ll-color-accent"]=g.accentColor),g.backgroundColor&&(Ue["--ll-color-bg"]=g.backgroundColor),g.textColor&&(Ue["--ll-color-fg"]=g.textColor);const En=["ll-widget",`ll-widget--${te}`,`ll-widget--${be?"mobile":"desktop"}`,ut].filter(Boolean).join(" ");return je?t.jsxs("div",{className:En,style:Ue,"data-display-mode":te,"data-position":v,children:[te==="hidden"&&t.jsx(Yn,{position:v,isMobile:be,isSpeaking:y.agentState==="speaking",onExpand:()=>se("expanded"),label:`Open ${nt} widget`,avatarImageUrl:mt,agentName:nt}),te==="minimized"&&t.jsx(Kn,{position:v,isMobile:be,agentName:nt,avatarImageUrl:mt,agentState:y.agentState,isMuted:K.isMuted,audioLevel:ze,onExpand:Sn,onToggleMute:K.toggleMute,onClose:St}),te==="expanded"&&t.jsx(Gn,{position:v,isMobile:be,agentName:nt,avatarImageUrl:mt,idleLoopUrl:_n,greeting:kn,branding:g,teamMembers:C,currentTeamMemberId:V,isSwitchingTeamMember:ue,teamSwitcherOpen:Oe,onToggleTeamSwitcher:()=>qe(m=>!m),onSelectTeamMember:vn,connectionState:y.connectionState,agentState:y.agentState,transcript:y.transcript,isMuted:K.isMuted,micDevices:le.mics,isCameraEnabled:ne.isEnabled,cameraPreviewEl:ne.previewEl,cameraDevices:le.cameras,activeCameraId:ne.activeDeviceId,isScreenShareEnabled:re.isEnabled,screenPreviewEl:re.previewEl,isSpeakerMuted:Ae,allowCamera:L,allowScreenShare:z,allowTyping:I,languageMenuOpen:de,onToggleLanguageMenu:()=>fe(m=>!m),needsUserGesture:Ne,canResume:y.canResume,micError:K.micError,error:y.error,avatarVideoContainerRef:wt,agentVideoEl:y.videoElement,micGateOpen:y.isControlled?!0:xe,onConnect:()=>void y.connect(),onDisconnect:()=>y.disconnect(),onRetry:jn,onResumeAudio:Ln,onToggleMute:K.toggleMute,onToggleCamera:()=>void ne.toggle(),onSwitchCameraDevice:m=>void ne.switchDevice(m),onToggleScreenShare:()=>void re.toggle(),onToggleSpeaker:xn,onSendMessage:bn,onMinimize:Cn,onClose:St,onClearMicError:K.clearError})]}):null}function kr(e){return t.jsx(Xt,{children:t.jsx(_r,{...e})})}const Sr=({agentId:e,baseUrl:r,apiKey:i,mode:o,onAgentEvent:s,className:a,style:u})=>{const f=n.useRef(null),p=n.useRef(null),b=n.useRef(s);b.current=s;const v=n.useCallback(c=>{var _;const l=c.detail;(_=b.current)==null||_.call(b,l)},[]);return n.useEffect(()=>{const c=f.current;if(!c)return;const l=document.createElement("livelayer-widget");return l.setAttribute("agent-id",e),r&&l.setAttribute("base-url",r),i&&l.setAttribute("api-key",i),o&&l.setAttribute("mode",o),l.addEventListener("agent-event",v),c.appendChild(l),p.current=l,()=>{l.removeEventListener("agent-event",v),c.removeChild(l),p.current=null}},[e]),n.useEffect(()=>{p.current&&(o?p.current.setAttribute("mode",o):p.current.removeAttribute("mode"))},[o]),t.jsx("div",{ref:f,className:a,style:u})},Cr=n.forwardRef(function({id:r,intent:i,as:o="div",className:s,style:a,children:u},f){return n.createElement(o,{ref:f,"data-ll-region":r,"data-ll-intent":i,className:s,style:a},u)}),Lr=n.forwardRef(function({id:r,intent:i,children:o,...s},a){return t.jsx("form",{ref:a,"data-ll-form":r,"data-ll-intent":i,...s,children:o})}),jr=n.forwardRef(function(r,i){const{name:o,label:s,labelClassName:a}=r,u={name:o,"data-ll-field":o};let f;if("as"in r&&r.as==="textarea"){const{name:p,label:b,labelClassName:v,as:c,...l}=r;f=t.jsx("textarea",{ref:i,...u,...l})}else if("as"in r&&r.as==="select"){const{name:p,label:b,labelClassName:v,as:c,children:l,..._}=r;f=t.jsx("select",{ref:i,...u,..._,children:l})}else{const{name:p,label:b,labelClassName:v,as:c,...l}=r;f=t.jsx("input",{ref:i,...u,...l})}return s===void 0?f:t.jsxs("label",{className:a,children:[s,f]})});let Kt=1;function Er({onMount:e,defaultOpen:r=!1,storageKey:i="ll-debug-open"}){const[o,s]=n.useState(r),[a,u]=n.useState([]),[f,p]=n.useState(""),[b,v]=n.useState(!1),c=n.useRef(new Set),l=n.useRef([]),_=n.useRef(b);_.current=b,n.useEffect(()=>{try{const x=localStorage.getItem(i);x==="1"&&s(!0),x==="0"&&s(!1)}catch{}},[i]),n.useEffect(()=>{try{localStorage.setItem(i,o?"1":"0")}catch{}},[o,i]),n.useEffect(()=>{const x=w=>{(w.metaKey||w.ctrlKey)&&w.shiftKey&&w.key.toLowerCase()==="l"&&(w.preventDefault(),s(P=>!P))};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[]),n.useEffect(()=>{const x=setInterval(()=>{if(l.current.length===0||_.current)return;const w=l.current.splice(0,l.current.length);u(P=>[...w.reverse(),...P].slice(0,200))},100);return()=>clearInterval(x)},[]);const C=n.useRef(!1);if(n.useEffect(()=>{!e||C.current||(C.current=!0,e(x=>{l.current.push({id:Kt++,ts:Date.now(),kind:"event",type:x.eventName,data:x.data})}))},[e]),n.useEffect(()=>{const x=console.warn,w=console.log,P=(E,D)=>function(...g){try{const L=typeof g[0]=="string"?g[0]:"";L.startsWith("[LiveLayer]")&&l.current.push({id:Kt++,ts:Date.now(),kind:E,type:L.slice(0,120),data:{args:g.slice(1).map(z=>Nr(z))}})}catch{}return D.apply(this,g)};return console.warn=P("warn",x),console.log=P("log",w),()=>{console.warn=x,console.log=w}},[]),!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 S=a.filter(x=>{if(!f)return!0;const w=f.toLowerCase();return x.type.toLowerCase().includes(w)||JSON.stringify(x.data||{}).toLowerCase().includes(w)});return t.jsxs("div",{style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,width:380,maxHeight:"60vh",background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:12,boxShadow:"0 16px 48px rgba(0,0,0,0.5)",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"8px 10px",background:"rgba(255,255,255,0.04)",borderBottom:"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),t.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[a.length," event",a.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>v(x=>!x),style:gt(b?"#f59e0b":"transparent"),title:"Pause / resume capture",children:b?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{u([]),l.current=[]},style:gt("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:gt("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:f,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:S.length===0?t.jsxs("div",{style:{padding:14,fontSize:11,color:"rgba(255,255,255,0.4)",lineHeight:1.5},children:["No events yet. Connect to the agent and trigger a tool call — the events will stream in here. You can also dispatch commands manually in DevTools:",t.jsx("pre",{style:{marginTop:6,background:"rgba(255,255,255,0.04)",padding:6,borderRadius:4,fontSize:10,whiteSpace:"pre-wrap"},children:`window.__livelayerSimulateCommand({
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),n=require("react"),En=require("@livelayer/sdk"),ct=require("livekit-client");class Jt extends n.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,i){var o,s;(s=(o=this.props).onError)==null||s.call(o,r,i)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[t.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),t.jsx("p",{className:"ll-error-boundary__message",children:((r=this.state.error)==null?void 0:r.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function Kt(e){const[r,i]=n.useState("idle"),[o,s]=n.useState("idle"),[a,u]=n.useState([]),[f,p]=n.useState(null),[b,v]=n.useState(null),[c,l]=n.useState(null),[_,C]=n.useState(!1),[S,x]=n.useState(null),w=n.useRef(null),P=n.useRef(e.onDataMessage);P.current=e.onDataMessage,n.useEffect(()=>{const L={onConnectionStateChange:I=>{i(I),I==="connected"&&x(null)},onAgentStateChange:s,onTranscript:I=>u([...I]),onAgentConfig:p,onAudioTrack:I=>l(I),onVideoTrack:I=>v(I),onVideoTrackRemoved:()=>v(null),onError:I=>x(I),onDataMessage:I=>{var j;(j=P.current)==null||j.call(P,I)},onResumabilityChange:C},z=new En.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},L);return w.current=z,i("idle"),s("idle"),u([]),p(null),v(null),l(null),C(!1),x(null),()=>{var I;(I=z.destroy)==null||I.call(z),w.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=n.useCallback(async()=>{const L=w.current;if(L)try{await L.connect()}catch(z){throw x(z instanceof Error?z.message:String(z)),z}},[]),D=n.useCallback(()=>{const L=w.current;L&&L.disconnect()},[]),g=n.useCallback(()=>{var L;return((L=w.current)==null?void 0:L.getRoom())??null},[]);return{connectionState:r,agentState:o,transcript:a,agentConfig:f,videoElement:b,audioElement:c,canResume:_,error:S,connect:E,disconnect:D,getRoom:g,session:w.current}}function Xt(){const e=n.useRef(null),r=n.useRef(null),i=n.useRef(null),o=n.useRef(null),s=n.useRef(new Set),a=n.useRef(null),u=n.useCallback(()=>{const c=r.current;if(!c){o.current=null;return}(!a.current||a.current.length!==c.frequencyBinCount)&&(a.current=new Uint8Array(new ArrayBuffer(c.frequencyBinCount)));const l=a.current;c.getByteFrequencyData(l);let _=0;for(let S=0;S<l.length;S++)_+=l[S];const C=_/l.length/255;for(const S of s.current)try{S(C)}catch(x){console.error("[useAudioLevel] subscriber threw:",x)}o.current=requestAnimationFrame(u)},[]),f=n.useCallback(()=>{if(e.current||typeof window>"u"||typeof AudioContext>"u")return;const c=new AudioContext,l=c.createAnalyser();l.fftSize=64,l.connect(c.destination),e.current=c,r.current=l},[]),p=n.useCallback(c=>{if(f(),!(!e.current||!r.current)){if(i.current){try{i.current.disconnect()}catch{}i.current=null}try{const l=e.current.createMediaElementSource(c);l.connect(r.current),i.current=l}catch(l){console.warn("[useAudioLevel] createMediaElementSource failed:",l);return}o.current===null&&(o.current=requestAnimationFrame(u))}},[f,u]),b=n.useCallback(()=>{if(o.current!==null&&(cancelAnimationFrame(o.current),o.current=null),i.current){try{i.current.disconnect()}catch{}i.current=null}},[]),v=n.useCallback(c=>(s.current.add(c),()=>{s.current.delete(c)}),[]);return n.useEffect(()=>()=>{if(b(),r.current){try{r.current.disconnect()}catch{}r.current=null}if(e.current){try{e.current.close()}catch{}e.current=null}s.current.clear(),a.current=null},[b]),{attach:p,detach:b,subscribe:v}}function Gt(){const[e,r]=n.useState(!1),[i,o]=n.useState(null),s=n.useRef(null),a=n.useRef(null),u=n.useCallback(async(c,l)=>{if(s.current&&a.current){try{await a.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}a.current=c,o(null);try{const _=await ct.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});l!=null&&l.startMuted&&await _.mute(),await c.localParticipant.publishTrack(_),s.current=_,r(_.isMuted)}catch(_){const C=_ instanceof Error&&_.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw o(C),_}},[]),f=n.useCallback(()=>{const c=s.current;c&&(c.isMuted?(c.unmute(),r(!1)):(c.mute(),r(!0)))},[]),p=n.useCallback(c=>{const l=s.current;l&&(c&&!l.isMuted?(l.mute(),r(!0)):!c&&l.isMuted&&(l.unmute(),r(!1)))},[]),b=n.useCallback(()=>{const c=s.current,l=a.current;if(c&&l){try{l.localParticipant.unpublishTrack(c)}catch{}c.stop()}s.current=null,a.current=null,r(!1)},[]),v=n.useCallback(()=>o(null),[]);return{isMuted:e,micError:i,toggleMute:f,setMuted:p,setupMic:u,teardownMic:b,clearError:v}}const Rn={resolution:{width:640,height:480,frameRate:24}};function Qt(){const[e,r]=n.useState(!1),[i,o]=n.useState(null),[s,a]=n.useState(null),[u,f]=n.useState(""),p=n.useRef(null),b=n.useRef(null),v=n.useCallback(w=>{p.current=w},[]),c=n.useCallback(()=>{const w=p.current,P=b.current;if(P&&w){const E=w.localParticipant.getTrackPublication(ct.Track.Source.Camera);if(E!=null&&E.track){try{w.localParticipant.unpublishTrack(E.track)}catch{}E.track.stop()}else P.stop()}b.current=null,a(null),r(!1)},[]),l=n.useCallback(async w=>{const P=p.current;if(P){o(null);try{const E={...Rn};w&&(E.deviceId=w);const D=await ct.createLocalVideoTrack(E);await P.localParticipant.publishTrack(D),b.current=D;const g=D.attach();a(g),r(!0),w&&f(w);try{P.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const D=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";o(D)}}},[]),_=n.useCallback(async()=>{e?c():await l(u||void 0)},[e,u,c,l]),C=n.useCallback(async w=>{c(),await l(w)},[c,l]),S=n.useCallback(()=>{c(),p.current=null,o(null),f("")},[c]),x=n.useCallback(()=>o(null),[]);return n.useEffect(()=>()=>{b.current&&b.current.stop()},[]),{isEnabled:e,error:i,previewEl:s,activeDeviceId:u,toggle:_,switchDevice:C,attachRoom:v,teardown:S,clearError:x}}function Zt(){const[e,r]=n.useState(!1),[i,o]=n.useState(null),[s,a]=n.useState(null),u=n.useRef(null),f=n.useCallback(l=>{u.current=l},[]),p=n.useCallback(()=>a(null),[]),b=n.useCallback(async()=>{const l=u.current;if(l){if(e){try{await l.localParticipant.setScreenShareEnabled(!1)}catch{}p(),r(!1);return}o(null);try{await l.localParticipant.setScreenShareEnabled(!0);let _=0;const C=()=>{const S=l.localParticipant.getTrackPublication(ct.Track.Source.ScreenShare);if(S!=null&&S.track){const x=S.track.attach();a(x),r(!0);try{l.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}_++<10?setTimeout(C,100):r(!0)};C()}catch(_){const C=_ instanceof Error?_.name:"";C!=="NotAllowedError"&&C!=="AbortError"&&o("Screen share unavailable. Try again."),r(!1)}}},[e,p]),v=n.useCallback(()=>{const l=u.current;if(l&&e)try{l.localParticipant.setScreenShareEnabled(!1)}catch{}p(),r(!1),o(null),u.current=null},[e,p]),c=n.useCallback(()=>o(null),[]);return{isEnabled:e,error:i,previewEl:s,toggle:b,attachRoom:f,teardown:v,clearError:c}}function en(){const[e,r]=n.useState([]),[i,o]=n.useState([]),s=n.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const a=await navigator.mediaDevices.enumerateDevices();r(a.filter(u=>u.kind==="audioinput")),o(a.filter(u=>u.kind==="videoinput"))}catch{}},[]);return n.useEffect(()=>{if(s(),typeof navigator>"u"||!navigator.mediaDevices)return;const a=()=>void s();return navigator.mediaDevices.addEventListener("devicechange",a),()=>navigator.mediaDevices.removeEventListener("devicechange",a)},[s]),{mics:e,cameras:i,refresh:s}}function tn(e,r,i=!1){const[o,s]=n.useState(null),[a,u]=n.useState(null),[f,p]=n.useState(!i&&!!e);return n.useEffect(()=>{if(i||!e){p(!1);return}const b=new AbortController,v=r||"https://app.livelayer.studio";return p(!0),u(null),fetch(`${v}/api/widget/agent/${encodeURIComponent(e)}`,{signal:b.signal}).then(async c=>{if(!c.ok){const l=await c.json().catch(()=>({}));throw new Error(l.error||`HTTP ${c.status}`)}return c.json()}).then(c=>{b.signal.aborted||(s(c),p(!1))}).catch(c=>{b.signal.aborted||(u(c instanceof Error?c.message:"Agent lookup failed"),p(!1))}),()=>b.abort()},[e,r,i]),{info:o,error:a,loading:f}}function Nn(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function An(e,r){if(!(typeof window>"u"))try{window.localStorage.setItem(e,r)}catch{}}function nn({value:e,defaultValue:r="expanded",onChange:i}={}){const o=e!==void 0,[s,a]=n.useState(r),u=o?e:s,f=n.useCallback(p=>{p!==u&&(o||a(p),i==null||i(p))},[u,o,i]);return[u,f]}const Mn=["hidden","minimized","expanded"];function In(e){return e&&Mn.includes(e)?e:null}function rn({value:e,defaultValue:r="expanded",onChange:i,persistKey:o="ll-widget",disablePersistence:s=!1}={}){const a=`${o}:display-mode`,u=n.useRef(!1),[f,p]=nn({value:e,defaultValue:r,onChange:b=>{e===void 0&&!s&&An(a,b),i==null||i(b)}});return n.useEffect(()=>{if(u.current||(u.current=!0,s||e!==void 0))return;const b=In(Nn(a));b&&b!==f&&p(b)},[]),[f,p]}const Tn=640;function on(e=Tn){const[r,i]=n.useState(!1);return n.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),a=()=>i(s.matches);return a(),typeof s.addEventListener=="function"?(s.addEventListener("change",a),()=>s.removeEventListener("change",a)):(s.addListener(a),()=>{s.removeListener(a)})},[e]),r}const Mt="__llHistoryPatched",ut="ll:pathname";function Pn(){if(typeof window>"u"||window.history[Mt])return;const e=window.history.pushState,r=window.history.replaceState;window.history.pushState=function(...i){const o=e.apply(this,i);return window.dispatchEvent(new Event(ut)),o},window.history.replaceState=function(...i){const o=r.apply(this,i);return window.dispatchEvent(new Event(ut)),o},window.history[Mt]=!0}function It(){return typeof window>"u"?"/":window.location.pathname||"/"}function sn(e){const[r,i]=n.useState(()=>e??It());return n.useEffect(()=>{if(e!==void 0)return;Pn();const o=()=>i(It());return o(),window.addEventListener("popstate",o),window.addEventListener(ut,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(ut,o)}},[e]),e??r}const Tt=new Map,Dn=/[\\^$+?.()|{}[\]]/g;function $n(e){return e.replace(Dn,"\\$&")}function zn(e){const r=Tt.get(e);if(r)return r;const i=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,o="",s="",a=i.replace(/\*\*/g,o).replace(/\*/g,s),f=$n(a).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),p=new RegExp(`^${f}\\/?$`);return Tt.set(e,p),p}function On(e,r){const i=r.length>1&&r.endsWith("/")?r.slice(0,-1):r;return zn(e).test(i)}function an(e,r){return typeof e=="function"?e(r):e instanceof RegExp?e.test(r):On(e,r)}function Pt(e,r){if(!e||e.length===0)return!1;for(const i of e)if(an(i,r))return!0;return!1}function ln(e,r,i){return e===void 0?!0:Pt(i,e)?!1:r&&r.length>0?Pt(r,e):!0}function cn(e,r,i){return n.useMemo(()=>ln(e,r,i),[e,r,i])}const Dt=({muted:e=!1,className:r})=>e?t.jsxs("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"})}),$t=({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"})}),Hn=({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"})}),qn={left:180,right:0,up:-90,down:90},zt=({direction:e="right",className:r})=>t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${qn[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function Bn(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const un="ll-hidden-tab-center-y",Wn=5,Ot=16;function Fn(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(un);if(!e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null}catch{return null}}function Ht(e){if(!(typeof window>"u"))try{window.localStorage.setItem(un,String(e))}catch{}}const Un=({position:e,isMobile:r,isSpeaking:i,onExpand:o,label:s="Open widget",avatarImageUrl:a,agentName:u})=>{const f=Bn(e),p=f==="right"?"left":"right",b=r?80:72,v=!!a,[c,l]=n.useState(null),[_,C]=n.useState(!1),S=n.useRef(null),x=n.useRef(!1),w=n.useCallback(j=>{if(typeof window>"u")return j;const $=b/2,O=Ot+$,Y=window.innerHeight-Ot-$;return Y<O?Math.max(O,j):Math.max(O,Math.min(Y,j))},[b]);n.useEffect(()=>{const j=Fn();l(w(j??window.innerHeight/2));const $=()=>{l(O=>O===null?null:w(O))};return window.addEventListener("resize",$),()=>window.removeEventListener("resize",$)},[w]);const P=n.useCallback(j=>{if(!(j.pointerType==="mouse"&&j.button!==0)&&c!==null){try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}S.current={startClientY:j.clientY,startCenterY:c,moved:!1}}},[c]),E=n.useCallback(j=>{const $=S.current;if(!$)return;const O=j.clientY-$.startClientY;!$.moved&&Math.abs(O)>Wn&&($.moved=!0,C(!0)),$.moved&&l(w($.startCenterY+O))},[w]),D=n.useCallback(j=>{const $=S.current;if($){try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}S.current=null,$.moved&&(C(!1),x.current=!0,l(O=>(O!==null&&Ht(O),O)))}},[]),g=n.useCallback(()=>{if(x.current){x.current=!1;return}o()},[o]),L=n.useCallback(j=>{if(j.key==="ArrowUp"||j.key==="ArrowDown"){j.preventDefault();const $=j.key==="ArrowUp"?-8:8;l(O=>{if(O===null)return O;const Y=w(O+$);return Ht(Y),Y})}},[w]),z=["ll-hidden",`ll-hidden--${f}`,r?"ll-hidden--mobile":"ll-hidden--desktop",i?"ll-hidden--speaking":null,_?"is-dragging":null,v?"ll-hidden--with-avatar":null].filter(Boolean).join(" "),I=c===null?void 0:{top:`${c-b/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:z,onPointerDown:P,onPointerMove:E,onPointerUp:D,onPointerCancel:D,onClick:g,onKeyDown:L,"aria-label":s,"data-position":e,style:I,children:v?t.jsxs(t.Fragment,{children:[t.jsx(zt,{direction:p,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:a,alt:u?`${u} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(zt,{direction:p,className:"ll-hidden__chevron"})})},Vn=({audioLevel:e,bars:r=20,maxHeight:i=20,minHeight:o=4,className:s,barClassName:a})=>{const u=n.useRef(null),f=n.useRef([]),p=n.useMemo(()=>{const v=(Math.sqrt(5)-1)/2;return Array.from({length:r},(c,l)=>.5+l*v%1*.5)},[r]);n.useEffect(()=>e.subscribe(c=>{for(let l=0;l<r;l++){const _=f.current[l];if(!_)continue;const C=Math.max(o,c*i*p[l]);_.style.height=`${C}px`}}),[e,r,i,o,p]);const b=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:u,className:b,"aria-hidden":"true",children:Array.from({length:r},(v,c)=>t.jsx("div",{ref:l=>{f.current[c]=l},className:["ll-waveform__bar",a].filter(Boolean).join(" "),style:{height:`${o}px`}},c))})},Yn=({position:e,isMobile:r,agentName:i,avatarImageUrl:o,agentState:s,isMuted:a,audioLevel:u,onExpand:f,onToggleMute:p,onClose:b})=>r?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:f,"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(Vn,{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:v=>{v.stopPropagation(),p()},onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.stopPropagation(),v.preventDefault(),p())},"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(Dt,{muted:a,className:"ll-minimized__icon"})}),t.jsx($t,{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":a?"Unmute microphone":"Mute microphone",children:t.jsx(Dt,{muted:a,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:f,"aria-label":`Expand ${i} widget`,children:t.jsx($t,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:b,"aria-label":"Close widget",children:t.jsx(Hn,{className:"ll-minimized__icon"})})]})]})}),Jn=({src:e,alt:r,preCannedPlaying:i=!1,className:o,style:s})=>{const[a,u]=n.useState(!1),f=n.useRef(e);if(n.useEffect(()=>{f.current!==e&&(f.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:a?1:0,...s};return t.jsx("img",{src:e,alt:r,className:o,style:p,loading:"eager",fetchPriority:"high",onLoad:()=>u(!0)})},Kn=({position:e,isMobile:r,agentName:i,avatarImageUrl:o,idleLoopUrl:s,greeting:a,branding:u,teamMembers:f,currentTeamMemberId:p,isSwitchingTeamMember:b,teamSwitcherOpen:v,onToggleTeamSwitcher:c,onSelectTeamMember:l,languageMenuOpen:_,onToggleLanguageMenu:C,connectionState:S,agentState:x,transcript:w,canResume:P,needsUserGesture:E,error:D,isMuted:g,micError:L,micDevices:z,isCameraEnabled:I,cameraPreviewEl:j,cameraDevices:$,activeCameraId:O,isScreenShareEnabled:Y,screenPreviewEl:ee,isSpeakerMuted:ge,allowCamera:Ge,allowScreenShare:Qe,allowTyping:Ze,avatarVideoContainerRef:et,agentVideoEl:Z,micGateOpen:oe,onConnect:ye,onDisconnect:Se,onRetry:Ce,onResumeAudio:Le,onToggleMute:je,onToggleCamera:Ee,onSwitchCameraDevice:B,onToggleScreenShare:ft,onToggleSpeaker:pt,onSendMessage:tt,onMinimize:se,onClose:Re,onClearMicError:Oe})=>{var Te;const be=((f==null?void 0:f.length)??0)>1,Ne=S==="connecting"||S==="connected",V=S==="connected",X=S==="idle"||S==="disconnected"||S==="error",[Ae,te]=n.useState(!1);n.useEffect(()=>{if(!Z){te(!1);return}if(!Z.paused&&Z.readyState>=2){te(!0);return}te(!1);const h=()=>te(!0);return Z.addEventListener("playing",h),Z.addEventListener("loadeddata",h),()=>{Z.removeEventListener("playing",h),Z.removeEventListener("loadeddata",h)}},[Z]);const[ae,xe]=n.useState(!1);n.useEffect(()=>{if(!V){xe(!1);return}if(Ae)return;const h=setTimeout(()=>xe(!0),8e3);return()=>clearTimeout(h)},[V,Ae]);const He=S==="connecting"||V&&!!o&&!Ae&&!ae,G=n.useRef(null),ne=n.useRef(null);n.useEffect(()=>{const h=G.current;h&&(h.innerHTML="",j&&(j.style.width="100%",j.style.height="100%",j.style.objectFit="cover",j.style.transform="scaleX(-1)",h.appendChild(j)))},[j]),n.useEffect(()=>{const h=ne.current;h&&(h.innerHTML="",ee&&(ee.style.width="100%",ee.style.height="100%",ee.style.objectFit="contain",h.appendChild(ee)))},[ee]);const[re,ce]=n.useState(!1),[Me,ue]=n.useState(!1);n.useEffect(()=>{if(!re&&!Me&&!_&&!v)return;const h=()=>{ce(!1),ue(!1),_&&C(),v&&c()};return document.addEventListener("click",h),()=>document.removeEventListener("click",h)},[re,Me,_,v,C,c]);const[de,qe]=n.useState(""),Be=n.useCallback(h=>{h.preventDefault();const W=de.trim();W&&(tt(W),qe(""))},[de,tt]),We=u.productName||"Live Layer";let fe=null,pe=null;for(let h=w.length-1;h>=0;h--){const W=w[h];if(!fe&&W.role==="agent"?fe=W:!pe&&W.role==="user"&&(pe=W),fe&&pe)break}const Ie=V?(fe==null?void 0:fe.text)||null:a||null,nt=V&&(pe==null?void 0:pe.text)||null,Fe=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:Fe,"data-position":e,"data-state":V?"connected":Ne?"connecting":"idle",role:"dialog","aria-label":`${i} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[o?t.jsx(Jn,{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:((Te=i==null?void 0:i.charAt(0))==null?void 0:Te.toUpperCase())||"A"})}),s&&!V&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:et,className:"ll-expanded__video"}),He&&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:b?"Switching...":"Connecting..."})]}),E&&V&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:Le,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"})]}),Ne?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:h=>{be&&(h.stopPropagation(),c())},"aria-haspopup":be?"listbox":void 0,"aria-expanded":be?v:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:i}),be&&t.jsx(ot,{})]}),be&&v&&t.jsx("div",{className:"ll-hmenu",onClick:h=>h.stopPropagation(),role:"listbox",children:f==null?void 0:f.map(h=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${h.id===p?"is-active":""}`,onClick:()=>l(h.id),role:"option","aria-selected":h.id===p,children:[h.avatarImageUrl&&t.jsx("img",{src:h.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:h.name}),h.role&&t.jsx("span",{className:"ll-hmenu__role",children:h.role})]},h.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:h=>{h.stopPropagation(),C()},"aria-haspopup":"listbox","aria-expanded":_,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(ot,{})]}),_&&t.jsx("div",{className:"ll-hmenu",onClick:h=>h.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:se,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(Bt,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Re,"aria-label":"End call",title:"End call",children:t.jsx(qt,{})})]})]}):t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:We}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:se,"aria-label":"Minimize widget",children:t.jsx(Bt,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Re,"aria-label":"Close widget",children:t.jsx(qt,{})})]})]}),X&&(()=>{const h=P?"Restart paused session":S==="disconnected"?"Reconnect to agent":"Start video call",W=P?"Pick up where you left off":null,rt=S==="idle"&&!P&&!D;return t.jsxs(t.Fragment,{children:[rt&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:ye,"aria-label":h,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:h})]}),t.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[a&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:a})}),W&&t.jsx("p",{className:"ll-expanded__cta-sublabel",children:W}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:ye,"aria-label":h,children:h})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${Ne&&(I||Y)?"is-visible":""}`,children:[t.jsx("div",{ref:ne,className:Y?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:G,className:!Y&&I?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Ne?t.jsxs("div",{className:"ll-expanded__bottom",children:[Ie&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Ie})}),nt&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:nt})}),t.jsxs("div",{className:"ll-toolbar",onClick:h=>h.stopPropagation(),children:[Qe&&t.jsx("button",{type:"button",className:`ll-tool ${Y?"is-on":""}`,onClick:ft,"aria-label":Y?"Stop sharing screen":"Share screen",title:Y?"Stop sharing":"Share screen",children:t.jsx(Xn,{})}),Ge&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${I?"is-on":""}`,onClick:Ee,"aria-label":I?"Turn off camera":"Turn on camera",title:I?"Stop camera":"Start camera",children:t.jsx(Gn,{})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${I?"is-on":""}`,onClick:h=>{h.stopPropagation(),ue(W=>!W),ce(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":Me,children:t.jsx(ot,{})}),Me&&$.length>0&&t.jsx(Wt,{label:"Camera",devices:$,activeId:O,onPick:h=>{ue(!1),B(h)}})]}),t.jsxs("div",{className:`ll-tool-split${!oe&&V?" ll-tool-split--gated":""}`,children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${g?"is-muted":""}`,onClick:je,disabled:!oe&&V,"aria-label":!oe&&V?"Microphone enables once the agent finishes its greeting":g?"Unmute microphone":"Mute microphone",title:!oe&&V?"Mic enables after greeting":g?"Unmute":"Mute",children:t.jsx(Qn,{muted:g})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${g?"is-muted":""}`,onClick:h=>{h.stopPropagation(),ce(W=>!W),ue(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":re,children:t.jsx(ot,{})}),re&&z.length>0&&t.jsx(Wt,{label:"Microphone",devices:z,activeId:"",onPick:()=>ce(!1)})]}),t.jsx("button",{type:"button",className:`ll-tool ${ge?"is-muted":""}`,onClick:pt,"aria-label":ge?"Unmute speaker":"Mute speaker",title:ge?"Unmute speaker":"Mute speaker",children:t.jsx(Zn,{muted:ge})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:Se,"aria-label":"End conversation",title:"End conversation",children:t.jsx(tr,{})})]}),Ze&&t.jsxs("form",{className:"ll-message-input",onSubmit:Be,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:de,onChange:h=>qe(h.target.value),"aria-label":"Message the agent"}),de.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(er,{})})]})]}):null,(()=>{if(L&&S!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:L}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:Oe,"aria-label":"Dismiss",children:"×"})]});if(!D||S!=="error")return null;let h="Failed to connect",W="Try again";return D==="MIC_PERMISSION_DENIED"?h="Microphone blocked. Allow access to talk.":D==="MIC_NOT_FOUND"?h="No microphone found. Plug one in + retry.":D==="MIC_UNAVAILABLE"?h="Mic unavailable. Check other apps using it.":D==="AGENT_TIMEOUT"?h="Agent didn't pick up. Try again.":D==="CONNECT_FAILED"?h="Connection failed. Check your network.":D.length<80&&(h=D),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:h}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:Ce,children:W})]})})()]})};function ot(){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 qt(){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 Bt(){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 Xn(){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 Gn(){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 Qn({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 Zn({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 er(){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 tr(){return t.jsx("svg",{width:"16",height:"16",viewBox:"-4 -4 32 32",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.93.37 1.84.71 2.7a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.38-1.38a2 2 0 0 1 2.11-.45c.86.34 1.77.58 2.7.71A2 2 0 0 1 22 16.92z",transform:"rotate(135 12 12)"})})}const Wt=({label:e,devices:r,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}),r.map((s,a)=>{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} ${a+1}`})]},s.deviceId||a)})]}),nr=['[data-ll-private="true"]',".ll-widget"];function vt(e){let r=e;for(;r;){for(const i of nr)if(r.matches(i))return!0;r=r.parentElement}return!1}function dt(e){if(vt(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const r=(e.getAttribute("autocomplete")||"").toLowerCase();if(r==="off"||r.startsWith("cc-"))return!1}return!0}const st=4096,rr=20,ir=20,or=10,sr=10,ar=30,Ft=500,lr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function Ke(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let r=e;for(;r;){for(const i of lr)if(r.matches(i))return!0;r=r.parentElement}return!1}function Xe(e){if(typeof window>"u")return!0;const r=e.getBoundingClientRect();if(r.width<=0||r.height<=0)return!1;const i=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth;return r.bottom>0&&r.right>0&&r.top<i&&r.left<o}function Ut(e){const r=e.getAttribute("id");if(r){const a=document.querySelector(`label[for="${CSS.escape(r)}"]`);if(a!=null&&a.textContent)return a.textContent.trim()}const 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 ke(e,r){return e.length<=r?e:e.slice(0,r-1)+"…"}function De(e){return e.length}function dn(e,r={}){const i=r.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||"/",a=i.title||"",u=Array.from(i.querySelectorAll("[data-ll-region]")),f=[];for(const g of u){if(f.length>=or)break;if(Ke(g)||!Xe(g))continue;const L=g.getAttribute("data-ll-region")??"",z=g.getAttribute("data-ll-intent")??void 0,I=ke((g.innerText||g.textContent||"").trim(),Ft*2);!L||!I||f.push({id:L,intent:z,text:I})}const p=[],b=["H1","H2","H3","H4","H5","H6"],v=Array.from(i.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const g of v){if(Ke(g)||!Xe(g))continue;const L=(g.textContent||"").trim();L&&p.push(`${g.tagName}: ${ke(L,200)}`)}const c=Array.from(i.querySelectorAll("p, li"));for(const g of c){if(Ke(g)||!Xe(g)||b.includes(g.tagName))continue;const L=(g.textContent||"").trim();L.length>10&&p.push(ke(L,Ft))}const l=p.join(`
2
+ `),_=[],C=Array.from(i.querySelectorAll("a[href]"));for(const g of C){if(_.length>=rr)break;if(Ke(g)||!Xe(g))continue;const L=g.getAttribute("href")||"",z=(g.textContent||"").trim();!L||!z||_.push({href:L,text:ke(z,100)})}const S=[],x=Array.from(i.querySelectorAll("input, textarea, select"));for(const g of x){if(S.length>=ir)break;if(Ke(g)||!dt(g)||!Xe(g))continue;const L=Ut(g),z=g instanceof HTMLInputElement?g.type:g.tagName.toLowerCase();L&&S.push({label:ke(L,100),type:z})}const w=Array.from(i.querySelectorAll("[data-ll-form]")),P=[];for(const g of w){if(P.length>=sr)break;if(vt(g))continue;const L=g.getAttribute("data-ll-form")||"";if(!L)continue;const z=g.getAttribute("data-ll-intent")||void 0,I=Array.from(g.querySelectorAll("[data-ll-field]")),j=[];for(const $ of I){if(j.length>=ar)break;if(!dt($))continue;const O=$.getAttribute("data-ll-field")||"";if(!O)continue;const Y=Ut($)||O,ee=$ instanceof HTMLInputElement?$.type:$.tagName.toLowerCase();j.push({name:O,label:ke(Y,100),type:ee})}P.push({id:L,intent:z,fields:j})}const E={url:o,title:a,pathname:s,regions:f,visibleText:l,visibleLinks:_,visibleFields:S,forms:P,extras:e};let D=De(JSON.stringify(E.regions))+De(E.visibleText)+De(JSON.stringify(E.visibleLinks))+De(JSON.stringify(E.visibleFields));for(;D>st&&E.visibleFields.length>0;)E.visibleFields.pop(),D=De(JSON.stringify(E.visibleFields));for(;D>st&&E.visibleLinks.length>0;)E.visibleLinks.pop(),D-=80;return De(E.visibleText)>st&&(E.visibleText=ke(E.visibleText,st-100)),E}let $e=null;function at(e,r={}){const i=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if($e&&$e.key===s&&i-$e.at<1e3)return $e.ctx;const a=dn(e,r);return $e={key:s,at:i,ctx:a},a}function fn(){$e=null}const cr=200;function pn(e){const r=String(e.href||"");return{href:r,text:String(e.text??e.title??r),internal:e.internal??!0,title:e.title,description:e.description}}function ur(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function hn(e){const r=e??(typeof document<"u"?document:null);if(!r)return[];const i=typeof window<"u"&&window.location.origin||"",o=new Set,s=[],a=Array.from(r.querySelectorAll("a[href]"));for(const u of a){if(s.length>=cr)break;if(vt(u))continue;const f=u.getAttribute("href")||"";if(!ur(f))continue;let p=f,b=!0;try{if(typeof window<"u"){const c=new URL(f,i);b=c.origin===i,b&&f.startsWith("http")&&(p=c.pathname+c.search+c.hash)}}catch{continue}if(o.has(p))continue;o.add(p);const v=(u.textContent||"").trim().slice(0,120);s.push({href:p,text:v,internal:b})}return s}let ze=null;const dr=5e3;function lt(){const e=Date.now(),r=typeof window<"u"&&window.location.pathname||"/";if(ze&&ze.pathname===r&&e-ze.at<dr)return ze.routes;const i=hn();return ze={at:e,pathname:r,routes:i},i}function mn(){ze=null}function fr(e,r){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,r):e.value=r}function pr(e,r,i={}){const o=i.triggerInput??!0,s=i.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const a=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),u=a==null?void 0:a.set,f=r==="true"||r==="1"||r==="on";u?u.call(e,f):e.checked=f,o&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}fr(e,r),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function hr(){if(typeof window>"u"||typeof document>"u")return!1;const e=document.scrollingElement||document.documentElement;if(!e||e.scrollHeight<=e.clientHeight+2)return!1;const r=window.getComputedStyle(e);return!(r.overflowY==="hidden"||r.overflowY==="clip")}function mr(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function gr(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let r=null,i=0;for(const o of e){if(!mr(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 a=s.width*s.height;a>i&&(i=a,r=o)}return r}function yr(){if(typeof window>"u")return null;if(hr())return window;const e=gr();return e||window}function Vt(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function br(e){var r,i;return e instanceof Window?typeof document>"u"?0:Math.max(((r=document.body)==null?void 0:r.scrollHeight)??0,((i=document.documentElement)==null?void 0:i.scrollHeight)??0):e.scrollHeight-e.clientHeight}const xr=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 vr(e){var Ct,Lt,jt,Et,Rt,Nt,At;const{agentId:r,apiKey:i,baseUrl:o="https://app.livelayer.studio",sessionEndpoint:s,sessionBody:a,autoConnect:u=!1,displayMode:f,defaultDisplayMode:p="expanded",onDisplayModeChange:b,position:v="bottom-right",mobileBreakpoint:c=640,persistKey:l="ll-widget",disablePersistence:_=!1,teamMembers:C,currentTeamMemberId:S,onTeamMemberChange:x,idleLoopUrl:w,greeting:P,avatarImageUrl:E,agentName:D,branding:g={},allowCamera:L=!0,allowScreenShare:z=!0,allowTyping:I=!0,showOn:j,hideOn:$,pathname:O,onNavigate:Y,onScrollToSelector:ee,getPageContext:ge,pageContextExtras:Ge,getRoutes:Qe,onScrollPage:Ze,onClick:et,capabilities:Z,onConnect:oe,onDisconnect:ye,onTranscript:Se,onAgentState:Ce,onConnectionStateChange:Le,onAgentEvent:je,onAgentCommand:Ee,controlledSession:B,className:ft,style:pt,zIndex:tt=2147483647}=e,se=sn(O),Re=cn(se,j,$);n.useEffect(()=>{fn(),mn()},[se]);const Oe=S!==void 0,[be,Ne]=n.useState(()=>{var m;return S??((m=C==null?void 0:C[0])==null?void 0:m.id)}),V=Oe?S:be,X=n.useMemo(()=>(C==null?void 0:C.find(m=>m.id===V))??null,[C,V]),Ae=(X==null?void 0:X.agentId)??r,[te,ae]=rn({value:f,defaultValue:p,onChange:b,persistKey:l,disablePersistence:_}),xe=on(c),He=Xt(),G=Gt(),ne=Qt(),re=Zt(),ce=en(),[Me,ue]=n.useState(!1),[de,qe]=n.useState(!1),[Be,We]=n.useState(!1),[fe,pe]=n.useState(!1),[Ie,nt]=n.useState(!1),Fe=n.useRef(Y),Te=n.useRef(ee),h=n.useRef(Ze),W=n.useRef(et),rt=n.useRef(ge),ht=n.useRef(Ge),wt=n.useRef(Qe),mt=n.useRef(Z),Q=n.useRef(null);Fe.current=Y,Te.current=ee,h.current=Ze,W.current=et,rt.current=ge,ht.current=Ge,wt.current=Qe,mt.current=Z;function he(m){const d=mt.current;return d?d.includes(m):!0}function me(m,d){console.warn(`[LiveLayer] Agent command "${m}" blocked — capability "${d}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const Ue=n.useCallback(m=>{var K,ve,le,Pe,we;const d=m;if(!(!d.type||typeof d.type!="string")){if(je==null||je({eventName:d.type,data:m}),d.type==="navigate"){if(!he("navigate")){me("navigate","navigate");return}const k=typeof d.href=="string"?d.href:null;if(!k){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(Fe.current){try{Fe.current(k)}catch(R){console.warn(`[LiveLayer] onNavigate threw for "${k}". Falling back. Error:`,R)}return}if(typeof document<"u"){const R=document.querySelector(`a[href="${k.replace(/"/g,'\\"')}"]`);if(R){R.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",k),window.dispatchEvent(new PopStateEvent("popstate"))}catch(R){console.warn(`[LiveLayer] history.pushState fallback failed for "${k}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,R)}return}if(d.type==="scroll_to"){if(!he("scroll")){me("scroll_to","scroll");return}const k=typeof d.selector=="string"?d.selector:null;if(!k)return;const R=d.behavior==="instant"?"instant":"smooth";if(Te.current){try{Te.current(k,R)}catch(A){console.warn("[LiveLayer] onScrollToSelector threw.",A)}return}if(typeof document<"u"){let A=null;try{A=document.querySelector(k)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${k}".`);return}if(!A){console.warn(`[LiveLayer] scroll_to: no element matched "${k}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}A.scrollIntoView({behavior:R,block:"start"})}return}if(d.type==="request_page_context"){if(!he("read_page")){me("request_page_context","read_page");return}const k=typeof d.requestId=="string"?d.requestId:void 0,R=(K=Q.current)==null?void 0:K.call(Q),A=U=>{const N=R,q=N==null?void 0:N.localParticipant;if(q!=null&&q.publishData)try{const T=k?{...U,requestId:k}:U,J=new TextEncoder().encode(JSON.stringify(T));q.publishData(J,{reliable:!0})}catch(T){console.warn("[LiveLayer] publishData failed.",T)}},M=ht.current,F=rt.current;try{if(F){const U=F(M);if(U instanceof Promise){A({type:"page_context_pending"}),U.then(N=>A({type:"page_context",context:N})).catch(N=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",N),A({type:"page_context",context:at(M)})});return}A({type:"page_context",context:U});return}A({type:"page_context",context:at(M)})}catch(U){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",U),A({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:M}})}return}if(d.type==="scroll_page"){if(!he("scroll")){me("scroll_page","scroll");return}const k=d.direction;if(k!=="up"&&k!=="down"&&k!=="top"&&k!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(k)}". Expected up | down | top | bottom.`);return}const R=d.behavior==="instant"?"instant":"smooth";if(h.current){try{h.current(k,R)}catch(N){console.warn("[LiveLayer] onScrollPage threw.",N)}return}if(typeof window>"u")return;const A={behavior:R},M=yr(),F=N=>{M instanceof Window?M.scrollBy({top:N,...A}):M.scrollBy({top:N,...A})},U=N=>{M instanceof Window?M.scrollTo({top:N,...A}):M.scrollTo({top:N,...A})};k==="up"?F(-Vt(M)):k==="down"?F(Vt(M)):U(k==="top"?0:br(M));return}if(d.type==="click"){if(!he("click")){me("click","click");return}const k=typeof d.selector=="string"?d.selector:null;if(!k){console.warn("[LiveLayer] click: missing selector.");return}if(W.current){try{W.current(k)}catch(A){console.warn("[LiveLayer] onClick threw.",A)}return}if(typeof document>"u")return;let R=null;try{R=document.querySelector(k)}catch{console.warn(`[LiveLayer] click: invalid selector "${k}".`);return}if(!R){console.warn(`[LiveLayer] click: no element matched "${k}". 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}(ve=R.click)==null||ve.call(R);return}if(d.type==="fill_form"||d.type==="focus_field"){if(!he("fill_forms")){me(d.type,"fill_forms");return}if(typeof document>"u")return;const k=typeof d.requestId=="string"?d.requestId:void 0,R=(le=Q.current)==null?void 0:le.call(Q),A=T=>{if(d.type!=="fill_form")return;const J=R,ie=J==null?void 0:J.localParticipant;if(ie!=null&&ie.publishData)try{const _e=k?{...T,requestId:k}:T,jn=new TextEncoder().encode(JSON.stringify(_e));ie.publishData(jn,{reliable:!0})}catch(_e){console.warn("[LiveLayer] publishData failed.",_e)}},M=typeof d.formId=="string"?d.formId:null;if(!M){console.warn(`[LiveLayer] ${d.type}: missing formId.`),A({type:"fill_form_result",ok:!1,reason:"missing formId"});return}const F=document.querySelector(`[data-ll-form="${M.replace(/"/g,'\\"')}"]`);if(!F){console.warn(`[LiveLayer] ${d.type}: no form with data-ll-form="${M}". Tag your form with <LiveLayerForm id> or data-ll-form. See https://livelayer.studio/docs/react/forms`),A({type:"fill_form_result",ok:!1,reason:`no form with data-ll-form="${M}" on this page`,formId:M});return}if(F.closest('[data-ll-private="true"], .ll-widget')){console.warn(`[LiveLayer] ${d.type}: refusing to touch a form in a private subtree.`),A({type:"fill_form_result",ok:!1,reason:"form is in a private subtree (data-ll-private)",formId:M});return}if(d.type==="focus_field"){const T=typeof d.fieldName=="string"?d.fieldName:null;if(!T){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const J=F.querySelector(`[data-ll-field="${T.replace(/"/g,'\\"')}"]`);if(!J){console.warn(`[LiveLayer] focus_field: no field "${T}" in form "${M}".`);return}if(!dt(J)){console.warn(`[LiveLayer] focus_field: field "${T}" is privacy-protected and not focusable.`);return}J.focus();return}const U=d.values&&typeof d.values=="object"?d.values:null;if(!U){console.warn("[LiveLayer] fill_form: missing or invalid values."),A({type:"fill_form_result",ok:!1,reason:"missing or invalid values",formId:M});return}const N=[],q=[];for(const[T,J]of Object.entries(U)){if(typeof J!="string")continue;const ie=F.querySelector(`[data-ll-field="${T.replace(/"/g,'\\"')}"]`);if(!ie){console.warn(`[LiveLayer] fill_form: no field "${T}" in form "${M}". Skipping.`),q.push(T);continue}if(!dt(ie)){console.warn(`[LiveLayer] fill_form: field "${T}" is privacy-protected (password / cc-* / private). Skipping.`),q.push(T);continue}try{pr(ie,J),N.push(T)}catch(_e){console.warn(`[LiveLayer] fill_form: failed to set "${T}".`,_e),q.push(T)}}A({type:"fill_form_result",ok:N.length>0,formId:M,filled:N,skipped:q,reason:N.length===0?`none of the requested fields exist on this form (skipped: ${q.join(", ")})`:void 0});return}if(d.type==="submit_form"){if(!he("submit_forms")){me("submit_form","submit_forms");return}if(typeof document>"u")return;const k=typeof d.formId=="string"?d.formId:null;if(!k){console.warn("[LiveLayer] submit_form: missing formId.");return}const R=document.querySelector(`[data-ll-form="${k.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${k}".`);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 A=typeof d.requestId=="string"?d.requestId:void 0,M=(Pe=Q.current)==null?void 0:Pe.call(Q),F=q=>{const T=M,J=T==null?void 0:T.localParticipant;if(J!=null&&J.publishData)try{const ie=A?{...q,requestId:A}:q,_e=new TextEncoder().encode(JSON.stringify(ie));J.publishData(_e,{reliable:!0})}catch{}};let U=!1;const N=()=>{U=!0,F({type:"form_submitted",formId:k})};R.addEventListener("submit",N,{once:!0});try{typeof R.requestSubmit=="function"?R.requestSubmit():R.submit()}catch(q){console.warn("[LiveLayer] submit_form: requestSubmit threw.",q),R.removeEventListener("submit",N),F({type:"form_submit_blocked",formId:k,reason:"exception"});return}setTimeout(()=>{U||(R.removeEventListener("submit",N),F({type:"form_submit_blocked",formId:k,reason:"validation"}))},500);return}if(d.type==="request_routes"){if(!he("read_page")){me("request_routes","read_page");return}const k=typeof d.requestId=="string"?d.requestId:void 0,A=(we=Q.current)==null?void 0:we.call(Q),M=A==null?void 0:A.localParticipant;if(!(M!=null&&M.publishData))return;const F=N=>{try{const q=k?{type:"routes",routes:N,requestId:k}:{type:"routes",routes:N},T=new TextEncoder().encode(JSON.stringify(q));M.publishData(T,{reliable:!0})}catch(q){console.warn("[LiveLayer] request_routes: publishData failed.",q)}},U=wt.current;if(U){try{const N=U(),q=T=>{if(!Array.isArray(T)){F([]);return}F(T.map(pn).slice(0,200))};N instanceof Promise?N.then(q).catch(T=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",T),F(lt())}):q(N)}catch(N){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",N),F(lt())}return}try{F(lt())}catch(N){console.warn("[LiveLayer] request_routes: extractRoutes threw.",N)}return}xr.has(d.type)||Ee==null||Ee(d)}},[Ee,je]),H=Kt({agentId:B?"__controlled__":Ae,baseUrl:o,apiKey:i,sessionEndpoint:s,sessionBody:a,onDataMessage:B?void 0:Ue});n.useEffect(()=>{if(B!=null&&B.subscribeToDataMessages)return B.subscribeToDataMessages(Ue)},[B,Ue]),Q.current=()=>{var m;return(m=H.getRoom)==null?void 0:m.call(H)},n.useEffect(()=>{var ve;if(!se)return;const m=(ve=H.getRoom)==null?void 0:ve.call(H),d=m==null?void 0:m.localParticipant;if(!(d!=null&&d.publishData))return;try{const le=new TextEncoder().encode(JSON.stringify({type:"pathname",pathname:se}));d.publishData(le,{reliable:!0})}catch{}const K=setTimeout(()=>{var le;try{const Pe=(le=H.getRoom)==null?void 0:le.call(H),we=Pe==null?void 0:Pe.localParticipant;if(!(we!=null&&we.publishData))return;const k=at(ht.current),R=new TextEncoder().encode(JSON.stringify({type:"page_context_push",pathname:se,context:k}));we.publishData(R,{reliable:!0})}catch{}},250);return()=>clearTimeout(K)},[se,H,H.connectionState]),n.useEffect(()=>{var K;if(typeof window>"u")return;const m=((K=window.location)==null?void 0:K.hostname)||"";if(m==="localhost"||m==="127.0.0.1"||m==="0.0.0.0"||m.endsWith(".local")||m.endsWith(".test"))return window.__livelayerSimulateCommand=ve=>{try{Ue(ve)}catch(le){console.warn("[LiveLayer] simulate-command threw:",le)}},()=>{delete window.__livelayerSimulateCommand}},[Ue]);const y=n.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:H.getRoom,isControlled:!0}:{connectionState:H.connectionState,agentState:H.agentState,transcript:H.transcript,videoElement:H.videoElement,audioElement:H.audioElement,canResume:H.canResume,error:H.error,agentConfig:H.agentConfig,connect:H.connect,disconnect:H.disconnect,getRoom:H.getRoom,isControlled:!1},[B,H]),_t=n.useRef(null);n.useEffect(()=>{const m=y.videoElement,d=_t.current;if(!(!m||!d))return d.appendChild(m),()=>{m.parentNode===d&&d.removeChild(m)}},[y.videoElement]),n.useEffect(()=>{const m=y.audioElement;if(!m)return;He.attach(m);const d=m.play();return d&&typeof d.catch=="function"&&d.catch(K=>{(K==null?void 0:K.name)==="NotAllowedError"&&ue(!0)}),()=>{He.detach()}},[y.audioElement]),n.useEffect(()=>{if(y.isControlled||y.connectionState!=="connected")return;const m=y.getRoom();if(m)return G.setupMic(m,{startMuted:!0}).catch(()=>{}),ne.attachRoom(m),re.attachRoom(m),ce.refresh(),()=>{G.teardownMic(),ne.teardown(),re.teardown()}},[y.isControlled,y.connectionState]);const[Ve,gt]=n.useState(!1),yt=n.useRef("idle");n.useEffect(()=>{if(y.connectionState==="idle"||y.connectionState==="disconnected"){gt(!1),yt.current="idle";return}!Ve&&yt.current==="speaking"&&y.agentState!=="speaking"&&(gt(!0),G.setMuted(!1)),yt.current=y.agentState},[y.agentState,y.connectionState,Ve]),n.useEffect(()=>{if(y.connectionState!=="connected"||Ve)return;const m=setTimeout(()=>{gt(!0),G.setMuted(!1)},4e3);return()=>clearTimeout(m)},[y.connectionState,Ve]),n.useEffect(()=>{const m=y.audioElement;m&&(m.muted=Ie)},[y.audioElement,Ie]);const gn=n.useCallback(m=>{const d=y.getRoom();if(d)try{const K=new TextEncoder().encode(JSON.stringify({type:"user_message",text:m}));d.localParticipant.publishData(K,{reliable:!0})}catch{}},[y]),yn=n.useCallback(()=>{nt(m=>!m)},[]);n.useEffect(()=>{Le==null||Le(y.connectionState),y.connectionState==="connected"?oe==null||oe():y.connectionState==="disconnected"&&(ye==null||ye())},[y.connectionState,oe,ye,Le]),n.useEffect(()=>{Se==null||Se(y.transcript)},[y.transcript,Se]),n.useEffect(()=>{Ce==null||Ce(y.agentState)},[y.agentState,Ce]);const kt=n.useRef(!1);n.useEffect(()=>{y.isControlled||!u||kt.current||Re&&y.connectionState==="idle"&&(kt.current=!0,y.connect())},[u,y.connectionState,y,Re]);const bn=n.useCallback(m=>{const d=C==null?void 0:C.find(K=>K.id===m);d&&(We(!1),m!==V&&(qe(!0),y.disconnect(),Oe||Ne(m),x==null||x(d)))},[C,V,y,Oe,x]);n.useEffect(()=>{de&&y.connectionState==="connected"&&qe(!1)},[y.connectionState,de]),n.useEffect(()=>{if(!Be)return;const m=d=>{d.key==="Escape"&&We(!1)};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[Be]);const xn=!!E||!!(X!=null&&X.avatarImageUrl)||y.isControlled,Ye=tn(Ae,o,xn);Z===void 0&&((Ct=Ye.info)!=null&&Ct.capabilities)&&(mt.current=Ye.info.capabilities);const it=(X==null?void 0:X.name)??D??((Lt=y.agentConfig)==null?void 0:Lt.name)??((jt=Ye.info)==null?void 0:jt.name)??"Live Layer",bt=(X==null?void 0:X.avatarImageUrl)??E??((Et=y.agentConfig)==null?void 0:Et.avatarImageUrl)??((Rt=Ye.info)==null?void 0:Rt.avatarImageUrl)??null,vn=w??((Nt=y.agentConfig)==null?void 0:Nt.idleLoopUrl)??((At=Ye.info)==null?void 0:At.idleLoopUrl)??null,wn=P??null,_n=n.useCallback(()=>ae("expanded"),[ae]),kn=n.useCallback(()=>ae("minimized"),[ae]),St=n.useCallback(()=>{y.disconnect(),ae("hidden")},[y,ae]),Sn=n.useCallback(()=>{const m=y.audioElement;m&&m.play().then(()=>ue(!1)).catch(()=>{})},[y.audioElement]),Cn=n.useCallback(()=>{ue(!1),y.connect()},[y]),Je={...pt,zIndex:tt};g.primaryColor&&(Je["--ll-color-primary"]=g.primaryColor),g.accentColor&&(Je["--ll-color-accent"]=g.accentColor),g.backgroundColor&&(Je["--ll-color-bg"]=g.backgroundColor),g.textColor&&(Je["--ll-color-fg"]=g.textColor);const Ln=["ll-widget",`ll-widget--${te}`,`ll-widget--${xe?"mobile":"desktop"}`,ft].filter(Boolean).join(" ");return Re?t.jsxs("div",{className:Ln,style:Je,"data-display-mode":te,"data-position":v,children:[te==="hidden"&&t.jsx(Un,{position:v,isMobile:xe,isSpeaking:y.agentState==="speaking",onExpand:()=>ae("expanded"),label:`Open ${it} widget`,avatarImageUrl:bt,agentName:it}),te==="minimized"&&t.jsx(Yn,{position:v,isMobile:xe,agentName:it,avatarImageUrl:bt,agentState:y.agentState,isMuted:G.isMuted,audioLevel:He,onExpand:_n,onToggleMute:G.toggleMute,onClose:St}),te==="expanded"&&t.jsx(Kn,{position:v,isMobile:xe,agentName:it,avatarImageUrl:bt,idleLoopUrl:vn,greeting:wn,branding:g,teamMembers:C,currentTeamMemberId:V,isSwitchingTeamMember:de,teamSwitcherOpen:Be,onToggleTeamSwitcher:()=>We(m=>!m),onSelectTeamMember:bn,connectionState:y.connectionState,agentState:y.agentState,transcript:y.transcript,isMuted:G.isMuted,micDevices:ce.mics,isCameraEnabled:ne.isEnabled,cameraPreviewEl:ne.previewEl,cameraDevices:ce.cameras,activeCameraId:ne.activeDeviceId,isScreenShareEnabled:re.isEnabled,screenPreviewEl:re.previewEl,isSpeakerMuted:Ie,allowCamera:L,allowScreenShare:z,allowTyping:I,languageMenuOpen:fe,onToggleLanguageMenu:()=>pe(m=>!m),needsUserGesture:Me,canResume:y.canResume,micError:G.micError,error:y.error,avatarVideoContainerRef:_t,agentVideoEl:y.videoElement,micGateOpen:y.isControlled?!0:Ve,onConnect:()=>void y.connect(),onDisconnect:()=>y.disconnect(),onRetry:Cn,onResumeAudio:Sn,onToggleMute:G.toggleMute,onToggleCamera:()=>void ne.toggle(),onSwitchCameraDevice:m=>void ne.switchDevice(m),onToggleScreenShare:()=>void re.toggle(),onToggleSpeaker:yn,onSendMessage:gn,onMinimize:kn,onClose:St,onClearMicError:G.clearError})]}):null}function wr(e){return t.jsx(Jt,{children:t.jsx(vr,{...e})})}const _r=({agentId:e,baseUrl:r,apiKey:i,mode:o,onAgentEvent:s,className:a,style:u})=>{const f=n.useRef(null),p=n.useRef(null),b=n.useRef(s);b.current=s;const v=n.useCallback(c=>{var _;const l=c.detail;(_=b.current)==null||_.call(b,l)},[]);return n.useEffect(()=>{const c=f.current;if(!c)return;const l=document.createElement("livelayer-widget");return l.setAttribute("agent-id",e),r&&l.setAttribute("base-url",r),i&&l.setAttribute("api-key",i),o&&l.setAttribute("mode",o),l.addEventListener("agent-event",v),c.appendChild(l),p.current=l,()=>{l.removeEventListener("agent-event",v),c.removeChild(l),p.current=null}},[e]),n.useEffect(()=>{p.current&&(o?p.current.setAttribute("mode",o):p.current.removeAttribute("mode"))},[o]),t.jsx("div",{ref:f,className:a,style:u})},kr=n.forwardRef(function({id:r,intent:i,as:o="div",className:s,style:a,children:u},f){return n.createElement(o,{ref:f,"data-ll-region":r,"data-ll-intent":i,className:s,style:a},u)}),Sr=n.forwardRef(function({id:r,intent:i,children:o,...s},a){return t.jsx("form",{ref:a,"data-ll-form":r,"data-ll-intent":i,...s,children:o})}),Cr=n.forwardRef(function(r,i){const{name:o,label:s,labelClassName:a}=r,u={name:o,"data-ll-field":o};let f;if("as"in r&&r.as==="textarea"){const{name:p,label:b,labelClassName:v,as:c,...l}=r;f=t.jsx("textarea",{ref:i,...u,...l})}else if("as"in r&&r.as==="select"){const{name:p,label:b,labelClassName:v,as:c,children:l,..._}=r;f=t.jsx("select",{ref:i,...u,..._,children:l})}else{const{name:p,label:b,labelClassName:v,as:c,...l}=r;f=t.jsx("input",{ref:i,...u,...l})}return s===void 0?f:t.jsxs("label",{className:a,children:[s,f]})});let Yt=1;function Lr({onMount:e,defaultOpen:r=!1,storageKey:i="ll-debug-open"}){const[o,s]=n.useState(r),[a,u]=n.useState([]),[f,p]=n.useState(""),[b,v]=n.useState(!1),c=n.useRef(new Set),l=n.useRef([]),_=n.useRef(b);_.current=b,n.useEffect(()=>{try{const x=localStorage.getItem(i);x==="1"&&s(!0),x==="0"&&s(!1)}catch{}},[i]),n.useEffect(()=>{try{localStorage.setItem(i,o?"1":"0")}catch{}},[o,i]),n.useEffect(()=>{const x=w=>{(w.metaKey||w.ctrlKey)&&w.shiftKey&&w.key.toLowerCase()==="l"&&(w.preventDefault(),s(P=>!P))};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[]),n.useEffect(()=>{const x=setInterval(()=>{if(l.current.length===0||_.current)return;const w=l.current.splice(0,l.current.length);u(P=>[...w.reverse(),...P].slice(0,200))},100);return()=>clearInterval(x)},[]);const C=n.useRef(!1);if(n.useEffect(()=>{!e||C.current||(C.current=!0,e(x=>{l.current.push({id:Yt++,ts:Date.now(),kind:"event",type:x.eventName,data:x.data})}))},[e]),n.useEffect(()=>{const x=console.warn,w=console.log,P=(E,D)=>function(...g){try{const L=typeof g[0]=="string"?g[0]:"";L.startsWith("[LiveLayer]")&&l.current.push({id:Yt++,ts:Date.now(),kind:E,type:L.slice(0,120),data:{args:g.slice(1).map(z=>Er(z))}})}catch{}return D.apply(this,g)};return console.warn=P("warn",x),console.log=P("log",w),()=>{console.warn=x,console.log=w}},[]),!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 S=a.filter(x=>{if(!f)return!0;const w=f.toLowerCase();return x.type.toLowerCase().includes(w)||JSON.stringify(x.data||{}).toLowerCase().includes(w)});return t.jsxs("div",{style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,width:380,maxHeight:"60vh",background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:12,boxShadow:"0 16px 48px rgba(0,0,0,0.5)",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"8px 10px",background:"rgba(255,255,255,0.04)",borderBottom:"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),t.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[a.length," event",a.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>v(x=>!x),style:xt(b?"#f59e0b":"transparent"),title:"Pause / resume capture",children:b?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{u([]),l.current=[]},style:xt("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:xt("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:f,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:S.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
- })`})]}):S.map(x=>t.jsx(Rr,{entry:x,expanded:c.current.has(x.id),onToggle:()=>{c.current.has(x.id)?c.current.delete(x.id):c.current.add(x.id),u(w=>[...w])}},x.id))})]})}function Rr({entry:e,expanded:r,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})]}),r&&e.data&&t.jsx("pre",{style:{marginTop:6,padding:6,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:10,overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(e.data,null,2)})]})}function gt(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 Nr(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Ar(){const[e,r]=n.useState([]),i=n.useCallback(s=>{r(a=>{const u=a.findIndex(f=>f.id===s.id);if(u>=0){const f=a.slice();return f[u]=s,f}return[...a,s]})},[]),o=n.useCallback(()=>r([]),[]);return{entries:e,pushSegment:i,clear:o,latest:e.length>0?e[e.length-1]:null}}exports.AvatarWidget=kr;exports.ErrorBoundary=Xt;exports.LiveLayerDebugPanel=Er;exports.LiveLayerField=jr;exports.LiveLayerForm=Lr;exports.LiveLayerRegion=Cr;exports.LiveLayerWidget=Sr;exports.clearPageContextCache=hn;exports.clearRoutesCache=yn;exports.extractPageContext=pn;exports.extractRoutes=gn;exports.getCachedPageContext=yt;exports.getCachedRoutes=st;exports.matchesPattern=cn;exports.normalizeRouteInput=mn;exports.shouldRenderAtPath=un;exports.useAgentInfo=rn;exports.useAudioLevel=Qt;exports.useCameraState=en;exports.useDisplayMode=on;exports.useDisplayModePersistence=sn;exports.useIsMobile=an;exports.useLiveKitSession=Gt;exports.useMediaDevices=nn;exports.useMicrophoneState=Zt;exports.usePathname=ln;exports.useRouteMatch=dn;exports.useScreenShareState=tn;exports.useTranscript=Ar;
5
+ })`})]}):S.map(x=>t.jsx(jr,{entry:x,expanded:c.current.has(x.id),onToggle:()=>{c.current.has(x.id)?c.current.delete(x.id):c.current.add(x.id),u(w=>[...w])}},x.id))})]})}function jr({entry:e,expanded:r,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})]}),r&&e.data&&t.jsx("pre",{style:{marginTop:6,padding:6,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:10,overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(e.data,null,2)})]})}function xt(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 Er(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Rr(){const[e,r]=n.useState([]),i=n.useCallback(s=>{r(a=>{const u=a.findIndex(f=>f.id===s.id);if(u>=0){const f=a.slice();return f[u]=s,f}return[...a,s]})},[]),o=n.useCallback(()=>r([]),[]);return{entries:e,pushSegment:i,clear:o,latest:e.length>0?e[e.length-1]:null}}exports.AvatarWidget=wr;exports.ErrorBoundary=Jt;exports.LiveLayerDebugPanel=Lr;exports.LiveLayerField=Cr;exports.LiveLayerForm=Sr;exports.LiveLayerRegion=kr;exports.LiveLayerWidget=_r;exports.clearPageContextCache=fn;exports.clearRoutesCache=mn;exports.extractPageContext=dn;exports.extractRoutes=hn;exports.getCachedPageContext=at;exports.getCachedRoutes=lt;exports.matchesPattern=an;exports.normalizeRouteInput=pn;exports.shouldRenderAtPath=ln;exports.useAgentInfo=tn;exports.useAudioLevel=Xt;exports.useCameraState=Qt;exports.useDisplayMode=nn;exports.useDisplayModePersistence=rn;exports.useIsMobile=on;exports.useLiveKitSession=Kt;exports.useMediaDevices=en;exports.useMicrophoneState=Gt;exports.usePathname=sn;exports.useRouteMatch=cn;exports.useScreenShareState=Zt;exports.useTranscript=Rr;