@livelayer/react 0.5.5-pr66c.6 → 0.5.5-pr66c.7
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 +3 -3
- package/dist/index.mjs +112 -112
- package/package.json +2 -2
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"),Ln=require("@livelayer/sdk"),rt=require("livekit-client");class Ut extends n.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,i){var o,s;(s=(o=this.props).onError)==null||s.call(o,r,i)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[t.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),t.jsx("p",{className:"ll-error-boundary__message",children:((r=this.state.error)==null?void 0:r.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function Vt(e){const[r,i]=n.useState("idle"),[o,s]=n.useState("idle"),[a,u]=n.useState([]),[d,f]=n.useState(null),[m,g]=n.useState(null),[l,c]=n.useState(null),[L,D]=n.useState(!1),[w,_]=n.useState(null),b=n.useRef(null),I=n.useRef(e.onDataMessage);I.current=e.onDataMessage,n.useEffect(()=>{const S={onConnectionStateChange:A=>{i(A),A==="connected"&&_(null)},onAgentStateChange:s,onTranscript:A=>u([...A]),onAgentConfig:f,onAudioTrack:A=>c(A),onVideoTrack:A=>g(A),onVideoTrackRemoved:()=>g(null),onError:A=>_(A),onDataMessage:A=>{var C;(C=I.current)==null||C.call(I,A)},onResumabilityChange:D},$=new Ln.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},S);return b.current=$,i("idle"),s("idle"),u([]),f(null),g(null),c(null),D(!1),_(null),()=>{var A;(A=$.destroy)==null||A.call($),b.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=n.useCallback(async()=>{const S=b.current;if(S)try{await S.connect()}catch($){throw _($ instanceof Error?$.message:String($)),$}},[]),T=n.useCallback(()=>{const S=b.current;S&&S.disconnect()},[]),x=n.useCallback(()=>{var S;return((S=b.current)==null?void 0:S.getRoom())??null},[]);return{connectionState:r,agentState:o,transcript:a,agentConfig:d,videoElement:m,audioElement:l,canResume:L,error:w,connect:E,disconnect:T,getRoom:x,session:b.current}}function Yt(){const e=n.useRef(null),r=n.useRef(null),i=n.useRef(null),o=n.useRef(null),s=n.useRef(new Set),a=n.useRef(null),u=n.useCallback(()=>{const l=r.current;if(!l){o.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 w=0;w<c.length;w++)L+=c[w];const D=L/c.length/255;for(const w of s.current)try{w(D)}catch(_){console.error("[useAudioLevel] subscriber threw:",_)}o.current=requestAnimationFrame(u)},[]),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},[]),f=n.useCallback(l=>{if(d(),!(!e.current||!r.current)){if(i.current){try{i.current.disconnect()}catch{}i.current=null}try{const c=e.current.createMediaElementSource(l);c.connect(r.current),i.current=c}catch(c){console.warn("[useAudioLevel] createMediaElementSource failed:",c);return}o.current===null&&(o.current=requestAnimationFrame(u))}},[d,u]),m=n.useCallback(()=>{if(o.current!==null&&(cancelAnimationFrame(o.current),o.current=null),i.current){try{i.current.disconnect()}catch{}i.current=null}},[]),g=n.useCallback(l=>(s.current.add(l),()=>{s.current.delete(l)}),[]);return n.useEffect(()=>()=>{if(m(),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},[m]),{attach:f,detach:m,subscribe:g}}function Gt(){const[e,r]=n.useState(!1),[i,o]=n.useState(null),s=n.useRef(null),a=n.useRef(null),u=n.useCallback(async g=>{if(s.current&&a.current){try{await a.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}a.current=g,o(null);try{const l=await rt.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await g.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 o(c),l}},[]),d=n.useCallback(()=>{const g=s.current;g&&(g.isMuted?(g.unmute(),r(!1)):(g.mute(),r(!0)))},[]),f=n.useCallback(()=>{const g=s.current,l=a.current;if(g&&l){try{l.localParticipant.unpublishTrack(g)}catch{}g.stop()}s.current=null,a.current=null,r(!1)},[]),m=n.useCallback(()=>o(null),[]);return{isMuted:e,micError:i,toggleMute:d,setupMic:u,teardownMic:f,clearError:m}}const jn={resolution:{width:640,height:480,frameRate:24}};function Kt(){const[e,r]=n.useState(!1),[i,o]=n.useState(null),[s,a]=n.useState(null),[u,d]=n.useState(""),f=n.useRef(null),m=n.useRef(null),g=n.useCallback(b=>{f.current=b},[]),l=n.useCallback(()=>{const b=f.current,I=m.current;if(I&&b){const E=b.localParticipant.getTrackPublication(rt.Track.Source.Camera);if(E!=null&&E.track){try{b.localParticipant.unpublishTrack(E.track)}catch{}E.track.stop()}else I.stop()}m.current=null,a(null),r(!1)},[]),c=n.useCallback(async b=>{const I=f.current;if(I){o(null);try{const E={...jn};b&&(E.deviceId=b);const T=await rt.createLocalVideoTrack(E);await I.localParticipant.publishTrack(T),m.current=T;const x=T.attach();a(x),r(!0),b&&d(b);try{I.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const T=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";o(T)}}},[]),L=n.useCallback(async()=>{e?l():await c(u||void 0)},[e,u,l,c]),D=n.useCallback(async b=>{l(),await c(b)},[l,c]),w=n.useCallback(()=>{l(),f.current=null,o(null),d("")},[l]),_=n.useCallback(()=>o(null),[]);return n.useEffect(()=>()=>{m.current&&m.current.stop()},[]),{isEnabled:e,error:i,previewEl:s,activeDeviceId:u,toggle:L,switchDevice:D,attachRoom:g,teardown:w,clearError:_}}function Xt(){const[e,r]=n.useState(!1),[i,o]=n.useState(null),[s,a]=n.useState(null),u=n.useRef(null),d=n.useCallback(c=>{u.current=c},[]),f=n.useCallback(()=>a(null),[]),m=n.useCallback(async()=>{const c=u.current;if(c){if(e){try{await c.localParticipant.setScreenShareEnabled(!1)}catch{}f(),r(!1);return}o(null);try{await c.localParticipant.setScreenShareEnabled(!0);let L=0;const D=()=>{const w=c.localParticipant.getTrackPublication(rt.Track.Source.ScreenShare);if(w!=null&&w.track){const _=w.track.attach();a(_),r(!0);try{c.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}L++<10?setTimeout(D,100):r(!0)};D()}catch(L){const D=L instanceof Error?L.name:"";D!=="NotAllowedError"&&D!=="AbortError"&&o("Screen share unavailable. Try again."),r(!1)}}},[e,f]),g=n.useCallback(()=>{const c=u.current;if(c&&e)try{c.localParticipant.setScreenShareEnabled(!1)}catch{}f(),r(!1),o(null),u.current=null},[e,f]),l=n.useCallback(()=>o(null),[]);return{isEnabled:e,error:i,previewEl:s,toggle:m,attachRoom:d,teardown:g,clearError:l}}function Jt(){const[e,r]=n.useState([]),[i,o]=n.useState([]),s=n.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const a=await navigator.mediaDevices.enumerateDevices();r(a.filter(u=>u.kind==="audioinput")),o(a.filter(u=>u.kind==="videoinput"))}catch{}},[]);return n.useEffect(()=>{if(s(),typeof navigator>"u"||!navigator.mediaDevices)return;const a=()=>void s();return navigator.mediaDevices.addEventListener("devicechange",a),()=>navigator.mediaDevices.removeEventListener("devicechange",a)},[s]),{mics:e,cameras:i,refresh:s}}function Qt(e,r,i=!1){const[o,s]=n.useState(null),[a,u]=n.useState(null),[d,f]=n.useState(!i&&!!e);return n.useEffect(()=>{if(i||!e){f(!1);return}const m=new AbortController,g=r||"https://app.livelayer.studio";return f(!0),u(null),fetch(`${g}/api/widget/agent/${encodeURIComponent(e)}`,{signal:m.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=>{m.signal.aborted||(s(l),f(!1))}).catch(l=>{m.signal.aborted||(u(l instanceof Error?l.message:"Agent lookup failed"),f(!1))}),()=>m.abort()},[e,r,i]),{info:o,error:a,loading:d}}function En(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Rn(e,r){if(!(typeof window>"u"))try{window.localStorage.setItem(e,r)}catch{}}function Zt({value:e,defaultValue:r="expanded",onChange:i}={}){const o=e!==void 0,[s,a]=n.useState(r),u=o?e:s,d=n.useCallback(f=>{f!==u&&(o||a(f),i==null||i(f))},[u,o,i]);return[u,d]}const Nn=["hidden","minimized","expanded"];function An(e){return e&&Nn.includes(e)?e:null}function en({value:e,defaultValue:r="expanded",onChange:i,persistKey:o="ll-widget",disablePersistence:s=!1}={}){const a=`${o}:display-mode`,u=n.useRef(!1),[d,f]=Zt({value:e,defaultValue:r,onChange:m=>{e===void 0&&!s&&Rn(a,m),i==null||i(m)}});return n.useEffect(()=>{if(u.current||(u.current=!0,s||e!==void 0))return;const m=An(En(a));m&&m!==d&&f(m)},[]),[d,f]}const Mn=640;function tn(e=Mn){const[r,i]=n.useState(!1);return n.useEffect(()=>{if(e===!1){i(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const o=`(max-width: ${e-1}px)`,s=window.matchMedia(o),a=()=>i(s.matches);return a(),typeof s.addEventListener=="function"?(s.addEventListener("change",a),()=>s.removeEventListener("change",a)):(s.addListener(a),()=>{s.removeListener(a)})},[e]),r}const Rt="__llHistoryPatched",it="ll:pathname";function In(){if(typeof window>"u"||window.history[Rt])return;const e=window.history.pushState,r=window.history.replaceState;window.history.pushState=function(...i){const o=e.apply(this,i);return window.dispatchEvent(new Event(it)),o},window.history.replaceState=function(...i){const o=r.apply(this,i);return window.dispatchEvent(new Event(it)),o},window.history[Rt]=!0}function Nt(){return typeof window>"u"?"/":window.location.pathname||"/"}function nn(e){const[r,i]=n.useState(()=>e??Nt());return n.useEffect(()=>{if(e!==void 0)return;In();const o=()=>i(Nt());return o(),window.addEventListener("popstate",o),window.addEventListener(it,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(it,o)}},[e]),e??r}const At=new Map,Tn=/[\\^$+?.()|{}[\]]/g;function Pn(e){return e.replace(Tn,"\\$&")}function Dn(e){const r=At.get(e);if(r)return r;const i=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,o="",s="",a=i.replace(/\*\*/g,o).replace(/\*/g,s),d=Pn(a).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),f=new RegExp(`^${d}\\/?$`);return At.set(e,f),f}function $n(e,r){const i=r.length>1&&r.endsWith("/")?r.slice(0,-1):r;return Dn(e).test(i)}function rn(e,r){return typeof e=="function"?e(r):e instanceof RegExp?e.test(r):$n(e,r)}function Mt(e,r){if(!e||e.length===0)return!1;for(const i of e)if(rn(i,r))return!0;return!1}function on(e,r,i){return e===void 0?!0:Mt(i,e)?!1:r&&r.length>0?Mt(r,e):!0}function sn(e,r,i){return n.useMemo(()=>on(e,r,i),[e,r,i])}function zn(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 Hn(e){const r=n.useMemo(()=>zn(e.config),[e.config]),i=e.baseUrl.replace(/\/+$/,""),o=n.useRef(null),s=n.useCallback(f=>{try{new Audio(`${i}${f}`).play().catch(()=>{})}catch{}},[i]),a=n.useCallback(()=>{r.navigate&&s("/audio/page-change-sound.mp3")},[r.navigate,s]),u=n.useCallback(()=>{r.action&&s("/audio/confirmation-sound.mp3")},[r.action,s]),d=n.useCallback(f=>{if(!r.thinking){if(o.current){try{o.current.pause()}catch{}o.current=null}return}if(f){if(o.current)return;try{const m=new Audio(`${i}/audio/thinking-sound.mp3`);m.loop=!0,m.volume=.3,m.play().catch(()=>{o.current=null}),o.current=m}catch{}}else if(o.current){try{o.current.pause()}catch{}o.current=null}},[i,r.thinking]);return n.useEffect(()=>()=>{if(o.current){try{o.current.pause()}catch{}o.current=null}},[]),n.useMemo(()=>({playPageChange:a,playConfirmation:u,setThinking:d}),[a,u,d])}const It=({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"})}),Tt=({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"})}),On=({className:e})=>t.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),qn={left:180,right:0,up:-90,down:90},Pt=({direction:e="right",className:r})=>t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${qn[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function Bn(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const an="ll-hidden-tab-center-y",Wn=5,Dt=16;function Fn(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(an);if(!e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null}catch{return null}}function $t(e){if(!(typeof window>"u"))try{window.localStorage.setItem(an,String(e))}catch{}}const Un=({position:e,isMobile:r,isSpeaking:i,onExpand:o,label:s="Open widget",avatarImageUrl:a,agentName:u})=>{const d=Bn(e),f=d==="right"?"left":"right",m=r?80:72,g=!!a,[l,c]=n.useState(null),[L,D]=n.useState(!1),w=n.useRef(null),_=n.useRef(!1),b=n.useCallback(C=>{if(typeof window>"u")return C;const R=m/2,z=Dt+R,F=window.innerHeight-Dt-R;return F<z?Math.max(z,C):Math.max(z,Math.min(F,C))},[m]);n.useEffect(()=>{const C=Fn();c(b(C??window.innerHeight/2));const R=()=>{c(z=>z===null?null:b(z))};return window.addEventListener("resize",R),()=>window.removeEventListener("resize",R)},[b]);const I=n.useCallback(C=>{if(!(C.pointerType==="mouse"&&C.button!==0)&&l!==null){try{C.currentTarget.setPointerCapture(C.pointerId)}catch{}w.current={startClientY:C.clientY,startCenterY:l,moved:!1}}},[l]),E=n.useCallback(C=>{const R=w.current;if(!R)return;const z=C.clientY-R.startClientY;!R.moved&&Math.abs(z)>Wn&&(R.moved=!0,D(!0)),R.moved&&c(b(R.startCenterY+z))},[b]),T=n.useCallback(C=>{const R=w.current;if(R){try{C.currentTarget.releasePointerCapture(C.pointerId)}catch{}w.current=null,R.moved&&(D(!1),_.current=!0,c(z=>(z!==null&&$t(z),z)))}},[]),x=n.useCallback(()=>{if(_.current){_.current=!1;return}o()},[o]),S=n.useCallback(C=>{if(C.key==="ArrowUp"||C.key==="ArrowDown"){C.preventDefault();const R=C.key==="ArrowUp"?-8:8;c(z=>{if(z===null)return z;const F=b(z+R);return $t(F),F})}},[b]),$=["ll-hidden",`ll-hidden--${d}`,r?"ll-hidden--mobile":"ll-hidden--desktop",i?"ll-hidden--speaking":null,L?"is-dragging":null,g?"ll-hidden--with-avatar":null].filter(Boolean).join(" "),A=l===null?void 0:{top:`${l-m/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:$,onPointerDown:I,onPointerMove:E,onPointerUp:T,onPointerCancel:T,onClick:x,onKeyDown:S,"aria-label":s,"data-position":e,style:A,children:g?t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:f,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:a,alt:u?`${u} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Pt,{direction:f,className:"ll-hidden__chevron"})})},Vn=({audioLevel:e,bars:r=20,maxHeight:i=20,minHeight:o=4,className:s,barClassName:a})=>{const u=n.useRef(null),d=n.useRef([]),f=n.useMemo(()=>{const g=(Math.sqrt(5)-1)/2;return Array.from({length:r},(l,c)=>.5+c*g%1*.5)},[r]);n.useEffect(()=>e.subscribe(l=>{for(let c=0;c<r;c++){const L=d.current[c];if(!L)continue;const D=Math.max(o,l*i*f[c]);L.style.height=`${D}px`}}),[e,r,i,o,f]);const m=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:u,className:m,"aria-hidden":"true",children:Array.from({length:r},(g,l)=>t.jsx("div",{ref:c=>{d.current[l]=c},className:["ll-waveform__bar",a].filter(Boolean).join(" "),style:{height:`${o}px`}},l))})},Yn=({position:e,isMobile:r,agentName:i,avatarImageUrl:o,agentState:s,isMuted:a,audioLevel:u,onExpand:d,onToggleMute:f,onClose:m})=>r?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${i} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:d,"aria-label":`Expand ${i} widget`,children:[o?t.jsx("img",{src:o,alt:i,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsx(Vn,{audioLevel:u,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),t.jsx("span",{className:"ll-minimized__name",children:i}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:g=>{g.stopPropagation(),f()},onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.stopPropagation(),g.preventDefault(),f())},"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(It,{muted:a,className:"ll-minimized__icon"})}),t.jsx(Tt,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):t.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${i} widget`,children:t.jsxs("div",{className:"ll-minimized__surface",children:[o?t.jsx("img",{src:o,alt:i,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsxs("div",{className:"ll-minimized__meta",children:[t.jsx("span",{className:"ll-minimized__name",children:i}),t.jsx("span",{className:"ll-minimized__state",children:s==="speaking"?"Speaking":s==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:f,"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(It,{muted:a,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:d,"aria-label":`Expand ${i} widget`,children:t.jsx(Tt,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:m,"aria-label":"Close widget",children:t.jsx(On,{className:"ll-minimized__icon"})})]})]})}),Gn=({src:e,alt:r,preCannedPlaying:i=!1,className:o,style:s})=>{const[a,u]=n.useState(!1),d=n.useRef(e);if(n.useEffect(()=>{d.current!==e&&(d.current=e,u(!1))},[e]),!e)return null;const f={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:i?"scale(1.02)":"scale(1)",opacity:a?1:0,...s};return t.jsx("img",{src:e,alt:r,className:o,style:f,loading:"eager",fetchPriority:"high",onLoad:()=>u(!0)})},Kn=({position:e,isMobile:r,agentName:i,avatarImageUrl:o,idleLoopUrl:s,greeting:a,branding:u,teamMembers:d,currentTeamMemberId:f,isSwitchingTeamMember:m,teamSwitcherOpen:g,onToggleTeamSwitcher:l,onSelectTeamMember:c,languageMenuOpen:L,onToggleLanguageMenu:D,connectionState:w,agentState:_,transcript:b,canResume:I,needsUserGesture:E,error:T,isMuted:x,micError:S,micDevices:$,isCameraEnabled:A,cameraPreviewEl:C,cameraDevices:R,activeCameraId:z,isScreenShareEnabled:F,screenPreviewEl:Z,isSpeakerMuted:J,allowCamera:be,allowScreenShare:oe,allowTyping:fe,avatarVideoContainerRef:se,agentVideoEl:Y,onConnect:ae,onDisconnect:ve,onRetry:we,onResumeAudio:_e,onToggleMute:ke,onToggleCamera:Se,onSwitchCameraDevice:Ce,onToggleScreenShare:Le,onToggleSpeaker:B,onSendMessage:Be,onMinimize:We,onClose:Fe,onClearMicError:Ue})=>{var Xe;const le=((d==null?void 0:d.length)??0)>1,pe=w==="connecting"||w==="connected",ee=w==="connected",st=w==="idle"||w==="disconnected"||w==="error",[ce,W]=n.useState(!1);n.useEffect(()=>{if(!Y){W(!1);return}if(!Y.paused&&Y.readyState>=2){W(!0);return}W(!1);const p=()=>W(!0);return Y.addEventListener("playing",p),Y.addEventListener("loadeddata",p),()=>{Y.removeEventListener("playing",p),Y.removeEventListener("loadeddata",p)}},[Y]);const[Ve,he]=n.useState(!1);n.useEffect(()=>{if(!ee){he(!1);return}if(ce)return;const p=setTimeout(()=>he(!0),8e3);return()=>clearTimeout(p)},[ee,ce]);const ue=w==="connecting"||ee&&!!o&&!ce&&!Ve,xe=n.useRef(null),je=n.useRef(null);n.useEffect(()=>{const p=xe.current;p&&(p.innerHTML="",C&&(C.style.width="100%",C.style.height="100%",C.style.objectFit="cover",C.style.transform="scaleX(-1)",p.appendChild(C)))},[C]),n.useEffect(()=>{const p=je.current;p&&(p.innerHTML="",Z&&(Z.style.width="100%",Z.style.height="100%",Z.style.objectFit="contain",p.appendChild(Z)))},[Z]);const[K,Q]=n.useState(!1),[te,me]=n.useState(!1);n.useEffect(()=>{if(!K&&!te&&!L&&!g)return;const p=()=>{Q(!1),me(!1),L&&D(),g&&l()};return document.addEventListener("click",p),()=>document.removeEventListener("click",p)},[K,te,L,g,D,l]);const[Ee,Re]=n.useState(""),Te=n.useCallback(p=>{p.preventDefault();const O=Ee.trim();O&&(Be(O),Re(""))},[Ee,Be]),Ye=u.productName||"Live Layer";let ne=null,re=null;for(let p=b.length-1;p>=0;p--){const O=b[p];if(!ne&&O.role==="agent"?ne=O:!re&&O.role==="user"&&(re=O),ne&&re)break}const Ge=ee?(ne==null?void 0:ne.text)||null:a||null,Ke=ee&&(re==null?void 0:re.text)||null,Pe=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:Pe,"data-position":e,"data-state":ee?"connected":pe?"connecting":"idle",role:"dialog","aria-label":`${i} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[o?t.jsx(Gn,{src:o,alt:i,className:"ll-expanded__bg-img"}):t.jsx("div",{className:"ll-expanded__bg-fallback",children:t.jsx("span",{className:"ll-expanded__bg-initial",children:((Xe=i==null?void 0:i.charAt(0))==null?void 0:Xe.toUpperCase())||"A"})}),s&&!ee&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:se,className:"ll-expanded__video"}),ue&&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:m?"Switching...":"Connecting..."})]}),E&&ee&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:_e,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"})]}),pe?t.jsxs("div",{className:"ll-expanded__topbar",children:[t.jsxs("div",{className:"ll-expanded__topbar-left",children:[t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill",onClick:p=>{le&&(p.stopPropagation(),l())},"aria-haspopup":le?"listbox":void 0,"aria-expanded":le?g:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:i}),le&&t.jsx(et,{})]}),le&&g&&t.jsx("div",{className:"ll-hmenu",onClick:p=>p.stopPropagation(),role:"listbox",children:d==null?void 0:d.map(p=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${p.id===f?"is-active":""}`,onClick:()=>c(p.id),role:"option","aria-selected":p.id===f,children:[p.avatarImageUrl&&t.jsx("img",{src:p.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:p.name}),p.role&&t.jsx("span",{className:"ll-hmenu__role",children:p.role})]},p.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:p=>{p.stopPropagation(),D()},"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(et,{})]}),L&&t.jsx("div",{className:"ll-hmenu",onClick:p=>p.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--${_}`,children:_})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn",onClick:We,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(Ht,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Fe,"aria-label":"End call",title:"End call",children:t.jsx(zt,{})})]})]}):t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:Ye}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:We,"aria-label":"Minimize widget",children:t.jsx(Ht,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Fe,"aria-label":"Close widget",children:t.jsx(zt,{})})]})]}),st&&(()=>{const p=I?"Restart paused session":w==="disconnected"?"Reconnect to agent":"Start video call",O=I?"Pick up where you left off":null,De=w==="idle"&&!I&&!T;return t.jsxs(t.Fragment,{children:[De&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:ae,"aria-label":p,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:p})]}),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})}),O&&t.jsx("p",{className:"ll-expanded__cta-sublabel",children:O}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:ae,"aria-label":p,children:p})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${pe&&(A||F)?"is-visible":""}`,children:[t.jsx("div",{ref:je,className:F?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:xe,className:!F&&A?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),pe?t.jsxs("div",{className:"ll-expanded__bottom",children:[Ge&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Ge})}),Ke&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Ke})}),t.jsxs("div",{className:"ll-toolbar",onClick:p=>p.stopPropagation(),children:[oe&&t.jsx("button",{type:"button",className:`ll-tool ${F?"is-on":""}`,onClick:Le,"aria-label":F?"Stop sharing screen":"Share screen",title:F?"Stop sharing":"Share screen",children:t.jsx(Xn,{})}),be&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${A?"is-on":""}`,onClick:Se,"aria-label":A?"Turn off camera":"Turn on camera",title:A?"Stop camera":"Start camera",children:t.jsx(Jn,{})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${A?"is-on":""}`,onClick:p=>{p.stopPropagation(),me(O=>!O),Q(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":te,children:t.jsx(et,{})}),te&&R.length>0&&t.jsx(Ot,{label:"Camera",devices:R,activeId:z,onPick:p=>{me(!1),Ce(p)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${x?"is-muted":""}`,onClick:ke,"aria-label":x?"Unmute microphone":"Mute microphone",title:x?"Unmute":"Mute",children:t.jsx(Qn,{muted:x})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${x?"is-muted":""}`,onClick:p=>{p.stopPropagation(),Q(O=>!O),me(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":K,children:t.jsx(et,{})}),K&&$.length>0&&t.jsx(Ot,{label:"Microphone",devices:$,activeId:"",onPick:()=>Q(!1)})]}),t.jsx("button",{type:"button",className:`ll-tool ${J?"is-muted":""}`,onClick:B,"aria-label":J?"Unmute speaker":"Mute speaker",title:J?"Unmute speaker":"Mute speaker",children:t.jsx(Zn,{muted:J})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:ve,"aria-label":"End conversation",title:"End conversation",children:t.jsx(tr,{})})]}),fe&&t.jsxs("form",{className:"ll-message-input",onSubmit:Te,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:Ee,onChange:p=>Re(p.target.value),"aria-label":"Message the agent"}),Ee.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(er,{})})]})]}):null,(()=>{if(S&&w!=="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:Ue,"aria-label":"Dismiss",children:"×"})]});if(!T||w!=="error")return null;let p="Failed to connect",O="Try again";return T==="MIC_PERMISSION_DENIED"?p="Microphone blocked. Allow access to talk.":T==="MIC_NOT_FOUND"?p="No microphone found. Plug one in + retry.":T==="MIC_UNAVAILABLE"?p="Mic unavailable. Check other apps using it.":T==="AGENT_TIMEOUT"?p="Agent didn't pick up. Try again.":T==="CONNECT_FAILED"?p="Connection failed. Check your network.":T.length<80&&(p=T),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:p}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:we,children:O})]})})()]})};function et(){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 zt(){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 Ht(){return t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function Xn(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),t.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),t.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function Jn(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M23 7l-7 5 7 5V7z"}),t.jsx("rect",{x:"1",y:"5",width:"15",height:"14",rx:"2"})]})}function Qn({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),t.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),t.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),e&&t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Zn({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e?t.jsx("line",{x1:"23",y1:"9",x2:"17",y2:"15"}):t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"}),t.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]})]})}function er(){return t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),t.jsx("polyline",{points:"12 5 19 12 12 19"})]})}function tr(){return t.jsx("svg",{width:"16",height:"16",viewBox:"-4 -4 32 32",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.93.37 1.84.71 2.7a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.38-1.38a2 2 0 0 1 2.11-.45c.86.34 1.77.58 2.7.71A2 2 0 0 1 22 16.92z",transform:"rotate(135 12 12)"})})}const Ot=({label:e,devices:r,activeId:i,onPick:o})=>t.jsxs("div",{className:"ll-device-menu",onClick:s=>s.stopPropagation(),role:"listbox",children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),r.map((s,a)=>{const u=i===s.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${u?"is-active":""}`,onClick:()=>o(s.deviceId),role:"option","aria-selected":u,children:[u&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:s.label||`${e} ${a+1}`})]},s.deviceId||a)})]}),nr=['[data-ll-private="true"]',".ll-widget"];function ht(e){let r=e;for(;r;){for(const i of nr)if(r.matches(i))return!0;r=r.parentElement}return!1}function ot(e){if(ht(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 tt=4096,rr=20,ir=20,or=10,sr=10,ar=30,lr=20,qt=500,cr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function Oe(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let r=e;for(;r;){for(const i of cr)if(r.matches(i))return!0;r=r.parentElement}return!1}function qe(e){if(typeof window>"u")return!0;const r=e.getBoundingClientRect();if(r.width<=0||r.height<=0)return!1;const i=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth;return r.bottom>0&&r.right>0&&r.top<i&&r.left<o}function Bt(e){const r=e.getAttribute("id");if(r){const a=document.querySelector(`label[for="${CSS.escape(r)}"]`);if(a!=null&&a.textContent)return a.textContent.trim()}const i=e.getAttribute("aria-label");if(i)return i.trim();const o=e.getAttribute("placeholder");if(o)return o.trim();const s=e.closest("label");return s!=null&&s.textContent?s.textContent.trim():""}function de(e,r){return e.length<=r?e:e.slice(0,r-1)+"…"}function Ae(e){return e.length}function ln(e,r={}){const i=r.doc??(typeof document<"u"?document:null);if(!i)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const o=typeof window<"u"&&window.location.href||"",s=typeof window<"u"&&window.location.pathname||"/",a=i.title||"",u=Array.from(i.querySelectorAll("[data-ll-region]")),d=[];for(const x of u){if(d.length>=or)break;if(Oe(x)||!qe(x))continue;const S=x.getAttribute("data-ll-region")??"",$=x.getAttribute("data-ll-intent")??void 0,A=de((x.innerText||x.textContent||"").trim(),qt*2);!S||!A||d.push({id:S,intent:$,text:A})}const f=[],m=["H1","H2","H3","H4","H5","H6"],g=Array.from(i.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const x of g){if(Oe(x)||!qe(x))continue;const S=(x.textContent||"").trim();S&&f.push(`${x.tagName}: ${de(S,200)}`)}const l=Array.from(i.querySelectorAll("p, li"));for(const x of l){if(Oe(x)||!qe(x)||m.includes(x.tagName))continue;const S=(x.textContent||"").trim();S.length>10&&f.push(de(S,qt))}const c=f.join(`
|
|
2
|
-
`),L=[],D=Array.from(i.querySelectorAll("a[href]"));for(const x of D){if(L.length>=rr)break;if(Oe(x)||!qe(x))continue;const S=x.getAttribute("href")||"",$=(x.textContent||"").trim();!S||!$||L.push({href:S,text:de($,100)})}const w=[],_=Array.from(i.querySelectorAll("input, textarea, select"));for(const x of _){if(w.length>=ir)break;if(Oe(x)||!ot(x)||!qe(x))continue;const S=Bt(x),$=x instanceof HTMLInputElement?x.type:x.tagName.toLowerCase();S&&w.push({label:de(S,100),type:$})}const b=Array.from(i.querySelectorAll("[data-ll-form]")),I=[];for(const x of b){if(I.length>=sr)break;if(ht(x))continue;const S=x.getAttribute("data-ll-form")||"";if(!S)continue;const $=x.getAttribute("data-ll-intent")||void 0,A=Array.from(x.querySelectorAll("[data-ll-field]")),C=[];for(const R of A){if(C.length>=ar)break;if(!ot(R))continue;const z=R.getAttribute("data-ll-field")||"";if(!z)continue;const F=Bt(R)||z,Z=R instanceof HTMLInputElement?R.type:R.tagName.toLowerCase(),J={name:z,label:de(F,100),type:Z};if(R.required===!0&&(J.required=!0),R instanceof HTMLSelectElement){const oe=[];for(let fe=0;fe<R.options.length&&!(oe.length>=lr);fe++){const se=R.options[fe];if(!se||se.disabled)continue;const Y=se.value||"",ae=(se.textContent||"").trim()||Y;!Y&&!ae||oe.push({value:Y,label:de(ae,60)})}oe.length>0&&(J.options=oe)}const be=typeof R.validationMessage=="string"?R.validationMessage:"";be&&(J.validationMessage=de(be,200)),C.push(J)}I.push({id:S,intent:$,fields:C})}const E={url:o,title:a,pathname:s,regions:d,visibleText:c,visibleLinks:L,visibleFields:w,forms:I,extras:e};let T=Ae(JSON.stringify(E.regions))+Ae(E.visibleText)+Ae(JSON.stringify(E.visibleLinks))+Ae(JSON.stringify(E.visibleFields));for(;T>tt&&E.visibleFields.length>0;)E.visibleFields.pop(),T=Ae(JSON.stringify(E.visibleFields));for(;T>tt&&E.visibleLinks.length>0;)E.visibleLinks.pop(),T-=80;return Ae(E.visibleText)>tt&&(E.visibleText=de(E.visibleText,tt-100)),E}let Me=null;function pt(e,r={}){const i=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(Me&&Me.key===s&&i-Me.at<1e3)return Me.ctx;const a=ln(e,r);return Me={key:s,at:i,ctx:a},a}function cn(){Me=null}const ur=200;function un(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 dr(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function dn(e){const r=e??(typeof document<"u"?document:null);if(!r)return[];const i=typeof window<"u"&&window.location.origin||"",o=new Set,s=[],a=Array.from(r.querySelectorAll("a[href]"));for(const u of a){if(s.length>=ur)break;if(ht(u))continue;const d=u.getAttribute("href")||"";if(!dr(d))continue;let f=d,m=!0;try{if(typeof window<"u"){const l=new URL(d,i);m=l.origin===i,m&&d.startsWith("http")&&(f=l.pathname+l.search+l.hash)}}catch{continue}if(o.has(f))continue;o.add(f);const g=(u.textContent||"").trim().slice(0,120);s.push({href:f,text:g,internal:m})}return s}let Ie=null;const fr=5e3;function nt(){const e=Date.now(),r=typeof window<"u"&&window.location.pathname||"/";if(Ie&&Ie.pathname===r&&e-Ie.at<fr)return Ie.routes;const i=dn();return Ie={at:e,pathname:r,routes:i},i}function fn(){Ie=null}function pr(e,r){const i=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,o=Object.getOwnPropertyDescriptor(i,"value"),s=o==null?void 0:o.set;s?s.call(e,r):e.value=r}function hr(e,r,i={}){const o=i.triggerInput??!0,s=i.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const a=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),u=a==null?void 0:a.set,d=r==="true"||r==="1"||r==="on";u?u.call(e,d):e.checked=d,o&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}pr(e,r),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function mr(){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 gr(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function yr(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let r=null,i=0;for(const o of e){if(!gr(o))continue;const s=o.getBoundingClientRect();if(s.bottom<=0||s.top>=window.innerHeight||s.right<=0||s.left>=window.innerWidth||s.width<=0||s.height<=0||o.closest(".ll-widget"))continue;const a=s.width*s.height;a>i&&(i=a,r=o)}return r}function br(){if(typeof window>"u")return null;if(mr())return window;const e=yr();return e||window}function Wt(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function xr(e){var r,i;return e instanceof Window?typeof document>"u"?0:Math.max(((r=document.body)==null?void 0:r.scrollHeight)??0,((i=document.documentElement)==null?void 0:i.scrollHeight)??0):e.scrollHeight-e.clientHeight}const vr=new Set(["agent_state","avatar_stream_ready","avatar_active","avatar_idle","bot_ready","agent_error","idle_warning","idle_timeout","navigate","scroll_to","request_page_context","scroll_page","click","fill_form","focus_field","submit_form","request_routes"]);function wr(e){var wt,_t,kt,St,Ct,Lt,jt;const{agentId:r,apiKey:i,baseUrl:o="https://app.livelayer.studio",sessionEndpoint:s,sessionBody:a,soundEffects:u,autoConnect:d=!1,displayMode:f,defaultDisplayMode:m="expanded",onDisplayModeChange:g,position:l="bottom-right",mobileBreakpoint:c=640,persistKey:L="ll-widget",disablePersistence:D=!1,teamMembers:w,currentTeamMemberId:_,onTeamMemberChange:b,idleLoopUrl:I,greeting:E,avatarImageUrl:T,agentName:x,branding:S={},allowCamera:$=!0,allowScreenShare:A=!0,allowTyping:C=!0,showOn:R,hideOn:z,pathname:F,onNavigate:Z,onScrollToSelector:J,getPageContext:be,pageContextExtras:oe,getRoutes:fe,onScrollPage:se,onClick:Y,capabilities:ae,onConnect:ve,onDisconnect:we,onTranscript:_e,onAgentState:ke,onConnectionStateChange:Se,onAgentEvent:Ce,onAgentCommand:Le,controlledSession:B,className:Be,style:We,zIndex:Fe=2147483647}=e,Ue=nn(F),le=sn(Ue,R,z);n.useEffect(()=>{cn(),fn()},[Ue]);const pe=_!==void 0,[ee,st]=n.useState(()=>{var y;return _??((y=w==null?void 0:w[0])==null?void 0:y.id)}),ce=pe?_:ee,W=n.useMemo(()=>(w==null?void 0:w.find(y=>y.id===ce))??null,[w,ce]),Ve=(W==null?void 0:W.agentId)??r,[he,ue]=en({value:f,defaultValue:m,onChange:g,persistKey:L,disablePersistence:D}),xe=tn(c),je=Yt(),K=Gt(),Q=Kt(),te=Xt(),me=Jt(),[Ee,Re]=n.useState(!1),[Te,Ye]=n.useState(!1),[ne,re]=n.useState(!1),[Ge,Ke]=n.useState(!1),[Pe,Xe]=n.useState(!1),p=Hn({baseUrl:o,config:u}),O=n.useRef(p);O.current=p;const De=n.useRef(Z),at=n.useRef(J),lt=n.useRef(se),ct=n.useRef(Y),mt=n.useRef(be),gt=n.useRef(oe),yt=n.useRef(fe),ut=n.useRef(ae),ie=n.useRef(null);De.current=Z,at.current=J,lt.current=se,ct.current=Y,mt.current=be,gt.current=oe,yt.current=fe,ut.current=ae;function ge(y){const h=ut.current;return h?h.includes(y):!0}function ye(y,h){console.warn(`[LiveLayer] Agent command "${y}" blocked — capability "${h}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const $e=n.useCallback(y=>{var X,Qe,Ze,Et;const h=y;if(!(!h.type||typeof h.type!="string")){if(Ce==null||Ce({eventName:h.type,data:y}),h.type==="navigate"){if(!ge("navigate")){ye("navigate","navigate");return}const k=typeof h.href=="string"?h.href:null;if(!k){console.warn(`[LiveLayer] Agent emitted "navigate" without href. Skipping. Check your agent's tool schema. See https://livelayer.studio/docs/errors/navigate-missing-href`);return}if(O.current.playPageChange(),De.current){try{De.current(k)}catch(j){console.warn(`[LiveLayer] onNavigate threw for "${k}". Falling back. Error:`,j)}return}if(typeof document<"u"){const j=document.querySelector(`a[href="${k.replace(/"/g,'\\"')}"]`);if(j){j.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",k),window.dispatchEvent(new PopStateEvent("popstate"))}catch(j){console.warn(`[LiveLayer] history.pushState fallback failed for "${k}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,j)}return}if(h.type==="scroll_to"){if(!ge("scroll")){ye("scroll_to","scroll");return}const k=typeof h.selector=="string"?h.selector:null;if(!k)return;const j=h.behavior==="instant"?"instant":"smooth";if(at.current){try{at.current(k,j)}catch(P){console.warn("[LiveLayer] onScrollToSelector threw.",P)}return}if(typeof document<"u"){let P=null;try{P=document.querySelector(k)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${k}".`);return}if(!P){console.warn(`[LiveLayer] scroll_to: no element matched "${k}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}P.scrollIntoView({behavior:j,block:"start"})}return}if(h.type==="request_page_context"){if(!ge("read_page")){ye("request_page_context","read_page");return}const k=typeof h.requestId=="string"?h.requestId:void 0,j=(X=ie.current)==null?void 0:X.call(ie),P=q=>{const N=j,V=N==null?void 0:N.localParticipant;if(V!=null&&V.publishData)try{const G=k?{...q,requestId:k}:q,Ne=new TextEncoder().encode(JSON.stringify(G));V.publishData(Ne,{reliable:!0})}catch(G){console.warn("[LiveLayer] publishData failed.",G)}},M=gt.current,H=mt.current;try{if(H){const q=H(M);if(q instanceof Promise){P({type:"page_context_pending"}),q.then(N=>P({type:"page_context",context:N})).catch(N=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",N),P({type:"page_context",context:pt(M)})});return}P({type:"page_context",context:q});return}P({type:"page_context",context:pt(M)})}catch(q){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",q),P({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:M}})}return}if(h.type==="scroll_page"){if(!ge("scroll")){ye("scroll_page","scroll");return}const k=h.direction;if(k!=="up"&&k!=="down"&&k!=="top"&&k!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(k)}". Expected up | down | top | bottom.`);return}const j=h.behavior==="instant"?"instant":"smooth";if(lt.current){try{lt.current(k,j)}catch(N){console.warn("[LiveLayer] onScrollPage threw.",N)}return}if(typeof window>"u")return;const P={behavior:j},M=br(),H=N=>{M instanceof Window?M.scrollBy({top:N,...P}):M.scrollBy({top:N,...P})},q=N=>{M instanceof Window?M.scrollTo({top:N,...P}):M.scrollTo({top:N,...P})};k==="up"?H(-Wt(M)):k==="down"?H(Wt(M)):q(k==="top"?0:xr(M));return}if(h.type==="click"){if(!ge("click")){ye("click","click");return}const k=typeof h.selector=="string"?h.selector:null;if(!k){console.warn("[LiveLayer] click: missing selector.");return}if(ct.current){try{ct.current(k)}catch(P){console.warn("[LiveLayer] onClick threw.",P)}return}if(typeof document>"u")return;let j=null;try{j=document.querySelector(k)}catch{console.warn(`[LiveLayer] click: invalid selector "${k}".`);return}if(!j){console.warn(`[LiveLayer] click: no element matched "${k}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(j.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(Qe=j.click)==null||Qe.call(j);return}if(h.type==="fill_form"||h.type==="focus_field"){if(!ge("fill_forms")){ye(h.type,"fill_forms");return}if(typeof document>"u")return;h.type==="fill_form"&&O.current.playConfirmation();const k=typeof h.formId=="string"?h.formId:null;if(!k){console.warn(`[LiveLayer] ${h.type}: missing formId.`);return}const j=document.querySelector(`[data-ll-form="${k.replace(/"/g,'\\"')}"]`);if(!j){console.warn(`[LiveLayer] ${h.type}: no form with data-ll-form="${k}". Tag your form with <LiveLayerForm id> or data-ll-form. See https://livelayer.studio/docs/react/forms`);return}if(j.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 M=typeof h.fieldName=="string"?h.fieldName:null;if(!M){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const H=j.querySelector(`[data-ll-field="${M.replace(/"/g,'\\"')}"]`);if(!H){console.warn(`[LiveLayer] focus_field: no field "${M}" in form "${k}".`);return}if(!ot(H)){console.warn(`[LiveLayer] focus_field: field "${M}" is privacy-protected and not focusable.`);return}H.focus();return}const P=h.values&&typeof h.values=="object"?h.values:null;if(!P){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[M,H]of Object.entries(P)){if(typeof H!="string")continue;const q=j.querySelector(`[data-ll-field="${M.replace(/"/g,'\\"')}"]`);if(!q){console.warn(`[LiveLayer] fill_form: no field "${M}" in form "${k}". Skipping.`);continue}if(!ot(q)){console.warn(`[LiveLayer] fill_form: field "${M}" is privacy-protected (password / cc-* / private). Skipping.`);continue}try{hr(q,H)}catch(N){console.warn(`[LiveLayer] fill_form: failed to set "${M}".`,N)}}return}if(h.type==="submit_form"){if(!ge("submit_forms")){ye("submit_form","submit_forms");return}if(typeof document>"u")return;const k=typeof h.formId=="string"?h.formId:null;if(!k){console.warn("[LiveLayer] submit_form: missing formId.");return}O.current.playConfirmation();const j=document.querySelector(`[data-ll-form="${k.replace(/"/g,'\\"')}"]`);if(!j){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${k}".`);return}if(j.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private subtree.");return}const P=typeof h.requestId=="string"?h.requestId:void 0,M=(Ze=ie.current)==null?void 0:Ze.call(ie),H=V=>{const G=M,Ne=G==null?void 0:G.localParticipant;if(Ne!=null&&Ne.publishData)try{const Sn=P?{...V,requestId:P}:V,Cn=new TextEncoder().encode(JSON.stringify(Sn));Ne.publishData(Cn,{reliable:!0})}catch{}};let q=!1;const N=()=>{q=!0,H({type:"form_submitted",formId:k})};j.addEventListener("submit",N,{once:!0});try{typeof j.requestSubmit=="function"?j.requestSubmit():j.submit()}catch(V){console.warn("[LiveLayer] submit_form: requestSubmit threw.",V),j.removeEventListener("submit",N),H({type:"form_submit_blocked",formId:k,reason:"exception"});return}setTimeout(()=>{q||(j.removeEventListener("submit",N),H({type:"form_submit_blocked",formId:k,reason:"validation"}))},500);return}if(h.type==="request_routes"){if(!ge("read_page")){ye("request_routes","read_page");return}const k=typeof h.requestId=="string"?h.requestId:void 0,P=(Et=ie.current)==null?void 0:Et.call(ie),M=P==null?void 0:P.localParticipant;if(!(M!=null&&M.publishData))return;const H=N=>{try{const V=k?{type:"routes",routes:N,requestId:k}:{type:"routes",routes:N},G=new TextEncoder().encode(JSON.stringify(V));M.publishData(G,{reliable:!0})}catch(V){console.warn("[LiveLayer] request_routes: publishData failed.",V)}},q=yt.current;if(q){try{const N=q(),V=G=>{if(!Array.isArray(G)){H([]);return}H(G.map(un).slice(0,200))};N instanceof Promise?N.then(V).catch(G=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",G),H(nt())}):V(N)}catch(N){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",N),H(nt())}return}try{H(nt())}catch(N){console.warn("[LiveLayer] request_routes: extractRoutes threw.",N)}return}vr.has(h.type)||Le==null||Le(h)}},[Le,Ce]),U=Vt({agentId:B?"__controlled__":Ve,baseUrl:o,apiKey:i,sessionEndpoint:s,sessionBody:a,onDataMessage:B?void 0:$e});n.useEffect(()=>{if(B!=null&&B.subscribeToDataMessages)return B.subscribeToDataMessages($e)},[B,$e]),ie.current=()=>{var y;return(y=U.getRoom)==null?void 0:y.call(U)},n.useEffect(()=>{var X;if(typeof window>"u")return;const y=((X=window.location)==null?void 0:X.hostname)||"";if(y==="localhost"||y==="127.0.0.1"||y==="0.0.0.0"||y.endsWith(".local")||y.endsWith(".test"))return window.__livelayerSimulateCommand=Qe=>{try{$e(Qe)}catch(Ze){console.warn("[LiveLayer] simulate-command threw:",Ze)}},()=>{delete window.__livelayerSimulateCommand}},[$e]);const v=n.useMemo(()=>B?{connectionState:B.connectionState,agentState:B.agentState,transcript:B.transcript,videoElement:B.videoElement,audioElement:B.audioElement,canResume:B.canResume,error:B.error,agentConfig:null,connect:async()=>{await B.onConnect()},disconnect:()=>B.onDisconnect(),getRoom: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},[B,U]),bt=n.useRef(null);n.useEffect(()=>{const y=v.videoElement,h=bt.current;if(!(!y||!h))return h.appendChild(y),()=>{y.parentNode===h&&h.removeChild(y)}},[v.videoElement]),n.useEffect(()=>{const y=v.audioElement;if(!y)return;je.attach(y);const h=y.play();return h&&typeof h.catch=="function"&&h.catch(X=>{(X==null?void 0:X.name)==="NotAllowedError"&&Re(!0)}),()=>{je.detach()}},[v.audioElement]),n.useEffect(()=>{if(v.isControlled||v.connectionState!=="connected")return;const y=v.getRoom();if(y)return K.setupMic(y).catch(()=>{}),Q.attachRoom(y),te.attachRoom(y),me.refresh(),()=>{K.teardownMic(),Q.teardown(),te.teardown()}},[v.isControlled,v.connectionState]),n.useEffect(()=>{const y=v.audioElement;y&&(y.muted=Pe)},[v.audioElement,Pe]);const pn=n.useCallback(y=>{const h=v.getRoom();if(h)try{const X=new TextEncoder().encode(JSON.stringify({type:"user_message",text:y}));h.localParticipant.publishData(X,{reliable:!0})}catch{}},[v]),hn=n.useCallback(()=>{Xe(y=>!y)},[]);n.useEffect(()=>{Se==null||Se(v.connectionState),v.connectionState==="connected"?ve==null||ve():v.connectionState==="disconnected"&&(we==null||we())},[v.connectionState,ve,we,Se]),n.useEffect(()=>{_e==null||_e(v.transcript)},[v.transcript,_e]),n.useEffect(()=>{ke==null||ke(v.agentState)},[v.agentState,ke]),n.useEffect(()=>{p.setThinking(v.agentState==="thinking")},[v.agentState,p]);const xt=n.useRef(!1);n.useEffect(()=>{v.isControlled||!d||xt.current||le&&v.connectionState==="idle"&&(xt.current=!0,v.connect())},[d,v.connectionState,v,le]);const mn=n.useCallback(y=>{const h=w==null?void 0:w.find(X=>X.id===y);h&&(re(!1),y!==ce&&(Ye(!0),v.disconnect(),pe||st(y),b==null||b(h)))},[w,ce,v,pe,b]);n.useEffect(()=>{Te&&v.connectionState==="connected"&&Ye(!1)},[v.connectionState,Te]),n.useEffect(()=>{if(!ne)return;const y=h=>{h.key==="Escape"&&re(!1)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[ne]);const gn=!!T||!!(W!=null&&W.avatarImageUrl)||v.isControlled,ze=Qt(Ve,o,gn);ae===void 0&&((wt=ze.info)!=null&&wt.capabilities)&&(ut.current=ze.info.capabilities);const Je=(W==null?void 0:W.name)??x??((_t=v.agentConfig)==null?void 0:_t.name)??((kt=ze.info)==null?void 0:kt.name)??"Live Layer",dt=(W==null?void 0:W.avatarImageUrl)??T??((St=v.agentConfig)==null?void 0:St.avatarImageUrl)??((Ct=ze.info)==null?void 0:Ct.avatarImageUrl)??null,yn=I??((Lt=v.agentConfig)==null?void 0:Lt.idleLoopUrl)??((jt=ze.info)==null?void 0:jt.idleLoopUrl)??null,bn=E??null,xn=n.useCallback(()=>ue("expanded"),[ue]),vn=n.useCallback(()=>ue("minimized"),[ue]),vt=n.useCallback(()=>{v.disconnect(),ue("hidden")},[v,ue]),wn=n.useCallback(()=>{const y=v.audioElement;y&&y.play().then(()=>Re(!1)).catch(()=>{})},[v.audioElement]),_n=n.useCallback(()=>{Re(!1),v.connect()},[v]),He={...We,zIndex:Fe};S.primaryColor&&(He["--ll-color-primary"]=S.primaryColor),S.accentColor&&(He["--ll-color-accent"]=S.accentColor),S.backgroundColor&&(He["--ll-color-bg"]=S.backgroundColor),S.textColor&&(He["--ll-color-fg"]=S.textColor);const kn=["ll-widget",`ll-widget--${he}`,`ll-widget--${xe?"mobile":"desktop"}`,Be].filter(Boolean).join(" ");return le?t.jsxs("div",{className:kn,style:He,"data-display-mode":he,"data-position":l,children:[he==="hidden"&&t.jsx(Un,{position:l,isMobile:xe,isSpeaking:v.agentState==="speaking",onExpand:()=>ue("expanded"),label:`Open ${Je} widget`,avatarImageUrl:dt,agentName:Je}),he==="minimized"&&t.jsx(Yn,{position:l,isMobile:xe,agentName:Je,avatarImageUrl:dt,agentState:v.agentState,isMuted:K.isMuted,audioLevel:je,onExpand:xn,onToggleMute:K.toggleMute,onClose:vt}),he==="expanded"&&t.jsx(Kn,{position:l,isMobile:xe,agentName:Je,avatarImageUrl:dt,idleLoopUrl:yn,greeting:bn,branding:S,teamMembers:w,currentTeamMemberId:ce,isSwitchingTeamMember:Te,teamSwitcherOpen:ne,onToggleTeamSwitcher:()=>re(y=>!y),onSelectTeamMember:mn,connectionState:v.connectionState,agentState:v.agentState,transcript:v.transcript,isMuted:K.isMuted,micDevices:me.mics,isCameraEnabled:Q.isEnabled,cameraPreviewEl:Q.previewEl,cameraDevices:me.cameras,activeCameraId:Q.activeDeviceId,isScreenShareEnabled:te.isEnabled,screenPreviewEl:te.previewEl,isSpeakerMuted:Pe,allowCamera:$,allowScreenShare:A,allowTyping:C,languageMenuOpen:Ge,onToggleLanguageMenu:()=>Ke(y=>!y),needsUserGesture:Ee,canResume:v.canResume,micError:K.micError,error:v.error,avatarVideoContainerRef:bt,agentVideoEl:v.videoElement,onConnect:()=>void v.connect(),onDisconnect:()=>v.disconnect(),onRetry:_n,onResumeAudio:wn,onToggleMute:K.toggleMute,onToggleCamera:()=>void Q.toggle(),onSwitchCameraDevice:y=>void Q.switchDevice(y),onToggleScreenShare:()=>void te.toggle(),onToggleSpeaker:hn,onSendMessage:pn,onMinimize:vn,onClose:vt,onClearMicError:K.clearError})]}):null}function _r(e){return t.jsx(Ut,{children:t.jsx(wr,{...e})})}const kr=({agentId:e,baseUrl:r,apiKey:i,mode:o,onAgentEvent:s,className:a,style:u})=>{const d=n.useRef(null),f=n.useRef(null),m=n.useRef(s);m.current=s;const g=n.useCallback(l=>{var L;const c=l.detail;(L=m.current)==null||L.call(m,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),i&&c.setAttribute("api-key",i),o&&c.setAttribute("mode",o),c.addEventListener("agent-event",g),l.appendChild(c),f.current=c,()=>{c.removeEventListener("agent-event",g),l.removeChild(c),f.current=null}},[e]),n.useEffect(()=>{f.current&&(o?f.current.setAttribute("mode",o):f.current.removeAttribute("mode"))},[o]),t.jsx("div",{ref:d,className:a,style:u})},Sr=n.forwardRef(function({id:r,intent:i,as:o="div",className:s,style:a,children:u},d){return n.createElement(o,{ref:d,"data-ll-region":r,"data-ll-intent":i,className:s,style:a},u)}),Cr=n.forwardRef(function({id:r,intent:i,children:o,...s},a){return t.jsx("form",{ref:a,"data-ll-form":r,"data-ll-intent":i,...s,children:o})}),Lr=n.forwardRef(function(r,i){const{name:o,label:s,labelClassName:a}=r,u={name:o,"data-ll-field":o};let d;if("as"in r&&r.as==="textarea"){const{name:f,label:m,labelClassName:g,as:l,...c}=r;d=t.jsx("textarea",{ref:i,...u,...c})}else if("as"in r&&r.as==="select"){const{name:f,label:m,labelClassName:g,as:l,children:c,...L}=r;d=t.jsx("select",{ref:i,...u,...L,children:c})}else{const{name:f,label:m,labelClassName:g,as:l,...c}=r;d=t.jsx("input",{ref:i,...u,...c})}return s===void 0?d:t.jsxs("label",{className:a,children:[s,d]})});let Ft=1;function jr({onMount:e,defaultOpen:r=!1,storageKey:i="ll-debug-open"}){const[o,s]=n.useState(r),[a,u]=n.useState([]),[d,f]=n.useState(""),[m,g]=n.useState(!1),l=n.useRef(new Set),c=n.useRef([]),L=n.useRef(m);L.current=m,n.useEffect(()=>{try{const _=localStorage.getItem(i);_==="1"&&s(!0),_==="0"&&s(!1)}catch{}},[i]),n.useEffect(()=>{try{localStorage.setItem(i,o?"1":"0")}catch{}},[o,i]),n.useEffect(()=>{const _=b=>{(b.metaKey||b.ctrlKey)&&b.shiftKey&&b.key.toLowerCase()==="l"&&(b.preventDefault(),s(I=>!I))};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[]),n.useEffect(()=>{const _=setInterval(()=>{if(c.current.length===0||L.current)return;const b=c.current.splice(0,c.current.length);u(I=>[...b.reverse(),...I].slice(0,200))},100);return()=>clearInterval(_)},[]);const D=n.useRef(!1);if(n.useEffect(()=>{!e||D.current||(D.current=!0,e(_=>{c.current.push({id:Ft++,ts:Date.now(),kind:"event",type:_.eventName,data:_.data})}))},[e]),n.useEffect(()=>{const _=console.warn,b=console.log,I=(E,T)=>function(...x){try{const S=typeof x[0]=="string"?x[0]:"";S.startsWith("[LiveLayer]")&&c.current.push({id:Ft++,ts:Date.now(),kind:E,type:S.slice(0,120),data:{args:x.slice(1).map($=>Rr($))}})}catch{}return T.apply(this,x)};return console.warn=I("warn",_),console.log=I("log",b),()=>{console.warn=_,console.log=b}},[]),!o)return t.jsx("button",{type:"button",onClick:()=>s(!0),title:"Open LiveLayer debug panel (Cmd/Ctrl + Shift + L)","aria-label":"Open LiveLayer debug panel",style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.18)",borderRadius:999,padding:"6px 10px",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",cursor:"pointer",boxShadow:"0 4px 12px rgba(0,0,0,0.35)",opacity:.85},children:"🛰 LL debug"});const w=a.filter(_=>{if(!d)return!0;const b=d.toLowerCase();return _.type.toLowerCase().includes(b)||JSON.stringify(_.data||{}).toLowerCase().includes(b)});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:()=>g(_=>!_),style:ft(m?"#f59e0b":"transparent"),title:"Pause / resume capture",children:m?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{u([]),c.current=[]},style:ft("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:ft("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:d,onChange:_=>f(_.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:w.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"),Ln=require("@livelayer/sdk"),rt=require("livekit-client");class Ut extends n.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,i){var o,s;(s=(o=this.props).onError)==null||s.call(o,r,i)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[t.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),t.jsx("p",{className:"ll-error-boundary__message",children:((r=this.state.error)==null?void 0:r.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function Vt(e){const[r,i]=n.useState("idle"),[o,s]=n.useState("idle"),[a,u]=n.useState([]),[d,f]=n.useState(null),[m,g]=n.useState(null),[l,c]=n.useState(null),[L,D]=n.useState(!1),[_,w]=n.useState(null),b=n.useRef(null),T=n.useRef(e.onDataMessage);T.current=e.onDataMessage,n.useEffect(()=>{const S={onConnectionStateChange:A=>{i(A),A==="connected"&&w(null)},onAgentStateChange:s,onTranscript:A=>u([...A]),onAgentConfig:f,onAudioTrack:A=>c(A),onVideoTrack:A=>g(A),onVideoTrackRemoved:()=>g(null),onError:A=>w(A),onDataMessage:A=>{var C;(C=T.current)==null||C.call(T,A)},onResumabilityChange:D},$=new Ln.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},S);return b.current=$,i("idle"),s("idle"),u([]),f(null),g(null),c(null),D(!1),w(null),()=>{var A;(A=$.destroy)==null||A.call($),b.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=n.useCallback(async()=>{const S=b.current;if(S)try{await S.connect()}catch($){throw w($ instanceof Error?$.message:String($)),$}},[]),I=n.useCallback(()=>{const S=b.current;S&&S.disconnect()},[]),x=n.useCallback(()=>{var S;return((S=b.current)==null?void 0:S.getRoom())??null},[]);return{connectionState:r,agentState:o,transcript:a,agentConfig:d,videoElement:m,audioElement:l,canResume:L,error:_,connect:E,disconnect:I,getRoom:x,session:b.current}}function Yt(){const e=n.useRef(null),r=n.useRef(null),i=n.useRef(null),o=n.useRef(null),s=n.useRef(new Set),a=n.useRef(null),u=n.useCallback(()=>{const l=r.current;if(!l){o.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 _=0;_<c.length;_++)L+=c[_];const D=L/c.length/255;for(const _ of s.current)try{_(D)}catch(w){console.error("[useAudioLevel] subscriber threw:",w)}o.current=requestAnimationFrame(u)},[]),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},[]),f=n.useCallback(l=>{if(d(),!(!e.current||!r.current)){if(i.current){try{i.current.disconnect()}catch{}i.current=null}try{const c=e.current.createMediaElementSource(l);c.connect(r.current),i.current=c}catch(c){console.warn("[useAudioLevel] createMediaElementSource failed:",c);return}o.current===null&&(o.current=requestAnimationFrame(u))}},[d,u]),m=n.useCallback(()=>{if(o.current!==null&&(cancelAnimationFrame(o.current),o.current=null),i.current){try{i.current.disconnect()}catch{}i.current=null}},[]),g=n.useCallback(l=>(s.current.add(l),()=>{s.current.delete(l)}),[]);return n.useEffect(()=>()=>{if(m(),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},[m]),{attach:f,detach:m,subscribe:g}}function Gt(){const[e,r]=n.useState(!1),[i,o]=n.useState(null),s=n.useRef(null),a=n.useRef(null),u=n.useCallback(async g=>{if(s.current&&a.current){try{await a.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}a.current=g,o(null);try{const l=await rt.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await g.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 o(c),l}},[]),d=n.useCallback(()=>{const g=s.current;g&&(g.isMuted?(g.unmute(),r(!1)):(g.mute(),r(!0)))},[]),f=n.useCallback(()=>{const g=s.current,l=a.current;if(g&&l){try{l.localParticipant.unpublishTrack(g)}catch{}g.stop()}s.current=null,a.current=null,r(!1)},[]),m=n.useCallback(()=>o(null),[]);return{isMuted:e,micError:i,toggleMute:d,setupMic:u,teardownMic:f,clearError:m}}const jn={resolution:{width:640,height:480,frameRate:24}};function Kt(){const[e,r]=n.useState(!1),[i,o]=n.useState(null),[s,a]=n.useState(null),[u,d]=n.useState(""),f=n.useRef(null),m=n.useRef(null),g=n.useCallback(b=>{f.current=b},[]),l=n.useCallback(()=>{const b=f.current,T=m.current;if(T&&b){const E=b.localParticipant.getTrackPublication(rt.Track.Source.Camera);if(E!=null&&E.track){try{b.localParticipant.unpublishTrack(E.track)}catch{}E.track.stop()}else T.stop()}m.current=null,a(null),r(!1)},[]),c=n.useCallback(async b=>{const T=f.current;if(T){o(null);try{const E={...jn};b&&(E.deviceId=b);const I=await rt.createLocalVideoTrack(E);await T.localParticipant.publishTrack(I),m.current=I;const x=I.attach();a(x),r(!0),b&&d(b);try{T.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const I=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";o(I)}}},[]),L=n.useCallback(async()=>{e?l():await c(u||void 0)},[e,u,l,c]),D=n.useCallback(async b=>{l(),await c(b)},[l,c]),_=n.useCallback(()=>{l(),f.current=null,o(null),d("")},[l]),w=n.useCallback(()=>o(null),[]);return n.useEffect(()=>()=>{m.current&&m.current.stop()},[]),{isEnabled:e,error:i,previewEl:s,activeDeviceId:u,toggle:L,switchDevice:D,attachRoom:g,teardown:_,clearError:w}}function Xt(){const[e,r]=n.useState(!1),[i,o]=n.useState(null),[s,a]=n.useState(null),u=n.useRef(null),d=n.useCallback(c=>{u.current=c},[]),f=n.useCallback(()=>a(null),[]),m=n.useCallback(async()=>{const c=u.current;if(c){if(e){try{await c.localParticipant.setScreenShareEnabled(!1)}catch{}f(),r(!1);return}o(null);try{await c.localParticipant.setScreenShareEnabled(!0);let L=0;const D=()=>{const _=c.localParticipant.getTrackPublication(rt.Track.Source.ScreenShare);if(_!=null&&_.track){const w=_.track.attach();a(w),r(!0);try{c.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}L++<10?setTimeout(D,100):r(!0)};D()}catch(L){const D=L instanceof Error?L.name:"";D!=="NotAllowedError"&&D!=="AbortError"&&o("Screen share unavailable. Try again."),r(!1)}}},[e,f]),g=n.useCallback(()=>{const c=u.current;if(c&&e)try{c.localParticipant.setScreenShareEnabled(!1)}catch{}f(),r(!1),o(null),u.current=null},[e,f]),l=n.useCallback(()=>o(null),[]);return{isEnabled:e,error:i,previewEl:s,toggle:m,attachRoom:d,teardown:g,clearError:l}}function Jt(){const[e,r]=n.useState([]),[i,o]=n.useState([]),s=n.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const a=await navigator.mediaDevices.enumerateDevices();r(a.filter(u=>u.kind==="audioinput")),o(a.filter(u=>u.kind==="videoinput"))}catch{}},[]);return n.useEffect(()=>{if(s(),typeof navigator>"u"||!navigator.mediaDevices)return;const a=()=>void s();return navigator.mediaDevices.addEventListener("devicechange",a),()=>navigator.mediaDevices.removeEventListener("devicechange",a)},[s]),{mics:e,cameras:i,refresh:s}}function Qt(e,r,i=!1){const[o,s]=n.useState(null),[a,u]=n.useState(null),[d,f]=n.useState(!i&&!!e);return n.useEffect(()=>{if(i||!e){f(!1);return}const m=new AbortController,g=r||"https://app.livelayer.studio";return f(!0),u(null),fetch(`${g}/api/widget/agent/${encodeURIComponent(e)}`,{signal:m.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=>{m.signal.aborted||(s(l),f(!1))}).catch(l=>{m.signal.aborted||(u(l instanceof Error?l.message:"Agent lookup failed"),f(!1))}),()=>m.abort()},[e,r,i]),{info:o,error:a,loading:d}}function En(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Rn(e,r){if(!(typeof window>"u"))try{window.localStorage.setItem(e,r)}catch{}}function Zt({value:e,defaultValue:r="expanded",onChange:i}={}){const o=e!==void 0,[s,a]=n.useState(r),u=o?e:s,d=n.useCallback(f=>{f!==u&&(o||a(f),i==null||i(f))},[u,o,i]);return[u,d]}const Nn=["hidden","minimized","expanded"];function An(e){return e&&Nn.includes(e)?e:null}function en({value:e,defaultValue:r="expanded",onChange:i,persistKey:o="ll-widget",disablePersistence:s=!1}={}){const a=`${o}:display-mode`,u=n.useRef(!1),[d,f]=Zt({value:e,defaultValue:r,onChange:m=>{e===void 0&&!s&&Rn(a,m),i==null||i(m)}});return n.useEffect(()=>{if(u.current||(u.current=!0,s||e!==void 0))return;const m=An(En(a));m&&m!==d&&f(m)},[]),[d,f]}const Mn=640;function tn(e=Mn){const[r,i]=n.useState(!1);return n.useEffect(()=>{if(e===!1){i(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const o=`(max-width: ${e-1}px)`,s=window.matchMedia(o),a=()=>i(s.matches);return a(),typeof s.addEventListener=="function"?(s.addEventListener("change",a),()=>s.removeEventListener("change",a)):(s.addListener(a),()=>{s.removeListener(a)})},[e]),r}const Rt="__llHistoryPatched",it="ll:pathname";function In(){if(typeof window>"u"||window.history[Rt])return;const e=window.history.pushState,r=window.history.replaceState;window.history.pushState=function(...i){const o=e.apply(this,i);return window.dispatchEvent(new Event(it)),o},window.history.replaceState=function(...i){const o=r.apply(this,i);return window.dispatchEvent(new Event(it)),o},window.history[Rt]=!0}function Nt(){return typeof window>"u"?"/":window.location.pathname||"/"}function nn(e){const[r,i]=n.useState(()=>e??Nt());return n.useEffect(()=>{if(e!==void 0)return;In();const o=()=>i(Nt());return o(),window.addEventListener("popstate",o),window.addEventListener(it,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(it,o)}},[e]),e??r}const At=new Map,Tn=/[\\^$+?.()|{}[\]]/g;function Pn(e){return e.replace(Tn,"\\$&")}function Dn(e){const r=At.get(e);if(r)return r;const i=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,o="",s="",a=i.replace(/\*\*/g,o).replace(/\*/g,s),d=Pn(a).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(s,"g"),"[^/]+"),f=new RegExp(`^${d}\\/?$`);return At.set(e,f),f}function $n(e,r){const i=r.length>1&&r.endsWith("/")?r.slice(0,-1):r;return Dn(e).test(i)}function rn(e,r){return typeof e=="function"?e(r):e instanceof RegExp?e.test(r):$n(e,r)}function Mt(e,r){if(!e||e.length===0)return!1;for(const i of e)if(rn(i,r))return!0;return!1}function on(e,r,i){return e===void 0?!0:Mt(i,e)?!1:r&&r.length>0?Mt(r,e):!0}function sn(e,r,i){return n.useMemo(()=>on(e,r,i),[e,r,i])}function zn(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 Hn(e){const r=n.useMemo(()=>zn(e.config),[e.config]),i=e.baseUrl.replace(/\/+$/,""),o=n.useRef(null),s=n.useCallback(f=>{try{new Audio(`${i}${f}`).play().catch(()=>{})}catch{}},[i]),a=n.useCallback(()=>{r.navigate&&s("/audio/page-change-sound.mp3")},[r.navigate,s]),u=n.useCallback(()=>{r.action&&s("/audio/confirmation-sound.mp3")},[r.action,s]),d=n.useCallback(f=>{if(!r.thinking){if(o.current){try{o.current.pause()}catch{}o.current=null}return}if(f){if(o.current)return;try{const m=new Audio(`${i}/audio/thinking-sound.mp3`);m.loop=!0,m.volume=.3,m.play().catch(()=>{o.current=null}),o.current=m}catch{}}else if(o.current){try{o.current.pause()}catch{}o.current=null}},[i,r.thinking]);return n.useEffect(()=>()=>{if(o.current){try{o.current.pause()}catch{}o.current=null}},[]),n.useMemo(()=>({playPageChange:a,playConfirmation:u,setThinking:d}),[a,u,d])}const It=({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"})}),Tt=({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"})}),On=({className:e})=>t.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),qn={left:180,right:0,up:-90,down:90},Pt=({direction:e="right",className:r})=>t.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${qn[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function Bn(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const an="ll-hidden-tab-center-y",Wn=5,Dt=16;function Fn(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(an);if(!e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null}catch{return null}}function $t(e){if(!(typeof window>"u"))try{window.localStorage.setItem(an,String(e))}catch{}}const Un=({position:e,isMobile:r,isSpeaking:i,onExpand:o,label:s="Open widget",avatarImageUrl:a,agentName:u})=>{const d=Bn(e),f=d==="right"?"left":"right",m=r?80:72,g=!!a,[l,c]=n.useState(null),[L,D]=n.useState(!1),_=n.useRef(null),w=n.useRef(!1),b=n.useCallback(C=>{if(typeof window>"u")return C;const R=m/2,z=Dt+R,F=window.innerHeight-Dt-R;return F<z?Math.max(z,C):Math.max(z,Math.min(F,C))},[m]);n.useEffect(()=>{const C=Fn();c(b(C??window.innerHeight/2));const R=()=>{c(z=>z===null?null:b(z))};return window.addEventListener("resize",R),()=>window.removeEventListener("resize",R)},[b]);const T=n.useCallback(C=>{if(!(C.pointerType==="mouse"&&C.button!==0)&&l!==null){try{C.currentTarget.setPointerCapture(C.pointerId)}catch{}_.current={startClientY:C.clientY,startCenterY:l,moved:!1}}},[l]),E=n.useCallback(C=>{const R=_.current;if(!R)return;const z=C.clientY-R.startClientY;!R.moved&&Math.abs(z)>Wn&&(R.moved=!0,D(!0)),R.moved&&c(b(R.startCenterY+z))},[b]),I=n.useCallback(C=>{const R=_.current;if(R){try{C.currentTarget.releasePointerCapture(C.pointerId)}catch{}_.current=null,R.moved&&(D(!1),w.current=!0,c(z=>(z!==null&&$t(z),z)))}},[]),x=n.useCallback(()=>{if(w.current){w.current=!1;return}o()},[o]),S=n.useCallback(C=>{if(C.key==="ArrowUp"||C.key==="ArrowDown"){C.preventDefault();const R=C.key==="ArrowUp"?-8:8;c(z=>{if(z===null)return z;const F=b(z+R);return $t(F),F})}},[b]),$=["ll-hidden",`ll-hidden--${d}`,r?"ll-hidden--mobile":"ll-hidden--desktop",i?"ll-hidden--speaking":null,L?"is-dragging":null,g?"ll-hidden--with-avatar":null].filter(Boolean).join(" "),A=l===null?void 0:{top:`${l-m/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:$,onPointerDown:T,onPointerMove:E,onPointerUp:I,onPointerCancel:I,onClick:x,onKeyDown:S,"aria-label":s,"data-position":e,style:A,children:g?t.jsxs(t.Fragment,{children:[t.jsx(Pt,{direction:f,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:a,alt:u?`${u} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(Pt,{direction:f,className:"ll-hidden__chevron"})})},Vn=({audioLevel:e,bars:r=20,maxHeight:i=20,minHeight:o=4,className:s,barClassName:a})=>{const u=n.useRef(null),d=n.useRef([]),f=n.useMemo(()=>{const g=(Math.sqrt(5)-1)/2;return Array.from({length:r},(l,c)=>.5+c*g%1*.5)},[r]);n.useEffect(()=>e.subscribe(l=>{for(let c=0;c<r;c++){const L=d.current[c];if(!L)continue;const D=Math.max(o,l*i*f[c]);L.style.height=`${D}px`}}),[e,r,i,o,f]);const m=["ll-waveform",s].filter(Boolean).join(" ");return t.jsx("div",{ref:u,className:m,"aria-hidden":"true",children:Array.from({length:r},(g,l)=>t.jsx("div",{ref:c=>{d.current[l]=c},className:["ll-waveform__bar",a].filter(Boolean).join(" "),style:{height:`${o}px`}},l))})},Yn=({position:e,isMobile:r,agentName:i,avatarImageUrl:o,agentState:s,isMuted:a,audioLevel:u,onExpand:d,onToggleMute:f,onClose:m})=>r?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${i} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:d,"aria-label":`Expand ${i} widget`,children:[o?t.jsx("img",{src:o,alt:i,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsx(Vn,{audioLevel:u,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),t.jsx("span",{className:"ll-minimized__name",children:i}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:g=>{g.stopPropagation(),f()},onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.stopPropagation(),g.preventDefault(),f())},"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(It,{muted:a,className:"ll-minimized__icon"})}),t.jsx(Tt,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):t.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":e,role:"region","aria-label":`${i} widget`,children:t.jsxs("div",{className:"ll-minimized__surface",children:[o?t.jsx("img",{src:o,alt:i,className:"ll-minimized__avatar"}):t.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),t.jsxs("div",{className:"ll-minimized__meta",children:[t.jsx("span",{className:"ll-minimized__name",children:i}),t.jsx("span",{className:"ll-minimized__state",children:s==="speaking"?"Speaking":s==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:f,"aria-label":a?"Unmute microphone":"Mute microphone",children:t.jsx(It,{muted:a,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:d,"aria-label":`Expand ${i} widget`,children:t.jsx(Tt,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:m,"aria-label":"Close widget",children:t.jsx(On,{className:"ll-minimized__icon"})})]})]})}),Gn=({src:e,alt:r,preCannedPlaying:i=!1,className:o,style:s})=>{const[a,u]=n.useState(!1),d=n.useRef(e);if(n.useEffect(()=>{d.current!==e&&(d.current=e,u(!1))},[e]),!e)return null;const f={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:i?"scale(1.02)":"scale(1)",opacity:a?1:0,...s};return t.jsx("img",{src:e,alt:r,className:o,style:f,loading:"eager",fetchPriority:"high",onLoad:()=>u(!0)})},Kn=({position:e,isMobile:r,agentName:i,avatarImageUrl:o,idleLoopUrl:s,greeting:a,branding:u,teamMembers:d,currentTeamMemberId:f,isSwitchingTeamMember:m,teamSwitcherOpen:g,onToggleTeamSwitcher:l,onSelectTeamMember:c,languageMenuOpen:L,onToggleLanguageMenu:D,connectionState:_,agentState:w,transcript:b,canResume:T,needsUserGesture:E,error:I,isMuted:x,micError:S,micDevices:$,isCameraEnabled:A,cameraPreviewEl:C,cameraDevices:R,activeCameraId:z,isScreenShareEnabled:F,screenPreviewEl:Z,isSpeakerMuted:J,allowCamera:be,allowScreenShare:oe,allowTyping:fe,avatarVideoContainerRef:se,agentVideoEl:Y,onConnect:ae,onDisconnect:ve,onRetry:we,onResumeAudio:_e,onToggleMute:ke,onToggleCamera:Se,onSwitchCameraDevice:Ce,onToggleScreenShare:Le,onToggleSpeaker:B,onSendMessage:Be,onMinimize:We,onClose:Fe,onClearMicError:Ue})=>{var Xe;const le=((d==null?void 0:d.length)??0)>1,pe=_==="connecting"||_==="connected",ee=_==="connected",st=_==="idle"||_==="disconnected"||_==="error",[ce,W]=n.useState(!1);n.useEffect(()=>{if(!Y){W(!1);return}if(!Y.paused&&Y.readyState>=2){W(!0);return}W(!1);const p=()=>W(!0);return Y.addEventListener("playing",p),Y.addEventListener("loadeddata",p),()=>{Y.removeEventListener("playing",p),Y.removeEventListener("loadeddata",p)}},[Y]);const[Ve,he]=n.useState(!1);n.useEffect(()=>{if(!ee){he(!1);return}if(ce)return;const p=setTimeout(()=>he(!0),8e3);return()=>clearTimeout(p)},[ee,ce]);const ue=_==="connecting"||ee&&!!o&&!ce&&!Ve,xe=n.useRef(null),je=n.useRef(null);n.useEffect(()=>{const p=xe.current;p&&(p.innerHTML="",C&&(C.style.width="100%",C.style.height="100%",C.style.objectFit="cover",C.style.transform="scaleX(-1)",p.appendChild(C)))},[C]),n.useEffect(()=>{const p=je.current;p&&(p.innerHTML="",Z&&(Z.style.width="100%",Z.style.height="100%",Z.style.objectFit="contain",p.appendChild(Z)))},[Z]);const[K,Q]=n.useState(!1),[te,me]=n.useState(!1);n.useEffect(()=>{if(!K&&!te&&!L&&!g)return;const p=()=>{Q(!1),me(!1),L&&D(),g&&l()};return document.addEventListener("click",p),()=>document.removeEventListener("click",p)},[K,te,L,g,D,l]);const[Ee,Re]=n.useState(""),Te=n.useCallback(p=>{p.preventDefault();const O=Ee.trim();O&&(Be(O),Re(""))},[Ee,Be]),Ye=u.productName||"Live Layer";let ne=null,re=null;for(let p=b.length-1;p>=0;p--){const O=b[p];if(!ne&&O.role==="agent"?ne=O:!re&&O.role==="user"&&(re=O),ne&&re)break}const Ge=ee?(ne==null?void 0:ne.text)||null:a||null,Ke=ee&&(re==null?void 0:re.text)||null,Pe=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:Pe,"data-position":e,"data-state":ee?"connected":pe?"connecting":"idle",role:"dialog","aria-label":`${i} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[o?t.jsx(Gn,{src:o,alt:i,className:"ll-expanded__bg-img"}):t.jsx("div",{className:"ll-expanded__bg-fallback",children:t.jsx("span",{className:"ll-expanded__bg-initial",children:((Xe=i==null?void 0:i.charAt(0))==null?void 0:Xe.toUpperCase())||"A"})}),s&&!ee&&t.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:se,className:"ll-expanded__video"}),ue&&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:m?"Switching...":"Connecting..."})]}),E&&ee&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:_e,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"})]}),pe?t.jsxs("div",{className:"ll-expanded__topbar",children:[t.jsxs("div",{className:"ll-expanded__topbar-left",children:[t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill",onClick:p=>{le&&(p.stopPropagation(),l())},"aria-haspopup":le?"listbox":void 0,"aria-expanded":le?g:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:i}),le&&t.jsx(et,{})]}),le&&g&&t.jsx("div",{className:"ll-hmenu",onClick:p=>p.stopPropagation(),role:"listbox",children:d==null?void 0:d.map(p=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${p.id===f?"is-active":""}`,onClick:()=>c(p.id),role:"option","aria-selected":p.id===f,children:[p.avatarImageUrl&&t.jsx("img",{src:p.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:p.name}),p.role&&t.jsx("span",{className:"ll-hmenu__role",children:p.role})]},p.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:p=>{p.stopPropagation(),D()},"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(et,{})]}),L&&t.jsx("div",{className:"ll-hmenu",onClick:p=>p.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--${w}`,children:w})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn",onClick:We,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(Ht,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Fe,"aria-label":"End call",title:"End call",children:t.jsx(zt,{})})]})]}):t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[t.jsx("span",{className:"ll-expanded__brand",children:Ye}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:We,"aria-label":"Minimize widget",children:t.jsx(Ht,{})}),t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:Fe,"aria-label":"Close widget",children:t.jsx(zt,{})})]})]}),st&&(()=>{const p=T?"Restart paused session":_==="disconnected"?"Reconnect to agent":"Start video call",O=T?"Pick up where you left off":null,De=!I;return t.jsxs(t.Fragment,{children:[De&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:ae,"aria-label":p,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:p})]}),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})}),O&&t.jsx("p",{className:"ll-expanded__cta-sublabel",children:O}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:ae,"aria-label":p,children:p})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${pe&&(A||F)?"is-visible":""}`,children:[t.jsx("div",{ref:je,className:F?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:xe,className:!F&&A?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),pe?t.jsxs("div",{className:"ll-expanded__bottom",children:[Ge&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Ge})}),Ke&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Ke})}),t.jsxs("div",{className:"ll-toolbar",onClick:p=>p.stopPropagation(),children:[oe&&t.jsx("button",{type:"button",className:`ll-tool ${F?"is-on":""}`,onClick:Le,"aria-label":F?"Stop sharing screen":"Share screen",title:F?"Stop sharing":"Share screen",children:t.jsx(Xn,{})}),be&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${A?"is-on":""}`,onClick:Se,"aria-label":A?"Turn off camera":"Turn on camera",title:A?"Stop camera":"Start camera",children:t.jsx(Jn,{})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${A?"is-on":""}`,onClick:p=>{p.stopPropagation(),me(O=>!O),Q(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":te,children:t.jsx(et,{})}),te&&R.length>0&&t.jsx(Ot,{label:"Camera",devices:R,activeId:z,onPick:p=>{me(!1),Ce(p)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${x?"is-muted":""}`,onClick:ke,"aria-label":x?"Unmute microphone":"Mute microphone",title:x?"Unmute":"Mute",children:t.jsx(Qn,{muted:x})}),t.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${x?"is-muted":""}`,onClick:p=>{p.stopPropagation(),Q(O=>!O),me(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":K,children:t.jsx(et,{})}),K&&$.length>0&&t.jsx(Ot,{label:"Microphone",devices:$,activeId:"",onPick:()=>Q(!1)})]}),t.jsx("button",{type:"button",className:`ll-tool ${J?"is-muted":""}`,onClick:B,"aria-label":J?"Unmute speaker":"Mute speaker",title:J?"Unmute speaker":"Mute speaker",children:t.jsx(Zn,{muted:J})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:ve,"aria-label":"End conversation",title:"End conversation",children:t.jsx(tr,{})})]}),fe&&t.jsxs("form",{className:"ll-message-input",onSubmit:Te,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:Ee,onChange:p=>Re(p.target.value),"aria-label":"Message the agent"}),Ee.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(er,{})})]})]}):null,(()=>{if(S&&_!=="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:Ue,"aria-label":"Dismiss",children:"×"})]});if(!I||_!=="error")return null;let p="Failed to connect",O="Try again";return I==="MIC_PERMISSION_DENIED"?p="Microphone blocked. Allow access to talk.":I==="MIC_NOT_FOUND"?p="No microphone found. Plug one in + retry.":I==="MIC_UNAVAILABLE"?p="Mic unavailable. Check other apps using it.":I==="AGENT_TIMEOUT"?p="Agent didn't pick up. Try again.":I==="CONNECT_FAILED"?p="Connection failed. Check your network.":I.length<80&&(p=I),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:p}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:we,children:O})]})})()]})};function et(){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 zt(){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 Ht(){return t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function Xn(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),t.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),t.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function Jn(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M23 7l-7 5 7 5V7z"}),t.jsx("rect",{x:"1",y:"5",width:"15",height:"14",rx:"2"})]})}function Qn({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),t.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),t.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),e&&t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Zn({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e?t.jsx("line",{x1:"23",y1:"9",x2:"17",y2:"15"}):t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"}),t.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]})]})}function er(){return t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),t.jsx("polyline",{points:"12 5 19 12 12 19"})]})}function tr(){return t.jsx("svg",{width:"16",height:"16",viewBox:"-4 -4 32 32",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.93.37 1.84.71 2.7a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.38-1.38a2 2 0 0 1 2.11-.45c.86.34 1.77.58 2.7.71A2 2 0 0 1 22 16.92z",transform:"rotate(135 12 12)"})})}const Ot=({label:e,devices:r,activeId:i,onPick:o})=>t.jsxs("div",{className:"ll-device-menu",onClick:s=>s.stopPropagation(),role:"listbox",children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),r.map((s,a)=>{const u=i===s.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${u?"is-active":""}`,onClick:()=>o(s.deviceId),role:"option","aria-selected":u,children:[u&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:s.label||`${e} ${a+1}`})]},s.deviceId||a)})]}),nr=['[data-ll-private="true"]',".ll-widget"];function ht(e){let r=e;for(;r;){for(const i of nr)if(r.matches(i))return!0;r=r.parentElement}return!1}function ot(e){if(ht(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 tt=4096,rr=20,ir=20,or=10,sr=10,ar=30,lr=20,qt=500,cr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function Oe(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let r=e;for(;r;){for(const i of cr)if(r.matches(i))return!0;r=r.parentElement}return!1}function qe(e){if(typeof window>"u")return!0;const r=e.getBoundingClientRect();if(r.width<=0||r.height<=0)return!1;const i=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth;return r.bottom>0&&r.right>0&&r.top<i&&r.left<o}function Bt(e){const r=e.getAttribute("id");if(r){const a=document.querySelector(`label[for="${CSS.escape(r)}"]`);if(a!=null&&a.textContent)return a.textContent.trim()}const i=e.getAttribute("aria-label");if(i)return i.trim();const o=e.getAttribute("placeholder");if(o)return o.trim();const s=e.closest("label");return s!=null&&s.textContent?s.textContent.trim():""}function de(e,r){return e.length<=r?e:e.slice(0,r-1)+"…"}function Ae(e){return e.length}function ln(e,r={}){const i=r.doc??(typeof document<"u"?document:null);if(!i)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const o=typeof window<"u"&&window.location.href||"",s=typeof window<"u"&&window.location.pathname||"/",a=i.title||"",u=Array.from(i.querySelectorAll("[data-ll-region]")),d=[];for(const x of u){if(d.length>=or)break;if(Oe(x)||!qe(x))continue;const S=x.getAttribute("data-ll-region")??"",$=x.getAttribute("data-ll-intent")??void 0,A=de((x.innerText||x.textContent||"").trim(),qt*2);!S||!A||d.push({id:S,intent:$,text:A})}const f=[],m=["H1","H2","H3","H4","H5","H6"],g=Array.from(i.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const x of g){if(Oe(x)||!qe(x))continue;const S=(x.textContent||"").trim();S&&f.push(`${x.tagName}: ${de(S,200)}`)}const l=Array.from(i.querySelectorAll("p, li"));for(const x of l){if(Oe(x)||!qe(x)||m.includes(x.tagName))continue;const S=(x.textContent||"").trim();S.length>10&&f.push(de(S,qt))}const c=f.join(`
|
|
2
|
+
`),L=[],D=Array.from(i.querySelectorAll("a[href]"));for(const x of D){if(L.length>=rr)break;if(Oe(x)||!qe(x))continue;const S=x.getAttribute("href")||"",$=(x.textContent||"").trim();!S||!$||L.push({href:S,text:de($,100)})}const _=[],w=Array.from(i.querySelectorAll("input, textarea, select"));for(const x of w){if(_.length>=ir)break;if(Oe(x)||!ot(x)||!qe(x))continue;const S=Bt(x),$=x instanceof HTMLInputElement?x.type:x.tagName.toLowerCase();S&&_.push({label:de(S,100),type:$})}const b=Array.from(i.querySelectorAll("[data-ll-form]")),T=[];for(const x of b){if(T.length>=sr)break;if(ht(x))continue;const S=x.getAttribute("data-ll-form")||"";if(!S)continue;const $=x.getAttribute("data-ll-intent")||void 0,A=Array.from(x.querySelectorAll("[data-ll-field]")),C=[];for(const R of A){if(C.length>=ar)break;if(!ot(R))continue;const z=R.getAttribute("data-ll-field")||"";if(!z)continue;const F=Bt(R)||z,Z=R instanceof HTMLInputElement?R.type:R.tagName.toLowerCase(),J={name:z,label:de(F,100),type:Z};if(R.required===!0&&(J.required=!0),R instanceof HTMLSelectElement){const oe=[];for(let fe=0;fe<R.options.length&&!(oe.length>=lr);fe++){const se=R.options[fe];if(!se||se.disabled)continue;const Y=se.value||"",ae=(se.textContent||"").trim()||Y;!Y&&!ae||oe.push({value:Y,label:de(ae,60)})}oe.length>0&&(J.options=oe)}const be=typeof R.validationMessage=="string"?R.validationMessage:"";be&&(J.validationMessage=de(be,200)),C.push(J)}T.push({id:S,intent:$,fields:C})}const E={url:o,title:a,pathname:s,regions:d,visibleText:c,visibleLinks:L,visibleFields:_,forms:T,extras:e};let I=Ae(JSON.stringify(E.regions))+Ae(E.visibleText)+Ae(JSON.stringify(E.visibleLinks))+Ae(JSON.stringify(E.visibleFields));for(;I>tt&&E.visibleFields.length>0;)E.visibleFields.pop(),I=Ae(JSON.stringify(E.visibleFields));for(;I>tt&&E.visibleLinks.length>0;)E.visibleLinks.pop(),I-=80;return Ae(E.visibleText)>tt&&(E.visibleText=de(E.visibleText,tt-100)),E}let Me=null;function pt(e,r={}){const i=Date.now(),s=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(Me&&Me.key===s&&i-Me.at<1e3)return Me.ctx;const a=ln(e,r);return Me={key:s,at:i,ctx:a},a}function cn(){Me=null}const ur=200;function un(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 dr(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function dn(e){const r=e??(typeof document<"u"?document:null);if(!r)return[];const i=typeof window<"u"&&window.location.origin||"",o=new Set,s=[],a=Array.from(r.querySelectorAll("a[href]"));for(const u of a){if(s.length>=ur)break;if(ht(u))continue;const d=u.getAttribute("href")||"";if(!dr(d))continue;let f=d,m=!0;try{if(typeof window<"u"){const l=new URL(d,i);m=l.origin===i,m&&d.startsWith("http")&&(f=l.pathname+l.search+l.hash)}}catch{continue}if(o.has(f))continue;o.add(f);const g=(u.textContent||"").trim().slice(0,120);s.push({href:f,text:g,internal:m})}return s}let Ie=null;const fr=5e3;function nt(){const e=Date.now(),r=typeof window<"u"&&window.location.pathname||"/";if(Ie&&Ie.pathname===r&&e-Ie.at<fr)return Ie.routes;const i=dn();return Ie={at:e,pathname:r,routes:i},i}function fn(){Ie=null}function pr(e,r){const i=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,o=Object.getOwnPropertyDescriptor(i,"value"),s=o==null?void 0:o.set;s?s.call(e,r):e.value=r}function hr(e,r,i={}){const o=i.triggerInput??!0,s=i.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const a=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),u=a==null?void 0:a.set,d=r==="true"||r==="1"||r==="on";u?u.call(e,d):e.checked=d,o&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}pr(e,r),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),s&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function mr(){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 gr(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function yr(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let r=null,i=0;for(const o of e){if(!gr(o))continue;const s=o.getBoundingClientRect();if(s.bottom<=0||s.top>=window.innerHeight||s.right<=0||s.left>=window.innerWidth||s.width<=0||s.height<=0||o.closest(".ll-widget"))continue;const a=s.width*s.height;a>i&&(i=a,r=o)}return r}function br(){if(typeof window>"u")return null;if(mr())return window;const e=yr();return e||window}function Wt(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function xr(e){var r,i;return e instanceof Window?typeof document>"u"?0:Math.max(((r=document.body)==null?void 0:r.scrollHeight)??0,((i=document.documentElement)==null?void 0:i.scrollHeight)??0):e.scrollHeight-e.clientHeight}const vr=new Set(["agent_state","avatar_stream_ready","avatar_active","avatar_idle","bot_ready","agent_error","idle_warning","idle_timeout","navigate","scroll_to","request_page_context","scroll_page","click","fill_form","focus_field","submit_form","request_routes"]);function wr(e){var wt,_t,kt,St,Ct,Lt,jt;const{agentId:r,apiKey:i,baseUrl:o="https://app.livelayer.studio",sessionEndpoint:s,sessionBody:a,soundEffects:u,autoConnect:d=!1,displayMode:f,defaultDisplayMode:m="expanded",onDisplayModeChange:g,position:l="bottom-right",mobileBreakpoint:c=640,persistKey:L="ll-widget",disablePersistence:D=!1,teamMembers:_,currentTeamMemberId:w,onTeamMemberChange:b,idleLoopUrl:T,greeting:E,avatarImageUrl:I,agentName:x,branding:S={},allowCamera:$=!0,allowScreenShare:A=!0,allowTyping:C=!0,showOn:R,hideOn:z,pathname:F,onNavigate:Z,onScrollToSelector:J,getPageContext:be,pageContextExtras:oe,getRoutes:fe,onScrollPage:se,onClick:Y,capabilities:ae,onConnect:ve,onDisconnect:we,onTranscript:_e,onAgentState:ke,onConnectionStateChange:Se,onAgentEvent:Ce,onAgentCommand:Le,controlledSession:B,className:Be,style:We,zIndex:Fe=2147483647}=e,Ue=nn(F),le=sn(Ue,R,z);n.useEffect(()=>{cn(),fn()},[Ue]);const pe=w!==void 0,[ee,st]=n.useState(()=>{var y;return w??((y=_==null?void 0:_[0])==null?void 0:y.id)}),ce=pe?w:ee,W=n.useMemo(()=>(_==null?void 0:_.find(y=>y.id===ce))??null,[_,ce]),Ve=(W==null?void 0:W.agentId)??r,[he,ue]=en({value:f,defaultValue:m,onChange:g,persistKey:L,disablePersistence:D}),xe=tn(c),je=Yt(),K=Gt(),Q=Kt(),te=Xt(),me=Jt(),[Ee,Re]=n.useState(!1),[Te,Ye]=n.useState(!1),[ne,re]=n.useState(!1),[Ge,Ke]=n.useState(!1),[Pe,Xe]=n.useState(!1),p=Hn({baseUrl:o,config:u}),O=n.useRef(p);O.current=p;const De=n.useRef(Z),at=n.useRef(J),lt=n.useRef(se),ct=n.useRef(Y),mt=n.useRef(be),gt=n.useRef(oe),yt=n.useRef(fe),ut=n.useRef(ae),ie=n.useRef(null);De.current=Z,at.current=J,lt.current=se,ct.current=Y,mt.current=be,gt.current=oe,yt.current=fe,ut.current=ae;function ge(y){const h=ut.current;return h?h.includes(y):!0}function ye(y,h){console.warn(`[LiveLayer] Agent command "${y}" blocked — capability "${h}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const $e=n.useCallback(y=>{var X,Qe,Ze,Et;const h=y;if(!(!h.type||typeof h.type!="string")){if(Ce==null||Ce({eventName:h.type,data:y}),h.type==="navigate"){if(!ge("navigate")){ye("navigate","navigate");return}const k=typeof h.href=="string"?h.href:null;if(!k){console.warn(`[LiveLayer] Agent emitted "navigate" without href. Skipping. Check your agent's tool schema. See https://livelayer.studio/docs/errors/navigate-missing-href`);return}if(O.current.playPageChange(),De.current){try{De.current(k)}catch(j){console.warn(`[LiveLayer] onNavigate threw for "${k}". Falling back. Error:`,j)}return}if(typeof document<"u"){const j=document.querySelector(`a[href="${k.replace(/"/g,'\\"')}"]`);if(j){j.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",k),window.dispatchEvent(new PopStateEvent("popstate"))}catch(j){console.warn(`[LiveLayer] history.pushState fallback failed for "${k}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,j)}return}if(h.type==="scroll_to"){if(!ge("scroll")){ye("scroll_to","scroll");return}const k=typeof h.selector=="string"?h.selector:null;if(!k)return;const j=h.behavior==="instant"?"instant":"smooth";if(at.current){try{at.current(k,j)}catch(P){console.warn("[LiveLayer] onScrollToSelector threw.",P)}return}if(typeof document<"u"){let P=null;try{P=document.querySelector(k)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${k}".`);return}if(!P){console.warn(`[LiveLayer] scroll_to: no element matched "${k}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}P.scrollIntoView({behavior:j,block:"start"})}return}if(h.type==="request_page_context"){if(!ge("read_page")){ye("request_page_context","read_page");return}const k=typeof h.requestId=="string"?h.requestId:void 0,j=(X=ie.current)==null?void 0:X.call(ie),P=q=>{const N=j,V=N==null?void 0:N.localParticipant;if(V!=null&&V.publishData)try{const G=k?{...q,requestId:k}:q,Ne=new TextEncoder().encode(JSON.stringify(G));V.publishData(Ne,{reliable:!0})}catch(G){console.warn("[LiveLayer] publishData failed.",G)}},M=gt.current,H=mt.current;try{if(H){const q=H(M);if(q instanceof Promise){P({type:"page_context_pending"}),q.then(N=>P({type:"page_context",context:N})).catch(N=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",N),P({type:"page_context",context:pt(M)})});return}P({type:"page_context",context:q});return}P({type:"page_context",context:pt(M)})}catch(q){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",q),P({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:M}})}return}if(h.type==="scroll_page"){if(!ge("scroll")){ye("scroll_page","scroll");return}const k=h.direction;if(k!=="up"&&k!=="down"&&k!=="top"&&k!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(k)}". Expected up | down | top | bottom.`);return}const j=h.behavior==="instant"?"instant":"smooth";if(lt.current){try{lt.current(k,j)}catch(N){console.warn("[LiveLayer] onScrollPage threw.",N)}return}if(typeof window>"u")return;const P={behavior:j},M=br(),H=N=>{M instanceof Window?M.scrollBy({top:N,...P}):M.scrollBy({top:N,...P})},q=N=>{M instanceof Window?M.scrollTo({top:N,...P}):M.scrollTo({top:N,...P})};k==="up"?H(-Wt(M)):k==="down"?H(Wt(M)):q(k==="top"?0:xr(M));return}if(h.type==="click"){if(!ge("click")){ye("click","click");return}const k=typeof h.selector=="string"?h.selector:null;if(!k){console.warn("[LiveLayer] click: missing selector.");return}if(ct.current){try{ct.current(k)}catch(P){console.warn("[LiveLayer] onClick threw.",P)}return}if(typeof document>"u")return;let j=null;try{j=document.querySelector(k)}catch{console.warn(`[LiveLayer] click: invalid selector "${k}".`);return}if(!j){console.warn(`[LiveLayer] click: no element matched "${k}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(j.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(Qe=j.click)==null||Qe.call(j);return}if(h.type==="fill_form"||h.type==="focus_field"){if(!ge("fill_forms")){ye(h.type,"fill_forms");return}if(typeof document>"u")return;h.type==="fill_form"&&O.current.playConfirmation();const k=typeof h.formId=="string"?h.formId:null;if(!k){console.warn(`[LiveLayer] ${h.type}: missing formId.`);return}const j=document.querySelector(`[data-ll-form="${k.replace(/"/g,'\\"')}"]`);if(!j){console.warn(`[LiveLayer] ${h.type}: no form with data-ll-form="${k}". Tag your form with <LiveLayerForm id> or data-ll-form. See https://livelayer.studio/docs/react/forms`);return}if(j.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 M=typeof h.fieldName=="string"?h.fieldName:null;if(!M){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const H=j.querySelector(`[data-ll-field="${M.replace(/"/g,'\\"')}"]`);if(!H){console.warn(`[LiveLayer] focus_field: no field "${M}" in form "${k}".`);return}if(!ot(H)){console.warn(`[LiveLayer] focus_field: field "${M}" is privacy-protected and not focusable.`);return}H.focus();return}const P=h.values&&typeof h.values=="object"?h.values:null;if(!P){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[M,H]of Object.entries(P)){if(typeof H!="string")continue;const q=j.querySelector(`[data-ll-field="${M.replace(/"/g,'\\"')}"]`);if(!q){console.warn(`[LiveLayer] fill_form: no field "${M}" in form "${k}". Skipping.`);continue}if(!ot(q)){console.warn(`[LiveLayer] fill_form: field "${M}" is privacy-protected (password / cc-* / private). Skipping.`);continue}try{hr(q,H)}catch(N){console.warn(`[LiveLayer] fill_form: failed to set "${M}".`,N)}}return}if(h.type==="submit_form"){if(!ge("submit_forms")){ye("submit_form","submit_forms");return}if(typeof document>"u")return;const k=typeof h.formId=="string"?h.formId:null;if(!k){console.warn("[LiveLayer] submit_form: missing formId.");return}O.current.playConfirmation();const j=document.querySelector(`[data-ll-form="${k.replace(/"/g,'\\"')}"]`);if(!j){console.warn(`[LiveLayer] submit_form: no form with data-ll-form="${k}".`);return}if(j.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private subtree.");return}const P=typeof h.requestId=="string"?h.requestId:void 0,M=(Ze=ie.current)==null?void 0:Ze.call(ie),H=V=>{const G=M,Ne=G==null?void 0:G.localParticipant;if(Ne!=null&&Ne.publishData)try{const Sn=P?{...V,requestId:P}:V,Cn=new TextEncoder().encode(JSON.stringify(Sn));Ne.publishData(Cn,{reliable:!0})}catch{}};let q=!1;const N=()=>{q=!0,H({type:"form_submitted",formId:k})};j.addEventListener("submit",N,{once:!0});try{typeof j.requestSubmit=="function"?j.requestSubmit():j.submit()}catch(V){console.warn("[LiveLayer] submit_form: requestSubmit threw.",V),j.removeEventListener("submit",N),H({type:"form_submit_blocked",formId:k,reason:"exception"});return}setTimeout(()=>{q||(j.removeEventListener("submit",N),H({type:"form_submit_blocked",formId:k,reason:"validation"}))},500);return}if(h.type==="request_routes"){if(!ge("read_page")){ye("request_routes","read_page");return}const k=typeof h.requestId=="string"?h.requestId:void 0,P=(Et=ie.current)==null?void 0:Et.call(ie),M=P==null?void 0:P.localParticipant;if(!(M!=null&&M.publishData))return;const H=N=>{try{const V=k?{type:"routes",routes:N,requestId:k}:{type:"routes",routes:N},G=new TextEncoder().encode(JSON.stringify(V));M.publishData(G,{reliable:!0})}catch(V){console.warn("[LiveLayer] request_routes: publishData failed.",V)}},q=yt.current;if(q){try{const N=q(),V=G=>{if(!Array.isArray(G)){H([]);return}H(G.map(un).slice(0,200))};N instanceof Promise?N.then(V).catch(G=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",G),H(nt())}):V(N)}catch(N){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",N),H(nt())}return}try{H(nt())}catch(N){console.warn("[LiveLayer] request_routes: extractRoutes threw.",N)}return}vr.has(h.type)||Le==null||Le(h)}},[Le,Ce]),U=Vt({agentId:B?"__controlled__":Ve,baseUrl:o,apiKey:i,sessionEndpoint:s,sessionBody:a,onDataMessage:B?void 0:$e});n.useEffect(()=>{if(B!=null&&B.subscribeToDataMessages)return B.subscribeToDataMessages($e)},[B,$e]),ie.current=()=>{var y;return(y=U.getRoom)==null?void 0:y.call(U)},n.useEffect(()=>{var X;if(typeof window>"u")return;const y=((X=window.location)==null?void 0:X.hostname)||"";if(y==="localhost"||y==="127.0.0.1"||y==="0.0.0.0"||y.endsWith(".local")||y.endsWith(".test"))return window.__livelayerSimulateCommand=Qe=>{try{$e(Qe)}catch(Ze){console.warn("[LiveLayer] simulate-command threw:",Ze)}},()=>{delete window.__livelayerSimulateCommand}},[$e]);const v=n.useMemo(()=>B?{connectionState:B.connectionState,agentState:B.agentState,transcript:B.transcript,videoElement:B.videoElement,audioElement:B.audioElement,canResume:B.canResume,error:B.error,agentConfig:null,connect:async()=>{await B.onConnect()},disconnect:()=>B.onDisconnect(),getRoom: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},[B,U]),bt=n.useRef(null);n.useEffect(()=>{const y=v.videoElement,h=bt.current;if(!(!y||!h))return h.appendChild(y),()=>{y.parentNode===h&&h.removeChild(y)}},[v.videoElement]),n.useEffect(()=>{const y=v.audioElement;if(!y)return;je.attach(y);const h=y.play();return h&&typeof h.catch=="function"&&h.catch(X=>{(X==null?void 0:X.name)==="NotAllowedError"&&Re(!0)}),()=>{je.detach()}},[v.audioElement]),n.useEffect(()=>{if(v.isControlled||v.connectionState!=="connected")return;const y=v.getRoom();if(y)return K.setupMic(y).catch(()=>{}),Q.attachRoom(y),te.attachRoom(y),me.refresh(),()=>{K.teardownMic(),Q.teardown(),te.teardown()}},[v.isControlled,v.connectionState]),n.useEffect(()=>{const y=v.audioElement;y&&(y.muted=Pe)},[v.audioElement,Pe]);const pn=n.useCallback(y=>{const h=v.getRoom();if(h)try{const X=new TextEncoder().encode(JSON.stringify({type:"user_message",text:y}));h.localParticipant.publishData(X,{reliable:!0})}catch{}},[v]),hn=n.useCallback(()=>{Xe(y=>!y)},[]);n.useEffect(()=>{Se==null||Se(v.connectionState),v.connectionState==="connected"?ve==null||ve():v.connectionState==="disconnected"&&(we==null||we())},[v.connectionState,ve,we,Se]),n.useEffect(()=>{_e==null||_e(v.transcript)},[v.transcript,_e]),n.useEffect(()=>{ke==null||ke(v.agentState)},[v.agentState,ke]),n.useEffect(()=>{p.setThinking(v.agentState==="thinking")},[v.agentState,p]);const xt=n.useRef(!1);n.useEffect(()=>{v.isControlled||!d||xt.current||le&&v.connectionState==="idle"&&(xt.current=!0,v.connect())},[d,v.connectionState,v,le]);const mn=n.useCallback(y=>{const h=_==null?void 0:_.find(X=>X.id===y);h&&(re(!1),y!==ce&&(Ye(!0),v.disconnect(),pe||st(y),b==null||b(h)))},[_,ce,v,pe,b]);n.useEffect(()=>{Te&&v.connectionState==="connected"&&Ye(!1)},[v.connectionState,Te]),n.useEffect(()=>{if(!ne)return;const y=h=>{h.key==="Escape"&&re(!1)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[ne]);const gn=!!I||!!(W!=null&&W.avatarImageUrl)||v.isControlled,ze=Qt(Ve,o,gn);ae===void 0&&((wt=ze.info)!=null&&wt.capabilities)&&(ut.current=ze.info.capabilities);const Je=(W==null?void 0:W.name)??x??((_t=v.agentConfig)==null?void 0:_t.name)??((kt=ze.info)==null?void 0:kt.name)??"Live Layer",dt=(W==null?void 0:W.avatarImageUrl)??I??((St=v.agentConfig)==null?void 0:St.avatarImageUrl)??((Ct=ze.info)==null?void 0:Ct.avatarImageUrl)??null,yn=T??((Lt=v.agentConfig)==null?void 0:Lt.idleLoopUrl)??((jt=ze.info)==null?void 0:jt.idleLoopUrl)??null,bn=E??null,xn=n.useCallback(()=>ue("expanded"),[ue]),vn=n.useCallback(()=>ue("minimized"),[ue]),vt=n.useCallback(()=>{v.disconnect(),ue("hidden")},[v,ue]),wn=n.useCallback(()=>{const y=v.audioElement;y&&y.play().then(()=>Re(!1)).catch(()=>{})},[v.audioElement]),_n=n.useCallback(()=>{Re(!1),v.connect()},[v]),He={...We,zIndex:Fe};S.primaryColor&&(He["--ll-color-primary"]=S.primaryColor),S.accentColor&&(He["--ll-color-accent"]=S.accentColor),S.backgroundColor&&(He["--ll-color-bg"]=S.backgroundColor),S.textColor&&(He["--ll-color-fg"]=S.textColor);const kn=["ll-widget",`ll-widget--${he}`,`ll-widget--${xe?"mobile":"desktop"}`,Be].filter(Boolean).join(" ");return le?t.jsxs("div",{className:kn,style:He,"data-display-mode":he,"data-position":l,children:[he==="hidden"&&t.jsx(Un,{position:l,isMobile:xe,isSpeaking:v.agentState==="speaking",onExpand:()=>ue("expanded"),label:`Open ${Je} widget`,avatarImageUrl:dt,agentName:Je}),he==="minimized"&&t.jsx(Yn,{position:l,isMobile:xe,agentName:Je,avatarImageUrl:dt,agentState:v.agentState,isMuted:K.isMuted,audioLevel:je,onExpand:xn,onToggleMute:K.toggleMute,onClose:vt}),he==="expanded"&&t.jsx(Kn,{position:l,isMobile:xe,agentName:Je,avatarImageUrl:dt,idleLoopUrl:yn,greeting:bn,branding:S,teamMembers:_,currentTeamMemberId:ce,isSwitchingTeamMember:Te,teamSwitcherOpen:ne,onToggleTeamSwitcher:()=>re(y=>!y),onSelectTeamMember:mn,connectionState:v.connectionState,agentState:v.agentState,transcript:v.transcript,isMuted:K.isMuted,micDevices:me.mics,isCameraEnabled:Q.isEnabled,cameraPreviewEl:Q.previewEl,cameraDevices:me.cameras,activeCameraId:Q.activeDeviceId,isScreenShareEnabled:te.isEnabled,screenPreviewEl:te.previewEl,isSpeakerMuted:Pe,allowCamera:$,allowScreenShare:A,allowTyping:C,languageMenuOpen:Ge,onToggleLanguageMenu:()=>Ke(y=>!y),needsUserGesture:Ee,canResume:v.canResume,micError:K.micError,error:v.error,avatarVideoContainerRef:bt,agentVideoEl:v.videoElement,onConnect:()=>void v.connect(),onDisconnect:()=>v.disconnect(),onRetry:_n,onResumeAudio:wn,onToggleMute:K.toggleMute,onToggleCamera:()=>void Q.toggle(),onSwitchCameraDevice:y=>void Q.switchDevice(y),onToggleScreenShare:()=>void te.toggle(),onToggleSpeaker:hn,onSendMessage:pn,onMinimize:vn,onClose:vt,onClearMicError:K.clearError})]}):null}function _r(e){return t.jsx(Ut,{children:t.jsx(wr,{...e})})}const kr=({agentId:e,baseUrl:r,apiKey:i,mode:o,onAgentEvent:s,className:a,style:u})=>{const d=n.useRef(null),f=n.useRef(null),m=n.useRef(s);m.current=s;const g=n.useCallback(l=>{var L;const c=l.detail;(L=m.current)==null||L.call(m,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),i&&c.setAttribute("api-key",i),o&&c.setAttribute("mode",o),c.addEventListener("agent-event",g),l.appendChild(c),f.current=c,()=>{c.removeEventListener("agent-event",g),l.removeChild(c),f.current=null}},[e]),n.useEffect(()=>{f.current&&(o?f.current.setAttribute("mode",o):f.current.removeAttribute("mode"))},[o]),t.jsx("div",{ref:d,className:a,style:u})},Sr=n.forwardRef(function({id:r,intent:i,as:o="div",className:s,style:a,children:u},d){return n.createElement(o,{ref:d,"data-ll-region":r,"data-ll-intent":i,className:s,style:a},u)}),Cr=n.forwardRef(function({id:r,intent:i,children:o,...s},a){return t.jsx("form",{ref:a,"data-ll-form":r,"data-ll-intent":i,...s,children:o})}),Lr=n.forwardRef(function(r,i){const{name:o,label:s,labelClassName:a}=r,u={name:o,"data-ll-field":o};let d;if("as"in r&&r.as==="textarea"){const{name:f,label:m,labelClassName:g,as:l,...c}=r;d=t.jsx("textarea",{ref:i,...u,...c})}else if("as"in r&&r.as==="select"){const{name:f,label:m,labelClassName:g,as:l,children:c,...L}=r;d=t.jsx("select",{ref:i,...u,...L,children:c})}else{const{name:f,label:m,labelClassName:g,as:l,...c}=r;d=t.jsx("input",{ref:i,...u,...c})}return s===void 0?d:t.jsxs("label",{className:a,children:[s,d]})});let Ft=1;function jr({onMount:e,defaultOpen:r=!1,storageKey:i="ll-debug-open"}){const[o,s]=n.useState(r),[a,u]=n.useState([]),[d,f]=n.useState(""),[m,g]=n.useState(!1),l=n.useRef(new Set),c=n.useRef([]),L=n.useRef(m);L.current=m,n.useEffect(()=>{try{const w=localStorage.getItem(i);w==="1"&&s(!0),w==="0"&&s(!1)}catch{}},[i]),n.useEffect(()=>{try{localStorage.setItem(i,o?"1":"0")}catch{}},[o,i]),n.useEffect(()=>{const w=b=>{(b.metaKey||b.ctrlKey)&&b.shiftKey&&b.key.toLowerCase()==="l"&&(b.preventDefault(),s(T=>!T))};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[]),n.useEffect(()=>{const w=setInterval(()=>{if(c.current.length===0||L.current)return;const b=c.current.splice(0,c.current.length);u(T=>[...b.reverse(),...T].slice(0,200))},100);return()=>clearInterval(w)},[]);const D=n.useRef(!1);if(n.useEffect(()=>{!e||D.current||(D.current=!0,e(w=>{c.current.push({id:Ft++,ts:Date.now(),kind:"event",type:w.eventName,data:w.data})}))},[e]),n.useEffect(()=>{const w=console.warn,b=console.log,T=(E,I)=>function(...x){try{const S=typeof x[0]=="string"?x[0]:"";S.startsWith("[LiveLayer]")&&c.current.push({id:Ft++,ts:Date.now(),kind:E,type:S.slice(0,120),data:{args:x.slice(1).map($=>Rr($))}})}catch{}return I.apply(this,x)};return console.warn=T("warn",w),console.log=T("log",b),()=>{console.warn=w,console.log=b}},[]),!o)return t.jsx("button",{type:"button",onClick:()=>s(!0),title:"Open LiveLayer debug panel (Cmd/Ctrl + Shift + L)","aria-label":"Open LiveLayer debug panel",style:{position:"fixed",left:16,bottom:16,zIndex:2147483640,background:"#0d0d0d",color:"#fff",border:"1px solid rgba(255,255,255,0.18)",borderRadius:999,padding:"6px 10px",font:"500 11px -apple-system, BlinkMacSystemFont, system-ui, sans-serif",letterSpacing:"-0.1px",cursor:"pointer",boxShadow:"0 4px 12px rgba(0,0,0,0.35)",opacity:.85},children:"🛰 LL debug"});const _=a.filter(w=>{if(!d)return!0;const b=d.toLowerCase();return w.type.toLowerCase().includes(b)||JSON.stringify(w.data||{}).toLowerCase().includes(b)});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:()=>g(w=>!w),style:ft(m?"#f59e0b":"transparent"),title:"Pause / resume capture",children:m?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{u([]),c.current=[]},style:ft("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>s(!1),style:ft("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:d,onChange:w=>f(w.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:_.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
|
+
})`})]}):_.map(w=>t.jsx(Er,{entry:w,expanded:l.current.has(w.id),onToggle:()=>{l.current.has(w.id)?l.current.delete(w.id):l.current.add(w.id),u(b=>[...b])}},w.id))})]})}function Er({entry:e,expanded:r,onToggle:i}){const o=e.kind==="warn"?"#f59e0b":e.type.startsWith("[LiveLayer]")?"#94a3b8":e.type==="navigate"||e.type==="scroll_page"||e.type==="scroll_to"||e.type==="click"?"#22c55e":e.type==="fill_form"||e.type==="submit_form"||e.type==="focus_field"?"#a78bfa":e.type==="request_page_context"||e.type==="request_routes"?"#38bdf8":e.type==="agent_state"?"#facc15":"#cbd5e1",s=new Date(e.ts).toLocaleTimeString("en-US",{hour12:!1});return t.jsxs("button",{type:"button",onClick:i,style:{textAlign:"left",background:"transparent",border:0,color:"#fff",width:"100%",padding:"6px 4px",cursor:"pointer",borderBottom:"1px solid rgba(255,255,255,0.04)",fontSize:11,lineHeight:1.4},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{color:"rgba(255,255,255,0.4)",fontVariantNumeric:"tabular-nums",fontSize:10},children:s}),t.jsx("span",{style:{color:o,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),r&&e.data&&t.jsx("pre",{style:{marginTop:6,padding:6,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:10,overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(e.data,null,2)})]})}function ft(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 Rr(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Nr(){const[e,r]=n.useState([]),i=n.useCallback(s=>{r(a=>{const u=a.findIndex(d=>d.id===s.id);if(u>=0){const d=a.slice();return d[u]=s,d}return[...a,s]})},[]),o=n.useCallback(()=>r([]),[]);return{entries:e,pushSegment:i,clear:o,latest:e.length>0?e[e.length-1]:null}}exports.AvatarWidget=_r;exports.ErrorBoundary=Ut;exports.LiveLayerDebugPanel=jr;exports.LiveLayerField=Lr;exports.LiveLayerForm=Cr;exports.LiveLayerRegion=Sr;exports.LiveLayerWidget=kr;exports.clearPageContextCache=cn;exports.clearRoutesCache=fn;exports.extractPageContext=ln;exports.extractRoutes=dn;exports.getCachedPageContext=pt;exports.getCachedRoutes=nt;exports.matchesPattern=rn;exports.normalizeRouteInput=un;exports.shouldRenderAtPath=on;exports.useAgentInfo=Qt;exports.useAudioLevel=Yt;exports.useCameraState=Kt;exports.useDisplayMode=Zt;exports.useDisplayModePersistence=en;exports.useIsMobile=tn;exports.useLiveKitSession=Vt;exports.useMediaDevices=Jt;exports.useMicrophoneState=Gt;exports.usePathname=nn;exports.useRouteMatch=sn;exports.useScreenShareState=Xt;exports.useTranscript=Nr;
|
package/dist/index.mjs
CHANGED
|
@@ -34,11 +34,11 @@ class vn extends pn {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
function bn(e) {
|
|
37
|
-
const [t, r] = C("idle"), [i, o] = C("idle"), [l, c] = C([]), [d, u] = C(null), [h, m] = C(null), [a, s] = C(null), [R, q] = C(!1), [
|
|
38
|
-
|
|
37
|
+
const [t, r] = C("idle"), [i, o] = C("idle"), [l, c] = C([]), [d, u] = C(null), [h, m] = C(null), [a, s] = C(null), [R, q] = C(!1), [_, w] = C(null), y = E(null), H = E(e.onDataMessage);
|
|
38
|
+
H.current = e.onDataMessage, N(() => {
|
|
39
39
|
const S = {
|
|
40
40
|
onConnectionStateChange: (D) => {
|
|
41
|
-
r(D), D === "connected" &&
|
|
41
|
+
r(D), D === "connected" && w(null);
|
|
42
42
|
},
|
|
43
43
|
onAgentStateChange: o,
|
|
44
44
|
onTranscript: (D) => c([...D]),
|
|
@@ -46,10 +46,10 @@ function bn(e) {
|
|
|
46
46
|
onAudioTrack: (D) => s(D),
|
|
47
47
|
onVideoTrack: (D) => m(D),
|
|
48
48
|
onVideoTrackRemoved: () => m(null),
|
|
49
|
-
onError: (D) =>
|
|
49
|
+
onError: (D) => w(D),
|
|
50
50
|
onDataMessage: (D) => {
|
|
51
51
|
var A;
|
|
52
|
-
(A =
|
|
52
|
+
(A = H.current) == null || A.call(H, D);
|
|
53
53
|
},
|
|
54
54
|
onResumabilityChange: q
|
|
55
55
|
}, B = new mn(
|
|
@@ -62,7 +62,7 @@ function bn(e) {
|
|
|
62
62
|
},
|
|
63
63
|
S
|
|
64
64
|
);
|
|
65
|
-
return y.current = B, r("idle"), o("idle"), c([]), u(null), m(null), s(null), q(!1),
|
|
65
|
+
return y.current = B, r("idle"), o("idle"), c([]), u(null), m(null), s(null), q(!1), w(null), () => {
|
|
66
66
|
var D;
|
|
67
67
|
(D = B.destroy) == null || D.call(B), y.current = null;
|
|
68
68
|
};
|
|
@@ -79,9 +79,9 @@ function bn(e) {
|
|
|
79
79
|
try {
|
|
80
80
|
await S.connect();
|
|
81
81
|
} catch (B) {
|
|
82
|
-
throw
|
|
82
|
+
throw w(B instanceof Error ? B.message : String(B)), B;
|
|
83
83
|
}
|
|
84
|
-
}, []),
|
|
84
|
+
}, []), z = k(() => {
|
|
85
85
|
const S = y.current;
|
|
86
86
|
S && S.disconnect();
|
|
87
87
|
}, []), v = k(() => {
|
|
@@ -96,9 +96,9 @@ function bn(e) {
|
|
|
96
96
|
videoElement: h,
|
|
97
97
|
audioElement: a,
|
|
98
98
|
canResume: R,
|
|
99
|
-
error:
|
|
99
|
+
error: _,
|
|
100
100
|
connect: M,
|
|
101
|
-
disconnect:
|
|
101
|
+
disconnect: z,
|
|
102
102
|
getRoom: v,
|
|
103
103
|
session: y.current
|
|
104
104
|
};
|
|
@@ -116,13 +116,13 @@ function wn() {
|
|
|
116
116
|
const s = l.current;
|
|
117
117
|
a.getByteFrequencyData(s);
|
|
118
118
|
let R = 0;
|
|
119
|
-
for (let
|
|
119
|
+
for (let _ = 0; _ < s.length; _++) R += s[_];
|
|
120
120
|
const q = R / s.length / 255;
|
|
121
|
-
for (const
|
|
121
|
+
for (const _ of o.current)
|
|
122
122
|
try {
|
|
123
|
-
|
|
124
|
-
} catch (
|
|
125
|
-
console.error("[useAudioLevel] subscriber threw:",
|
|
123
|
+
_(q);
|
|
124
|
+
} catch (w) {
|
|
125
|
+
console.error("[useAudioLevel] subscriber threw:", w);
|
|
126
126
|
}
|
|
127
127
|
i.current = requestAnimationFrame(c);
|
|
128
128
|
}, []), d = k(() => {
|
|
@@ -227,8 +227,8 @@ function kn() {
|
|
|
227
227
|
const [e, t] = C(!1), [r, i] = C(null), [o, l] = C(null), [c, d] = C(""), u = E(null), h = E(null), m = k((y) => {
|
|
228
228
|
u.current = y;
|
|
229
229
|
}, []), a = k(() => {
|
|
230
|
-
const y = u.current,
|
|
231
|
-
if (
|
|
230
|
+
const y = u.current, H = h.current;
|
|
231
|
+
if (H && y) {
|
|
232
232
|
const M = y.localParticipant.getTrackPublication(Kt.Source.Camera);
|
|
233
233
|
if (M != null && M.track) {
|
|
234
234
|
try {
|
|
@@ -237,39 +237,39 @@ function kn() {
|
|
|
237
237
|
}
|
|
238
238
|
M.track.stop();
|
|
239
239
|
} else
|
|
240
|
-
|
|
240
|
+
H.stop();
|
|
241
241
|
}
|
|
242
242
|
h.current = null, l(null), t(!1);
|
|
243
243
|
}, []), s = k(async (y) => {
|
|
244
|
-
const
|
|
245
|
-
if (
|
|
244
|
+
const H = u.current;
|
|
245
|
+
if (H) {
|
|
246
246
|
i(null);
|
|
247
247
|
try {
|
|
248
248
|
const M = { ...xn };
|
|
249
249
|
y && (M.deviceId = y);
|
|
250
|
-
const
|
|
251
|
-
await
|
|
252
|
-
const v =
|
|
250
|
+
const z = await yn(M);
|
|
251
|
+
await H.localParticipant.publishTrack(z), h.current = z;
|
|
252
|
+
const v = z.attach();
|
|
253
253
|
l(v), t(!0), y && d(y);
|
|
254
254
|
try {
|
|
255
|
-
|
|
255
|
+
H.localParticipant.publishData(
|
|
256
256
|
new TextEncoder().encode(JSON.stringify({ type: "user_camera_on" })),
|
|
257
257
|
{ reliable: !0 }
|
|
258
258
|
);
|
|
259
259
|
} catch {
|
|
260
260
|
}
|
|
261
261
|
} catch (M) {
|
|
262
|
-
const
|
|
263
|
-
i(
|
|
262
|
+
const z = M instanceof Error && M.name === "NotAllowedError" ? "Enable your camera in the browser to share video." : "Camera unavailable. Check permissions and try again.";
|
|
263
|
+
i(z);
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
}, []), R = k(async () => {
|
|
267
267
|
e ? a() : await s(c || void 0);
|
|
268
268
|
}, [e, c, a, s]), q = k(async (y) => {
|
|
269
269
|
a(), await s(y);
|
|
270
|
-
}, [a, s]),
|
|
270
|
+
}, [a, s]), _ = k(() => {
|
|
271
271
|
a(), u.current = null, i(null), d("");
|
|
272
|
-
}, [a]),
|
|
272
|
+
}, [a]), w = k(() => i(null), []);
|
|
273
273
|
return N(() => () => {
|
|
274
274
|
h.current && h.current.stop();
|
|
275
275
|
}, []), {
|
|
@@ -280,8 +280,8 @@ function kn() {
|
|
|
280
280
|
toggle: R,
|
|
281
281
|
switchDevice: q,
|
|
282
282
|
attachRoom: m,
|
|
283
|
-
teardown:
|
|
284
|
-
clearError:
|
|
283
|
+
teardown: _,
|
|
284
|
+
clearError: w
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
287
|
function Ln() {
|
|
@@ -303,10 +303,10 @@ function Ln() {
|
|
|
303
303
|
await s.localParticipant.setScreenShareEnabled(!0);
|
|
304
304
|
let R = 0;
|
|
305
305
|
const q = () => {
|
|
306
|
-
const
|
|
307
|
-
if (
|
|
308
|
-
const
|
|
309
|
-
l(
|
|
306
|
+
const _ = s.localParticipant.getTrackPublication(Kt.Source.ScreenShare);
|
|
307
|
+
if (_ != null && _.track) {
|
|
308
|
+
const w = _.track.attach();
|
|
309
|
+
l(w), t(!0);
|
|
310
310
|
try {
|
|
311
311
|
s.localParticipant.publishData(
|
|
312
312
|
new TextEncoder().encode(JSON.stringify({ type: "user_screen_share_on" })),
|
|
@@ -690,7 +690,7 @@ const Kn = ({
|
|
|
690
690
|
avatarImageUrl: l,
|
|
691
691
|
agentName: c
|
|
692
692
|
}) => {
|
|
693
|
-
const d = Gn(e), u = d === "right" ? "left" : "right", h = t ? 80 : 72, m = !!l, [a, s] = C(null), [R, q] = C(!1),
|
|
693
|
+
const d = Gn(e), u = d === "right" ? "left" : "right", h = t ? 80 : 72, m = !!l, [a, s] = C(null), [R, q] = C(!1), _ = E(null), w = E(!1), y = k(
|
|
694
694
|
(A) => {
|
|
695
695
|
if (typeof window > "u") return A;
|
|
696
696
|
const T = h / 2, W = Bt + T, G = window.innerHeight - Bt - T;
|
|
@@ -706,14 +706,14 @@ const Kn = ({
|
|
|
706
706
|
};
|
|
707
707
|
return window.addEventListener("resize", T), () => window.removeEventListener("resize", T);
|
|
708
708
|
}, [y]);
|
|
709
|
-
const
|
|
709
|
+
const H = k(
|
|
710
710
|
(A) => {
|
|
711
711
|
if (!(A.pointerType === "mouse" && A.button !== 0) && a !== null) {
|
|
712
712
|
try {
|
|
713
713
|
A.currentTarget.setPointerCapture(A.pointerId);
|
|
714
714
|
} catch {
|
|
715
715
|
}
|
|
716
|
-
|
|
716
|
+
_.current = {
|
|
717
717
|
startClientY: A.clientY,
|
|
718
718
|
startCenterY: a,
|
|
719
719
|
moved: !1
|
|
@@ -723,27 +723,27 @@ const Kn = ({
|
|
|
723
723
|
[a]
|
|
724
724
|
), M = k(
|
|
725
725
|
(A) => {
|
|
726
|
-
const T =
|
|
726
|
+
const T = _.current;
|
|
727
727
|
if (!T) return;
|
|
728
728
|
const W = A.clientY - T.startClientY;
|
|
729
729
|
!T.moved && Math.abs(W) > Xn && (T.moved = !0, q(!0)), T.moved && s(y(T.startCenterY + W));
|
|
730
730
|
},
|
|
731
731
|
[y]
|
|
732
|
-
),
|
|
732
|
+
), z = k(
|
|
733
733
|
(A) => {
|
|
734
|
-
const T =
|
|
734
|
+
const T = _.current;
|
|
735
735
|
if (T) {
|
|
736
736
|
try {
|
|
737
737
|
A.currentTarget.releasePointerCapture(A.pointerId);
|
|
738
738
|
} catch {
|
|
739
739
|
}
|
|
740
|
-
|
|
740
|
+
_.current = null, T.moved && (q(!1), w.current = !0, s((W) => (W !== null && Wt(W), W)));
|
|
741
741
|
}
|
|
742
742
|
},
|
|
743
743
|
[]
|
|
744
744
|
), v = k(() => {
|
|
745
|
-
if (
|
|
746
|
-
|
|
745
|
+
if (w.current) {
|
|
746
|
+
w.current = !1;
|
|
747
747
|
return;
|
|
748
748
|
}
|
|
749
749
|
i();
|
|
@@ -773,10 +773,10 @@ const Kn = ({
|
|
|
773
773
|
{
|
|
774
774
|
type: "button",
|
|
775
775
|
className: B,
|
|
776
|
-
onPointerDown:
|
|
776
|
+
onPointerDown: H,
|
|
777
777
|
onPointerMove: M,
|
|
778
|
-
onPointerUp:
|
|
779
|
-
onPointerCancel:
|
|
778
|
+
onPointerUp: z,
|
|
779
|
+
onPointerCancel: z,
|
|
780
780
|
onClick: v,
|
|
781
781
|
onKeyDown: S,
|
|
782
782
|
"aria-label": o,
|
|
@@ -1026,12 +1026,12 @@ const Kn = ({
|
|
|
1026
1026
|
onSelectTeamMember: s,
|
|
1027
1027
|
languageMenuOpen: R,
|
|
1028
1028
|
onToggleLanguageMenu: q,
|
|
1029
|
-
connectionState:
|
|
1030
|
-
agentState:
|
|
1029
|
+
connectionState: _,
|
|
1030
|
+
agentState: w,
|
|
1031
1031
|
transcript: y,
|
|
1032
|
-
canResume:
|
|
1032
|
+
canResume: H,
|
|
1033
1033
|
needsUserGesture: M,
|
|
1034
|
-
error:
|
|
1034
|
+
error: z,
|
|
1035
1035
|
isMuted: v,
|
|
1036
1036
|
micError: S,
|
|
1037
1037
|
micDevices: B,
|
|
@@ -1062,7 +1062,7 @@ const Kn = ({
|
|
|
1062
1062
|
onClearMicError: Xe
|
|
1063
1063
|
}) => {
|
|
1064
1064
|
var et;
|
|
1065
|
-
const fe = ((d == null ? void 0 : d.length) ?? 0) > 1, ye =
|
|
1065
|
+
const fe = ((d == null ? void 0 : d.length) ?? 0) > 1, ye = _ === "connecting" || _ === "connected", ie = _ === "connected", ct = _ === "idle" || _ === "disconnected" || _ === "error", [pe, Y] = C(!1);
|
|
1066
1066
|
N(() => {
|
|
1067
1067
|
if (!K) {
|
|
1068
1068
|
Y(!1);
|
|
@@ -1088,7 +1088,7 @@ const Kn = ({
|
|
|
1088
1088
|
const f = setTimeout(() => ve(!0), 8e3);
|
|
1089
1089
|
return () => clearTimeout(f);
|
|
1090
1090
|
}, [ie, pe]);
|
|
1091
|
-
const he =
|
|
1091
|
+
const he = _ === "connecting" || ie && !!i && !pe && !Je, ke = E(null), Ie = E(null);
|
|
1092
1092
|
N(() => {
|
|
1093
1093
|
const f = ke.current;
|
|
1094
1094
|
f && (f.innerHTML = "", A && (A.style.width = "100%", A.style.height = "100%", A.style.objectFit = "cover", A.style.transform = "scaleX(-1)", f.appendChild(A)));
|
|
@@ -1267,8 +1267,8 @@ const Kn = ({
|
|
|
1267
1267
|
/* @__PURE__ */ n(
|
|
1268
1268
|
"span",
|
|
1269
1269
|
{
|
|
1270
|
-
className: `ll-expanded__state ll-expanded__state--${
|
|
1271
|
-
children:
|
|
1270
|
+
className: `ll-expanded__state ll-expanded__state--${w}`,
|
|
1271
|
+
children: w
|
|
1272
1272
|
}
|
|
1273
1273
|
)
|
|
1274
1274
|
] }),
|
|
@@ -1325,9 +1325,9 @@ const Kn = ({
|
|
|
1325
1325
|
] })
|
|
1326
1326
|
),
|
|
1327
1327
|
ct && /* @__PURE__ */ (() => {
|
|
1328
|
-
const f =
|
|
1328
|
+
const f = H ? "Restart paused session" : _ === "disconnected" ? "Reconnect to agent" : "Start video call", U = H ? "Pick up where you left off" : null;
|
|
1329
1329
|
return /* @__PURE__ */ x(yt, { children: [
|
|
1330
|
-
|
|
1330
|
+
!z && /* @__PURE__ */ x(
|
|
1331
1331
|
"button",
|
|
1332
1332
|
{
|
|
1333
1333
|
type: "button",
|
|
@@ -1528,7 +1528,7 @@ const Kn = ({
|
|
|
1528
1528
|
] })
|
|
1529
1529
|
] }) : null,
|
|
1530
1530
|
(() => {
|
|
1531
|
-
if (S &&
|
|
1531
|
+
if (S && _ !== "error")
|
|
1532
1532
|
return /* @__PURE__ */ x("div", { className: "ll-expanded__banner", role: "alert", children: [
|
|
1533
1533
|
/* @__PURE__ */ n("span", { children: S }),
|
|
1534
1534
|
/* @__PURE__ */ n(
|
|
@@ -1542,9 +1542,9 @@ const Kn = ({
|
|
|
1542
1542
|
}
|
|
1543
1543
|
)
|
|
1544
1544
|
] });
|
|
1545
|
-
if (!
|
|
1545
|
+
if (!z || _ !== "error") return null;
|
|
1546
1546
|
let f = "Failed to connect", U = "Try again";
|
|
1547
|
-
return
|
|
1547
|
+
return z === "MIC_PERMISSION_DENIED" ? f = "Microphone blocked. Allow access to talk." : z === "MIC_NOT_FOUND" ? f = "No microphone found. Plug one in + retry." : z === "MIC_UNAVAILABLE" ? f = "Mic unavailable. Check other apps using it." : z === "AGENT_TIMEOUT" ? f = "Agent didn't pick up. Try again." : z === "CONNECT_FAILED" ? f = "Connection failed. Check your network." : z.length < 80 && (f = z), /* @__PURE__ */ x("div", { className: "ll-expanded__banner ll-expanded__banner--error", role: "alert", children: [
|
|
1548
1548
|
/* @__PURE__ */ n("span", { children: f }),
|
|
1549
1549
|
/* @__PURE__ */ n(
|
|
1550
1550
|
"button",
|
|
@@ -1760,22 +1760,22 @@ function gr(e, t = {}) {
|
|
|
1760
1760
|
const S = v.getAttribute("href") || "", B = (v.textContent || "").trim();
|
|
1761
1761
|
!S || !B || R.push({ href: S, text: me(B, 100) });
|
|
1762
1762
|
}
|
|
1763
|
-
const
|
|
1763
|
+
const _ = [], w = Array.from(
|
|
1764
1764
|
r.querySelectorAll(
|
|
1765
1765
|
"input, textarea, select"
|
|
1766
1766
|
)
|
|
1767
1767
|
);
|
|
1768
|
-
for (const v of
|
|
1769
|
-
if (
|
|
1768
|
+
for (const v of w) {
|
|
1769
|
+
if (_.length >= dr) break;
|
|
1770
1770
|
if (Ue(v) || !st(v) || !je(v)) continue;
|
|
1771
1771
|
const S = Yt(v), B = v instanceof HTMLInputElement ? v.type : v.tagName.toLowerCase();
|
|
1772
|
-
S &&
|
|
1772
|
+
S && _.push({ label: me(S, 100), type: B });
|
|
1773
1773
|
}
|
|
1774
1774
|
const y = Array.from(
|
|
1775
1775
|
r.querySelectorAll("[data-ll-form]")
|
|
1776
|
-
),
|
|
1776
|
+
), H = [];
|
|
1777
1777
|
for (const v of y) {
|
|
1778
|
-
if (
|
|
1778
|
+
if (H.length >= fr) break;
|
|
1779
1779
|
if (bt(v)) continue;
|
|
1780
1780
|
const S = v.getAttribute("data-ll-form") || "";
|
|
1781
1781
|
if (!S) continue;
|
|
@@ -1807,7 +1807,7 @@ function gr(e, t = {}) {
|
|
|
1807
1807
|
const xe = typeof T.validationMessage == "string" ? T.validationMessage : "";
|
|
1808
1808
|
xe && (te.validationMessage = me(xe, 200)), A.push(te);
|
|
1809
1809
|
}
|
|
1810
|
-
|
|
1810
|
+
H.push({ id: S, intent: B, fields: A });
|
|
1811
1811
|
}
|
|
1812
1812
|
const M = {
|
|
1813
1813
|
url: i,
|
|
@@ -1816,15 +1816,15 @@ function gr(e, t = {}) {
|
|
|
1816
1816
|
regions: d,
|
|
1817
1817
|
visibleText: s,
|
|
1818
1818
|
visibleLinks: R,
|
|
1819
|
-
visibleFields:
|
|
1820
|
-
forms:
|
|
1819
|
+
visibleFields: _,
|
|
1820
|
+
forms: H,
|
|
1821
1821
|
extras: e
|
|
1822
1822
|
};
|
|
1823
|
-
let
|
|
1824
|
-
for (;
|
|
1825
|
-
M.visibleFields.pop(),
|
|
1826
|
-
for (;
|
|
1827
|
-
M.visibleLinks.pop(),
|
|
1823
|
+
let z = De(JSON.stringify(M.regions)) + De(M.visibleText) + De(JSON.stringify(M.visibleLinks)) + De(JSON.stringify(M.visibleFields));
|
|
1824
|
+
for (; z > lt && M.visibleFields.length > 0; )
|
|
1825
|
+
M.visibleFields.pop(), z = De(JSON.stringify(M.visibleFields));
|
|
1826
|
+
for (; z > lt && M.visibleLinks.length > 0; )
|
|
1827
|
+
M.visibleLinks.pop(), z -= 80;
|
|
1828
1828
|
return De(M.visibleText) > lt && (M.visibleText = me(M.visibleText, lt - 100)), M;
|
|
1829
1829
|
}
|
|
1830
1830
|
let $e = null;
|
|
@@ -1990,12 +1990,12 @@ function Mr(e) {
|
|
|
1990
1990
|
mobileBreakpoint: s = 640,
|
|
1991
1991
|
persistKey: R = "ll-widget",
|
|
1992
1992
|
disablePersistence: q = !1,
|
|
1993
|
-
teamMembers:
|
|
1994
|
-
currentTeamMemberId:
|
|
1993
|
+
teamMembers: _,
|
|
1994
|
+
currentTeamMemberId: w,
|
|
1995
1995
|
onTeamMemberChange: y,
|
|
1996
|
-
idleLoopUrl:
|
|
1996
|
+
idleLoopUrl: H,
|
|
1997
1997
|
greeting: M,
|
|
1998
|
-
avatarImageUrl:
|
|
1998
|
+
avatarImageUrl: z,
|
|
1999
1999
|
agentName: v,
|
|
2000
2000
|
branding: S = {},
|
|
2001
2001
|
allowCamera: B = !0,
|
|
@@ -2027,12 +2027,12 @@ function Mr(e) {
|
|
|
2027
2027
|
N(() => {
|
|
2028
2028
|
yr(), kr();
|
|
2029
2029
|
}, [Xe]);
|
|
2030
|
-
const ye =
|
|
2030
|
+
const ye = w !== void 0, [ie, ct] = C(() => {
|
|
2031
2031
|
var g;
|
|
2032
|
-
return
|
|
2033
|
-
}), pe = ye ?
|
|
2034
|
-
() => (
|
|
2035
|
-
[
|
|
2032
|
+
return w ?? ((g = _ == null ? void 0 : _[0]) == null ? void 0 : g.id);
|
|
2033
|
+
}), pe = ye ? w : ie, Y = He(
|
|
2034
|
+
() => (_ == null ? void 0 : _.find((g) => g.id === pe)) ?? null,
|
|
2035
|
+
[_, pe]
|
|
2036
2036
|
), Je = (Y == null ? void 0 : Y.agentId) ?? t, [ve, he] = Mn({
|
|
2037
2037
|
value: u,
|
|
2038
2038
|
defaultValue: h,
|
|
@@ -2572,11 +2572,11 @@ function Mr(e) {
|
|
|
2572
2572
|
}, [d, b.connectionState, b, fe]);
|
|
2573
2573
|
const tn = k(
|
|
2574
2574
|
(g) => {
|
|
2575
|
-
const p =
|
|
2575
|
+
const p = _ == null ? void 0 : _.find((ee) => ee.id === g);
|
|
2576
2576
|
p && (ae(!1), g !== pe && (Ke(!0), b.disconnect(), ye || ct(g), y == null || y(p)));
|
|
2577
2577
|
},
|
|
2578
2578
|
[
|
|
2579
|
-
|
|
2579
|
+
_,
|
|
2580
2580
|
pe,
|
|
2581
2581
|
b,
|
|
2582
2582
|
ye,
|
|
@@ -2592,9 +2592,9 @@ function Mr(e) {
|
|
|
2592
2592
|
};
|
|
2593
2593
|
return window.addEventListener("keydown", g), () => window.removeEventListener("keydown", g);
|
|
2594
2594
|
}, [le]);
|
|
2595
|
-
const nn = !!
|
|
2595
|
+
const nn = !!z || !!(Y != null && Y.avatarImageUrl) || b.isControlled, We = Cn(Je, i, nn);
|
|
2596
2596
|
ue === void 0 && ((Ct = We.info) != null && Ct.capabilities) && (pt.current = We.info.capabilities);
|
|
2597
|
-
const nt = (Y == null ? void 0 : Y.name) ?? v ?? ((Et = b.agentConfig) == null ? void 0 : Et.name) ?? ((Nt = We.info) == null ? void 0 : Nt.name) ?? "Live Layer", ht = (Y == null ? void 0 : Y.avatarImageUrl) ??
|
|
2597
|
+
const nt = (Y == null ? void 0 : Y.name) ?? v ?? ((Et = b.agentConfig) == null ? void 0 : Et.name) ?? ((Nt = We.info) == null ? void 0 : Nt.name) ?? "Live Layer", ht = (Y == null ? void 0 : Y.avatarImageUrl) ?? z ?? ((At = b.agentConfig) == null ? void 0 : At.avatarImageUrl) ?? ((Rt = We.info) == null ? void 0 : Rt.avatarImageUrl) ?? null, rn = H ?? ((It = b.agentConfig) == null ? void 0 : It.idleLoopUrl) ?? ((Mt = We.info) == null ? void 0 : Mt.idleLoopUrl) ?? null, on = M ?? null, ln = k(() => he("expanded"), [he]), an = k(
|
|
2598
2598
|
() => he("minimized"),
|
|
2599
2599
|
[he]
|
|
2600
2600
|
), St = k(() => {
|
|
@@ -2661,7 +2661,7 @@ function Mr(e) {
|
|
|
2661
2661
|
idleLoopUrl: rn,
|
|
2662
2662
|
greeting: on,
|
|
2663
2663
|
branding: S,
|
|
2664
|
-
teamMembers:
|
|
2664
|
+
teamMembers: _,
|
|
2665
2665
|
currentTeamMemberId: pe,
|
|
2666
2666
|
isSwitchingTeamMember: Oe,
|
|
2667
2667
|
teamSwitcherOpen: le,
|
|
@@ -2816,8 +2816,8 @@ function jr({
|
|
|
2816
2816
|
const [i, o] = C(t), [l, c] = C([]), [d, u] = C(""), [h, m] = C(!1), a = E(/* @__PURE__ */ new Set()), s = E([]), R = E(h);
|
|
2817
2817
|
R.current = h, N(() => {
|
|
2818
2818
|
try {
|
|
2819
|
-
const
|
|
2820
|
-
|
|
2819
|
+
const w = localStorage.getItem(r);
|
|
2820
|
+
w === "1" && o(!0), w === "0" && o(!1);
|
|
2821
2821
|
} catch {
|
|
2822
2822
|
}
|
|
2823
2823
|
}, [r]), N(() => {
|
|
@@ -2826,33 +2826,33 @@ function jr({
|
|
|
2826
2826
|
} catch {
|
|
2827
2827
|
}
|
|
2828
2828
|
}, [i, r]), N(() => {
|
|
2829
|
-
const
|
|
2830
|
-
(y.metaKey || y.ctrlKey) && y.shiftKey && y.key.toLowerCase() === "l" && (y.preventDefault(), o((
|
|
2829
|
+
const w = (y) => {
|
|
2830
|
+
(y.metaKey || y.ctrlKey) && y.shiftKey && y.key.toLowerCase() === "l" && (y.preventDefault(), o((H) => !H));
|
|
2831
2831
|
};
|
|
2832
|
-
return window.addEventListener("keydown",
|
|
2832
|
+
return window.addEventListener("keydown", w), () => window.removeEventListener("keydown", w);
|
|
2833
2833
|
}, []), N(() => {
|
|
2834
|
-
const
|
|
2834
|
+
const w = setInterval(() => {
|
|
2835
2835
|
if (s.current.length === 0 || R.current) return;
|
|
2836
2836
|
const y = s.current.splice(0, s.current.length);
|
|
2837
2837
|
c(
|
|
2838
|
-
(
|
|
2838
|
+
(H) => [...y.reverse(), ...H].slice(0, 200)
|
|
2839
2839
|
);
|
|
2840
2840
|
}, 100);
|
|
2841
|
-
return () => clearInterval(
|
|
2841
|
+
return () => clearInterval(w);
|
|
2842
2842
|
}, []);
|
|
2843
2843
|
const q = E(!1);
|
|
2844
2844
|
if (N(() => {
|
|
2845
|
-
!e || q.current || (q.current = !0, e((
|
|
2845
|
+
!e || q.current || (q.current = !0, e((w) => {
|
|
2846
2846
|
s.current.push({
|
|
2847
2847
|
id: Jt++,
|
|
2848
2848
|
ts: Date.now(),
|
|
2849
2849
|
kind: "event",
|
|
2850
|
-
type:
|
|
2851
|
-
data:
|
|
2850
|
+
type: w.eventName,
|
|
2851
|
+
data: w.data
|
|
2852
2852
|
});
|
|
2853
2853
|
}));
|
|
2854
2854
|
}, [e]), N(() => {
|
|
2855
|
-
const
|
|
2855
|
+
const w = console.warn, y = console.log, H = (M, z) => function(...v) {
|
|
2856
2856
|
try {
|
|
2857
2857
|
const S = typeof v[0] == "string" ? v[0] : "";
|
|
2858
2858
|
S.startsWith("[LiveLayer]") && s.current.push({
|
|
@@ -2864,10 +2864,10 @@ function jr({
|
|
|
2864
2864
|
});
|
|
2865
2865
|
} catch {
|
|
2866
2866
|
}
|
|
2867
|
-
return
|
|
2867
|
+
return z.apply(this, v);
|
|
2868
2868
|
};
|
|
2869
|
-
return console.warn =
|
|
2870
|
-
console.warn =
|
|
2869
|
+
return console.warn = H("warn", w), console.log = H("log", y), () => {
|
|
2870
|
+
console.warn = w, console.log = y;
|
|
2871
2871
|
};
|
|
2872
2872
|
}, []), !i)
|
|
2873
2873
|
return /* @__PURE__ */ n(
|
|
@@ -2896,10 +2896,10 @@ function jr({
|
|
|
2896
2896
|
children: "🛰 LL debug"
|
|
2897
2897
|
}
|
|
2898
2898
|
);
|
|
2899
|
-
const
|
|
2899
|
+
const _ = l.filter((w) => {
|
|
2900
2900
|
if (!d) return !0;
|
|
2901
2901
|
const y = d.toLowerCase();
|
|
2902
|
-
return
|
|
2902
|
+
return w.type.toLowerCase().includes(y) || JSON.stringify(w.data || {}).toLowerCase().includes(y);
|
|
2903
2903
|
});
|
|
2904
2904
|
return /* @__PURE__ */ x(
|
|
2905
2905
|
"div",
|
|
@@ -2946,7 +2946,7 @@ function jr({
|
|
|
2946
2946
|
"button",
|
|
2947
2947
|
{
|
|
2948
2948
|
type: "button",
|
|
2949
|
-
onClick: () => m((
|
|
2949
|
+
onClick: () => m((w) => !w),
|
|
2950
2950
|
style: gt(h ? "#f59e0b" : "transparent"),
|
|
2951
2951
|
title: "Pause / resume capture",
|
|
2952
2952
|
children: h ? "▶ resume" : "⏸ pause"
|
|
@@ -2983,7 +2983,7 @@ function jr({
|
|
|
2983
2983
|
{
|
|
2984
2984
|
type: "text",
|
|
2985
2985
|
value: d,
|
|
2986
|
-
onChange: (
|
|
2986
|
+
onChange: (w) => u(w.target.value),
|
|
2987
2987
|
placeholder: "filter by type or data…",
|
|
2988
2988
|
style: {
|
|
2989
2989
|
margin: 8,
|
|
@@ -3005,7 +3005,7 @@ function jr({
|
|
|
3005
3005
|
overflowY: "auto",
|
|
3006
3006
|
padding: "0 8px 8px"
|
|
3007
3007
|
},
|
|
3008
|
-
children:
|
|
3008
|
+
children: _.length === 0 ? /* @__PURE__ */ x(
|
|
3009
3009
|
"div",
|
|
3010
3010
|
{
|
|
3011
3011
|
style: {
|
|
@@ -3035,16 +3035,16 @@ function jr({
|
|
|
3035
3035
|
)
|
|
3036
3036
|
]
|
|
3037
3037
|
}
|
|
3038
|
-
) :
|
|
3038
|
+
) : _.map((w) => /* @__PURE__ */ n(
|
|
3039
3039
|
Tr,
|
|
3040
3040
|
{
|
|
3041
|
-
entry:
|
|
3042
|
-
expanded: a.current.has(
|
|
3041
|
+
entry: w,
|
|
3042
|
+
expanded: a.current.has(w.id),
|
|
3043
3043
|
onToggle: () => {
|
|
3044
|
-
a.current.has(
|
|
3044
|
+
a.current.has(w.id) ? a.current.delete(w.id) : a.current.add(w.id), c((y) => [...y]);
|
|
3045
3045
|
}
|
|
3046
3046
|
},
|
|
3047
|
-
|
|
3047
|
+
w.id
|
|
3048
3048
|
))
|
|
3049
3049
|
}
|
|
3050
3050
|
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livelayer/react",
|
|
3
|
-
"version": "0.5.5-pr66c.
|
|
3
|
+
"version": "0.5.5-pr66c.7",
|
|
4
4
|
"description": "LiveLayer agent widget for React — avatar video, team switching, responsive layouts, full-fidelity embed",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"livekit-client": "^2.17.3",
|
|
25
|
-
"@livelayer/sdk": "0.3.0-pr66c.
|
|
25
|
+
"@livelayer/sdk": "0.3.0-pr66c.7"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@testing-library/dom": "^10.4.1",
|