@livelayer/react 0.9.3 → 0.9.4
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 +2 -2
- package/dist/index.mjs +47 -44
- package/package.json +1 -1
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"),Un=require("@livelayer/sdk"),ut=require("livekit-client"),Vn=require("react-dom");class rn 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,o){var i,s;(s=(i=this.props).onError)==null||s.call(i,r,o)}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 on(e){const[r,o]=n.useState("idle"),[i,s]=n.useState("idle"),[a,f]=n.useState([]),[d,u]=n.useState(null),[p,m]=n.useState(null),[l,c]=n.useState(null),[L,N]=n.useState(!1),[k,x]=n.useState(null),v=n.useRef(null),C=n.useRef(e.onDataMessage);C.current=e.onDataMessage,n.useEffect(()=>{const S={onConnectionStateChange:I=>{o(I),I==="connected"&&x(null)},onAgentStateChange:s,onTranscript:I=>f([...I]),onAgentConfig:u,onAudioTrack:I=>c(I),onVideoTrack:I=>m(I),onVideoTrackRemoved:()=>m(null),onError:I=>x(I),onDataMessage:I=>{var j;(j=C.current)==null||j.call(C,I)},onResumabilityChange:N},$=new Un.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},S);return v.current=$,o("idle"),s("idle"),f([]),u(null),m(null),c(null),N(!1),x(null),()=>{var I;(I=$.destroy)==null||I.call($),v.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=n.useCallback(async()=>{const S=v.current;if(S)try{await S.connect()}catch($){throw x($ instanceof Error?$.message:String($)),$}},[]),M=n.useCallback(()=>{const S=v.current;S&&S.disconnect()},[]),b=n.useCallback(()=>{var S;return((S=v.current)==null?void 0:S.getRoom())??null},[]);return{connectionState:r,agentState:i,transcript:a,agentConfig:d,videoElement:p,audioElement:l,canResume:L,error:k,connect:E,disconnect:M,getRoom:b,session:v.current}}function sn(){const e=n.useRef(null),r=n.useRef(null),o=n.useRef(null),i=n.useRef(null),s=n.useRef(new Set),a=n.useRef(null),f=n.useCallback(()=>{const l=r.current;if(!l){i.current=null;return}(!a.current||a.current.length!==l.frequencyBinCount)&&(a.current=new Uint8Array(new ArrayBuffer(l.frequencyBinCount)));const c=a.current;l.getByteFrequencyData(c);let L=0;for(let k=0;k<c.length;k++)L+=c[k];const N=L/c.length/255;for(const k of s.current)try{k(N)}catch(x){console.error("[useAudioLevel] subscriber threw:",x)}i.current=requestAnimationFrame(f)},[]),d=n.useCallback(()=>{if(e.current||typeof window>"u"||typeof AudioContext>"u")return;const l=new AudioContext,c=l.createAnalyser();c.fftSize=64,c.connect(l.destination),e.current=l,r.current=c},[]),u=n.useCallback(l=>{if(d(),!(!e.current||!r.current)){if(o.current){try{o.current.disconnect()}catch{}o.current=null}try{const c=e.current.createMediaElementSource(l);c.connect(r.current),o.current=c}catch(c){console.warn("[useAudioLevel] createMediaElementSource failed:",c);return}i.current===null&&(i.current=requestAnimationFrame(f))}},[d,f]),p=n.useCallback(()=>{if(i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),o.current){try{o.current.disconnect()}catch{}o.current=null}},[]),m=n.useCallback(l=>(s.current.add(l),()=>{s.current.delete(l)}),[]);return n.useEffect(()=>()=>{if(p(),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},[p]),{attach:u,detach:p,subscribe:m}}function an(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),s=n.useRef(null),a=n.useRef(null),f=n.useCallback(async m=>{if(s.current&&a.current){try{await a.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}a.current=m,i(null);try{const l=await ut.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await m.localParticipant.publishTrack(l),s.current=l,r(l.isMuted)}catch(l){const c=l instanceof Error&&l.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw i(c),l}},[]),d=n.useCallback(()=>{const m=s.current;m&&(m.isMuted?(m.unmute(),r(!1)):(m.mute(),r(!0)))},[]),u=n.useCallback(()=>{const m=s.current,l=a.current;if(m&&l){try{l.localParticipant.unpublishTrack(m)}catch{}m.stop()}s.current=null,a.current=null,r(!1)},[]),p=n.useCallback(()=>i(null),[]);return{isMuted:e,micError:o,toggleMute:d,setupMic:f,teardownMic:u,clearError:p}}const Yn={resolution:{width:640,height:480,frameRate:24}};function ln(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),[f,d]=n.useState(""),u=n.useRef(null),p=n.useRef(null),m=n.useCallback(v=>{u.current=v},[]),l=n.useCallback(()=>{const v=u.current,C=p.current;if(C&&v){const E=v.localParticipant.getTrackPublication(ut.Track.Source.Camera);if(E!=null&&E.track){try{v.localParticipant.unpublishTrack(E.track)}catch{}E.track.stop()}else C.stop()}p.current=null,a(null),r(!1)},[]),c=n.useCallback(async v=>{const C=u.current;if(C){i(null);try{const E={...Yn};v&&(E.deviceId=v);const M=await ut.createLocalVideoTrack(E);await C.localParticipant.publishTrack(M),p.current=M;const b=M.attach();a(b),r(!0),v&&d(v);try{C.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const M=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";i(M)}}},[]),L=n.useCallback(async()=>{e?l():await c(f||void 0)},[e,f,l,c]),N=n.useCallback(async v=>{l(),await c(v)},[l,c]),k=n.useCallback(()=>{l(),u.current=null,i(null),d("")},[l]),x=n.useCallback(()=>i(null),[]);return n.useEffect(()=>()=>{p.current&&p.current.stop()},[]),{isEnabled:e,error:o,previewEl:s,activeDeviceId:f,toggle:L,switchDevice:N,attachRoom:m,teardown:k,clearError:x}}function cn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),f=n.useRef(null),d=n.useCallback(c=>{f.current=c},[]),u=n.useCallback(()=>a(null),[]),p=n.useCallback(async()=>{const c=f.current;if(c){if(e){try{await c.localParticipant.setScreenShareEnabled(!1)}catch{}u(),r(!1);return}i(null);try{await c.localParticipant.setScreenShareEnabled(!0);let L=0;const N=()=>{const k=c.localParticipant.getTrackPublication(ut.Track.Source.ScreenShare);if(k!=null&&k.track){const x=k.track.attach();a(x),r(!0);try{c.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}L++<10?setTimeout(N,100):r(!0)};N()}catch(L){const N=L instanceof Error?L.name:"";N!=="NotAllowedError"&&N!=="AbortError"&&i("Screen share unavailable. Try again."),r(!1)}}},[e,u]),m=n.useCallback(()=>{const c=f.current;if(c&&e)try{c.localParticipant.setScreenShareEnabled(!1)}catch{}u(),r(!1),i(null),f.current=null},[e,u]),l=n.useCallback(()=>i(null),[]);return{isEnabled:e,error:o,previewEl:s,toggle:p,attachRoom:d,teardown:m,clearError:l}}function un(){const[e,r]=n.useState([]),[o,i]=n.useState([]),s=n.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const a=await navigator.mediaDevices.enumerateDevices();r(a.filter(f=>f.kind==="audioinput")),i(a.filter(f=>f.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:o,refresh:s}}function dn(e,r,o=!1){const[i,s]=n.useState(null),[a,f]=n.useState(null),[d,u]=n.useState(!o&&!!e);return n.useEffect(()=>{if(o||!e){u(!1);return}const p=new AbortController,m=r||"https://app.livelayer.studio";return u(!0),f(null),fetch(`${m}/api/widget/agent/${encodeURIComponent(e)}`,{signal:p.signal}).then(async l=>{if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||`HTTP ${l.status}`)}return l.json()}).then(l=>{p.signal.aborted||(s(l),u(!1))}).catch(l=>{p.signal.aborted||(f(l instanceof Error?l.message:"Agent lookup failed"),u(!1))}),()=>p.abort()},[e,r,o]),{info:i,error:a,loading:d}}function Gn(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Kn(e,r){if(!(typeof window>"u"))try{window.localStorage.setItem(e,r)}catch{}}function fn({value:e,defaultValue:r="expanded",onChange:o}={}){const i=e!==void 0,[s,a]=n.useState(r),f=i?e:s,d=n.useCallback(u=>{u!==f&&(i||a(u),o==null||o(u))},[f,i,o]);return[f,d]}const Jn=["hidden","minimized","expanded"];function Xn(e){return e&&Jn.includes(e)?e:null}function pn({value:e,defaultValue:r="expanded",onChange:o,persistKey:i="ll-widget",disablePersistence:s=!1}={}){const a=`${i}:display-mode`,f=n.useRef(!1),[d,u]=fn({value:e,defaultValue:r,onChange:p=>{e===void 0&&!s&&Kn(a,p),o==null||o(p)}});return n.useEffect(()=>{if(f.current||(f.current=!0,s||e!==void 0))return;const p=Xn(Gn(a));p&&p!==d&&u(p)},[]),[d,u]}const Qn=640;function hn(e=Qn){const[r,o]=n.useState(!1);return n.useEffect(()=>{if(e===!1){o(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const i=`(max-width: ${e-1}px)`,s=window.matchMedia(i),a=()=>o(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 Ht="__llHistoryPatched",dt="ll:pathname";function Zn(){if(typeof window>"u"||window.history[Ht])return;const e=window.history.pushState,r=window.history.replaceState;window.history.pushState=function(...o){const i=e.apply(this,o);return window.dispatchEvent(new Event(dt)),i},window.history.replaceState=function(...o){const i=r.apply(this,o);return window.dispatchEvent(new Event(dt)),i},window.history[Ht]=!0}function Wt(){return typeof window>"u"?"/":window.location.pathname||"/"}function mn(e){const[r,o]=n.useState(()=>e??Wt());return n.useEffect(()=>{if(e!==void 0)return;Zn();const i=()=>o(Wt());return i(),window.addEventListener("popstate",i),window.addEventListener(dt,i),()=>{window.removeEventListener("popstate",i),window.removeEventListener(dt,i)}},[e]),e??r}const Bt=new Map,er=/[\\^$+?.()|{}[\]]/g;function tr(e){return e.replace(er,"\\$&")}function nr(e){const r=Bt.get(e);if(r)return r;const o=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,i="",s="",a=o.replace(/\*\*/g,i).replace(/\*/g,s),d=tr(a).replace(new RegExp(`\\/${i}`,"g"),"(?:\\/.*)?").replace(new RegExp(i,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),u=new RegExp(`^${d}\\/?$`);return Bt.set(e,u),u}function rr(e,r){const o=r.length>1&&r.endsWith("/")?r.slice(0,-1):r;return nr(e).test(o)}function gn(e,r){return typeof e=="function"?e(r):e instanceof RegExp?e.test(r):rr(e,r)}function qt(e,r){if(!e||e.length===0)return!1;for(const o of e)if(gn(o,r))return!0;return!1}function yn(e,r,o){return e===void 0?!0:qt(o,e)?!1:r&&r.length>0?qt(r,e):!0}function xn(e,r,o){return n.useMemo(()=>yn(e,r,o),[e,r,o])}function or(e){return e===!1?{navigate:!1,thinking:!1,action:!1}:e===void 0||e===!0?{navigate:!0,thinking:!0,action:!0}:{navigate:e.navigate!==!1,thinking:e.thinking!==!1,action:e.action!==!1}}function ir(e){const r=n.useMemo(()=>or(e.config),[e.config]),o=e.baseUrl.replace(/\/+$/,""),i=n.useRef(null),s=n.useCallback(u=>{try{new Audio(`${o}${u}`).play().catch(()=>{})}catch{}},[o]),a=n.useCallback(()=>{r.navigate&&s("/audio/page-change-sound.mp3")},[r.navigate,s]),f=n.useCallback(()=>{r.action&&s("/audio/confirmation-sound.mp3")},[r.action,s]),d=n.useCallback(u=>{if(!r.thinking){if(i.current){try{i.current.pause()}catch{}i.current=null}return}if(u){if(i.current)return;try{const p=new Audio(`${o}/audio/thinking-sound.mp3`);p.loop=!0,p.volume=.3,p.play().catch(()=>{i.current=null}),i.current=p}catch{}}else if(i.current){try{i.current.pause()}catch{}i.current=null}},[o,r.thinking]);return n.useEffect(()=>()=>{if(i.current){try{i.current.pause()}catch{}i.current=null}},[]),n.useMemo(()=>({playPageChange:a,playConfirmation:f,setThinking:d}),[a,f,d])}const Ft=({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"})}),Ut=({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"})}),sr=({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"})}),ar={left:180,right:0,up:-90,down:90},Vt=({direction:e="right",className:r})=>t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${ar[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function lr(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const vn="ll-hidden-tab-center-y",cr=5,Yt=16;function ur(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(vn);if(!e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null}catch{return null}}function Gt(e){if(!(typeof window>"u"))try{window.localStorage.setItem(vn,String(e))}catch{}}const dr=({position:e,isMobile:r,isSpeaking:o,onExpand:i,label:s="Open widget",avatarImageUrl:a,agentName:f})=>{const d=lr(e),u=d==="right"?"left":"right",p=r?80:72,m=!!a,[l,c]=n.useState(null),[L,N]=n.useState(!1),k=n.useRef(null),x=n.useRef(!1),v=n.useCallback(j=>{if(typeof window>"u")return j;const A=p/2,O=Yt+A,F=window.innerHeight-Yt-A;return F<O?Math.max(O,j):Math.max(O,Math.min(F,j))},[p]);n.useEffect(()=>{const j=ur();c(v(j??window.innerHeight/2));const A=()=>{c(O=>O===null?null:v(O))};return window.addEventListener("resize",A),()=>window.removeEventListener("resize",A)},[v]);const C=n.useCallback(j=>{if(!(j.pointerType==="mouse"&&j.button!==0)&&l!==null){try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}k.current={startClientY:j.clientY,startCenterY:l,moved:!1}}},[l]),E=n.useCallback(j=>{const A=k.current;if(!A)return;const O=j.clientY-A.startClientY;!A.moved&&Math.abs(O)>cr&&(A.moved=!0,N(!0)),A.moved&&c(v(A.startCenterY+O))},[v]),M=n.useCallback(j=>{const A=k.current;if(A){try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}k.current=null,A.moved&&(N(!1),x.current=!0,c(O=>(O!==null&&Gt(O),O)))}},[]),b=n.useCallback(()=>{if(x.current){x.current=!1;return}i()},[i]),S=n.useCallback(j=>{if(j.key==="ArrowUp"||j.key==="ArrowDown"){j.preventDefault();const A=j.key==="ArrowUp"?-8:8;c(O=>{if(O===null)return O;const F=v(O+A);return Gt(F),F})}},[v]),$=["ll-hidden",`ll-hidden--${d}`,r?"ll-hidden--mobile":"ll-hidden--desktop",o?"ll-hidden--speaking":null,L?"is-dragging":null,m?"ll-hidden--with-avatar":null].filter(Boolean).join(" "),I=l===null?void 0:{top:`${l-p/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:$,onPointerDown:C,onPointerMove:E,onPointerUp:M,onPointerCancel:M,onClick:b,onKeyDown:S,"aria-label":s,"data-position":e,style:I,children:m?t.jsxs(t.Fragment,{children:[t.jsx(Vt,{direction:u,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:a,alt:f?`${f} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Vt,{direction:u,className:"ll-hidden__chevron"})})},fr=({audioLevel:e,bars:r=20,maxHeight:o=20,minHeight:i=4,className:s,barClassName:a})=>{const f=n.useRef(null),d=n.useRef([]),u=n.useMemo(()=>{const m=(Math.sqrt(5)-1)/2;return Array.from({length:r},(l,c)=>.5+c*m%1*.5)},[r]);n.useEffect(()=>e.subscribe(l=>{for(let c=0;c<r;c++){const L=d.current[c];if(!L)continue;const N=Math.max(i,l*o*u[c]);L.style.height=`${N}px`}}),[e,r,o,i,u]);const p=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:f,className:p,"aria-hidden":"true",children:Array.from({length:r},(m,l)=>t.jsx("div",{ref:c=>{d.current[l]=c},className:["ll-waveform__bar",a].filter(Boolean).join(" "),style:{height:`${i}px`}},l))})},pr=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,agentState:s,isMuted:a,audioLevel:f,onExpand:d,onToggleMute:u,onClose:p})=>r?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${o} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:d,"aria-label":`Expand ${o} widget`,children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsx(fr,{audioLevel:f,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:m=>{m.stopPropagation(),u()},onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.stopPropagation(),m.preventDefault(),u())},"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(Ft,{muted:a,className:"ll-minimized__icon"})}),t.jsx(Ut,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):t.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${o} widget`,children:t.jsxs("div",{className:"ll-minimized__surface",children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsxs("div",{className:"ll-minimized__meta",children:[t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsx("span",{className:"ll-minimized__state",children:s==="speaking"?"Speaking":s==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:u,"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(Ft,{muted:a,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:d,"aria-label":`Expand ${o} widget`,children:t.jsx(Ut,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:p,"aria-label":"Close widget",children:t.jsx(sr,{className:"ll-minimized__icon"})})]})]})}),hr=({src:e,alt:r,preCannedPlaying:o=!1,className:i,style:s})=>{const[a,f]=n.useState(!1),d=n.useRef(e);if(n.useEffect(()=>{d.current!==e&&(d.current=e,f(!1))},[e]),!e)return null;const u={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:o?"scale(1.02)":"scale(1)",opacity:a?1:0,...s};return t.jsx("img",{src:e,alt:r,className:i,style:u,loading:"eager",fetchPriority:"high",onLoad:()=>f(!0)})},mr=8,Kt=8,gr=({open:e,onClose:r,anchorRef:o,children:i})=>{const s=n.useRef(null),[a,f]=n.useState(null);return n.useLayoutEffect(()=>{if(!e){f(null);return}const d=o.current;if(!d)return;const u=()=>{const p=d.getBoundingClientRect(),m={top:p.top-mr,left:p.left+p.width/2},l=Kt+90,c=window.innerWidth-Kt-90;m.left<l&&(m.left=l),m.left>c&&(m.left=c),f(m)};return u(),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[e,o]),n.useEffect(()=>{if(!e)return;const d=p=>{const m=p.target,l=s.current,c=o.current;l&&l.contains(m)||c&&c.contains(m)||r()},u=p=>{p.key==="Escape"&&(p.stopPropagation(),r())};return document.addEventListener("mousedown",d),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",u)}},[e,r,o]),!e||a===null||typeof document>"u"?null:Vn.createPortal(t.jsx("div",{ref:s,className:"ll-overflow-popover",role:"menu",style:{position:"fixed",top:a.top,left:a.left,transform:"translate(-50%, -100%)"},children:i}),document.body)},yr=({isMuted:e,onToggleMute:r,isCameraEnabled:o,onToggleCamera:i,allowCamera:s,isScreenShareEnabled:a,onToggleScreenShare:f,allowScreenShare:d,isSpeakerMuted:u,onToggleSpeaker:p,allowTyping:m,isTypingOpen:l,onToggleTyping:c,onDisconnect:L})=>{const[N,k]=n.useState(!1),x=n.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:v=>v.stopPropagation(),children:[t.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:r,"aria-label":e?"Unmute microphone":"Mute microphone",children:t.jsx(_n,{muted:e})}),t.jsx("button",{ref:x,type:"button",className:`ll-tool ${N?"is-on":""}`,onClick:()=>k(v=>!v),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":N,children:t.jsx(xr,{})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:L,"aria-label":"End conversation",children:t.jsx(jn,{})})]}),t.jsxs(gr,{open:N,onClose:()=>k(!1),anchorRef:x,children:[s&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${o?"is-on":""}`,onClick:()=>{i(),k(!1)},children:[t.jsx(wn,{}),t.jsx("span",{children:o?"Stop camera":"Start camera"})]}),d&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${a?"is-on":""}`,onClick:()=>{f(),k(!1)},children:[t.jsx(bn,{}),t.jsx("span",{children:a?"Stop sharing":"Share screen"})]}),t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${u?"is-on":""}`,onClick:()=>{p(),k(!1)},children:[t.jsx(kn,{muted:u}),t.jsx("span",{children:u?"Unmute speaker":"Mute speaker"})]}),m&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${l?"is-on":""}`,onClick:()=>{c(),k(!1)},children:[t.jsx(vr,{}),t.jsx("span",{children:l?"Hide typing":"Type a message"})]}),t.jsxs("button",{type:"button",className:"ll-overflow-popover__item is-active",disabled:!0,"aria-current":"true",children:[t.jsx("span",{className:"ll-overflow-popover__lang-code",children:"EN"}),t.jsx("span",{children:"English"})]})]})]})};function xr(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[t.jsx("circle",{cx:"6",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"18",cy:"12",r:"1.5"})]})}function vr(){return t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}const br=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,idleLoopUrl:s,greeting:a,branding:f,teamMembers:d,currentTeamMemberId:u,isSwitchingTeamMember:p,teamSwitcherOpen:m,onToggleTeamSwitcher:l,onSelectTeamMember:c,languageMenuOpen:L,onToggleLanguageMenu:N,connectionState:k,agentState:x,transcript:v,canResume:C,needsUserGesture:E,error:M,isMuted:b,micError:S,micDevices:$,isCameraEnabled:I,cameraPreviewEl:j,cameraDevices:A,activeCameraId:O,isScreenShareEnabled:F,screenPreviewEl:ne,isSpeakerMuted:K,allowCamera:be,allowScreenShare:ae,allowTyping:he,showMinimize:le=!0,chromeless:re=!1,compactControls:J=!1,transforming:tt,transformingLabel:We,avatarVideoContainerRef:nt,agentVideoEl:Q,onConnect:Be,onDisconnect:qe,onRetry:rt,onResumeAudio:Fe,onToggleMute:we,onToggleCamera:_e,onSwitchCameraDevice:Ae,onToggleScreenShare:ke,onToggleSpeaker:je,onSendMessage:Ce,onMinimize:Le,onClose:z,onClearMicError:pt})=>{var Pe;const Se=((d==null?void 0:d.length)??0)>1,Me=k==="connecting"||k==="connected",Z=k==="connected",Ue=k==="idle"||k==="disconnected"||k==="error",[Ee,Ie]=n.useState(!1);n.useEffect(()=>{if(!Q){Ie(!1);return}if(!Q.paused&&Q.readyState>=2){Ie(!0);return}Ie(!1);const g=()=>Ie(!0);return Q.addEventListener("playing",g),Q.addEventListener("loadeddata",g),()=>{Q.removeEventListener("playing",g),Q.removeEventListener("loadeddata",g)}},[Q]);const[ht,me]=n.useState(!1);n.useEffect(()=>{if(!Z){me(!1);return}if(Ee)return;const g=setTimeout(()=>me(!0),8e3);return()=>clearTimeout(g)},[Z,Ee]);const Y=k==="connecting"||Z&&!!i&&!Ee&&!ht,Ve=n.useRef(null),Re=n.useRef(null);n.useEffect(()=>{const g=Ve.current;g&&(g.innerHTML="",j&&(j.style.width="100%",j.style.height="100%",j.style.objectFit="cover",j.style.transform="scaleX(-1)",g.appendChild(j)))},[j]),n.useEffect(()=>{const g=Re.current;g&&(g.innerHTML="",ne&&(ne.style.width="100%",ne.style.height="100%",ne.style.objectFit="contain",g.appendChild(ne)))},[ne]);const[oe,X]=n.useState(!1),[ce,ge]=n.useState(!1);n.useEffect(()=>{if(!oe&&!ce&&!L&&!m)return;const g=()=>{X(!1),ge(!1),L&&N(),m&&l()};return document.addEventListener("click",g),()=>document.removeEventListener("click",g)},[oe,ce,L,m,N,l]);const[ee,ue]=n.useState(!1),Ne=n.useCallback(()=>ue(g=>!g),[]),[ye,ot]=n.useState(""),Ye=n.useCallback(g=>{g.preventDefault();const W=ye.trim();W&&(Ce(W),ot(""))},[ye,Ce]),Ge=f.productName||"Live Layer";let de=null,ie=null;for(let g=v.length-1;g>=0;g--){const W=v[g];if(!de&&W.role==="agent"?de=W:!ie&&W.role==="user"&&(ie=W),de&&ie)break}const Te=Z?(de==null?void 0:de.text)||null:a||null,it=Z&&(ie==null?void 0:ie.text)||null,mt=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:mt,"data-position":e,"data-state":Z?"connected":Me?"connecting":"idle",role:"dialog","aria-label":`${o} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[i?t.jsx(hr,{src:i,alt:o,className:"ll-expanded__bg-img"}):t.jsx("div",{className:"ll-expanded__bg-fallback",children:t.jsx("span",{className:"ll-expanded__bg-initial",children:((Pe=o==null?void 0:o.charAt(0))==null?void 0:Pe.toUpperCase())||"A"})}),s&&!Z&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:nt,className:"ll-expanded__video"}),Y&&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:p?"Switching...":"Connecting..."})]}),E&&Z&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:Fe,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"})]}),tt&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":We,children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:We})]}),Me?t.jsxs(t.Fragment,{children:[!J&&t.jsxs("div",{className:"ll-expanded__topbar",children:[!re&&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:g=>{Se&&(g.stopPropagation(),l())},"aria-haspopup":Se?"listbox":void 0,"aria-expanded":Se?m:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:o}),Se&&t.jsx(at,{})]}),Se&&m&&t.jsx("div",{className:"ll-hmenu",onClick:g=>g.stopPropagation(),role:"listbox",children:d==null?void 0:d.map(g=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${g.id===u?"is-active":""}`,onClick:()=>c(g.id),role:"option","aria-selected":g.id===u,children:[g.avatarImageUrl&&t.jsx("img",{src:g.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:g.name}),g.role&&t.jsx("span",{className:"ll-hmenu__role",children:g.role})]},g.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:g=>{g.stopPropagation(),N()},"aria-haspopup":"listbox","aria-expanded":L,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(at,{})]}),L&&t.jsx("div",{className:"ll-hmenu",onClick:g=>g.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:[le!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn",onClick:Le,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(Xt,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:z,"aria-label":"End call",title:"End call",children:t.jsx(Jt,{})})]})]}),J&&t.jsxs("div",{className:"ll-compact-status","data-state":x,children:[t.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),t.jsx("span",{className:"ll-compact-status__label",children:x})]})]}):t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:Ge}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[le!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:Le,"aria-label":"Minimize widget",children:t.jsx(Xt,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:z,"aria-label":"Close widget",children:t.jsx(Jt,{})})]})]}),Ue&&(()=>{const g=C?"Restart paused session":k==="disconnected"?"Reconnect to agent":"Start video call",W=C?"Pick up where you left off":null,De=!M;return t.jsxs(t.Fragment,{children:[De&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:Be,"aria-label":g,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:g})]}),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:Be,"aria-label":g,children:g})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${Me&&(I||F)?"is-visible":""}`,children:[t.jsx("div",{ref:Re,className:F?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:Ve,className:!F&&I?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Me?t.jsxs("div",{className:"ll-expanded__bottom",children:[!J&&Te&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Te})}),!J&&it&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:it})}),!re&&!J&&t.jsxs("div",{className:"ll-toolbar",onClick:g=>g.stopPropagation(),children:[ae&&t.jsx("button",{type:"button",className:`ll-tool ${F?"is-on":""}`,onClick:ke,"aria-label":F?"Stop sharing screen":"Share screen",title:F?"Stop sharing":"Share screen",children:t.jsx(bn,{})}),be&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${I?"is-on":""}`,onClick:_e,"aria-label":I?"Turn off camera":"Turn on camera",title:I?"Stop camera":"Start camera",children:t.jsx(wn,{})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${I?"is-on":""}`,onClick:g=>{g.stopPropagation(),ge(W=>!W),X(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":ce,children:t.jsx(at,{})}),ce&&A.length>0&&t.jsx(Qt,{label:"Camera",devices:A,activeId:O,onPick:g=>{ge(!1),Ae(g)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${b?"is-muted":""}`,onClick:we,"aria-label":b?"Unmute microphone":"Mute microphone",title:b?"Unmute":"Mute",children:t.jsx(_n,{muted:b})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${b?"is-muted":""}`,onClick:g=>{g.stopPropagation(),X(W=>!W),ge(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":oe,children:t.jsx(at,{})}),oe&&$.length>0&&t.jsx(Qt,{label:"Microphone",devices:$,activeId:"",onPick:()=>X(!1)})]}),t.jsx("button",{type:"button",className:`ll-tool ${K?"is-muted":""}`,onClick:je,"aria-label":K?"Unmute speaker":"Mute speaker",title:K?"Unmute speaker":"Mute speaker",children:t.jsx(kn,{muted:K})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:qe,"aria-label":"End conversation",title:"End conversation",children:t.jsx(jn,{})})]}),!re&&J&&t.jsx(yr,{isMuted:b,onToggleMute:we,isCameraEnabled:I,onToggleCamera:_e,allowCamera:be,isScreenShareEnabled:F,onToggleScreenShare:ke,allowScreenShare:ae,isSpeakerMuted:K,onToggleSpeaker:je,allowTyping:he,isTypingOpen:ee,onToggleTyping:Ne,onDisconnect:qe}),!re&&he&&(J?ee:!0)&&t.jsxs("form",{className:"ll-message-input",onSubmit:Ye,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:ye,onChange:g=>ot(g.target.value),"aria-label":"Message the agent"}),ye.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(wr,{})})]})]}):null,(()=>{if(S&&k!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:S}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:pt,"aria-label":"Dismiss",children:"×"})]});if(!M||k!=="error")return null;let g="Failed to connect",W="Try again";return M==="MIC_PERMISSION_DENIED"?g="Microphone blocked. Allow access to talk.":M==="MIC_NOT_FOUND"?g="No microphone found. Plug one in + retry.":M==="MIC_UNAVAILABLE"?g="Mic unavailable. Check other apps using it.":M==="AGENT_TIMEOUT"?g="Agent didn't pick up. Try again.":M==="CONNECT_FAILED"?g="Connection failed. Check your network.":M.length<80&&(g=M),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:g}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:rt,children:W})]})})()]})};function at(){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 Jt(){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 Xt(){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 bn(){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 wn(){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 _n({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 kn({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 wr(){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 jn(){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 Qt=({label:e,devices:r,activeId:o,onPick:i})=>t.jsxs("div",{className:"ll-device-menu",onClick:s=>s.stopPropagation(),role:"listbox",children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),r.map((s,a)=>{const f=o===s.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${f?"is-active":""}`,onClick:()=>i(s.deviceId),role:"option","aria-selected":f,children:[f&&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)})]}),_r=['[data-ll-private="true"]',".ll-widget"];function jt(e){let r=e;for(;r;){for(const o of _r)if(r.matches(o))return!0;r=r.parentElement}return!1}function ft(e){if(jt(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 lt=4096,kr=20,jr=20,Cr=10,Lr=10,Sr=30,Er=20,Zt=500,Rr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function Ze(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let r=e;for(;r;){for(const o of Rr)if(r.matches(o))return!0;r=r.parentElement}return!1}function et(e){if(typeof window>"u")return!0;const r=e.getBoundingClientRect();if(r.width<=0||r.height<=0)return!1;const o=window.innerHeight||document.documentElement.clientHeight,i=window.innerWidth||document.documentElement.clientWidth;return r.bottom>0&&r.right>0&&r.top<o&&r.left<i}function en(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 o=e.getAttribute("aria-label");if(o)return o.trim();const i=e.getAttribute("placeholder");if(i)return i.trim();const s=e.closest("label");return s!=null&&s.textContent?s.textContent.trim():""}function pe(e,r){return e.length<=r?e:e.slice(0,r-1)+"…"}function ze(e){return e.length}function Cn(e,r={}){const o=r.doc??(typeof document<"u"?document:null);if(!o)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const i=typeof window<"u"&&window.location.href||"",s=typeof window<"u"&&window.location.pathname||"/",a=o.title||"",f=Array.from(o.querySelectorAll("[data-ll-region]")),d=[];for(const b of f){if(d.length>=Cr)break;if(Ze(b)||!et(b))continue;const S=b.getAttribute("data-ll-region")??"",$=b.getAttribute("data-ll-intent")??void 0,I=pe((b.innerText||b.textContent||"").trim(),Zt*2);!S||!I||d.push({id:S,intent:$,text:I})}const u=[],p=["H1","H2","H3","H4","H5","H6"],m=Array.from(o.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const b of m){if(Ze(b)||!et(b))continue;const S=(b.textContent||"").trim();S&&u.push(`${b.tagName}: ${pe(S,200)}`)}const l=Array.from(o.querySelectorAll("p, li"));for(const b of l){if(Ze(b)||!et(b)||p.includes(b.tagName))continue;const S=(b.textContent||"").trim();S.length>10&&u.push(pe(S,Zt))}const c=u.join(`
|
|
2
|
-
`),L=[],N=Array.from(o.querySelectorAll("a[href]"));for(const b of N){if(L.length>=kr)break;if(Ze(b)||!et(b))continue;const S=b.getAttribute("href")||"",$=(b.textContent||"").trim();!S||!$||L.push({href:S,text:pe($,100)})}const k=[],x=Array.from(o.querySelectorAll("input, textarea, select"));for(const b of x){if(k.length>=jr)break;if(Ze(b)||!ft(b)||!et(b))continue;const S=en(b),$=b instanceof HTMLInputElement?b.type:b.tagName.toLowerCase();S&&k.push({label:pe(S,100),type:$})}const v=Array.from(o.querySelectorAll("[data-ll-form]")),C=[];for(const b of v){if(C.length>=Lr)break;if(jt(b))continue;const S=b.getAttribute("data-ll-form")||"";if(!S)continue;const $=b.getAttribute("data-ll-intent")||void 0,I=Array.from(b.querySelectorAll("[data-ll-field]")),j=[];for(const A of I){if(j.length>=Sr)break;if(!ft(A))continue;const O=A.getAttribute("data-ll-field")||"";if(!O)continue;const F=en(A)||O,ne=A instanceof HTMLInputElement?A.type:A.tagName.toLowerCase(),K={name:O,label:pe(F,100),type:ne};if(A.required===!0&&(K.required=!0),A instanceof HTMLSelectElement){const ae=[];for(let he=0;he<A.options.length&&!(ae.length>=Er);he++){const le=A.options[he];if(!le||le.disabled)continue;const re=le.value||"",J=(le.textContent||"").trim()||re;!re&&!J||ae.push({value:re,label:pe(J,60)})}ae.length>0&&(K.options=ae)}const be=typeof A.validationMessage=="string"?A.validationMessage:"";be&&(K.validationMessage=pe(be,200)),j.push(K)}C.push({id:S,intent:$,fields:j})}const E={url:i,title:a,pathname:s,regions:d,visibleText:c,visibleLinks:L,visibleFields:k,forms:C,extras:e};let M=ze(JSON.stringify(E.regions))+ze(E.visibleText)+ze(JSON.stringify(E.visibleLinks))+ze(JSON.stringify(E.visibleFields));for(;M>lt&&E.visibleFields.length>0;)E.visibleFields.pop(),M=ze(JSON.stringify(E.visibleFields));for(;M>lt&&E.visibleLinks.length>0;)E.visibleLinks.pop(),M-=80;return ze(E.visibleText)>lt&&(E.visibleText=pe(E.visibleText,lt-100)),E}let Oe=null;function kt(e,r={}){const o=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(Oe&&Oe.key===s&&o-Oe.at<1e3)return Oe.ctx;const a=Cn(e,r);return Oe={key:s,at:o,ctx:a},a}function Ln(){Oe=null}const Nr=200;function Sn(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 Ar(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function En(e){const r=e??(typeof document<"u"?document:null);if(!r)return[];const o=typeof window<"u"&&window.location.origin||"",i=new Set,s=[],a=Array.from(r.querySelectorAll("a[href]"));for(const f of a){if(s.length>=Nr)break;if(jt(f))continue;const d=f.getAttribute("href")||"";if(!Ar(d))continue;let u=d,p=!0;try{if(typeof window<"u"){const l=new URL(d,o);p=l.origin===o,p&&d.startsWith("http")&&(u=l.pathname+l.search+l.hash)}}catch{continue}if(i.has(u))continue;i.add(u);const m=(f.textContent||"").trim().slice(0,120);s.push({href:u,text:m,internal:p})}return s}let He=null;const Mr=5e3;function ct(){const e=Date.now(),r=typeof window<"u"&&window.location.pathname||"/";if(He&&He.pathname===r&&e-He.at<Mr)return He.routes;const o=En();return He={at:e,pathname:r,routes:o},o}function Rn(){He=null}function Ir(e,r){const o=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,i=Object.getOwnPropertyDescriptor(o,"value"),s=i==null?void 0:i.set;s?s.call(e,r):e.value=r}function Tr(e,r,o={}){const i=o.triggerInput??!0,s=o.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const a=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),f=a==null?void 0:a.set,d=r==="true"||r==="1"||r==="on";f?f.call(e,d):e.checked=d,i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}Ir(e,r),i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function Pr(){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 Dr(e){if(!(e instanceof HTMLElement))return!1;const o=window.getComputedStyle(e).overflowY;return!(o!=="auto"&&o!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function $r(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let r=null,o=0;for(const i of e){if(!Dr(i))continue;const s=i.getBoundingClientRect();if(s.bottom<=0||s.top>=window.innerHeight||s.right<=0||s.left>=window.innerWidth||s.width<=0||s.height<=0||i.closest(".ll-widget"))continue;const a=s.width*s.height;a>o&&(o=a,r=i)}return r}function zr(){if(typeof window>"u")return null;if(Pr())return window;const e=$r();return e||window}function tn(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function Or(e){var r,o;return e instanceof Window?typeof document>"u"?0:Math.max(((r=document.body)==null?void 0:r.scrollHeight)??0,((o=document.documentElement)==null?void 0:o.scrollHeight)??0):e.scrollHeight-e.clientHeight}const Hr=new Set(["agent_state","avatar_stream_ready","avatar_active","avatar_idle","bot_ready","agent_error","idle_warning","idle_timeout","navigate","scroll_to","request_page_context","scroll_page","click","fill_form","focus_field","submit_form","request_routes"]),Nn=n.forwardRef(function(r,o){var It,Tt,Pt,Dt,$t,zt,Ot;const{agentId:i,apiKey:s,baseUrl:a="https://app.livelayer.studio",sessionEndpoint:f,sessionBody:d,soundEffects:u,experienceMode:p="WIDGET",autoConnect:m=!1,displayMode:l,defaultDisplayMode:c="expanded",onDisplayModeChange:L,position:N="bottom-right",mobileBreakpoint:k=640,persistKey:x="ll-widget",disablePersistence:v=!1,teamMembers:C,currentTeamMemberId:E,onTeamMemberChange:M,idleLoopUrl:b,greeting:S,avatarImageUrl:$,agentName:I,branding:j={},allowCamera:A=!0,allowScreenShare:O=!0,allowTyping:F=!0,showMinimize:ne=!0,chromeless:K=!1,compactControls:be=!1,transforming:ae=!1,transformingLabel:he="Transforming…",showOn:le,hideOn:re,pathname:J,onNavigate:tt,onScrollToSelector:We,getPageContext:nt,pageContextExtras:Q,getRoutes:Be,onScrollPage:qe,onClick:rt,capabilities:Fe,onConnect:we,onDisconnect:_e,onTranscript:Ae,onAgentState:ke,onConnectionStateChange:je,onAgentEvent:Ce,onAgentCommand:Le,controlledSession:z,className:pt,style:Se,zIndex:Me=2147483647}=r,Z=mn(J),Ue=xn(Z,le,re);n.useEffect(()=>{Ln(),Rn()},[Z]);const Ee=E!==void 0,[Ie,ht]=n.useState(()=>{var y;return E??((y=C==null?void 0:C[0])==null?void 0:y.id)}),me=Ee?E:Ie,Y=n.useMemo(()=>(C==null?void 0:C.find(y=>y.id===me))??null,[C,me]),Ve=(Y==null?void 0:Y.agentId)??i,Re=p==="EMBEDDED",[oe,X]=pn({value:Re?"expanded":l,defaultValue:Re?"expanded":c,onChange:L,persistKey:x,disablePersistence:Re||v}),ce=hn(k),ge=sn(),ee=an(),ue=ln(),Ne=cn(),ye=un(),[ot,Ye]=n.useState(!1),[Ge,de]=n.useState(!1),[ie,Te]=n.useState(!1),[it,mt]=n.useState(!1),[Pe,g]=n.useState(!1),W=ir({baseUrl:a,config:u}),De=n.useRef(W);De.current=W;const gt=n.useRef(tt),yt=n.useRef(We),xt=n.useRef(qe),vt=n.useRef(rt),Ct=n.useRef(nt),Lt=n.useRef(Q),St=n.useRef(Be),bt=n.useRef(Fe),se=n.useRef(null);gt.current=tt,yt.current=We,xt.current=qe,vt.current=rt,Ct.current=nt,Lt.current=Q,St.current=Be,bt.current=Fe;function xe(y){const h=bt.current;return h?h.includes(y):!0}function ve(y,h){console.warn(`[LiveLayer] Agent command "${y}" blocked — capability "${h}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const Ke=n.useCallback(y=>{var q,te,fe,Qe;const h=y;if(!(!h.type||typeof h.type!="string")){if(Ce==null||Ce({eventName:h.type,data:y}),h.type==="navigate"){if(!xe("navigate")){ve("navigate","navigate");return}const _=typeof h.href=="string"?h.href:null;if(!_){console.warn(`[LiveLayer] Agent emitted "navigate" without href. Skipping. Check your agent's tool schema. See https://livelayer.studio/docs/errors/navigate-missing-href`);return}if(De.current.playPageChange(),gt.current){try{gt.current(_)}catch(R){console.warn(`[LiveLayer] onNavigate threw for "${_}". Falling back. Error:`,R)}return}if(typeof document<"u"){const R=document.querySelector(`a[href="${_.replace(/"/g,'\\"')}"]`);if(R){R.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",_),window.dispatchEvent(new PopStateEvent("popstate"))}catch(R){console.warn(`[LiveLayer] history.pushState fallback failed for "${_}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,R)}return}if(h.type==="scroll_to"){if(!xe("scroll")){ve("scroll_to","scroll");return}const _=typeof h.selector=="string"?h.selector:null;if(!_)return;const R=h.behavior==="instant"?"instant":"smooth";if(yt.current){try{yt.current(_,R)}catch(D){console.warn("[LiveLayer] onScrollToSelector threw.",D)}return}if(typeof document<"u"){let D=null;try{D=document.querySelector(_)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${_}".`);return}if(!D){console.warn(`[LiveLayer] scroll_to: no element matched "${_}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}D.scrollIntoView({behavior:R,block:"start"})}return}if(h.type==="request_page_context"){if(!xe("read_page")){ve("request_page_context","read_page");return}const _=typeof h.requestId=="string"?h.requestId:void 0,R=(q=se.current)==null?void 0:q.call(se),D=B=>{const T=R,V=T==null?void 0:T.localParticipant;if(V!=null&&V.publishData)try{const G=_?{...B,requestId:_}:B,$e=new TextEncoder().encode(JSON.stringify(G));V.publishData($e,{reliable:!0})}catch(G){console.warn("[LiveLayer] publishData failed.",G)}},P=Lt.current,H=Ct.current;try{if(H){const B=H(P);if(B instanceof Promise){D({type:"page_context_pending"}),B.then(T=>D({type:"page_context",context:T})).catch(T=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",T),D({type:"page_context",context:kt(P)})});return}D({type:"page_context",context:B});return}D({type:"page_context",context:kt(P)})}catch(B){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",B),D({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:P}})}return}if(h.type==="scroll_page"){if(!xe("scroll")){ve("scroll_page","scroll");return}const _=h.direction;if(_!=="up"&&_!=="down"&&_!=="top"&&_!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(_)}". Expected up | down | top | bottom.`);return}const R=h.behavior==="instant"?"instant":"smooth";if(xt.current){try{xt.current(_,R)}catch(T){console.warn("[LiveLayer] onScrollPage threw.",T)}return}if(typeof window>"u")return;const D={behavior:R},P=zr(),H=T=>{P instanceof Window?P.scrollBy({top:T,...D}):P.scrollBy({top:T,...D})},B=T=>{P instanceof Window?P.scrollTo({top:T,...D}):P.scrollTo({top:T,...D})};_==="up"?H(-tn(P)):_==="down"?H(tn(P)):B(_==="top"?0:Or(P));return}if(h.type==="click"){if(!xe("click")){ve("click","click");return}const _=typeof h.selector=="string"?h.selector:null;if(!_){console.warn("[LiveLayer] click: missing selector.");return}if(vt.current){try{vt.current(_)}catch(D){console.warn("[LiveLayer] onClick threw.",D)}return}if(typeof document>"u")return;let R=null;try{R=document.querySelector(_)}catch{console.warn(`[LiveLayer] click: invalid selector "${_}".`);return}if(!R){console.warn(`[LiveLayer] click: no element matched "${_}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(te=R.click)==null||te.call(R);return}if(h.type==="fill_form"||h.type==="focus_field"){if(!xe("fill_forms")){ve(h.type,"fill_forms");return}if(typeof document>"u")return;h.type==="fill_form"&&De.current.playConfirmation();const _=typeof h.formId=="string"?h.formId:null;if(!_){console.warn(`[LiveLayer] ${h.type}: missing formId.`);return}const R=document.querySelector(`[data-ll-form="${_.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] ${h.type}: no form with data-ll-form="${_}". Tag your form with <LiveLayerForm id> or data-ll-form. See https://livelayer.studio/docs/react/forms`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn(`[LiveLayer] ${h.type}: refusing to touch a form in a private subtree.`);return}if(h.type==="focus_field"){const P=typeof h.fieldName=="string"?h.fieldName:null;if(!P){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const H=R.querySelector(`[data-ll-field="${P.replace(/"/g,'\\"')}"]`);if(!H){console.warn(`[LiveLayer] focus_field: no field "${P}" in form "${_}".`);return}if(!ft(H)){console.warn(`[LiveLayer] focus_field: field "${P}" is privacy-protected and not focusable.`);return}H.focus();return}const D=h.values&&typeof h.values=="object"?h.values:null;if(!D){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[P,H]of Object.entries(D)){if(typeof H!="string")continue;const B=R.querySelector(`[data-ll-field="${P.replace(/"/g,'\\"')}"]`);if(!B){console.warn(`[LiveLayer] fill_form: no field "${P}" in form "${_}". Skipping.`);continue}if(!ft(B)){console.warn(`[LiveLayer] fill_form: field "${P}" is privacy-protected (password / cc-* / private). Skipping.`);continue}try{Tr(B,H)}catch(T){console.warn(`[LiveLayer] fill_form: failed to set "${P}".`,T)}}return}if(h.type==="submit_form"){if(!xe("submit_forms")){ve("submit_form","submit_forms");return}if(typeof document>"u")return;const _=typeof h.formId=="string"?h.formId:null;if(!_){console.warn("[LiveLayer] submit_form: missing formId.");return}De.current.playConfirmation();const R=document.querySelector(`[data-ll-form="${_.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${_}".`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private subtree.");return}const D=typeof h.requestId=="string"?h.requestId:void 0,P=(fe=se.current)==null?void 0:fe.call(se),H=V=>{const G=P,$e=G==null?void 0:G.localParticipant;if($e!=null&&$e.publishData)try{const qn=D?{...V,requestId:D}:V,Fn=new TextEncoder().encode(JSON.stringify(qn));$e.publishData(Fn,{reliable:!0})}catch{}};let B=!1;const T=()=>{B=!0,H({type:"form_submitted",formId:_})};R.addEventListener("submit",T,{once:!0});try{typeof R.requestSubmit=="function"?R.requestSubmit():R.submit()}catch(V){console.warn("[LiveLayer] submit_form: requestSubmit threw.",V),R.removeEventListener("submit",T),H({type:"form_submit_blocked",formId:_,reason:"exception"});return}setTimeout(()=>{B||(R.removeEventListener("submit",T),H({type:"form_submit_blocked",formId:_,reason:"validation"}))},500);return}if(h.type==="request_routes"){if(!xe("read_page")){ve("request_routes","read_page");return}const _=typeof h.requestId=="string"?h.requestId:void 0,D=(Qe=se.current)==null?void 0:Qe.call(se),P=D==null?void 0:D.localParticipant;if(!(P!=null&&P.publishData))return;const H=T=>{try{const V=_?{type:"routes",routes:T,requestId:_}:{type:"routes",routes:T},G=new TextEncoder().encode(JSON.stringify(V));P.publishData(G,{reliable:!0})}catch(V){console.warn("[LiveLayer] request_routes: publishData failed.",V)}},B=St.current;if(B){try{const T=B(),V=G=>{if(!Array.isArray(G)){H([]);return}H(G.map(Sn).slice(0,200))};T instanceof Promise?T.then(V).catch(G=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",G),H(ct())}):V(T)}catch(T){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",T),H(ct())}return}try{H(ct())}catch(T){console.warn("[LiveLayer] request_routes: extractRoutes threw.",T)}return}Hr.has(h.type)||Le==null||Le(h)}},[Le,Ce]),U=on({agentId:z?"__controlled__":Ve,baseUrl:a,apiKey:s,sessionEndpoint:f,sessionBody:d,onDataMessage:z?void 0:Ke});n.useEffect(()=>{if(z!=null&&z.subscribeToDataMessages)return z.subscribeToDataMessages(Ke)},[z,Ke]),se.current=()=>{var y;return(y=U.getRoom)==null?void 0:y.call(U)},n.useEffect(()=>{var q;if(typeof window>"u")return;const y=((q=window.location)==null?void 0:q.hostname)||"";if(y==="localhost"||y==="127.0.0.1"||y==="0.0.0.0"||y.endsWith(".local")||y.endsWith(".test"))return window.__livelayerSimulateCommand=te=>{try{Ke(te)}catch(fe){console.warn("[LiveLayer] simulate-command threw:",fe)}},()=>{delete window.__livelayerSimulateCommand}},[Ke]);const w=n.useMemo(()=>z?{connectionState:z.connectionState,agentState:z.agentState,transcript:z.transcript,videoElement:z.videoElement,audioElement:z.audioElement,canResume:z.canResume,error:z.error,agentConfig:null,connect:async()=>{await z.onConnect()},disconnect:()=>z.onDisconnect(),getRoom:U.getRoom,isControlled:!0}:{connectionState:U.connectionState,agentState:U.agentState,transcript:U.transcript,videoElement:U.videoElement,audioElement:U.audioElement,canResume:U.canResume,error:U.error,agentConfig:U.agentConfig,connect:U.connect,disconnect:U.disconnect,getRoom:U.getRoom,isControlled:!1},[z,U]),Et=n.useRef(w);Et.current=w;const Rt=n.useRef(z);Rt.current=z,n.useImperativeHandle(o,()=>({sendData:async y=>{var fe,Qe;const h=Rt.current;if(h!=null&&h.publishData){try{await h.publishData(y)}catch(_){console.warn("[AvatarWidget] sendData (controlled) failed:",_)}return}const q=(Qe=(fe=Et.current)==null?void 0:fe.getRoom)==null?void 0:Qe.call(fe),te=q==null?void 0:q.localParticipant;if(te!=null&&te.publishData)try{const _=new TextEncoder().encode(JSON.stringify(y));await te.publishData(_,{reliable:!0})}catch(_){console.warn("[AvatarWidget] sendData failed:",_)}}}),[]);const Nt=n.useRef(null);n.useEffect(()=>{const y=w.videoElement,h=Nt.current;if(!(!y||!h))return h.appendChild(y),()=>{y.parentNode===h&&h.removeChild(y)}},[w.videoElement]),n.useEffect(()=>{const y=w.audioElement;if(!y)return;ge.attach(y);const h=y.play();return h&&typeof h.catch=="function"&&h.catch(q=>{(q==null?void 0:q.name)==="NotAllowedError"&&Ye(!0)}),()=>{ge.detach()}},[w.audioElement]),n.useEffect(()=>{if(w.isControlled||w.connectionState!=="connected")return;const y=w.getRoom();if(y)return ee.setupMic(y).catch(()=>{}),ue.attachRoom(y),Ne.attachRoom(y),ye.refresh(),()=>{ee.teardownMic(),ue.teardown(),Ne.teardown()}},[w.isControlled,w.connectionState]),n.useEffect(()=>{const y=w.audioElement;y&&(y.muted=Pe)},[w.audioElement,Pe]);const Mn=n.useCallback(y=>{const h={type:"user_message",text:y};if(z!=null&&z.publishData){try{z.publishData(h)}catch{}return}const q=w.getRoom();if(q)try{const te=new TextEncoder().encode(JSON.stringify(h));q.localParticipant.publishData(te,{reliable:!0})}catch{}},[w,z]),In=n.useCallback(()=>{g(y=>!y)},[]);n.useEffect(()=>{je==null||je(w.connectionState),w.connectionState==="connected"?we==null||we():w.connectionState==="disconnected"&&(_e==null||_e())},[w.connectionState,we,_e,je]),n.useEffect(()=>{Ae==null||Ae(w.transcript)},[w.transcript,Ae]),n.useEffect(()=>{ke==null||ke(w.agentState)},[w.agentState,ke]),n.useEffect(()=>{W.setThinking(w.agentState==="thinking")},[w.agentState,W]);const At=n.useRef(!1);n.useEffect(()=>{w.isControlled||!m||At.current||Ue&&w.connectionState==="idle"&&(At.current=!0,w.connect())},[m,w.connectionState,w,Ue]);const Tn=n.useCallback(y=>{const h=C==null?void 0:C.find(q=>q.id===y);h&&(Te(!1),y!==me&&(de(!0),w.disconnect(),Ee||ht(y),M==null||M(h)))},[C,me,w,Ee,M]);n.useEffect(()=>{Ge&&w.connectionState==="connected"&&de(!1)},[w.connectionState,Ge]),n.useEffect(()=>{if(!ie)return;const y=h=>{h.key==="Escape"&&Te(!1)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[ie]);const Pn=!!$||!!(Y!=null&&Y.avatarImageUrl)||w.isControlled,Je=dn(Ve,a,Pn);Fe===void 0&&((It=Je.info)!=null&&It.capabilities)&&(bt.current=Je.info.capabilities);const st=(Y==null?void 0:Y.name)??I??((Tt=w.agentConfig)==null?void 0:Tt.name)??((Pt=Je.info)==null?void 0:Pt.name)??"Live Layer",wt=(Y==null?void 0:Y.avatarImageUrl)??$??((Dt=w.agentConfig)==null?void 0:Dt.avatarImageUrl)??(($t=Je.info)==null?void 0:$t.avatarImageUrl)??null,Dn=b??((zt=w.agentConfig)==null?void 0:zt.idleLoopUrl)??((Ot=Je.info)==null?void 0:Ot.idleLoopUrl)??null,$n=S??null,zn=n.useCallback(()=>X("expanded"),[X]),On=n.useCallback(()=>X("minimized"),[X]),Mt=n.useCallback(()=>{w.disconnect(),X("hidden")},[w,X]),Hn=n.useCallback(()=>{const y=w.audioElement;y&&y.play().then(()=>Ye(!1)).catch(()=>{})},[w.audioElement]),Wn=n.useCallback(()=>{Ye(!1),w.connect()},[w]),Xe={...Se,...Re?{}:{zIndex:Me}};j.primaryColor&&(Xe["--ll-color-primary"]=j.primaryColor),j.accentColor&&(Xe["--ll-color-accent"]=j.accentColor),j.backgroundColor&&(Xe["--ll-color-bg"]=j.backgroundColor),j.textColor&&(Xe["--ll-color-fg"]=j.textColor);const Bn=["ll-widget",`ll-widget--${oe}`,`ll-widget--${ce?"mobile":"desktop"}`,pt].filter(Boolean).join(" ");return Ue?t.jsxs("div",{className:Bn,style:Xe,"data-display-mode":oe,"data-position":N,"data-experience-mode":p==="EMBEDDED"?"embedded":"widget",children:[oe==="hidden"&&t.jsx(dr,{position:N,isMobile:ce,isSpeaking:w.agentState==="speaking",onExpand:()=>X("expanded"),label:`Open ${st} widget`,avatarImageUrl:wt,agentName:st}),oe==="minimized"&&t.jsx(pr,{position:N,isMobile:ce,agentName:st,avatarImageUrl:wt,agentState:w.agentState,isMuted:ee.isMuted,audioLevel:ge,onExpand:zn,onToggleMute:ee.toggleMute,onClose:Mt}),oe==="expanded"&&t.jsx(br,{position:N,isMobile:ce,agentName:st,avatarImageUrl:wt,idleLoopUrl:Dn,greeting:$n,branding:j,teamMembers:C,currentTeamMemberId:me,isSwitchingTeamMember:Ge,teamSwitcherOpen:ie,onToggleTeamSwitcher:()=>Te(y=>!y),onSelectTeamMember:Tn,connectionState:w.connectionState,agentState:w.agentState,transcript:w.transcript,isMuted:ee.isMuted,micDevices:ye.mics,isCameraEnabled:ue.isEnabled,cameraPreviewEl:ue.previewEl,cameraDevices:ye.cameras,activeCameraId:ue.activeDeviceId,isScreenShareEnabled:Ne.isEnabled,screenPreviewEl:Ne.previewEl,isSpeakerMuted:Pe,allowCamera:A,allowScreenShare:O,allowTyping:F,showMinimize:ne,chromeless:K,compactControls:be,transforming:ae,transformingLabel:he,languageMenuOpen:it,onToggleLanguageMenu:()=>mt(y=>!y),needsUserGesture:ot,canResume:w.canResume,micError:ee.micError,error:w.error,avatarVideoContainerRef:Nt,agentVideoEl:w.videoElement,onConnect:()=>void w.connect(),onDisconnect:()=>w.disconnect(),onRetry:Wn,onResumeAudio:Hn,onToggleMute:ee.toggleMute,onToggleCamera:()=>void ue.toggle(),onSwitchCameraDevice:y=>void ue.switchDevice(y),onToggleScreenShare:()=>void Ne.toggle(),onToggleSpeaker:In,onSendMessage:Mn,onMinimize:On,onClose:Mt,onClearMicError:ee.clearError})]}):null});Nn.displayName="AvatarWidgetInner";const An=n.forwardRef(function(r,o){return t.jsx(rn,{children:t.jsx(Nn,{...r,ref:o})})});An.displayName="AvatarWidget";const Wr=({agentId:e,baseUrl:r,apiKey:o,mode:i,onAgentEvent:s,className:a,style:f})=>{const d=n.useRef(null),u=n.useRef(null),p=n.useRef(s);p.current=s;const m=n.useCallback(l=>{var L;const c=l.detail;(L=p.current)==null||L.call(p,c)},[]);return n.useEffect(()=>{const l=d.current;if(!l)return;const c=document.createElement("livelayer-widget");return c.setAttribute("agent-id",e),r&&c.setAttribute("base-url",r),o&&c.setAttribute("api-key",o),i&&c.setAttribute("mode",i),c.addEventListener("agent-event",m),l.appendChild(c),u.current=c,()=>{c.removeEventListener("agent-event",m),l.removeChild(c),u.current=null}},[e]),n.useEffect(()=>{u.current&&(i?u.current.setAttribute("mode",i):u.current.removeAttribute("mode"))},[i]),t.jsx("div",{ref:d,className:a,style:f})},Br=n.forwardRef(function({id:r,intent:o,as:i="div",className:s,style:a,children:f},d){return n.createElement(i,{ref:d,"data-ll-region":r,"data-ll-intent":o,className:s,style:a},f)}),qr=n.forwardRef(function({id:r,intent:o,children:i,...s},a){return t.jsx("form",{ref:a,"data-ll-form":r,"data-ll-intent":o,...s,children:i})}),Fr=n.forwardRef(function(r,o){const{name:i,label:s,labelClassName:a}=r,f={name:i,"data-ll-field":i};let d;if("as"in r&&r.as==="textarea"){const{name:u,label:p,labelClassName:m,as:l,...c}=r;d=t.jsx("textarea",{ref:o,...f,...c})}else if("as"in r&&r.as==="select"){const{name:u,label:p,labelClassName:m,as:l,children:c,...L}=r;d=t.jsx("select",{ref:o,...f,...L,children:c})}else{const{name:u,label:p,labelClassName:m,as:l,...c}=r;d=t.jsx("input",{ref:o,...f,...c})}return s===void 0?d:t.jsxs("label",{className:a,children:[s,d]})});let nn=1;function Ur({onMount:e,defaultOpen:r=!1,storageKey:o="ll-debug-open"}){const[i,s]=n.useState(r),[a,f]=n.useState([]),[d,u]=n.useState(""),[p,m]=n.useState(!1),l=n.useRef(new Set),c=n.useRef([]),L=n.useRef(p);L.current=p,n.useEffect(()=>{try{const x=localStorage.getItem(o);x==="1"&&s(!0),x==="0"&&s(!1)}catch{}},[o]),n.useEffect(()=>{try{localStorage.setItem(o,i?"1":"0")}catch{}},[i,o]),n.useEffect(()=>{const x=v=>{(v.metaKey||v.ctrlKey)&&v.shiftKey&&v.key.toLowerCase()==="l"&&(v.preventDefault(),s(C=>!C))};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[]),n.useEffect(()=>{const x=setInterval(()=>{if(c.current.length===0||L.current)return;const v=c.current.splice(0,c.current.length);f(C=>[...v.reverse(),...C].slice(0,200))},100);return()=>clearInterval(x)},[]);const N=n.useRef(!1);if(n.useEffect(()=>{!e||N.current||(N.current=!0,e(x=>{c.current.push({id:nn++,ts:Date.now(),kind:"event",type:x.eventName,data:x.data})}))},[e]),n.useEffect(()=>{const x=console.warn,v=console.log,C=(E,M)=>function(...b){try{const S=typeof b[0]=="string"?b[0]:"";S.startsWith("[LiveLayer]")&&c.current.push({id:nn++,ts:Date.now(),kind:E,type:S.slice(0,120),data:{args:b.slice(1).map($=>Yr($))}})}catch{}return M.apply(this,b)};return console.warn=C("warn",x),console.log=C("log",v),()=>{console.warn=x,console.log=v}},[]),!i)return t.jsx("button",{type:"button",onClick:()=>s(!0),title:"Open LiveLayer debug panel (Cmd/Ctrl + Shift + L)","aria-label":"Open LiveLayer debug panel",style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.18)",borderRadius:999,padding:"6px 10px",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",cursor:"pointer",boxShadow:"0 4px 12px rgba(0,0,0,0.35)",opacity:.85},children:"🛰 LL debug"});const k=a.filter(x=>{if(!d)return!0;const v=d.toLowerCase();return x.type.toLowerCase().includes(v)||JSON.stringify(x.data||{}).toLowerCase().includes(v)});return t.jsxs("div",{style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,width:380,maxHeight:"60vh",background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:12,boxShadow:"0 16px 48px rgba(0,0,0,0.5)",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"8px 10px",background:"rgba(255,255,255,0.04)",borderBottom:"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),t.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[a.length," event",a.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>m(x=>!x),style:_t(p?"#f59e0b":"transparent"),title:"Pause / resume capture",children:p?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{f([]),c.current=[]},style:_t("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:_t("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:d,onChange:x=>u(x.target.value),placeholder:"filter by type or data…",style:{margin:8,padding:"6px 8px",background:"rgba(255,255,255,0.06)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:"#fff",fontSize:11,outline:"none"}}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 8px 8px"},children:k.length===0?t.jsxs("div",{style:{padding:14,fontSize:11,color:"rgba(255,255,255,0.4)",lineHeight:1.5},children:["No events yet. Connect to the agent and trigger a tool call — the events will stream in here. You can also dispatch commands manually in DevTools:",t.jsx("pre",{style:{marginTop:6,background:"rgba(255,255,255,0.04)",padding:6,borderRadius:4,fontSize:10,whiteSpace:"pre-wrap"},children:`window.__livelayerSimulateCommand({
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),n=require("react"),Un=require("@livelayer/sdk"),ut=require("livekit-client"),Vn=require("react-dom");class rn 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,o){var i,s;(s=(i=this.props).onError)==null||s.call(i,r,o)}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 on(e){const[r,o]=n.useState("idle"),[i,s]=n.useState("idle"),[a,f]=n.useState([]),[d,u]=n.useState(null),[p,m]=n.useState(null),[l,c]=n.useState(null),[L,N]=n.useState(!1),[k,x]=n.useState(null),v=n.useRef(null),C=n.useRef(e.onDataMessage);C.current=e.onDataMessage,n.useEffect(()=>{const S={onConnectionStateChange:I=>{o(I),I==="connected"&&x(null)},onAgentStateChange:s,onTranscript:I=>f([...I]),onAgentConfig:u,onAudioTrack:I=>c(I),onVideoTrack:I=>m(I),onVideoTrackRemoved:()=>m(null),onError:I=>x(I),onDataMessage:I=>{var j;(j=C.current)==null||j.call(C,I)},onResumabilityChange:N},$=new Un.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},S);return v.current=$,o("idle"),s("idle"),f([]),u(null),m(null),c(null),N(!1),x(null),()=>{var I;(I=$.destroy)==null||I.call($),v.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=n.useCallback(async()=>{const S=v.current;if(S)try{await S.connect()}catch($){throw x($ instanceof Error?$.message:String($)),$}},[]),M=n.useCallback(()=>{const S=v.current;S&&S.disconnect()},[]),b=n.useCallback(()=>{var S;return((S=v.current)==null?void 0:S.getRoom())??null},[]);return{connectionState:r,agentState:i,transcript:a,agentConfig:d,videoElement:p,audioElement:l,canResume:L,error:k,connect:E,disconnect:M,getRoom:b,session:v.current}}function sn(){const e=n.useRef(null),r=n.useRef(null),o=n.useRef(null),i=n.useRef(null),s=n.useRef(new Set),a=n.useRef(null),f=n.useCallback(()=>{const l=r.current;if(!l){i.current=null;return}(!a.current||a.current.length!==l.frequencyBinCount)&&(a.current=new Uint8Array(new ArrayBuffer(l.frequencyBinCount)));const c=a.current;l.getByteFrequencyData(c);let L=0;for(let k=0;k<c.length;k++)L+=c[k];const N=L/c.length/255;for(const k of s.current)try{k(N)}catch(x){console.error("[useAudioLevel] subscriber threw:",x)}i.current=requestAnimationFrame(f)},[]),d=n.useCallback(()=>{if(e.current||typeof window>"u"||typeof AudioContext>"u")return;const l=new AudioContext,c=l.createAnalyser();c.fftSize=64,c.connect(l.destination),e.current=l,r.current=c},[]),u=n.useCallback(l=>{if(d(),!(!e.current||!r.current)){if(o.current){try{o.current.disconnect()}catch{}o.current=null}try{const c=e.current.createMediaElementSource(l);c.connect(r.current),o.current=c}catch(c){console.warn("[useAudioLevel] createMediaElementSource failed:",c);return}i.current===null&&(i.current=requestAnimationFrame(f))}},[d,f]),p=n.useCallback(()=>{if(i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),o.current){try{o.current.disconnect()}catch{}o.current=null}},[]),m=n.useCallback(l=>(s.current.add(l),()=>{s.current.delete(l)}),[]);return n.useEffect(()=>()=>{if(p(),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},[p]),{attach:u,detach:p,subscribe:m}}function an(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),s=n.useRef(null),a=n.useRef(null),f=n.useCallback(async m=>{if(s.current&&a.current){try{await a.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}a.current=m,i(null);try{const l=await ut.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await m.localParticipant.publishTrack(l),s.current=l,r(l.isMuted)}catch(l){const c=l instanceof Error&&l.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw i(c),l}},[]),d=n.useCallback(()=>{const m=s.current;m&&(m.isMuted?(m.unmute(),r(!1)):(m.mute(),r(!0)))},[]),u=n.useCallback(()=>{const m=s.current,l=a.current;if(m&&l){try{l.localParticipant.unpublishTrack(m)}catch{}m.stop()}s.current=null,a.current=null,r(!1)},[]),p=n.useCallback(()=>i(null),[]);return{isMuted:e,micError:o,toggleMute:d,setupMic:f,teardownMic:u,clearError:p}}const Yn={resolution:{width:640,height:480,frameRate:24}};function ln(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),[f,d]=n.useState(""),u=n.useRef(null),p=n.useRef(null),m=n.useCallback(v=>{u.current=v},[]),l=n.useCallback(()=>{const v=u.current,C=p.current;if(C&&v){const E=v.localParticipant.getTrackPublication(ut.Track.Source.Camera);if(E!=null&&E.track){try{v.localParticipant.unpublishTrack(E.track)}catch{}E.track.stop()}else C.stop()}p.current=null,a(null),r(!1)},[]),c=n.useCallback(async v=>{const C=u.current;if(C){i(null);try{const E={...Yn};v&&(E.deviceId=v);const M=await ut.createLocalVideoTrack(E);await C.localParticipant.publishTrack(M),p.current=M;const b=M.attach();a(b),r(!0),v&&d(v);try{C.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const M=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";i(M)}}},[]),L=n.useCallback(async()=>{e?l():await c(f||void 0)},[e,f,l,c]),N=n.useCallback(async v=>{l(),await c(v)},[l,c]),k=n.useCallback(()=>{l(),u.current=null,i(null),d("")},[l]),x=n.useCallback(()=>i(null),[]);return n.useEffect(()=>()=>{p.current&&p.current.stop()},[]),{isEnabled:e,error:o,previewEl:s,activeDeviceId:f,toggle:L,switchDevice:N,attachRoom:m,teardown:k,clearError:x}}function cn(){const[e,r]=n.useState(!1),[o,i]=n.useState(null),[s,a]=n.useState(null),f=n.useRef(null),d=n.useCallback(c=>{f.current=c},[]),u=n.useCallback(()=>a(null),[]),p=n.useCallback(async()=>{const c=f.current;if(c){if(e){try{await c.localParticipant.setScreenShareEnabled(!1)}catch{}u(),r(!1);return}i(null);try{await c.localParticipant.setScreenShareEnabled(!0);let L=0;const N=()=>{const k=c.localParticipant.getTrackPublication(ut.Track.Source.ScreenShare);if(k!=null&&k.track){const x=k.track.attach();a(x),r(!0);try{c.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}L++<10?setTimeout(N,100):r(!0)};N()}catch(L){const N=L instanceof Error?L.name:"";N!=="NotAllowedError"&&N!=="AbortError"&&i("Screen share unavailable. Try again."),r(!1)}}},[e,u]),m=n.useCallback(()=>{const c=f.current;if(c&&e)try{c.localParticipant.setScreenShareEnabled(!1)}catch{}u(),r(!1),i(null),f.current=null},[e,u]),l=n.useCallback(()=>i(null),[]);return{isEnabled:e,error:o,previewEl:s,toggle:p,attachRoom:d,teardown:m,clearError:l}}function un(){const[e,r]=n.useState([]),[o,i]=n.useState([]),s=n.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const a=await navigator.mediaDevices.enumerateDevices();r(a.filter(f=>f.kind==="audioinput")),i(a.filter(f=>f.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:o,refresh:s}}function dn(e,r,o=!1){const[i,s]=n.useState(null),[a,f]=n.useState(null),[d,u]=n.useState(!o&&!!e);return n.useEffect(()=>{if(o||!e){u(!1);return}const p=new AbortController,m=r||"https://app.livelayer.studio";return u(!0),f(null),fetch(`${m}/api/widget/agent/${encodeURIComponent(e)}`,{signal:p.signal}).then(async l=>{if(!l.ok){const c=await l.json().catch(()=>({}));throw new Error(c.error||`HTTP ${l.status}`)}return l.json()}).then(l=>{p.signal.aborted||(s(l),u(!1))}).catch(l=>{p.signal.aborted||(f(l instanceof Error?l.message:"Agent lookup failed"),u(!1))}),()=>p.abort()},[e,r,o]),{info:i,error:a,loading:d}}function Gn(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Kn(e,r){if(!(typeof window>"u"))try{window.localStorage.setItem(e,r)}catch{}}function fn({value:e,defaultValue:r="expanded",onChange:o}={}){const i=e!==void 0,[s,a]=n.useState(r),f=i?e:s,d=n.useCallback(u=>{u!==f&&(i||a(u),o==null||o(u))},[f,i,o]);return[f,d]}const Jn=["hidden","minimized","expanded"];function Xn(e){return e&&Jn.includes(e)?e:null}function pn({value:e,defaultValue:r="expanded",onChange:o,persistKey:i="ll-widget",disablePersistence:s=!1}={}){const a=`${i}:display-mode`,f=n.useRef(!1),[d,u]=fn({value:e,defaultValue:r,onChange:p=>{e===void 0&&!s&&Kn(a,p),o==null||o(p)}});return n.useEffect(()=>{if(f.current||(f.current=!0,s||e!==void 0))return;const p=Xn(Gn(a));p&&p!==d&&u(p)},[]),[d,u]}const Qn=640;function hn(e=Qn){const[r,o]=n.useState(!1);return n.useEffect(()=>{if(e===!1){o(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const i=`(max-width: ${e-1}px)`,s=window.matchMedia(i),a=()=>o(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 Ht="__llHistoryPatched",dt="ll:pathname";function Zn(){if(typeof window>"u"||window.history[Ht])return;const e=window.history.pushState,r=window.history.replaceState;window.history.pushState=function(...o){const i=e.apply(this,o);return window.dispatchEvent(new Event(dt)),i},window.history.replaceState=function(...o){const i=r.apply(this,o);return window.dispatchEvent(new Event(dt)),i},window.history[Ht]=!0}function Wt(){return typeof window>"u"?"/":window.location.pathname||"/"}function mn(e){const[r,o]=n.useState(()=>e??Wt());return n.useEffect(()=>{if(e!==void 0)return;Zn();const i=()=>o(Wt());return i(),window.addEventListener("popstate",i),window.addEventListener(dt,i),()=>{window.removeEventListener("popstate",i),window.removeEventListener(dt,i)}},[e]),e??r}const Bt=new Map,er=/[\\^$+?.()|{}[\]]/g;function tr(e){return e.replace(er,"\\$&")}function nr(e){const r=Bt.get(e);if(r)return r;const o=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,i="",s="",a=o.replace(/\*\*/g,i).replace(/\*/g,s),d=tr(a).replace(new RegExp(`\\/${i}`,"g"),"(?:\\/.*)?").replace(new RegExp(i,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),u=new RegExp(`^${d}\\/?$`);return Bt.set(e,u),u}function rr(e,r){const o=r.length>1&&r.endsWith("/")?r.slice(0,-1):r;return nr(e).test(o)}function gn(e,r){return typeof e=="function"?e(r):e instanceof RegExp?e.test(r):rr(e,r)}function qt(e,r){if(!e||e.length===0)return!1;for(const o of e)if(gn(o,r))return!0;return!1}function yn(e,r,o){return e===void 0?!0:qt(o,e)?!1:r&&r.length>0?qt(r,e):!0}function xn(e,r,o){return n.useMemo(()=>yn(e,r,o),[e,r,o])}function or(e){return e===!1?{navigate:!1,thinking:!1,action:!1}:e===void 0||e===!0?{navigate:!0,thinking:!0,action:!0}:{navigate:e.navigate!==!1,thinking:e.thinking!==!1,action:e.action!==!1}}function ir(e){const r=n.useMemo(()=>or(e.config),[e.config]),o=e.baseUrl.replace(/\/+$/,""),i=n.useRef(null),s=n.useCallback(u=>{try{new Audio(`${o}${u}`).play().catch(()=>{})}catch{}},[o]),a=n.useCallback(()=>{r.navigate&&s("/audio/page-change-sound.mp3")},[r.navigate,s]),f=n.useCallback(()=>{r.action&&s("/audio/confirmation-sound.mp3")},[r.action,s]),d=n.useCallback(u=>{if(!r.thinking){if(i.current){try{i.current.pause()}catch{}i.current=null}return}if(u){if(i.current)return;try{const p=new Audio(`${o}/audio/thinking-sound.mp3`);p.loop=!0,p.volume=.3,p.play().catch(()=>{i.current=null}),i.current=p}catch{}}else if(i.current){try{i.current.pause()}catch{}i.current=null}},[o,r.thinking]);return n.useEffect(()=>()=>{if(i.current){try{i.current.pause()}catch{}i.current=null}},[]),n.useMemo(()=>({playPageChange:a,playConfirmation:f,setThinking:d}),[a,f,d])}const Ft=({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"})}),Ut=({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"})}),sr=({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"})}),ar={left:180,right:0,up:-90,down:90},Vt=({direction:e="right",className:r})=>t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${ar[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function lr(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const vn="ll-hidden-tab-center-y",cr=5,Yt=16;function ur(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(vn);if(!e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null}catch{return null}}function Gt(e){if(!(typeof window>"u"))try{window.localStorage.setItem(vn,String(e))}catch{}}const dr=({position:e,isMobile:r,isSpeaking:o,onExpand:i,label:s="Open widget",avatarImageUrl:a,agentName:f})=>{const d=lr(e),u=d==="right"?"left":"right",p=r?80:72,m=!!a,[l,c]=n.useState(null),[L,N]=n.useState(!1),k=n.useRef(null),x=n.useRef(!1),v=n.useCallback(j=>{if(typeof window>"u")return j;const A=p/2,O=Yt+A,F=window.innerHeight-Yt-A;return F<O?Math.max(O,j):Math.max(O,Math.min(F,j))},[p]);n.useEffect(()=>{const j=ur();c(v(j??window.innerHeight/2));const A=()=>{c(O=>O===null?null:v(O))};return window.addEventListener("resize",A),()=>window.removeEventListener("resize",A)},[v]);const C=n.useCallback(j=>{if(!(j.pointerType==="mouse"&&j.button!==0)&&l!==null){try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}k.current={startClientY:j.clientY,startCenterY:l,moved:!1}}},[l]),E=n.useCallback(j=>{const A=k.current;if(!A)return;const O=j.clientY-A.startClientY;!A.moved&&Math.abs(O)>cr&&(A.moved=!0,N(!0)),A.moved&&c(v(A.startCenterY+O))},[v]),M=n.useCallback(j=>{const A=k.current;if(A){try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}k.current=null,A.moved&&(N(!1),x.current=!0,c(O=>(O!==null&&Gt(O),O)))}},[]),b=n.useCallback(()=>{if(x.current){x.current=!1;return}i()},[i]),S=n.useCallback(j=>{if(j.key==="ArrowUp"||j.key==="ArrowDown"){j.preventDefault();const A=j.key==="ArrowUp"?-8:8;c(O=>{if(O===null)return O;const F=v(O+A);return Gt(F),F})}},[v]),$=["ll-hidden",`ll-hidden--${d}`,r?"ll-hidden--mobile":"ll-hidden--desktop",o?"ll-hidden--speaking":null,L?"is-dragging":null,m?"ll-hidden--with-avatar":null].filter(Boolean).join(" "),I=l===null?void 0:{top:`${l-p/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:$,onPointerDown:C,onPointerMove:E,onPointerUp:M,onPointerCancel:M,onClick:b,onKeyDown:S,"aria-label":s,"data-position":e,style:I,children:m?t.jsxs(t.Fragment,{children:[t.jsx(Vt,{direction:u,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:a,alt:f?`${f} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Vt,{direction:u,className:"ll-hidden__chevron"})})},fr=({audioLevel:e,bars:r=20,maxHeight:o=20,minHeight:i=4,className:s,barClassName:a})=>{const f=n.useRef(null),d=n.useRef([]),u=n.useMemo(()=>{const m=(Math.sqrt(5)-1)/2;return Array.from({length:r},(l,c)=>.5+c*m%1*.5)},[r]);n.useEffect(()=>e.subscribe(l=>{for(let c=0;c<r;c++){const L=d.current[c];if(!L)continue;const N=Math.max(i,l*o*u[c]);L.style.height=`${N}px`}}),[e,r,o,i,u]);const p=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:f,className:p,"aria-hidden":"true",children:Array.from({length:r},(m,l)=>t.jsx("div",{ref:c=>{d.current[l]=c},className:["ll-waveform__bar",a].filter(Boolean).join(" "),style:{height:`${i}px`}},l))})},pr=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,agentState:s,isMuted:a,audioLevel:f,onExpand:d,onToggleMute:u,onClose:p})=>r?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${o} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:d,"aria-label":`Expand ${o} widget`,children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsx(fr,{audioLevel:f,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:m=>{m.stopPropagation(),u()},onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.stopPropagation(),m.preventDefault(),u())},"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(Ft,{muted:a,className:"ll-minimized__icon"})}),t.jsx(Ut,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):t.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${o} widget`,children:t.jsxs("div",{className:"ll-minimized__surface",children:[i?t.jsx("img",{src:i,alt:o,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsxs("div",{className:"ll-minimized__meta",children:[t.jsx("span",{className:"ll-minimized__name",children:o}),t.jsx("span",{className:"ll-minimized__state",children:s==="speaking"?"Speaking":s==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:u,"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(Ft,{muted:a,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:d,"aria-label":`Expand ${o} widget`,children:t.jsx(Ut,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:p,"aria-label":"Close widget",children:t.jsx(sr,{className:"ll-minimized__icon"})})]})]})}),hr=({src:e,alt:r,preCannedPlaying:o=!1,className:i,style:s})=>{const[a,f]=n.useState(!1),d=n.useRef(e);if(n.useEffect(()=>{d.current!==e&&(d.current=e,f(!1))},[e]),!e)return null;const u={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:o?"scale(1.02)":"scale(1)",opacity:a?1:0,...s};return t.jsx("img",{src:e,alt:r,className:i,style:u,loading:"eager",fetchPriority:"high",onLoad:()=>f(!0)})},mr=8,Kt=8,gr=({open:e,onClose:r,anchorRef:o,children:i})=>{const s=n.useRef(null),[a,f]=n.useState(null);return n.useLayoutEffect(()=>{if(!e){f(null);return}const d=o.current;if(!d)return;const u=()=>{const p=d.getBoundingClientRect(),m={top:p.top-mr,left:p.left+p.width/2},l=Kt+90,c=window.innerWidth-Kt-90;m.left<l&&(m.left=l),m.left>c&&(m.left=c),f(m)};return u(),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[e,o]),n.useEffect(()=>{if(!e)return;const d=p=>{const m=p.target,l=s.current,c=o.current;l&&l.contains(m)||c&&c.contains(m)||r()},u=p=>{p.key==="Escape"&&(p.stopPropagation(),r())};return document.addEventListener("mousedown",d),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",u)}},[e,r,o]),!e||a===null||typeof document>"u"?null:Vn.createPortal(t.jsx("div",{ref:s,className:"ll-overflow-popover",role:"menu",style:{position:"fixed",top:a.top,left:a.left,transform:"translate(-50%, -100%)"},children:i}),document.body)},yr=({isMuted:e,onToggleMute:r,isCameraEnabled:o,onToggleCamera:i,allowCamera:s,isScreenShareEnabled:a,onToggleScreenShare:f,allowScreenShare:d,isSpeakerMuted:u,onToggleSpeaker:p,allowTyping:m,isTypingOpen:l,onToggleTyping:c,onDisconnect:L})=>{const[N,k]=n.useState(!1),x=n.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:v=>v.stopPropagation(),children:[t.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:r,"aria-label":e?"Unmute microphone":"Mute microphone",children:t.jsx(_n,{muted:e})}),t.jsx("button",{ref:x,type:"button",className:`ll-tool ${N?"is-on":""}`,onClick:()=>k(v=>!v),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":N,children:t.jsx(xr,{})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:L,"aria-label":"End conversation",children:t.jsx(jn,{})})]}),t.jsxs(gr,{open:N,onClose:()=>k(!1),anchorRef:x,children:[s&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${o?"is-on":""}`,onClick:()=>{i(),k(!1)},children:[t.jsx(wn,{}),t.jsx("span",{children:o?"Stop camera":"Start camera"})]}),d&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${a?"is-on":""}`,onClick:()=>{f(),k(!1)},children:[t.jsx(bn,{}),t.jsx("span",{children:a?"Stop sharing":"Share screen"})]}),t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${u?"is-on":""}`,onClick:()=>{p(),k(!1)},children:[t.jsx(kn,{muted:u}),t.jsx("span",{children:u?"Unmute speaker":"Mute speaker"})]}),m&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${l?"is-on":""}`,onClick:()=>{c(),k(!1)},children:[t.jsx(vr,{}),t.jsx("span",{children:l?"Hide typing":"Type a message"})]}),t.jsxs("button",{type:"button",className:"ll-overflow-popover__item is-active",disabled:!0,"aria-current":"true",children:[t.jsx("span",{className:"ll-overflow-popover__lang-code",children:"EN"}),t.jsx("span",{children:"English"})]})]})]})};function xr(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[t.jsx("circle",{cx:"6",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"18",cy:"12",r:"1.5"})]})}function vr(){return t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}const br=({position:e,isMobile:r,agentName:o,avatarImageUrl:i,idleLoopUrl:s,greeting:a,branding:f,teamMembers:d,currentTeamMemberId:u,isSwitchingTeamMember:p,teamSwitcherOpen:m,onToggleTeamSwitcher:l,onSelectTeamMember:c,languageMenuOpen:L,onToggleLanguageMenu:N,connectionState:k,agentState:x,transcript:v,canResume:C,needsUserGesture:E,error:M,isMuted:b,micError:S,micDevices:$,isCameraEnabled:I,cameraPreviewEl:j,cameraDevices:A,activeCameraId:O,isScreenShareEnabled:F,screenPreviewEl:ne,isSpeakerMuted:J,allowCamera:be,allowScreenShare:ae,allowTyping:he,showMinimize:le=!0,chromeless:re=!1,compactControls:Y=!1,transforming:tt,transformingLabel:We,avatarVideoContainerRef:nt,agentVideoEl:Q,onConnect:Be,onDisconnect:qe,onRetry:rt,onResumeAudio:Fe,onToggleMute:we,onToggleCamera:_e,onSwitchCameraDevice:Ae,onToggleScreenShare:ke,onToggleSpeaker:je,onSendMessage:Ce,onMinimize:Le,onClose:z,onClearMicError:pt})=>{var Pe;const Se=((d==null?void 0:d.length)??0)>1,Me=k==="connecting"||k==="connected",Z=k==="connected",Ue=k==="idle"||k==="disconnected"||k==="error",[Ee,Ie]=n.useState(!1);n.useEffect(()=>{if(!Q){Ie(!1);return}if(!Q.paused&&Q.readyState>=2){Ie(!0);return}Ie(!1);const g=()=>Ie(!0);return Q.addEventListener("playing",g),Q.addEventListener("loadeddata",g),()=>{Q.removeEventListener("playing",g),Q.removeEventListener("loadeddata",g)}},[Q]);const[ht,me]=n.useState(!1);n.useEffect(()=>{if(!Z){me(!1);return}if(Ee)return;const g=setTimeout(()=>me(!0),8e3);return()=>clearTimeout(g)},[Z,Ee]);const G=k==="connecting"||Z&&!!i&&!Ee&&!ht,Ve=n.useRef(null),Re=n.useRef(null);n.useEffect(()=>{const g=Ve.current;g&&(g.innerHTML="",j&&(j.style.width="100%",j.style.height="100%",j.style.objectFit="cover",j.style.transform="scaleX(-1)",g.appendChild(j)))},[j]),n.useEffect(()=>{const g=Re.current;g&&(g.innerHTML="",ne&&(ne.style.width="100%",ne.style.height="100%",ne.style.objectFit="contain",g.appendChild(ne)))},[ne]);const[oe,X]=n.useState(!1),[ce,ge]=n.useState(!1);n.useEffect(()=>{if(!oe&&!ce&&!L&&!m)return;const g=()=>{X(!1),ge(!1),L&&N(),m&&l()};return document.addEventListener("click",g),()=>document.removeEventListener("click",g)},[oe,ce,L,m,N,l]);const[ee,ue]=n.useState(!1),Ne=n.useCallback(()=>ue(g=>!g),[]),[ye,ot]=n.useState(""),Ye=n.useCallback(g=>{g.preventDefault();const W=ye.trim();W&&(Ce(W),ot(""))},[ye,Ce]),Ge=f.productName||"Live Layer";let de=null,ie=null;for(let g=v.length-1;g>=0;g--){const W=v[g];if(!de&&W.role==="agent"?de=W:!ie&&W.role==="user"&&(ie=W),de&&ie)break}const Te=Z?(de==null?void 0:de.text)||null:a||null,it=Z&&(ie==null?void 0:ie.text)||null,mt=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:mt,"data-position":e,"data-state":Z?"connected":Me?"connecting":"idle",role:"dialog","aria-label":`${o} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[i?t.jsx(hr,{src:i,alt:o,className:"ll-expanded__bg-img"}):t.jsx("div",{className:"ll-expanded__bg-fallback",children:t.jsx("span",{className:"ll-expanded__bg-initial",children:((Pe=o==null?void 0:o.charAt(0))==null?void 0:Pe.toUpperCase())||"A"})}),s&&!Z&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:nt,className:"ll-expanded__video"}),G&&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:p?"Switching...":"Connecting..."})]}),E&&Z&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:Fe,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"})]}),tt&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":We,children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:We})]}),Me?t.jsxs(t.Fragment,{children:[!Y&&t.jsxs("div",{className:"ll-expanded__topbar",children:[!re&&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:g=>{Se&&(g.stopPropagation(),l())},"aria-haspopup":Se?"listbox":void 0,"aria-expanded":Se?m:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:o}),Se&&t.jsx(at,{})]}),Se&&m&&t.jsx("div",{className:"ll-hmenu",onClick:g=>g.stopPropagation(),role:"listbox",children:d==null?void 0:d.map(g=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${g.id===u?"is-active":""}`,onClick:()=>c(g.id),role:"option","aria-selected":g.id===u,children:[g.avatarImageUrl&&t.jsx("img",{src:g.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:g.name}),g.role&&t.jsx("span",{className:"ll-hmenu__role",children:g.role})]},g.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:g=>{g.stopPropagation(),N()},"aria-haspopup":"listbox","aria-expanded":L,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(at,{})]}),L&&t.jsx("div",{className:"ll-hmenu",onClick:g=>g.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:[le!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn",onClick:Le,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(Xt,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:z,"aria-label":"End call",title:"End call",children:t.jsx(Jt,{})})]})]}),Y&&t.jsxs("div",{className:"ll-compact-status","data-state":x,children:[t.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),t.jsx("span",{className:"ll-compact-status__label",children:x})]})]}):!Y&&t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:Ge}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[le!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:Le,"aria-label":"Minimize widget",children:t.jsx(Xt,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:z,"aria-label":"Close widget",children:t.jsx(Jt,{})})]})]}),Ue&&(()=>{const g=C?"Restart paused session":k==="disconnected"?"Reconnect to agent":"Start video call",W=C?"Pick up where you left off":null,De=!M;return t.jsxs(t.Fragment,{children:[De&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:Be,"aria-label":g,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:g})]}),!Y&&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:Be,"aria-label":g,children:g})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${Me&&(I||F)?"is-visible":""}`,children:[t.jsx("div",{ref:Re,className:F?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:Ve,className:!F&&I?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),Me?t.jsxs("div",{className:"ll-expanded__bottom",children:[!Y&&Te&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Te})}),!Y&&it&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:it})}),!re&&!Y&&t.jsxs("div",{className:"ll-toolbar",onClick:g=>g.stopPropagation(),children:[ae&&t.jsx("button",{type:"button",className:`ll-tool ${F?"is-on":""}`,onClick:ke,"aria-label":F?"Stop sharing screen":"Share screen",title:F?"Stop sharing":"Share screen",children:t.jsx(bn,{})}),be&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${I?"is-on":""}`,onClick:_e,"aria-label":I?"Turn off camera":"Turn on camera",title:I?"Stop camera":"Start camera",children:t.jsx(wn,{})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${I?"is-on":""}`,onClick:g=>{g.stopPropagation(),ge(W=>!W),X(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":ce,children:t.jsx(at,{})}),ce&&A.length>0&&t.jsx(Qt,{label:"Camera",devices:A,activeId:O,onPick:g=>{ge(!1),Ae(g)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${b?"is-muted":""}`,onClick:we,"aria-label":b?"Unmute microphone":"Mute microphone",title:b?"Unmute":"Mute",children:t.jsx(_n,{muted:b})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${b?"is-muted":""}`,onClick:g=>{g.stopPropagation(),X(W=>!W),ge(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":oe,children:t.jsx(at,{})}),oe&&$.length>0&&t.jsx(Qt,{label:"Microphone",devices:$,activeId:"",onPick:()=>X(!1)})]}),t.jsx("button",{type:"button",className:`ll-tool ${J?"is-muted":""}`,onClick:je,"aria-label":J?"Unmute speaker":"Mute speaker",title:J?"Unmute speaker":"Mute speaker",children:t.jsx(kn,{muted:J})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:qe,"aria-label":"End conversation",title:"End conversation",children:t.jsx(jn,{})})]}),!re&&Y&&t.jsx(yr,{isMuted:b,onToggleMute:we,isCameraEnabled:I,onToggleCamera:_e,allowCamera:be,isScreenShareEnabled:F,onToggleScreenShare:ke,allowScreenShare:ae,isSpeakerMuted:J,onToggleSpeaker:je,allowTyping:he,isTypingOpen:ee,onToggleTyping:Ne,onDisconnect:qe}),!re&&he&&(Y?ee:!0)&&t.jsxs("form",{className:"ll-message-input",onSubmit:Ye,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:ye,onChange:g=>ot(g.target.value),"aria-label":"Message the agent"}),ye.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(wr,{})})]})]}):null,(()=>{if(S&&k!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:S}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:pt,"aria-label":"Dismiss",children:"×"})]});if(!M||k!=="error")return null;let g="Failed to connect",W="Try again";return M==="MIC_PERMISSION_DENIED"?g="Microphone blocked. Allow access to talk.":M==="MIC_NOT_FOUND"?g="No microphone found. Plug one in + retry.":M==="MIC_UNAVAILABLE"?g="Mic unavailable. Check other apps using it.":M==="AGENT_TIMEOUT"?g="Agent didn't pick up. Try again.":M==="CONNECT_FAILED"?g="Connection failed. Check your network.":M.length<80&&(g=M),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:g}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:rt,children:W})]})})()]})};function at(){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 Jt(){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 Xt(){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 bn(){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 wn(){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 _n({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 kn({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 wr(){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 jn(){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 Qt=({label:e,devices:r,activeId:o,onPick:i})=>t.jsxs("div",{className:"ll-device-menu",onClick:s=>s.stopPropagation(),role:"listbox",children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),r.map((s,a)=>{const f=o===s.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${f?"is-active":""}`,onClick:()=>i(s.deviceId),role:"option","aria-selected":f,children:[f&&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)})]}),_r=['[data-ll-private="true"]',".ll-widget"];function jt(e){let r=e;for(;r;){for(const o of _r)if(r.matches(o))return!0;r=r.parentElement}return!1}function ft(e){if(jt(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 lt=4096,kr=20,jr=20,Cr=10,Lr=10,Sr=30,Er=20,Zt=500,Rr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function Ze(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let r=e;for(;r;){for(const o of Rr)if(r.matches(o))return!0;r=r.parentElement}return!1}function et(e){if(typeof window>"u")return!0;const r=e.getBoundingClientRect();if(r.width<=0||r.height<=0)return!1;const o=window.innerHeight||document.documentElement.clientHeight,i=window.innerWidth||document.documentElement.clientWidth;return r.bottom>0&&r.right>0&&r.top<o&&r.left<i}function en(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 o=e.getAttribute("aria-label");if(o)return o.trim();const i=e.getAttribute("placeholder");if(i)return i.trim();const s=e.closest("label");return s!=null&&s.textContent?s.textContent.trim():""}function pe(e,r){return e.length<=r?e:e.slice(0,r-1)+"…"}function ze(e){return e.length}function Cn(e,r={}){const o=r.doc??(typeof document<"u"?document:null);if(!o)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const i=typeof window<"u"&&window.location.href||"",s=typeof window<"u"&&window.location.pathname||"/",a=o.title||"",f=Array.from(o.querySelectorAll("[data-ll-region]")),d=[];for(const b of f){if(d.length>=Cr)break;if(Ze(b)||!et(b))continue;const S=b.getAttribute("data-ll-region")??"",$=b.getAttribute("data-ll-intent")??void 0,I=pe((b.innerText||b.textContent||"").trim(),Zt*2);!S||!I||d.push({id:S,intent:$,text:I})}const u=[],p=["H1","H2","H3","H4","H5","H6"],m=Array.from(o.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const b of m){if(Ze(b)||!et(b))continue;const S=(b.textContent||"").trim();S&&u.push(`${b.tagName}: ${pe(S,200)}`)}const l=Array.from(o.querySelectorAll("p, li"));for(const b of l){if(Ze(b)||!et(b)||p.includes(b.tagName))continue;const S=(b.textContent||"").trim();S.length>10&&u.push(pe(S,Zt))}const c=u.join(`
|
|
2
|
+
`),L=[],N=Array.from(o.querySelectorAll("a[href]"));for(const b of N){if(L.length>=kr)break;if(Ze(b)||!et(b))continue;const S=b.getAttribute("href")||"",$=(b.textContent||"").trim();!S||!$||L.push({href:S,text:pe($,100)})}const k=[],x=Array.from(o.querySelectorAll("input, textarea, select"));for(const b of x){if(k.length>=jr)break;if(Ze(b)||!ft(b)||!et(b))continue;const S=en(b),$=b instanceof HTMLInputElement?b.type:b.tagName.toLowerCase();S&&k.push({label:pe(S,100),type:$})}const v=Array.from(o.querySelectorAll("[data-ll-form]")),C=[];for(const b of v){if(C.length>=Lr)break;if(jt(b))continue;const S=b.getAttribute("data-ll-form")||"";if(!S)continue;const $=b.getAttribute("data-ll-intent")||void 0,I=Array.from(b.querySelectorAll("[data-ll-field]")),j=[];for(const A of I){if(j.length>=Sr)break;if(!ft(A))continue;const O=A.getAttribute("data-ll-field")||"";if(!O)continue;const F=en(A)||O,ne=A instanceof HTMLInputElement?A.type:A.tagName.toLowerCase(),J={name:O,label:pe(F,100),type:ne};if(A.required===!0&&(J.required=!0),A instanceof HTMLSelectElement){const ae=[];for(let he=0;he<A.options.length&&!(ae.length>=Er);he++){const le=A.options[he];if(!le||le.disabled)continue;const re=le.value||"",Y=(le.textContent||"").trim()||re;!re&&!Y||ae.push({value:re,label:pe(Y,60)})}ae.length>0&&(J.options=ae)}const be=typeof A.validationMessage=="string"?A.validationMessage:"";be&&(J.validationMessage=pe(be,200)),j.push(J)}C.push({id:S,intent:$,fields:j})}const E={url:i,title:a,pathname:s,regions:d,visibleText:c,visibleLinks:L,visibleFields:k,forms:C,extras:e};let M=ze(JSON.stringify(E.regions))+ze(E.visibleText)+ze(JSON.stringify(E.visibleLinks))+ze(JSON.stringify(E.visibleFields));for(;M>lt&&E.visibleFields.length>0;)E.visibleFields.pop(),M=ze(JSON.stringify(E.visibleFields));for(;M>lt&&E.visibleLinks.length>0;)E.visibleLinks.pop(),M-=80;return ze(E.visibleText)>lt&&(E.visibleText=pe(E.visibleText,lt-100)),E}let Oe=null;function kt(e,r={}){const o=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(Oe&&Oe.key===s&&o-Oe.at<1e3)return Oe.ctx;const a=Cn(e,r);return Oe={key:s,at:o,ctx:a},a}function Ln(){Oe=null}const Nr=200;function Sn(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 Ar(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function En(e){const r=e??(typeof document<"u"?document:null);if(!r)return[];const o=typeof window<"u"&&window.location.origin||"",i=new Set,s=[],a=Array.from(r.querySelectorAll("a[href]"));for(const f of a){if(s.length>=Nr)break;if(jt(f))continue;const d=f.getAttribute("href")||"";if(!Ar(d))continue;let u=d,p=!0;try{if(typeof window<"u"){const l=new URL(d,o);p=l.origin===o,p&&d.startsWith("http")&&(u=l.pathname+l.search+l.hash)}}catch{continue}if(i.has(u))continue;i.add(u);const m=(f.textContent||"").trim().slice(0,120);s.push({href:u,text:m,internal:p})}return s}let He=null;const Mr=5e3;function ct(){const e=Date.now(),r=typeof window<"u"&&window.location.pathname||"/";if(He&&He.pathname===r&&e-He.at<Mr)return He.routes;const o=En();return He={at:e,pathname:r,routes:o},o}function Rn(){He=null}function Ir(e,r){const o=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,i=Object.getOwnPropertyDescriptor(o,"value"),s=i==null?void 0:i.set;s?s.call(e,r):e.value=r}function Tr(e,r,o={}){const i=o.triggerInput??!0,s=o.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const a=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),f=a==null?void 0:a.set,d=r==="true"||r==="1"||r==="on";f?f.call(e,d):e.checked=d,i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}Ir(e,r),i&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function Pr(){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 Dr(e){if(!(e instanceof HTMLElement))return!1;const o=window.getComputedStyle(e).overflowY;return!(o!=="auto"&&o!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function $r(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let r=null,o=0;for(const i of e){if(!Dr(i))continue;const s=i.getBoundingClientRect();if(s.bottom<=0||s.top>=window.innerHeight||s.right<=0||s.left>=window.innerWidth||s.width<=0||s.height<=0||i.closest(".ll-widget"))continue;const a=s.width*s.height;a>o&&(o=a,r=i)}return r}function zr(){if(typeof window>"u")return null;if(Pr())return window;const e=$r();return e||window}function tn(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function Or(e){var r,o;return e instanceof Window?typeof document>"u"?0:Math.max(((r=document.body)==null?void 0:r.scrollHeight)??0,((o=document.documentElement)==null?void 0:o.scrollHeight)??0):e.scrollHeight-e.clientHeight}const Hr=new Set(["agent_state","avatar_stream_ready","avatar_active","avatar_idle","bot_ready","agent_error","idle_warning","idle_timeout","navigate","scroll_to","request_page_context","scroll_page","click","fill_form","focus_field","submit_form","request_routes"]),Nn=n.forwardRef(function(r,o){var It,Tt,Pt,Dt,$t,zt,Ot;const{agentId:i,apiKey:s,baseUrl:a="https://app.livelayer.studio",sessionEndpoint:f,sessionBody:d,soundEffects:u,experienceMode:p="WIDGET",autoConnect:m=!1,displayMode:l,defaultDisplayMode:c="expanded",onDisplayModeChange:L,position:N="bottom-right",mobileBreakpoint:k=640,persistKey:x="ll-widget",disablePersistence:v=!1,teamMembers:C,currentTeamMemberId:E,onTeamMemberChange:M,idleLoopUrl:b,greeting:S,avatarImageUrl:$,agentName:I,branding:j={},allowCamera:A=!0,allowScreenShare:O=!0,allowTyping:F=!0,showMinimize:ne=!0,chromeless:J=!1,compactControls:be=!1,transforming:ae=!1,transformingLabel:he="Transforming…",showOn:le,hideOn:re,pathname:Y,onNavigate:tt,onScrollToSelector:We,getPageContext:nt,pageContextExtras:Q,getRoutes:Be,onScrollPage:qe,onClick:rt,capabilities:Fe,onConnect:we,onDisconnect:_e,onTranscript:Ae,onAgentState:ke,onConnectionStateChange:je,onAgentEvent:Ce,onAgentCommand:Le,controlledSession:z,className:pt,style:Se,zIndex:Me=2147483647}=r,Z=mn(Y),Ue=xn(Z,le,re);n.useEffect(()=>{Ln(),Rn()},[Z]);const Ee=E!==void 0,[Ie,ht]=n.useState(()=>{var y;return E??((y=C==null?void 0:C[0])==null?void 0:y.id)}),me=Ee?E:Ie,G=n.useMemo(()=>(C==null?void 0:C.find(y=>y.id===me))??null,[C,me]),Ve=(G==null?void 0:G.agentId)??i,Re=p==="EMBEDDED",[oe,X]=pn({value:Re?"expanded":l,defaultValue:Re?"expanded":c,onChange:L,persistKey:x,disablePersistence:Re||v}),ce=hn(k),ge=sn(),ee=an(),ue=ln(),Ne=cn(),ye=un(),[ot,Ye]=n.useState(!1),[Ge,de]=n.useState(!1),[ie,Te]=n.useState(!1),[it,mt]=n.useState(!1),[Pe,g]=n.useState(!1),W=ir({baseUrl:a,config:u}),De=n.useRef(W);De.current=W;const gt=n.useRef(tt),yt=n.useRef(We),xt=n.useRef(qe),vt=n.useRef(rt),Ct=n.useRef(nt),Lt=n.useRef(Q),St=n.useRef(Be),bt=n.useRef(Fe),se=n.useRef(null);gt.current=tt,yt.current=We,xt.current=qe,vt.current=rt,Ct.current=nt,Lt.current=Q,St.current=Be,bt.current=Fe;function xe(y){const h=bt.current;return h?h.includes(y):!0}function ve(y,h){console.warn(`[LiveLayer] Agent command "${y}" blocked — capability "${h}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const Ke=n.useCallback(y=>{var q,te,fe,Qe;const h=y;if(!(!h.type||typeof h.type!="string")){if(Ce==null||Ce({eventName:h.type,data:y}),h.type==="navigate"){if(!xe("navigate")){ve("navigate","navigate");return}const _=typeof h.href=="string"?h.href:null;if(!_){console.warn(`[LiveLayer] Agent emitted "navigate" without href. Skipping. Check your agent's tool schema. See https://livelayer.studio/docs/errors/navigate-missing-href`);return}if(De.current.playPageChange(),gt.current){try{gt.current(_)}catch(R){console.warn(`[LiveLayer] onNavigate threw for "${_}". Falling back. Error:`,R)}return}if(typeof document<"u"){const R=document.querySelector(`a[href="${_.replace(/"/g,'\\"')}"]`);if(R){R.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",_),window.dispatchEvent(new PopStateEvent("popstate"))}catch(R){console.warn(`[LiveLayer] history.pushState fallback failed for "${_}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,R)}return}if(h.type==="scroll_to"){if(!xe("scroll")){ve("scroll_to","scroll");return}const _=typeof h.selector=="string"?h.selector:null;if(!_)return;const R=h.behavior==="instant"?"instant":"smooth";if(yt.current){try{yt.current(_,R)}catch(D){console.warn("[LiveLayer] onScrollToSelector threw.",D)}return}if(typeof document<"u"){let D=null;try{D=document.querySelector(_)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${_}".`);return}if(!D){console.warn(`[LiveLayer] scroll_to: no element matched "${_}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}D.scrollIntoView({behavior:R,block:"start"})}return}if(h.type==="request_page_context"){if(!xe("read_page")){ve("request_page_context","read_page");return}const _=typeof h.requestId=="string"?h.requestId:void 0,R=(q=se.current)==null?void 0:q.call(se),D=B=>{const T=R,V=T==null?void 0:T.localParticipant;if(V!=null&&V.publishData)try{const K=_?{...B,requestId:_}:B,$e=new TextEncoder().encode(JSON.stringify(K));V.publishData($e,{reliable:!0})}catch(K){console.warn("[LiveLayer] publishData failed.",K)}},P=Lt.current,H=Ct.current;try{if(H){const B=H(P);if(B instanceof Promise){D({type:"page_context_pending"}),B.then(T=>D({type:"page_context",context:T})).catch(T=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",T),D({type:"page_context",context:kt(P)})});return}D({type:"page_context",context:B});return}D({type:"page_context",context:kt(P)})}catch(B){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",B),D({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:P}})}return}if(h.type==="scroll_page"){if(!xe("scroll")){ve("scroll_page","scroll");return}const _=h.direction;if(_!=="up"&&_!=="down"&&_!=="top"&&_!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(_)}". Expected up | down | top | bottom.`);return}const R=h.behavior==="instant"?"instant":"smooth";if(xt.current){try{xt.current(_,R)}catch(T){console.warn("[LiveLayer] onScrollPage threw.",T)}return}if(typeof window>"u")return;const D={behavior:R},P=zr(),H=T=>{P instanceof Window?P.scrollBy({top:T,...D}):P.scrollBy({top:T,...D})},B=T=>{P instanceof Window?P.scrollTo({top:T,...D}):P.scrollTo({top:T,...D})};_==="up"?H(-tn(P)):_==="down"?H(tn(P)):B(_==="top"?0:Or(P));return}if(h.type==="click"){if(!xe("click")){ve("click","click");return}const _=typeof h.selector=="string"?h.selector:null;if(!_){console.warn("[LiveLayer] click: missing selector.");return}if(vt.current){try{vt.current(_)}catch(D){console.warn("[LiveLayer] onClick threw.",D)}return}if(typeof document>"u")return;let R=null;try{R=document.querySelector(_)}catch{console.warn(`[LiveLayer] click: invalid selector "${_}".`);return}if(!R){console.warn(`[LiveLayer] click: no element matched "${_}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(te=R.click)==null||te.call(R);return}if(h.type==="fill_form"||h.type==="focus_field"){if(!xe("fill_forms")){ve(h.type,"fill_forms");return}if(typeof document>"u")return;h.type==="fill_form"&&De.current.playConfirmation();const _=typeof h.formId=="string"?h.formId:null;if(!_){console.warn(`[LiveLayer] ${h.type}: missing formId.`);return}const R=document.querySelector(`[data-ll-form="${_.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] ${h.type}: no form with data-ll-form="${_}". Tag your form with <LiveLayerForm id> or data-ll-form. See https://livelayer.studio/docs/react/forms`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn(`[LiveLayer] ${h.type}: refusing to touch a form in a private subtree.`);return}if(h.type==="focus_field"){const P=typeof h.fieldName=="string"?h.fieldName:null;if(!P){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const H=R.querySelector(`[data-ll-field="${P.replace(/"/g,'\\"')}"]`);if(!H){console.warn(`[LiveLayer] focus_field: no field "${P}" in form "${_}".`);return}if(!ft(H)){console.warn(`[LiveLayer] focus_field: field "${P}" is privacy-protected and not focusable.`);return}H.focus();return}const D=h.values&&typeof h.values=="object"?h.values:null;if(!D){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[P,H]of Object.entries(D)){if(typeof H!="string")continue;const B=R.querySelector(`[data-ll-field="${P.replace(/"/g,'\\"')}"]`);if(!B){console.warn(`[LiveLayer] fill_form: no field "${P}" in form "${_}". Skipping.`);continue}if(!ft(B)){console.warn(`[LiveLayer] fill_form: field "${P}" is privacy-protected (password / cc-* / private). Skipping.`);continue}try{Tr(B,H)}catch(T){console.warn(`[LiveLayer] fill_form: failed to set "${P}".`,T)}}return}if(h.type==="submit_form"){if(!xe("submit_forms")){ve("submit_form","submit_forms");return}if(typeof document>"u")return;const _=typeof h.formId=="string"?h.formId:null;if(!_){console.warn("[LiveLayer] submit_form: missing formId.");return}De.current.playConfirmation();const R=document.querySelector(`[data-ll-form="${_.replace(/"/g,'\\"')}"]`);if(!R){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${_}".`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private subtree.");return}const D=typeof h.requestId=="string"?h.requestId:void 0,P=(fe=se.current)==null?void 0:fe.call(se),H=V=>{const K=P,$e=K==null?void 0:K.localParticipant;if($e!=null&&$e.publishData)try{const qn=D?{...V,requestId:D}:V,Fn=new TextEncoder().encode(JSON.stringify(qn));$e.publishData(Fn,{reliable:!0})}catch{}};let B=!1;const T=()=>{B=!0,H({type:"form_submitted",formId:_})};R.addEventListener("submit",T,{once:!0});try{typeof R.requestSubmit=="function"?R.requestSubmit():R.submit()}catch(V){console.warn("[LiveLayer] submit_form: requestSubmit threw.",V),R.removeEventListener("submit",T),H({type:"form_submit_blocked",formId:_,reason:"exception"});return}setTimeout(()=>{B||(R.removeEventListener("submit",T),H({type:"form_submit_blocked",formId:_,reason:"validation"}))},500);return}if(h.type==="request_routes"){if(!xe("read_page")){ve("request_routes","read_page");return}const _=typeof h.requestId=="string"?h.requestId:void 0,D=(Qe=se.current)==null?void 0:Qe.call(se),P=D==null?void 0:D.localParticipant;if(!(P!=null&&P.publishData))return;const H=T=>{try{const V=_?{type:"routes",routes:T,requestId:_}:{type:"routes",routes:T},K=new TextEncoder().encode(JSON.stringify(V));P.publishData(K,{reliable:!0})}catch(V){console.warn("[LiveLayer] request_routes: publishData failed.",V)}},B=St.current;if(B){try{const T=B(),V=K=>{if(!Array.isArray(K)){H([]);return}H(K.map(Sn).slice(0,200))};T instanceof Promise?T.then(V).catch(K=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",K),H(ct())}):V(T)}catch(T){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",T),H(ct())}return}try{H(ct())}catch(T){console.warn("[LiveLayer] request_routes: extractRoutes threw.",T)}return}Hr.has(h.type)||Le==null||Le(h)}},[Le,Ce]),U=on({agentId:z?"__controlled__":Ve,baseUrl:a,apiKey:s,sessionEndpoint:f,sessionBody:d,onDataMessage:z?void 0:Ke});n.useEffect(()=>{if(z!=null&&z.subscribeToDataMessages)return z.subscribeToDataMessages(Ke)},[z,Ke]),se.current=()=>{var y;return(y=U.getRoom)==null?void 0:y.call(U)},n.useEffect(()=>{var q;if(typeof window>"u")return;const y=((q=window.location)==null?void 0:q.hostname)||"";if(y==="localhost"||y==="127.0.0.1"||y==="0.0.0.0"||y.endsWith(".local")||y.endsWith(".test"))return window.__livelayerSimulateCommand=te=>{try{Ke(te)}catch(fe){console.warn("[LiveLayer] simulate-command threw:",fe)}},()=>{delete window.__livelayerSimulateCommand}},[Ke]);const w=n.useMemo(()=>z?{connectionState:z.connectionState,agentState:z.agentState,transcript:z.transcript,videoElement:z.videoElement,audioElement:z.audioElement,canResume:z.canResume,error:z.error,agentConfig:null,connect:async()=>{await z.onConnect()},disconnect:()=>z.onDisconnect(),getRoom:U.getRoom,isControlled:!0}:{connectionState:U.connectionState,agentState:U.agentState,transcript:U.transcript,videoElement:U.videoElement,audioElement:U.audioElement,canResume:U.canResume,error:U.error,agentConfig:U.agentConfig,connect:U.connect,disconnect:U.disconnect,getRoom:U.getRoom,isControlled:!1},[z,U]),Et=n.useRef(w);Et.current=w;const Rt=n.useRef(z);Rt.current=z,n.useImperativeHandle(o,()=>({sendData:async y=>{var fe,Qe;const h=Rt.current;if(h!=null&&h.publishData){try{await h.publishData(y)}catch(_){console.warn("[AvatarWidget] sendData (controlled) failed:",_)}return}const q=(Qe=(fe=Et.current)==null?void 0:fe.getRoom)==null?void 0:Qe.call(fe),te=q==null?void 0:q.localParticipant;if(te!=null&&te.publishData)try{const _=new TextEncoder().encode(JSON.stringify(y));await te.publishData(_,{reliable:!0})}catch(_){console.warn("[AvatarWidget] sendData failed:",_)}}}),[]);const Nt=n.useRef(null);n.useEffect(()=>{const y=w.videoElement,h=Nt.current;if(!(!y||!h))return h.appendChild(y),()=>{y.parentNode===h&&h.removeChild(y)}},[w.videoElement]),n.useEffect(()=>{const y=w.audioElement;if(!y)return;ge.attach(y);const h=y.play();return h&&typeof h.catch=="function"&&h.catch(q=>{(q==null?void 0:q.name)==="NotAllowedError"&&Ye(!0)}),()=>{ge.detach()}},[w.audioElement]),n.useEffect(()=>{if(w.isControlled||w.connectionState!=="connected")return;const y=w.getRoom();if(y)return ee.setupMic(y).catch(()=>{}),ue.attachRoom(y),Ne.attachRoom(y),ye.refresh(),()=>{ee.teardownMic(),ue.teardown(),Ne.teardown()}},[w.isControlled,w.connectionState]),n.useEffect(()=>{const y=w.audioElement;y&&(y.muted=Pe)},[w.audioElement,Pe]);const Mn=n.useCallback(y=>{const h={type:"user_message",text:y};if(z!=null&&z.publishData){try{z.publishData(h)}catch{}return}const q=w.getRoom();if(q)try{const te=new TextEncoder().encode(JSON.stringify(h));q.localParticipant.publishData(te,{reliable:!0})}catch{}},[w,z]),In=n.useCallback(()=>{g(y=>!y)},[]);n.useEffect(()=>{je==null||je(w.connectionState),w.connectionState==="connected"?we==null||we():w.connectionState==="disconnected"&&(_e==null||_e())},[w.connectionState,we,_e,je]),n.useEffect(()=>{Ae==null||Ae(w.transcript)},[w.transcript,Ae]),n.useEffect(()=>{ke==null||ke(w.agentState)},[w.agentState,ke]),n.useEffect(()=>{W.setThinking(w.agentState==="thinking")},[w.agentState,W]);const At=n.useRef(!1);n.useEffect(()=>{w.isControlled||!m||At.current||Ue&&w.connectionState==="idle"&&(At.current=!0,w.connect())},[m,w.connectionState,w,Ue]);const Tn=n.useCallback(y=>{const h=C==null?void 0:C.find(q=>q.id===y);h&&(Te(!1),y!==me&&(de(!0),w.disconnect(),Ee||ht(y),M==null||M(h)))},[C,me,w,Ee,M]);n.useEffect(()=>{Ge&&w.connectionState==="connected"&&de(!1)},[w.connectionState,Ge]),n.useEffect(()=>{if(!ie)return;const y=h=>{h.key==="Escape"&&Te(!1)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[ie]);const Pn=!!$||!!(G!=null&&G.avatarImageUrl)||w.isControlled,Je=dn(Ve,a,Pn);Fe===void 0&&((It=Je.info)!=null&&It.capabilities)&&(bt.current=Je.info.capabilities);const st=(G==null?void 0:G.name)??I??((Tt=w.agentConfig)==null?void 0:Tt.name)??((Pt=Je.info)==null?void 0:Pt.name)??"Live Layer",wt=(G==null?void 0:G.avatarImageUrl)??$??((Dt=w.agentConfig)==null?void 0:Dt.avatarImageUrl)??(($t=Je.info)==null?void 0:$t.avatarImageUrl)??null,Dn=b??((zt=w.agentConfig)==null?void 0:zt.idleLoopUrl)??((Ot=Je.info)==null?void 0:Ot.idleLoopUrl)??null,$n=S??null,zn=n.useCallback(()=>X("expanded"),[X]),On=n.useCallback(()=>X("minimized"),[X]),Mt=n.useCallback(()=>{w.disconnect(),X("hidden")},[w,X]),Hn=n.useCallback(()=>{const y=w.audioElement;y&&y.play().then(()=>Ye(!1)).catch(()=>{})},[w.audioElement]),Wn=n.useCallback(()=>{Ye(!1),w.connect()},[w]),Xe={...Se,...Re?{}:{zIndex:Me}};j.primaryColor&&(Xe["--ll-color-primary"]=j.primaryColor),j.accentColor&&(Xe["--ll-color-accent"]=j.accentColor),j.backgroundColor&&(Xe["--ll-color-bg"]=j.backgroundColor),j.textColor&&(Xe["--ll-color-fg"]=j.textColor);const Bn=["ll-widget",`ll-widget--${oe}`,`ll-widget--${ce?"mobile":"desktop"}`,pt].filter(Boolean).join(" ");return Ue?t.jsxs("div",{className:Bn,style:Xe,"data-display-mode":oe,"data-position":N,"data-experience-mode":p==="EMBEDDED"?"embedded":"widget",children:[oe==="hidden"&&t.jsx(dr,{position:N,isMobile:ce,isSpeaking:w.agentState==="speaking",onExpand:()=>X("expanded"),label:`Open ${st} widget`,avatarImageUrl:wt,agentName:st}),oe==="minimized"&&t.jsx(pr,{position:N,isMobile:ce,agentName:st,avatarImageUrl:wt,agentState:w.agentState,isMuted:ee.isMuted,audioLevel:ge,onExpand:zn,onToggleMute:ee.toggleMute,onClose:Mt}),oe==="expanded"&&t.jsx(br,{position:N,isMobile:ce,agentName:st,avatarImageUrl:wt,idleLoopUrl:Dn,greeting:$n,branding:j,teamMembers:C,currentTeamMemberId:me,isSwitchingTeamMember:Ge,teamSwitcherOpen:ie,onToggleTeamSwitcher:()=>Te(y=>!y),onSelectTeamMember:Tn,connectionState:w.connectionState,agentState:w.agentState,transcript:w.transcript,isMuted:ee.isMuted,micDevices:ye.mics,isCameraEnabled:ue.isEnabled,cameraPreviewEl:ue.previewEl,cameraDevices:ye.cameras,activeCameraId:ue.activeDeviceId,isScreenShareEnabled:Ne.isEnabled,screenPreviewEl:Ne.previewEl,isSpeakerMuted:Pe,allowCamera:A,allowScreenShare:O,allowTyping:F,showMinimize:ne,chromeless:J,compactControls:be,transforming:ae,transformingLabel:he,languageMenuOpen:it,onToggleLanguageMenu:()=>mt(y=>!y),needsUserGesture:ot,canResume:w.canResume,micError:ee.micError,error:w.error,avatarVideoContainerRef:Nt,agentVideoEl:w.videoElement,onConnect:()=>void w.connect(),onDisconnect:()=>w.disconnect(),onRetry:Wn,onResumeAudio:Hn,onToggleMute:ee.toggleMute,onToggleCamera:()=>void ue.toggle(),onSwitchCameraDevice:y=>void ue.switchDevice(y),onToggleScreenShare:()=>void Ne.toggle(),onToggleSpeaker:In,onSendMessage:Mn,onMinimize:On,onClose:Mt,onClearMicError:ee.clearError})]}):null});Nn.displayName="AvatarWidgetInner";const An=n.forwardRef(function(r,o){return t.jsx(rn,{children:t.jsx(Nn,{...r,ref:o})})});An.displayName="AvatarWidget";const Wr=({agentId:e,baseUrl:r,apiKey:o,mode:i,onAgentEvent:s,className:a,style:f})=>{const d=n.useRef(null),u=n.useRef(null),p=n.useRef(s);p.current=s;const m=n.useCallback(l=>{var L;const c=l.detail;(L=p.current)==null||L.call(p,c)},[]);return n.useEffect(()=>{const l=d.current;if(!l)return;const c=document.createElement("livelayer-widget");return c.setAttribute("agent-id",e),r&&c.setAttribute("base-url",r),o&&c.setAttribute("api-key",o),i&&c.setAttribute("mode",i),c.addEventListener("agent-event",m),l.appendChild(c),u.current=c,()=>{c.removeEventListener("agent-event",m),l.removeChild(c),u.current=null}},[e]),n.useEffect(()=>{u.current&&(i?u.current.setAttribute("mode",i):u.current.removeAttribute("mode"))},[i]),t.jsx("div",{ref:d,className:a,style:f})},Br=n.forwardRef(function({id:r,intent:o,as:i="div",className:s,style:a,children:f},d){return n.createElement(i,{ref:d,"data-ll-region":r,"data-ll-intent":o,className:s,style:a},f)}),qr=n.forwardRef(function({id:r,intent:o,children:i,...s},a){return t.jsx("form",{ref:a,"data-ll-form":r,"data-ll-intent":o,...s,children:i})}),Fr=n.forwardRef(function(r,o){const{name:i,label:s,labelClassName:a}=r,f={name:i,"data-ll-field":i};let d;if("as"in r&&r.as==="textarea"){const{name:u,label:p,labelClassName:m,as:l,...c}=r;d=t.jsx("textarea",{ref:o,...f,...c})}else if("as"in r&&r.as==="select"){const{name:u,label:p,labelClassName:m,as:l,children:c,...L}=r;d=t.jsx("select",{ref:o,...f,...L,children:c})}else{const{name:u,label:p,labelClassName:m,as:l,...c}=r;d=t.jsx("input",{ref:o,...f,...c})}return s===void 0?d:t.jsxs("label",{className:a,children:[s,d]})});let nn=1;function Ur({onMount:e,defaultOpen:r=!1,storageKey:o="ll-debug-open"}){const[i,s]=n.useState(r),[a,f]=n.useState([]),[d,u]=n.useState(""),[p,m]=n.useState(!1),l=n.useRef(new Set),c=n.useRef([]),L=n.useRef(p);L.current=p,n.useEffect(()=>{try{const x=localStorage.getItem(o);x==="1"&&s(!0),x==="0"&&s(!1)}catch{}},[o]),n.useEffect(()=>{try{localStorage.setItem(o,i?"1":"0")}catch{}},[i,o]),n.useEffect(()=>{const x=v=>{(v.metaKey||v.ctrlKey)&&v.shiftKey&&v.key.toLowerCase()==="l"&&(v.preventDefault(),s(C=>!C))};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[]),n.useEffect(()=>{const x=setInterval(()=>{if(c.current.length===0||L.current)return;const v=c.current.splice(0,c.current.length);f(C=>[...v.reverse(),...C].slice(0,200))},100);return()=>clearInterval(x)},[]);const N=n.useRef(!1);if(n.useEffect(()=>{!e||N.current||(N.current=!0,e(x=>{c.current.push({id:nn++,ts:Date.now(),kind:"event",type:x.eventName,data:x.data})}))},[e]),n.useEffect(()=>{const x=console.warn,v=console.log,C=(E,M)=>function(...b){try{const S=typeof b[0]=="string"?b[0]:"";S.startsWith("[LiveLayer]")&&c.current.push({id:nn++,ts:Date.now(),kind:E,type:S.slice(0,120),data:{args:b.slice(1).map($=>Yr($))}})}catch{}return M.apply(this,b)};return console.warn=C("warn",x),console.log=C("log",v),()=>{console.warn=x,console.log=v}},[]),!i)return t.jsx("button",{type:"button",onClick:()=>s(!0),title:"Open LiveLayer debug panel (Cmd/Ctrl + Shift + L)","aria-label":"Open LiveLayer debug panel",style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.18)",borderRadius:999,padding:"6px 10px",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",cursor:"pointer",boxShadow:"0 4px 12px rgba(0,0,0,0.35)",opacity:.85},children:"🛰 LL debug"});const k=a.filter(x=>{if(!d)return!0;const v=d.toLowerCase();return x.type.toLowerCase().includes(v)||JSON.stringify(x.data||{}).toLowerCase().includes(v)});return t.jsxs("div",{style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,width:380,maxHeight:"60vh",background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.16)",borderRadius:12,boxShadow:"0 16px 48px rgba(0,0,0,0.5)",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"8px 10px",background:"rgba(255,255,255,0.04)",borderBottom:"1px solid rgba(255,255,255,0.1)",display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{fontWeight:600,fontSize:12},children:"LiveLayer debug"}),t.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:[a.length," event",a.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>m(x=>!x),style:_t(p?"#f59e0b":"transparent"),title:"Pause / resume capture",children:p?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{f([]),c.current=[]},style:_t("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:_t("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:d,onChange:x=>u(x.target.value),placeholder:"filter by type or data…",style:{margin:8,padding:"6px 8px",background:"rgba(255,255,255,0.06)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:"#fff",fontSize:11,outline:"none"}}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 8px 8px"},children:k.length===0?t.jsxs("div",{style:{padding:14,fontSize:11,color:"rgba(255,255,255,0.4)",lineHeight:1.5},children:["No events yet. Connect to the agent and trigger a tool call — the events will stream in here. You can also dispatch commands manually in DevTools:",t.jsx("pre",{style:{marginTop:6,background:"rgba(255,255,255,0.04)",padding:6,borderRadius:4,fontSize:10,whiteSpace:"pre-wrap"},children:`window.__livelayerSimulateCommand({
|
|
3
3
|
type: "navigate",
|
|
4
4
|
href: "/about"
|
|
5
5
|
})`})]}):k.map(x=>t.jsx(Vr,{entry:x,expanded:l.current.has(x.id),onToggle:()=>{l.current.has(x.id)?l.current.delete(x.id):l.current.add(x.id),f(v=>[...v])}},x.id))})]})}function Vr({entry:e,expanded:r,onToggle:o}){const i=e.kind==="warn"?"#f59e0b":e.type.startsWith("[LiveLayer]")?"#94a3b8":e.type==="navigate"||e.type==="scroll_page"||e.type==="scroll_to"||e.type==="click"?"#22c55e":e.type==="fill_form"||e.type==="submit_form"||e.type==="focus_field"?"#a78bfa":e.type==="request_page_context"||e.type==="request_routes"?"#38bdf8":e.type==="agent_state"?"#facc15":"#cbd5e1",s=new Date(e.ts).toLocaleTimeString("en-US",{hour12:!1});return t.jsxs("button",{type:"button",onClick:o,style:{textAlign:"left",background:"transparent",border:0,color:"#fff",width:"100%",padding:"6px 4px",cursor:"pointer",borderBottom:"1px solid rgba(255,255,255,0.04)",fontSize:11,lineHeight:1.4},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums",fontSize:10},children:s}),t.jsx("span",{style:{color:i,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),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 _t(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 Yr(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Gr(){const[e,r]=n.useState([]),o=n.useCallback(s=>{r(a=>{const f=a.findIndex(d=>d.id===s.id);if(f>=0){const d=a.slice();return d[f]=s,d}return[...a,s]})},[]),i=n.useCallback(()=>r([]),[]);return{entries:e,pushSegment:o,clear:i,latest:e.length>0?e[e.length-1]:null}}exports.AvatarWidget=An;exports.ErrorBoundary=rn;exports.LiveLayerDebugPanel=Ur;exports.LiveLayerField=Fr;exports.LiveLayerForm=qr;exports.LiveLayerRegion=Br;exports.LiveLayerWidget=Wr;exports.clearPageContextCache=Ln;exports.clearRoutesCache=Rn;exports.extractPageContext=Cn;exports.extractRoutes=En;exports.getCachedPageContext=kt;exports.getCachedRoutes=ct;exports.matchesPattern=gn;exports.normalizeRouteInput=Sn;exports.shouldRenderAtPath=yn;exports.useAgentInfo=dn;exports.useAudioLevel=sn;exports.useCameraState=ln;exports.useDisplayMode=fn;exports.useDisplayModePersistence=pn;exports.useIsMobile=hn;exports.useLiveKitSession=on;exports.useMediaDevices=un;exports.useMicrophoneState=an;exports.usePathname=mn;exports.useRouteMatch=xn;exports.useScreenShareState=cn;exports.useTranscript=Gr;
|
package/dist/index.mjs
CHANGED
|
@@ -1273,13 +1273,13 @@ const Sr = ({
|
|
|
1273
1273
|
activeCameraId: F,
|
|
1274
1274
|
isScreenShareEnabled: G,
|
|
1275
1275
|
screenPreviewEl: le,
|
|
1276
|
-
isSpeakerMuted:
|
|
1276
|
+
isSpeakerMuted: ee,
|
|
1277
1277
|
allowCamera: Le,
|
|
1278
1278
|
allowScreenShare: ue,
|
|
1279
1279
|
allowTyping: ve,
|
|
1280
1280
|
showMinimize: fe = !0,
|
|
1281
1281
|
chromeless: ae = !1,
|
|
1282
|
-
compactControls:
|
|
1282
|
+
compactControls: X = !1,
|
|
1283
1283
|
transforming: st,
|
|
1284
1284
|
transformingLabel: je,
|
|
1285
1285
|
avatarVideoContainerRef: ct,
|
|
@@ -1325,7 +1325,7 @@ const Sr = ({
|
|
|
1325
1325
|
const m = setTimeout(() => be(!0), 8e3);
|
|
1326
1326
|
return () => clearTimeout(m);
|
|
1327
1327
|
}, [re, Te]);
|
|
1328
|
-
const
|
|
1328
|
+
const Q = E === "connecting" || re && !!o && !Te && !bt, Ke = S(null), Me = S(null);
|
|
1329
1329
|
A(() => {
|
|
1330
1330
|
const m = Ke.current;
|
|
1331
1331
|
m && (m.innerHTML = "", C && (C.style.width = "100%", C.style.height = "100%", C.style.objectFit = "cover", C.style.transform = "scaleX(-1)", m.appendChild(C)));
|
|
@@ -1396,7 +1396,7 @@ const Sr = ({
|
|
|
1396
1396
|
)
|
|
1397
1397
|
] }),
|
|
1398
1398
|
/* @__PURE__ */ n("div", { ref: ct, className: "ll-expanded__video" }),
|
|
1399
|
-
|
|
1399
|
+
Q && /* @__PURE__ */ g("div", { className: "ll-expanded__overlay ll-expanded__overlay--connecting", children: [
|
|
1400
1400
|
/* @__PURE__ */ n("div", { className: "ll-expanded__spinner" }),
|
|
1401
1401
|
/* @__PURE__ */ n("p", { className: "ll-expanded__overlay-text", children: f ? "Switching..." : "Connecting..." })
|
|
1402
1402
|
] }),
|
|
@@ -1426,7 +1426,7 @@ const Sr = ({
|
|
|
1426
1426
|
}
|
|
1427
1427
|
),
|
|
1428
1428
|
$e ? /* @__PURE__ */ g(lt, { children: [
|
|
1429
|
-
!
|
|
1429
|
+
!X && /* @__PURE__ */ g("div", { className: "ll-expanded__topbar", children: [
|
|
1430
1430
|
!ae && /* @__PURE__ */ g("div", { className: "ll-expanded__topbar-left", children: [
|
|
1431
1431
|
/* @__PURE__ */ g("div", { className: "ll-expanded__pill-wrap", children: [
|
|
1432
1432
|
/* @__PURE__ */ g(
|
|
@@ -1548,13 +1548,16 @@ const Sr = ({
|
|
|
1548
1548
|
)
|
|
1549
1549
|
] })
|
|
1550
1550
|
] }),
|
|
1551
|
-
|
|
1551
|
+
X && /* @__PURE__ */ g("div", { className: "ll-compact-status", "data-state": v, children: [
|
|
1552
1552
|
/* @__PURE__ */ n("span", { className: "ll-compact-status__dot", "aria-hidden": !0 }),
|
|
1553
1553
|
/* @__PURE__ */ n("span", { className: "ll-compact-status__label", children: v })
|
|
1554
1554
|
] })
|
|
1555
1555
|
] }) : (
|
|
1556
|
-
// Idle-state header with Live Layer product name + minimize/close
|
|
1557
|
-
|
|
1556
|
+
// Idle-state header with Live Layer product name + minimize/close.
|
|
1557
|
+
// Hidden in compact mode — on a 140×210 docked slot the brand pill
|
|
1558
|
+
// and 40px buttons crowded out the central "Start video call"
|
|
1559
|
+
// affordance. The user can dismiss by scrolling past the slot.
|
|
1560
|
+
!X && /* @__PURE__ */ g("div", { className: "ll-expanded__header ll-expanded__header--idle", children: [
|
|
1558
1561
|
/* @__PURE__ */ n("span", { className: "ll-expanded__brand", children: Qe }),
|
|
1559
1562
|
/* @__PURE__ */ g("div", { className: "ll-expanded__header-actions", children: [
|
|
1560
1563
|
fe !== !1 && /* @__PURE__ */ n(
|
|
@@ -1596,7 +1599,7 @@ const Sr = ({
|
|
|
1596
1599
|
]
|
|
1597
1600
|
}
|
|
1598
1601
|
),
|
|
1599
|
-
/* @__PURE__ */ g("div", { className: "ll-expanded__bottom ll-expanded__bottom--idle", children: [
|
|
1602
|
+
!X && /* @__PURE__ */ g("div", { className: "ll-expanded__bottom ll-expanded__bottom--idle", children: [
|
|
1600
1603
|
l && /* @__PURE__ */ n("div", { className: "ll-expanded__transcript", children: /* @__PURE__ */ n("p", { className: "ll-expanded__transcript-text", children: l }) }),
|
|
1601
1604
|
j && /* @__PURE__ */ n("p", { className: "ll-expanded__cta-sublabel", children: j }),
|
|
1602
1605
|
/* @__PURE__ */ n(
|
|
@@ -1635,7 +1638,7 @@ const Sr = ({
|
|
|
1635
1638
|
}
|
|
1636
1639
|
),
|
|
1637
1640
|
$e ? /* @__PURE__ */ g("div", { className: "ll-expanded__bottom", children: [
|
|
1638
|
-
!
|
|
1641
|
+
!X && Oe && /* @__PURE__ */ n(
|
|
1639
1642
|
"div",
|
|
1640
1643
|
{
|
|
1641
1644
|
className: "ll-expanded__transcript ll-expanded__transcript--agent",
|
|
@@ -1643,7 +1646,7 @@ const Sr = ({
|
|
|
1643
1646
|
children: /* @__PURE__ */ n("p", { className: "ll-expanded__transcript-text", children: Oe })
|
|
1644
1647
|
}
|
|
1645
1648
|
),
|
|
1646
|
-
!
|
|
1649
|
+
!X && ft && /* @__PURE__ */ n(
|
|
1647
1650
|
"div",
|
|
1648
1651
|
{
|
|
1649
1652
|
className: "ll-expanded__transcript ll-expanded__transcript--user",
|
|
@@ -1651,7 +1654,7 @@ const Sr = ({
|
|
|
1651
1654
|
children: /* @__PURE__ */ n("p", { className: "ll-expanded__transcript-text", children: ft })
|
|
1652
1655
|
}
|
|
1653
1656
|
),
|
|
1654
|
-
!ae && !
|
|
1657
|
+
!ae && !X && /* @__PURE__ */ g("div", { className: "ll-toolbar", onClick: (m) => m.stopPropagation(), children: [
|
|
1655
1658
|
ue && /* @__PURE__ */ n(
|
|
1656
1659
|
"button",
|
|
1657
1660
|
{
|
|
@@ -1741,11 +1744,11 @@ const Sr = ({
|
|
|
1741
1744
|
"button",
|
|
1742
1745
|
{
|
|
1743
1746
|
type: "button",
|
|
1744
|
-
className: `ll-tool ${
|
|
1747
|
+
className: `ll-tool ${ee ? "is-muted" : ""}`,
|
|
1745
1748
|
onClick: Ne,
|
|
1746
|
-
"aria-label":
|
|
1747
|
-
title:
|
|
1748
|
-
children: /* @__PURE__ */ n(mn, { muted:
|
|
1749
|
+
"aria-label": ee ? "Unmute speaker" : "Mute speaker",
|
|
1750
|
+
title: ee ? "Unmute speaker" : "Mute speaker",
|
|
1751
|
+
children: /* @__PURE__ */ n(mn, { muted: ee })
|
|
1749
1752
|
}
|
|
1750
1753
|
),
|
|
1751
1754
|
/* @__PURE__ */ n(
|
|
@@ -1760,7 +1763,7 @@ const Sr = ({
|
|
|
1760
1763
|
}
|
|
1761
1764
|
)
|
|
1762
1765
|
] }),
|
|
1763
|
-
!ae &&
|
|
1766
|
+
!ae && X && /* @__PURE__ */ n(
|
|
1764
1767
|
Lr,
|
|
1765
1768
|
{
|
|
1766
1769
|
isMuted: w,
|
|
@@ -1771,7 +1774,7 @@ const Sr = ({
|
|
|
1771
1774
|
isScreenShareEnabled: G,
|
|
1772
1775
|
onToggleScreenShare: Se,
|
|
1773
1776
|
allowScreenShare: ue,
|
|
1774
|
-
isSpeakerMuted:
|
|
1777
|
+
isSpeakerMuted: ee,
|
|
1775
1778
|
onToggleSpeaker: Ne,
|
|
1776
1779
|
allowTyping: ve,
|
|
1777
1780
|
isTypingOpen: oe,
|
|
@@ -1779,7 +1782,7 @@ const Sr = ({
|
|
|
1779
1782
|
onDisconnect: Ye
|
|
1780
1783
|
}
|
|
1781
1784
|
),
|
|
1782
|
-
!ae && ve && (
|
|
1785
|
+
!ae && ve && (X ? oe : !0) && /* @__PURE__ */ g("form", { className: "ll-message-input", onSubmit: Xe, children: [
|
|
1783
1786
|
/* @__PURE__ */ n(
|
|
1784
1787
|
"input",
|
|
1785
1788
|
{
|
|
@@ -2064,23 +2067,23 @@ function zr(e, t = {}) {
|
|
|
2064
2067
|
if (!yt(P)) continue;
|
|
2065
2068
|
const F = P.getAttribute("data-ll-field") || "";
|
|
2066
2069
|
if (!F) continue;
|
|
2067
|
-
const G = ln(P) || F, le = P instanceof HTMLInputElement ? P.type : P.tagName.toLowerCase(),
|
|
2070
|
+
const G = ln(P) || F, le = P instanceof HTMLInputElement ? P.type : P.tagName.toLowerCase(), ee = {
|
|
2068
2071
|
name: F,
|
|
2069
2072
|
label: ye(G, 100),
|
|
2070
2073
|
type: le
|
|
2071
2074
|
};
|
|
2072
|
-
if (P.required === !0 && (
|
|
2075
|
+
if (P.required === !0 && (ee.required = !0), P instanceof HTMLSelectElement) {
|
|
2073
2076
|
const ue = [];
|
|
2074
2077
|
for (let ve = 0; ve < P.options.length && !(ue.length >= Pr); ve++) {
|
|
2075
2078
|
const fe = P.options[ve];
|
|
2076
2079
|
if (!fe || fe.disabled) continue;
|
|
2077
|
-
const ae = fe.value || "",
|
|
2078
|
-
!ae && !
|
|
2080
|
+
const ae = fe.value || "", X = (fe.textContent || "").trim() || ae;
|
|
2081
|
+
!ae && !X || ue.push({ value: ae, label: ye(X, 60) });
|
|
2079
2082
|
}
|
|
2080
|
-
ue.length > 0 && (
|
|
2083
|
+
ue.length > 0 && (ee.options = ue);
|
|
2081
2084
|
}
|
|
2082
2085
|
const Le = typeof P.validationMessage == "string" ? P.validationMessage : "";
|
|
2083
|
-
Le && (
|
|
2086
|
+
Le && (ee.validationMessage = ye(Le, 200)), C.push(ee);
|
|
2084
2087
|
}
|
|
2085
2088
|
N.push({ id: I, intent: B, fields: C });
|
|
2086
2089
|
}
|
|
@@ -2278,13 +2281,13 @@ const Qr = /* @__PURE__ */ new Set([
|
|
|
2278
2281
|
allowScreenShare: F = !0,
|
|
2279
2282
|
allowTyping: G = !0,
|
|
2280
2283
|
showMinimize: le = !0,
|
|
2281
|
-
chromeless:
|
|
2284
|
+
chromeless: ee = !1,
|
|
2282
2285
|
compactControls: Le = !1,
|
|
2283
2286
|
transforming: ue = !1,
|
|
2284
2287
|
transformingLabel: ve = "Transforming…",
|
|
2285
2288
|
showOn: fe,
|
|
2286
2289
|
hideOn: ae,
|
|
2287
|
-
pathname:
|
|
2290
|
+
pathname: X,
|
|
2288
2291
|
onNavigate: st,
|
|
2289
2292
|
onScrollToSelector: je,
|
|
2290
2293
|
getPageContext: ct,
|
|
@@ -2304,17 +2307,17 @@ const Qr = /* @__PURE__ */ new Set([
|
|
|
2304
2307
|
className: vt,
|
|
2305
2308
|
style: Ie,
|
|
2306
2309
|
zIndex: $e = 2147483647
|
|
2307
|
-
} = t, re = rr(
|
|
2310
|
+
} = t, re = rr(X), Je = dr(re, fe, ae);
|
|
2308
2311
|
A(() => {
|
|
2309
2312
|
Or(), Ur();
|
|
2310
2313
|
}, [re]);
|
|
2311
2314
|
const Te = T !== void 0, [ze, bt] = L(() => {
|
|
2312
2315
|
var y;
|
|
2313
2316
|
return T ?? ((y = N == null ? void 0 : N[0]) == null ? void 0 : y.id);
|
|
2314
|
-
}), be = Te ? T : ze,
|
|
2317
|
+
}), be = Te ? T : ze, Q = Ue(
|
|
2315
2318
|
() => (N == null ? void 0 : N.find((y) => y.id === be)) ?? null,
|
|
2316
2319
|
[N, be]
|
|
2317
|
-
), Ke = (
|
|
2320
|
+
), Ke = (Q == null ? void 0 : Q.agentId) ?? o, Me = f === "EMBEDDED", [se, te] = Zn({
|
|
2318
2321
|
value: Me ? "expanded" : a,
|
|
2319
2322
|
defaultValue: Me ? "expanded" : s,
|
|
2320
2323
|
onChange: R,
|
|
@@ -2432,10 +2435,10 @@ const Qr = /* @__PURE__ */ new Set([
|
|
|
2432
2435
|
const O = M, K = O == null ? void 0 : O.localParticipant;
|
|
2433
2436
|
if (K != null && K.publishData)
|
|
2434
2437
|
try {
|
|
2435
|
-
const
|
|
2438
|
+
const Z = x ? { ...V, requestId: x } : V, We = new TextEncoder().encode(JSON.stringify(Z));
|
|
2436
2439
|
K.publishData(We, { reliable: !0 });
|
|
2437
|
-
} catch (
|
|
2438
|
-
console.warn("[LiveLayer] publishData failed.",
|
|
2440
|
+
} catch (Z) {
|
|
2441
|
+
console.warn("[LiveLayer] publishData failed.", Z);
|
|
2439
2442
|
}
|
|
2440
2443
|
}, H = It.current, U = Rt.current;
|
|
2441
2444
|
try {
|
|
@@ -2655,7 +2658,7 @@ const Qr = /* @__PURE__ */ new Set([
|
|
|
2655
2658
|
return;
|
|
2656
2659
|
}
|
|
2657
2660
|
const W = typeof p.requestId == "string" ? p.requestId : void 0, H = (ge = de.current) == null ? void 0 : ge.call(de), U = (K) => {
|
|
2658
|
-
const
|
|
2661
|
+
const Z = H, We = Z == null ? void 0 : Z.localParticipant;
|
|
2659
2662
|
if (We != null && We.publishData)
|
|
2660
2663
|
try {
|
|
2661
2664
|
const An = W ? { ...K, requestId: W } : K, Rn = new TextEncoder().encode(JSON.stringify(An));
|
|
@@ -2696,25 +2699,25 @@ const Qr = /* @__PURE__ */ new Set([
|
|
|
2696
2699
|
if (!(H != null && H.publishData)) return;
|
|
2697
2700
|
const U = (O) => {
|
|
2698
2701
|
try {
|
|
2699
|
-
const K = x ? { type: "routes", routes: O, requestId: x } : { type: "routes", routes: O },
|
|
2700
|
-
H.publishData(
|
|
2702
|
+
const K = x ? { type: "routes", routes: O, requestId: x } : { type: "routes", routes: O }, Z = new TextEncoder().encode(JSON.stringify(K));
|
|
2703
|
+
H.publishData(Z, { reliable: !0 });
|
|
2701
2704
|
} catch (K) {
|
|
2702
2705
|
console.warn("[LiveLayer] request_routes: publishData failed.", K);
|
|
2703
2706
|
}
|
|
2704
2707
|
}, V = Tt.current;
|
|
2705
2708
|
if (V) {
|
|
2706
2709
|
try {
|
|
2707
|
-
const O = V(), K = (
|
|
2708
|
-
if (!Array.isArray(
|
|
2710
|
+
const O = V(), K = (Z) => {
|
|
2711
|
+
if (!Array.isArray(Z)) {
|
|
2709
2712
|
U([]);
|
|
2710
2713
|
return;
|
|
2711
2714
|
}
|
|
2712
|
-
U(
|
|
2715
|
+
U(Z.map(Wr).slice(0, 200));
|
|
2713
2716
|
};
|
|
2714
|
-
O instanceof Promise ? O.then(K).catch((
|
|
2717
|
+
O instanceof Promise ? O.then(K).catch((Z) => {
|
|
2715
2718
|
console.warn(
|
|
2716
2719
|
"[LiveLayer] getRoutes rejected; falling back to DOM walker.",
|
|
2717
|
-
|
|
2720
|
+
Z
|
|
2718
2721
|
), U(St());
|
|
2719
2722
|
}) : K(O);
|
|
2720
2723
|
} catch (O) {
|
|
@@ -2908,9 +2911,9 @@ const Qr = /* @__PURE__ */ new Set([
|
|
|
2908
2911
|
};
|
|
2909
2912
|
return window.addEventListener("keydown", y), () => window.removeEventListener("keydown", y);
|
|
2910
2913
|
}, [ce]);
|
|
2911
|
-
const _n = !!B || !!(
|
|
2914
|
+
const _n = !!B || !!(Q != null && Q.avatarImageUrl) || _.isControlled, tt = Yn(Ke, l, _n);
|
|
2912
2915
|
Ge === void 0 && ((Ot = tt.info) != null && Ot.capabilities) && (Et.current = tt.info.capabilities);
|
|
2913
|
-
const pt = (
|
|
2916
|
+
const pt = (Q == null ? void 0 : Q.name) ?? z ?? ((Ht = _.agentConfig) == null ? void 0 : Ht.name) ?? ((Wt = tt.info) == null ? void 0 : Wt.name) ?? "Live Layer", Ct = (Q == null ? void 0 : Q.avatarImageUrl) ?? B ?? ((Bt = _.agentConfig) == null ? void 0 : Bt.avatarImageUrl) ?? ((qt = tt.info) == null ? void 0 : qt.avatarImageUrl) ?? null, xn = w ?? ((Ft = _.agentConfig) == null ? void 0 : Ft.idleLoopUrl) ?? ((Ut = tt.info) == null ? void 0 : Ut.idleLoopUrl) ?? null, kn = I ?? null, Ln = k(() => te("expanded"), [te]), En = k(
|
|
2914
2917
|
() => te("minimized"),
|
|
2915
2918
|
[te]
|
|
2916
2919
|
), zt = k(() => {
|
|
@@ -3000,7 +3003,7 @@ const Qr = /* @__PURE__ */ new Set([
|
|
|
3000
3003
|
allowScreenShare: F,
|
|
3001
3004
|
allowTyping: G,
|
|
3002
3005
|
showMinimize: le,
|
|
3003
|
-
chromeless:
|
|
3006
|
+
chromeless: ee,
|
|
3004
3007
|
compactControls: Le,
|
|
3005
3008
|
transforming: ue,
|
|
3006
3009
|
transformingLabel: ve,
|
package/package.json
CHANGED