@livelayer/react 0.17.1 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/dist/index.mjs +758 -754
- package/dist/styles.css +10 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),r=require("react"),It=require("react-dom"),Ge=require("@livelayer/sdk"),vt=require("livekit-client");class vn extends r.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,i){var o,l;(l=(o=this.props).onError)==null||l.call(o,n,i)}render(){var n;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[t.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),t.jsx("p",{className:"ll-error-boundary__message",children:((n=this.state.error)==null?void 0:n.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function bn(e){const[n,i]=r.useState("idle"),[o,l]=r.useState("idle"),[s,c]=r.useState([]),[a,u]=r.useState(null),[h,w]=r.useState(null),[g,p]=r.useState(null),[N,_]=r.useState(!1),[v,f]=r.useState(null),m=r.useRef(null),k=r.useRef(e.onDataMessage);k.current=e.onDataMessage,r.useEffect(()=>{const x={onConnectionStateChange:P=>{i(P),P==="connected"&&f(null)},onAgentStateChange:l,onTranscript:P=>c([...P]),onAgentConfig:u,onAudioTrack:P=>p(P),onVideoTrack:P=>w(P),onVideoTrackRemoved:()=>w(null),onError:P=>f(P),onDataMessage:P=>{var H;(H=k.current)==null||H.call(k,P)},onResumabilityChange:_},A=new Ge.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},x);return m.current=A,i("idle"),l("idle"),c([]),u(null),w(null),p(null),_(!1),f(null),()=>{var P;(P=A.destroy)==null||P.call(A),m.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=r.useCallback(async()=>{const x=m.current;if(x)try{await x.connect()}catch(A){throw f(A instanceof Error?A.message:String(A)),A}},[]),j=r.useCallback(()=>{const x=m.current;x&&x.disconnect()},[]),O=r.useCallback(()=>{var x;return((x=m.current)==null?void 0:x.getRoom())??null},[]);return{connectionState:n,agentState:o,transcript:s,agentConfig:a,videoElement:h,audioElement:g,canResume:N,error:v,connect:E,disconnect:j,getRoom:O,session:m.current}}function xn(){const e=r.useRef(null),n=r.useRef(new Map),i=r.useRef(null),o=r.useRef(new Set),l=r.useCallback(()=>{const _=n.current;if(_.size===0){i.current=null;return}let v=0;for(const{analyser:f,buffer:m}of _.values()){f.getByteFrequencyData(m);let k=0;for(let j=0;j<m.length;j++)k+=m[j];const E=k/m.length/255;E>v&&(v=E)}for(const f of o.current)try{f(v)}catch(m){console.error("[useAudioLevel] subscriber threw:",m)}i.current=requestAnimationFrame(l)},[]),s=r.useCallback(()=>e.current?e.current:typeof window>"u"||typeof AudioContext>"u"?null:(e.current=new AudioContext,e.current),[]),c=r.useCallback(()=>{i.current===null&&n.current.size>0&&(i.current=requestAnimationFrame(l))},[l]),a=r.useCallback(_=>{const v=n.current.get(_);if(v){try{v.node.disconnect()}catch{}try{v.analyser.disconnect()}catch{}n.current.delete(_)}},[]),u=r.useCallback((_,v)=>{const f=s();if(!f)return;a(_);const m=v(f);if(!m)return;const k=f.createAnalyser();k.fftSize=64;try{m.connect(k)}catch(E){console.warn("[useAudioLevel] connect failed for slot",_,E);return}n.current.set(_,{analyser:k,node:m,buffer:new Uint8Array(new ArrayBuffer(k.frequencyBinCount))}),c()},[a,s,c]),h=r.useCallback((_,v="agent")=>{u(v,f=>{try{return f.createMediaElementSource(_)}catch(m){return console.warn("[useAudioLevel] createMediaElementSource failed for slot",v,m),null}})},[u]),w=r.useCallback((_,v="mic")=>{u(v,f=>{try{return f.createMediaStreamSource(_)}catch(m){return console.warn("[useAudioLevel] createMediaStreamSource failed for slot",v,m),null}})},[u]),g=r.useCallback(_=>{a(_),n.current.size===0&&i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[a]),p=r.useCallback(()=>{i.current!==null&&(cancelAnimationFrame(i.current),i.current=null);for(const _ of Array.from(n.current.keys()))a(_)},[a]),N=r.useCallback(_=>(o.current.add(_),()=>{o.current.delete(_)}),[]);return r.useEffect(()=>()=>{if(p(),e.current){try{e.current.close()}catch{}e.current=null}o.current.clear()},[p]),{attach:h,attachStream:w,detach:p,detachSlot:g,subscribe:N}}function ar(e){const n=e==null?void 0:e.mediaStreamTrack;return n?new MediaStream([n]):null}function wn(){const[e,n]=r.useState(!1),[i,o]=r.useState(""),[l,s]=r.useState(null),c=r.useRef(null),a=r.useRef(null),u=r.useCallback(async v=>{var f,m;if(c.current&&a.current){try{await a.current.localParticipant.unpublishTrack(c.current)}catch{}c.current.stop(),c.current=null}a.current=v,s(null);try{const k=await vt.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await v.localParticipant.publishTrack(k),c.current=k,n(k.isMuted);const E=(m=(f=k.mediaStreamTrack)==null?void 0:f.getSettings)==null?void 0:m.call(f);E!=null&&E.deviceId&&o(E.deviceId)}catch(k){const E=k instanceof Error&&k.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw s(E),k}},[]),h=r.useCallback(v=>{a.current=v},[]),w=r.useCallback(async v=>{const f=a.current;if(f)try{await f.switchActiveDevice("audioinput",v),o(v)}catch(m){console.warn("[useMicrophoneState] switchDevice failed:",m)}},[]),g=r.useCallback(async()=>{const v=a.current,f=!e;if(n(f),!!v)try{await v.localParticipant.setMicrophoneEnabled(!f)}catch(m){console.warn("[useMicrophoneState] setMicrophoneEnabled failed:",m),n(!f)}},[e]),p=r.useCallback(()=>{const v=c.current,f=a.current;if(v&&f){try{f.localParticipant.unpublishTrack(v)}catch{}v.stop()}c.current=null,a.current=null,n(!1),o("")},[]),N=r.useCallback(()=>s(null),[]),_=r.useCallback(()=>ar(c.current),[]);return{isMuted:e,activeDeviceId:i,micError:l,toggleMute:g,setupMic:u,attachRoom:h,switchDevice:w,teardownMic:p,clearError:N,getMicStream:_}}const lr={resolution:{width:640,height:480,frameRate:24}};function _n(){const[e,n]=r.useState(!1),[i,o]=r.useState(null),[l,s]=r.useState(null),[c,a]=r.useState(""),u=r.useRef(null),h=r.useRef(null),w=r.useCallback(m=>{u.current=m},[]),g=r.useCallback(()=>{var E;const m=u.current,k=h.current;if(k&&m){const j=m.localParticipant.getTrackPublication(vt.Track.Source.Camera),x=(j==null?void 0:j.track)??k;try{m.localParticipant.unpublishTrack(x)}catch{}try{(E=x.stop)==null||E.call(x)}catch{}}h.current=null,s(null),n(!1)},[]),p=r.useCallback(async m=>{const k=u.current;if(k){o(null);try{const E={...lr};m&&(E.deviceId=m);const j=await vt.createLocalVideoTrack(E);await k.localParticipant.publishTrack(j),h.current=j;const O=j.attach();s(O),n(!0),m&&a(m);try{k.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const j=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";o(j)}}},[]),N=r.useCallback(async()=>{e?g():await p(c||void 0)},[e,c,g,p]),_=r.useCallback(async m=>{g(),await p(m)},[g,p]),v=r.useCallback(()=>{g(),u.current=null,o(null),a("")},[g]),f=r.useCallback(()=>o(null),[]);return r.useEffect(()=>()=>{h.current&&h.current.stop()},[]),{isEnabled:e,error:i,previewEl:l,activeDeviceId:c,toggle:N,switchDevice:_,attachRoom:w,teardown:v,clearError:f}}function kn(){const[e,n]=r.useState(!1),[i,o]=r.useState(null),[l,s]=r.useState(null),c=r.useRef(null),a=r.useCallback(p=>{c.current=p},[]),u=r.useCallback(()=>s(null),[]),h=r.useCallback(async()=>{const p=c.current;if(p){if(e){try{await p.localParticipant.setScreenShareEnabled(!1)}catch{}u(),n(!1);return}o(null);try{await p.localParticipant.setScreenShareEnabled(!0);let N=0;const _=()=>{const v=p.localParticipant.getTrackPublication(vt.Track.Source.ScreenShare);if(v!=null&&v.track){const f=v.track.attach();s(f),n(!0);try{p.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}N++<10?setTimeout(_,100):n(!0)};_()}catch(N){const _=N instanceof Error?N.name:"";_!=="NotAllowedError"&&_!=="AbortError"&&o("Screen share unavailable. Try again."),n(!1)}}},[e,u]),w=r.useCallback(()=>{const p=c.current;if(p&&e)try{p.localParticipant.setScreenShareEnabled(!1)}catch{}u(),n(!1),o(null),c.current=null},[e,u]),g=r.useCallback(()=>o(null),[]);return{isEnabled:e,error:i,previewEl:l,toggle:h,attachRoom:a,teardown:w,clearError:g}}function Cn(){const[e,n]=r.useState([]),[i,o]=r.useState([]),l=r.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const s=await navigator.mediaDevices.enumerateDevices();n(s.filter(c=>c.kind==="audioinput")),o(s.filter(c=>c.kind==="videoinput"))}catch{}},[]);return r.useEffect(()=>{if(l(),typeof navigator>"u"||!navigator.mediaDevices)return;const s=()=>void l();return navigator.mediaDevices.addEventListener("devicechange",s),()=>navigator.mediaDevices.removeEventListener("devicechange",s)},[l]),{mics:e,cameras:i,refresh:l}}function Ln(e,n,i=!1){const[o,l]=r.useState(null),[s,c]=r.useState(null),[a,u]=r.useState(!i&&!!e);return r.useEffect(()=>{if(i||!e){u(!1);return}const h=new AbortController,w=n||"https://app.livelayer.studio";return u(!0),c(null),fetch(`${w}/api/widget/agent/${encodeURIComponent(e)}`,{signal:h.signal}).then(async g=>{if(!g.ok){const p=await g.json().catch(()=>({}));throw new Error(p.error||`HTTP ${g.status}`)}return g.json()}).then(g=>{h.signal.aborted||(l(g),u(!1))}).catch(g=>{h.signal.aborted||(c(g instanceof Error?g.message:"Agent lookup failed"),u(!1))}),()=>h.abort()},[e,n,i]),{info:o,error:s,loading:a}}function cr(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function ur(e,n){if(!(typeof window>"u"))try{window.localStorage.setItem(e,n)}catch{}}function Sn({value:e,defaultValue:n="expanded",onChange:i}={}){const o=e!==void 0,[l,s]=r.useState(n),c=o?e:l,a=r.useCallback(u=>{u!==c&&(o||s(u),i==null||i(u))},[c,o,i]);return[c,a]}const dr=["hidden","minimized","expanded"];function fr(e){return e&&dr.includes(e)?e:null}function En({value:e,defaultValue:n="expanded",onChange:i,persistKey:o="ll-widget",disablePersistence:l=!1}={}){const s=`${o}:display-mode`,c=r.useRef(!1),[a,u]=Sn({value:e,defaultValue:n,onChange:h=>{e===void 0&&!l&&ur(s,h),i==null||i(h)}});return r.useEffect(()=>{if(c.current||(c.current=!0,l||e!==void 0))return;const h=fr(cr(s));h&&h!==a&&u(h)},[]),[a,u]}const pr=640;function jn(e=pr){const[n,i]=r.useState(!1);return r.useEffect(()=>{if(e===!1){i(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const o=`(max-width: ${e-1}px)`,l=window.matchMedia(o),s=()=>i(l.matches);return s(),typeof l.addEventListener=="function"?(l.addEventListener("change",s),()=>l.removeEventListener("change",s)):(l.addListener(s),()=>{l.removeListener(s)})},[e]),n}const Xt="__llHistoryPatched",bt="ll:pathname";function hr(){if(typeof window>"u"||window.history[Xt])return;const e=window.history.pushState,n=window.history.replaceState;window.history.pushState=function(...i){const o=e.apply(this,i);return window.dispatchEvent(new Event(bt)),o},window.history.replaceState=function(...i){const o=n.apply(this,i);return window.dispatchEvent(new Event(bt)),o},window.history[Xt]=!0}function Zt(){return typeof window>"u"?"/":window.location.pathname||"/"}function Nn(e){const[n,i]=r.useState(()=>e??Zt());return r.useEffect(()=>{if(e!==void 0)return;hr();const o=()=>i(Zt());return o(),window.addEventListener("popstate",o),window.addEventListener(bt,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(bt,o)}},[e]),e??n}const Qt=new Map,mr=/[\\^$+?.()|{}[\]]/g;function gr(e){return e.replace(mr,"\\$&")}function yr(e){const n=Qt.get(e);if(n)return n;const i=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,o="",l="",s=i.replace(/\*\*/g,o).replace(/\*/g,l),a=gr(s).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(l,"g"),"[^/]+"),u=new RegExp(`^${a}\\/?$`);return Qt.set(e,u),u}function vr(e,n){const i=n.length>1&&n.endsWith("/")?n.slice(0,-1):n;return yr(e).test(i)}function Rn(e,n){return typeof e=="function"?e(n):e instanceof RegExp?e.test(n):vr(e,n)}function en(e,n){if(!e||e.length===0)return!1;for(const i of e)if(Rn(i,n))return!0;return!1}function An(e,n,i){return e===void 0?!0:en(i,e)?!1:n&&n.length>0?en(n,e):!0}function In(e,n,i){return r.useMemo(()=>An(e,n,i),[e,n,i])}function br(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 xr(e){const n=r.useMemo(()=>br(e.config),[e.config]),i=e.baseUrl.replace(/\/+$/,""),o=r.useRef(null),l=r.useCallback(u=>{try{new Audio(`${i}${u}`).play().catch(()=>{})}catch{}},[i]),s=r.useCallback(()=>{n.navigate&&l("/audio/page-change-sound.mp3")},[n.navigate,l]),c=r.useCallback(()=>{n.action&&l("/audio/confirmation-sound.mp3")},[n.action,l]),a=r.useCallback(u=>{if(!n.thinking){if(o.current){try{o.current.pause()}catch{}o.current=null}return}if(u){if(o.current)return;try{const h=new Audio(`${i}/audio/thinking-sound.mp3`);h.loop=!0,h.volume=.3,h.play().catch(()=>{o.current=null}),o.current=h}catch{}}else if(o.current){try{o.current.pause()}catch{}o.current=null}},[i,n.thinking]);return r.useEffect(()=>()=>{if(o.current){try{o.current.pause()}catch{}o.current=null}},[]),r.useMemo(()=>({playPageChange:s,playConfirmation:c,setThinking:a}),[s,c,a])}const tn=({muted:e=!1,className:n})=>e?t.jsxs("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):t.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"})}),nn=({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"})}),wr=({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"})}),_r={left:180,right:0,up:-90,down:90},rn=({direction:e="right",className:n})=>t.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${_r[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function kr(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const Mn="ll-hidden-tab-center-y",Cr=5,on=16;function Lr(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(Mn);if(!e)return null;const n=Number.parseFloat(e);return Number.isFinite(n)?n:null}catch{return null}}function sn(e){if(!(typeof window>"u"))try{window.localStorage.setItem(Mn,String(e))}catch{}}const Sr=({position:e,isMobile:n,isSpeaking:i,onExpand:o,label:l="Open widget",avatarImageUrl:s,agentName:c,containerEl:a})=>{const u=kr(e),h=u==="right"?"left":"right",w=n?80:72,g=!!s,p=!!a,[N,_]=r.useState(null),[v,f]=r.useState(!1),m=r.useRef(null),k=r.useRef(!1),E=r.useCallback(D=>{if(typeof window>"u")return D;const F=w/2,S=on+F,K=window.innerHeight-on-F;return K<S?Math.max(S,D):Math.max(S,Math.min(K,D))},[w]);r.useEffect(()=>{if(p){_(null);return}const D=Lr();_(E(D??window.innerHeight/2));const F=()=>{_(S=>S===null?null:E(S))};return window.addEventListener("resize",F),()=>window.removeEventListener("resize",F)},[E,p]);const j=r.useCallback(D=>{if(!p&&!(D.pointerType==="mouse"&&D.button!==0)&&N!==null){try{D.currentTarget.setPointerCapture(D.pointerId)}catch{}m.current={startClientY:D.clientY,startCenterY:N,moved:!1}}},[N,p]),O=r.useCallback(D=>{const F=m.current;if(!F)return;const S=D.clientY-F.startClientY;!F.moved&&Math.abs(S)>Cr&&(F.moved=!0,f(!0)),F.moved&&_(E(F.startCenterY+S))},[E]),x=r.useCallback(D=>{const F=m.current;if(F){try{D.currentTarget.releasePointerCapture(D.pointerId)}catch{}m.current=null,F.moved&&(f(!1),k.current=!0,_(S=>(S!==null&&sn(S),S)))}},[]),A=r.useCallback(()=>{if(k.current){k.current=!1;return}o()},[o]),P=r.useCallback(D=>{if(D.key==="ArrowUp"||D.key==="ArrowDown"){D.preventDefault();const F=D.key==="ArrowUp"?-8:8;_(S=>{if(S===null)return S;const K=E(S+F);return sn(K),K})}},[E]),H=["ll-hidden",`ll-hidden--${u}`,n?"ll-hidden--mobile":"ll-hidden--desktop",i?"ll-hidden--speaking":null,v?"is-dragging":null,g?"ll-hidden--with-avatar":null,p?"ll-hidden--scoped":null].filter(Boolean).join(" "),Z=N===null?void 0:{top:`${N-w/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:H,onPointerDown:j,onPointerMove:O,onPointerUp:x,onPointerCancel:x,onClick:A,onKeyDown:P,"aria-label":l,"data-position":e,style:Z,children:g?t.jsxs(t.Fragment,{children:[t.jsx(rn,{direction:h,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:s,alt:c?`${c} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(rn,{direction:h,className:"ll-hidden__chevron"})})},Er=({audioLevel:e,bars:n=20,maxHeight:i=20,minHeight:o=4,className:l,barClassName:s})=>{const c=r.useRef(null),a=r.useRef([]),u=r.useMemo(()=>{const w=(Math.sqrt(5)-1)/2;return Array.from({length:n},(g,p)=>.5+p*w%1*.5)},[n]);r.useEffect(()=>e.subscribe(g=>{for(let p=0;p<n;p++){const N=a.current[p];if(!N)continue;const _=Math.max(o,g*i*u[p]);N.style.height=`${_}px`}}),[e,n,i,o,u]);const h=["ll-waveform",l].filter(Boolean).join(" ");return t.jsx("div",{ref:c,className:h,"aria-hidden":"true",children:Array.from({length:n},(w,g)=>t.jsx("div",{ref:p=>{a.current[g]=p},className:["ll-waveform__bar",s].filter(Boolean).join(" "),style:{height:`${o}px`}},g))})},jr=({position:e,isMobile:n,agentName:i,avatarImageUrl:o,agentState:l,isMuted:s,audioLevel:c,onExpand:a,onToggleMute:u,onClose:h})=>n?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${i} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:a,"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(Er,{audioLevel:c,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:w=>{w.stopPropagation(),u()},onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.stopPropagation(),w.preventDefault(),u())},"aria-label":s?"Unmute microphone":"Mute microphone",children:t.jsx(tn,{muted:s,className:"ll-minimized__icon"})}),t.jsx(nn,{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:l==="speaking"?"Speaking":l==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:u,"aria-label":s?"Unmute microphone":"Mute microphone",children:t.jsx(tn,{muted:s,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:a,"aria-label":`Expand ${i} widget`,children:t.jsx(nn,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:h,"aria-label":"Close widget",children:t.jsx(wr,{className:"ll-minimized__icon"})})]})]})}),Nr=({src:e,alt:n,preCannedPlaying:i=!1,className:o,style:l})=>{const[s,c]=r.useState(!1),a=r.useRef(e);if(r.useEffect(()=>{a.current!==e&&(a.current=e,c(!1))},[e]),!e)return null;const u={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:i?"scale(1.02)":"scale(1)",opacity:s?1:0,...l};return t.jsx("img",{src:e,alt:n,className:o,style:u,loading:"eager",fetchPriority:"high",onLoad:()=>c(!0)})},Rr="#E06540";function Ar({size:e=14,className:n,fill:i=Rr}){return t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 52 52",fill:"none",className:n,"aria-hidden":!0,children:[t.jsx("path",{d:"M44.5714 26C44.5714 23.5612 44.0908 21.146 43.1575 18.8928C42.2242 16.6397 40.8565 14.5924 39.132 12.868C37.4076 11.1435 35.3603 9.77577 33.1072 8.84247C30.854 7.90917 28.4388 7.42857 26 7.42857C23.5612 7.42857 21.146 7.90916 18.8928 8.84247C16.6397 9.77577 14.5924 11.1435 12.868 12.868C11.1435 14.5924 9.77577 16.6397 8.84247 18.8928C7.90917 21.146 7.42857 23.5612 7.42857 26C7.42857 28.4388 7.90916 30.854 8.84247 33.1072C9.77577 35.3603 11.1435 37.4076 12.868 39.132C14.5924 40.8565 16.6397 42.2242 18.8928 43.1575C21.146 44.0908 23.5612 44.5714 26 44.5714H48.2857C50.3371 44.5714 52 46.2344 52 48.2857C52 50.3371 50.3371 52 48.2857 52H26C22.5857 52 19.2049 51.3275 16.0505 50.021C12.896 48.7144 10.0293 46.7993 7.61501 44.385C5.20069 41.9707 3.28564 39.104 1.97902 35.9495C0.67247 32.7951 -3.54212e-07 29.4143 0 26C-1.68163e-07 22.5857 0.672469 19.2049 1.97902 16.0505C3.28564 12.896 5.20069 10.0293 7.61501 7.61501C10.0293 5.20069 12.896 3.28564 16.0505 1.97902C19.2049 0.67247 22.5857 0 26 0C29.4143 1.86048e-07 32.7951 0.67247 35.9495 1.97902C39.104 3.28564 41.9707 5.20069 44.385 7.61501C46.7993 10.0293 48.7144 12.896 50.021 16.0505C51.3275 19.2049 52 22.5857 52 26C52 28.0513 50.3371 29.7143 48.2857 29.7143C46.2344 29.7143 44.5714 28.0513 44.5714 26Z",fill:i}),t.jsx("path",{d:"M28.9717 23.7714C28.9717 21.3098 30.9672 19.3143 33.4288 19.3143C35.8904 19.3143 37.886 21.3098 37.886 23.7714C37.886 26.233 35.8904 28.2286 33.4288 28.2286C30.9672 28.2286 28.9717 26.233 28.9717 23.7714Z",fill:i}),t.jsx("path",{d:"M18.5714 19.3143C16.1098 19.3143 14.1143 21.3098 14.1143 23.7714C14.1143 26.233 16.1098 28.2286 18.5714 28.2286C21.033 28.2286 23.0285 26.233 23.0285 23.7714C23.0285 21.3098 21.033 19.3143 18.5714 19.3143Z",fill:i})]})}const Ir=8,an=8,Mr=({open:e,onClose:n,anchorRef:i,children:o})=>{const l=r.useRef(null),[s,c]=r.useState(null);return r.useLayoutEffect(()=>{if(!e){c(null);return}const a=i.current;if(!a)return;const u=()=>{const h=a.getBoundingClientRect(),w={top:h.top-Ir,left:h.left+h.width/2},g=an+90,p=window.innerWidth-an-90;w.left<g&&(w.left=g),w.left>p&&(w.left=p),c(w)};return u(),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[e,i]),r.useEffect(()=>{if(!e)return;const a=h=>{const w=h.target,g=l.current,p=i.current;g&&g.contains(w)||p&&p.contains(w)||n()},u=h=>{h.key==="Escape"&&(h.stopPropagation(),n())};return document.addEventListener("mousedown",a),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",a),document.removeEventListener("keydown",u)}},[e,n,i]),!e||s===null||typeof document>"u"?null:It.createPortal(t.jsx("div",{ref:l,className:"ll-overflow-popover",role:"menu",style:{position:"fixed",top:s.top,left:s.left,transform:"translate(-50%, -100%)"},children:o}),document.body)},Tr=({isMuted:e,onToggleMute:n,isCameraEnabled:i,onToggleCamera:o,allowCamera:l,isScreenShareEnabled:s,onToggleScreenShare:c,allowScreenShare:a,isSpeakerMuted:u,onToggleSpeaker:h,allowTyping:w,isTypingOpen:g,onToggleTyping:p,onDisconnect:N})=>{const[_,v]=r.useState(!1),f=r.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:m=>m.stopPropagation(),children:[t.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:n,"aria-label":e?"Unmute microphone":"Mute microphone",children:t.jsx(Dn,{muted:e})}),t.jsx("button",{ref:f,type:"button",className:`ll-tool ${_?"is-on":""}`,onClick:()=>v(m=>!m),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":_,children:t.jsx(Pr,{})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:N,"aria-label":"End conversation",children:t.jsx(zn,{})})]}),t.jsxs(Mr,{open:_,onClose:()=>v(!1),anchorRef:f,children:[l&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${i?"is-on":""}`,onClick:()=>{o(),v(!1)},children:[t.jsx(Pn,{}),t.jsx("span",{children:i?"Stop camera":"Start camera"})]}),a&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${s?"is-on":""}`,onClick:()=>{c(),v(!1)},children:[t.jsx(Tn,{}),t.jsx("span",{children:s?"Stop sharing":"Share screen"})]}),t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${u?"is-on":""}`,onClick:()=>{h(),v(!1)},children:[t.jsx($n,{muted:u}),t.jsx("span",{children:u?"Unmute speaker":"Mute speaker"})]}),w&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${g?"is-on":""}`,onClick:()=>{p(),v(!1)},children:[t.jsx(Dr,{}),t.jsx("span",{children:g?"Hide typing":"Type a message"})]}),t.jsxs("button",{type:"button",className:"ll-overflow-popover__item is-active",disabled:!0,"aria-current":"true",children:[t.jsx("span",{className:"ll-overflow-popover__lang-code",children:"EN"}),t.jsx("span",{children:"English"})]})]})]})};function Pr(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[t.jsx("circle",{cx:"6",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"18",cy:"12",r:"1.5"})]})}function Dr(){return t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}const $r=({position:e,isMobile:n,agentName:i,avatarImageUrl:o,idleLoopUrl:l,greeting:s,branding:c,teamMembers:a,currentTeamMemberId:u,isSwitchingTeamMember:h,teamSwitcherOpen:w,onToggleTeamSwitcher:g,onSelectTeamMember:p,languageMenuOpen:N,onToggleLanguageMenu:_,connectionState:v,agentState:f,transcript:m,canResume:k,needsUserGesture:E,error:j,isMuted:O,micError:x,micDevices:A,activeMicId:P,isCameraEnabled:H,cameraPreviewEl:Z,cameraDevices:D,activeCameraId:F,isScreenShareEnabled:S,screenPreviewEl:K,isSpeakerMuted:ye,allowCamera:se,allowScreenShare:Me,allowTyping:Te,showMinimize:Y=!0,showClose:ke=!0,chromeless:ve=!1,compactControls:$=!1,transforming:te,transformingLabel:W,avatarVideoContainerRef:le,agentVideoEl:U,onConnect:Ke,onDisconnect:Je,onRetry:at,onResumeAudio:Xe,onToggleMute:Ce,onSwitchMicDevice:Pe,onToggleCamera:Le,onSwitchCameraDevice:De,onToggleScreenShare:Se,onToggleSpeaker:Ee,onSendMessage:je,onMinimize:Ne,onClose:I,onClearMicError:xt})=>{var dt;const Re=((a==null?void 0:a.length)??0)>1,$e=v==="connecting"||v==="connected",ce=v==="connected",Ze=v==="idle"||v==="disconnected"||v==="error",[Ae,ze]=r.useState(!1);r.useEffect(()=>{if(!U){ze(!1);return}if(!U.paused&&U.readyState>=2){ze(!0);return}ze(!1);const y=()=>ze(!0);return U.addEventListener("playing",y),U.addEventListener("loadeddata",y),()=>{U.removeEventListener("playing",y),U.removeEventListener("loadeddata",y)}},[U]);const[wt,we]=r.useState(!1);r.useEffect(()=>{if(!ce){we(!1);return}if(Ae)return;const y=setTimeout(()=>we(!0),8e3);return()=>clearTimeout(y)},[ce,Ae]);const ne=v==="connecting"||ce&&!!o&&!Ae&&!wt,Qe=r.useRef(null),ue=r.useRef(null);r.useEffect(()=>{const y=Qe.current;y&&(y.innerHTML="",Z&&(Z.style.width="100%",Z.style.height="100%",Z.style.objectFit="cover",Z.style.transform="scaleX(-1)",y.appendChild(Z)))},[Z]),r.useEffect(()=>{const y=ue.current;y&&(y.innerHTML="",K&&(K.style.width="100%",K.style.height="100%",K.style.objectFit="contain",y.appendChild(K)))},[K]);const[de,He]=r.useState(!1),[Oe,re]=r.useState(!1),fe=r.useRef(null),lt=r.useRef(null);r.useEffect(()=>{if(!de&&!Oe&&!N&&!w)return;const y=()=>{He(!1),re(!1),N&&_(),w&&g()};return document.addEventListener("click",y),()=>document.removeEventListener("click",y)},[de,Oe,N,w,_,g]);const[ct,Ie]=r.useState(!1),ie=r.useCallback(()=>Ie(y=>!y),[]),[ae,_e]=r.useState(""),et=r.useCallback(y=>{y.preventDefault();const G=ae.trim();G&&(je(G),_e(""))},[ae,je]),ut=c.productName||"Live Layer",tt=!c.productName;let pe=null,be=null;for(let y=m.length-1;y>=0;y--){const G=m[y];if(!pe&&G.role==="agent"?pe=G:!be&&G.role==="user"&&(be=G),pe&&be)break}const Fe=ce?(pe==null?void 0:pe.text)||null:s||null,Be=ce&&(be==null?void 0:be.text)||null,_t=["ll-expanded",n?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:_t,"data-position":e,"data-state":ce?"connected":$e?"connecting":"idle",role:"dialog","aria-label":`${i} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[o?t.jsx(Nr,{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:((dt=i==null?void 0:i.charAt(0))==null?void 0:dt.toUpperCase())||"A"})}),l&&!ce&&t.jsx("video",{className:"ll-expanded__bg-idle",src:l,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:le,className:"ll-expanded__video"}),ne&&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:h?"Switching...":"Connecting..."})]}),E&&ce&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:Xe,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"})]}),te&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":W,children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:W})]}),$e?t.jsxs(t.Fragment,{children:[!$&&t.jsxs("div",{className:"ll-expanded__topbar",children:[!ve&&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:y=>{Re&&(y.stopPropagation(),g())},"aria-haspopup":Re?"listbox":void 0,"aria-expanded":Re?w:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:i}),Re&&t.jsx(mt,{})]}),Re&&w&&t.jsx("div",{className:"ll-hmenu",onClick:y=>y.stopPropagation(),role:"listbox",children:a==null?void 0:a.map(y=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${y.id===u?"is-active":""}`,onClick:()=>p(y.id),role:"option","aria-selected":y.id===u,children:[y.avatarImageUrl&&t.jsx("img",{src:y.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:y.name}),y.role&&t.jsx("span",{className:"ll-hmenu__role",children:y.role})]},y.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:y=>{y.stopPropagation(),_()},"aria-haspopup":"listbox","aria-expanded":N,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(mt,{})]}),N&&t.jsx("div",{className:"ll-hmenu",onClick:y=>y.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--${f}`,children:f})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[Y!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn",onClick:Ne,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(cn,{})}),ke!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:I,"aria-label":"End call",title:"End call",children:t.jsx(ln,{})})]})]}),$&&t.jsxs("div",{className:"ll-compact-status","data-state":f,children:[t.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),t.jsx("span",{className:"ll-compact-status__label",children:f})]})]}):!$&&t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[tt?t.jsxs("a",{className:"ll-expanded__brand ll-expanded__brand--link",href:"https://livelayer.studio?utm_source=widget&utm_medium=brand-badge",target:"_blank",rel:"noopener noreferrer","aria-label":"Powered by LiveLayer — opens livelayer.studio in a new tab",title:"Powered by LiveLayer — visit livelayer.studio",children:[t.jsx(Ar,{size:14,className:"ll-expanded__brand-mark"}),t.jsx("span",{children:ut})]}):t.jsx("span",{className:"ll-expanded__brand",children:ut}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[Y!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:Ne,"aria-label":"Minimize widget",children:t.jsx(cn,{})}),ke!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:I,"aria-label":"Close widget",children:t.jsx(ln,{})})]})]}),Ze&&(()=>{const y=k?"Resume session":v==="disconnected"?"Reconnect to agent":"Start video call",G=!j;return t.jsxs(t.Fragment,{children:[G&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:Ke,"aria-label":y,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:y})]}),!$&&t.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[s&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:s})}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:Ke,"aria-label":y,children:y})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${$e&&(H||S)?"is-visible":""}`,children:[t.jsx("div",{ref:ue,className:S?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:Qe,className:!S&&H?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),$e?t.jsxs("div",{className:"ll-expanded__bottom",children:[!$&&Fe&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Fe})}),!$&&Be&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Be})}),!ve&&!$&&t.jsxs("div",{className:"ll-toolbar",onClick:y=>y.stopPropagation(),children:[Me&&t.jsx("button",{type:"button",className:`ll-tool ${S?"is-on":""}`,onClick:Se,"aria-label":S?"Stop sharing screen":"Share screen",title:S?"Stop sharing":"Share screen",children:t.jsx(Tn,{})}),se&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${H?"is-on":""}`,onClick:Le,"aria-label":H?"Turn off camera":"Turn on camera",title:H?"Stop camera":"Start camera",children:t.jsx(Pn,{})}),t.jsx("button",{ref:lt,type:"button",className:`ll-tool ll-tool--right ${H?"is-on":""}`,onClick:y=>{y.stopPropagation(),re(G=>!G),He(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":Oe,children:t.jsx(mt,{})}),Oe&&D.length>0&&t.jsx(un,{label:"Camera",devices:D,activeId:F,anchorRef:lt,onPick:y=>{re(!1),De(y)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${O?"is-muted":""}`,onClick:Ce,"aria-label":O?"Unmute microphone":"Mute microphone",title:O?"Unmute":"Mute",children:t.jsx(Dn,{muted:O})}),t.jsx("button",{ref:fe,type:"button",className:`ll-tool ll-tool--right ${O?"is-muted":""}`,onClick:y=>{y.stopPropagation(),He(G=>!G),re(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":de,children:t.jsx(mt,{})}),de&&A.length>0&&t.jsx(un,{label:"Microphone",devices:A,activeId:P,anchorRef:fe,onPick:y=>{He(!1),Pe(y)}})]}),t.jsx("button",{type:"button",className:`ll-tool ${ye?"is-muted":""}`,onClick:Ee,"aria-label":ye?"Unmute speaker":"Mute speaker",title:ye?"Unmute speaker":"Mute speaker",children:t.jsx($n,{muted:ye})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:Je,"aria-label":"End conversation",title:"End conversation",children:t.jsx(zn,{})})]}),!ve&&$&&t.jsx(Tr,{isMuted:O,onToggleMute:Ce,isCameraEnabled:H,onToggleCamera:Le,allowCamera:se,isScreenShareEnabled:S,onToggleScreenShare:Se,allowScreenShare:Me,isSpeakerMuted:ye,onToggleSpeaker:Ee,allowTyping:Te,isTypingOpen:ct,onToggleTyping:ie,onDisconnect:Je}),!ve&&Te&&($?ct:!0)&&t.jsxs("form",{className:"ll-message-input",onSubmit:et,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:ae,onChange:y=>_e(y.target.value),"aria-label":"Message the agent"}),ae.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(zr,{})})]})]}):null,(()=>{if(x&&v!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:x}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:xt,"aria-label":"Dismiss",children:"×"})]});if(!j||v!=="error")return null;let y="Failed to connect",G="Try again";return j==="MIC_PERMISSION_DENIED"?y="Microphone blocked. Allow access to talk.":j==="MIC_NOT_FOUND"?y="No microphone found. Plug one in + retry.":j==="MIC_UNAVAILABLE"?y="Mic unavailable. Check other apps using it.":j==="AGENT_TIMEOUT"?y="Agent didn't pick up. Try again.":j==="CONNECT_FAILED"?y="Connection failed. Check your network.":j.length<80&&(y=j),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:y}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:at,children:G})]})})()]})};function mt(){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 ln(){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 cn(){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 Tn(){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 Pn(){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 Dn({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 $n({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("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 zr(){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 zn(){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 un=({label:e,devices:n,activeId:i,onPick:o,anchorRef:l})=>{const[s,c]=r.useState(null);return r.useLayoutEffect(()=>{const a=()=>{const u=l.current;if(!u)return;const h=u.getBoundingClientRect(),w=126,g=window.innerWidth-16-110,p=h.left+h.width/2;c({top:h.top-8,left:Math.max(w,Math.min(g,p))})};return a(),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[l]),s===null||typeof document>"u"?null:It.createPortal(t.jsxs("div",{className:"ll-device-menu ll-device-menu--floating",onClick:a=>a.stopPropagation(),role:"listbox",style:{position:"fixed",top:s.top,left:s.left,transform:"translate(-50%, -100%)"},children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),n.map((a,u)=>{const h=i===a.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${h?"is-active":""}`,onClick:()=>o(a.deviceId),role:"option","aria-selected":h,children:[h&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:a.label||`${e} ${u+1}`})]},a.deviceId||u)})]}),document.body)},Hr=["[data-ll-private]","[data-ll-skip]",".ll-widget"];function Mt(e){let n=e;for(;n;){for(const i of Hr)if(n.matches(i))return!0;n=n.parentElement}return!1}function Rt(e){if(Mt(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const n=(e.getAttribute("autocomplete")||"").toLowerCase();if(n==="off"||n.startsWith("cc-"))return!1}return!0}const gt=4096,Or=20,Fr=20,Br=10,Wr=10,qr=30,Ur=20,dn=500,Vr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function ot(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let n=e;for(;n;){for(const i of Vr)if(n.matches(i))return!0;n=n.parentElement}return!1}function st(e){if(typeof window>"u")return!0;const n=e.getBoundingClientRect();if(n.width<=0||n.height<=0)return!1;const i=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth;return n.bottom>0&&n.right>0&&n.top<i&&n.left<o}function fn(e){const n=e.getAttribute("id");if(n){const s=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/"/g,'\\"'),c=document.querySelector(`label[for="${s}"]`);if(c!=null&&c.textContent)return c.textContent.trim()}const i=e.getAttribute("aria-label");if(i)return i.trim();const o=e.closest("label");if(o){const s=[];for(const a of Array.from(o.childNodes))if(a.nodeType===Node.TEXT_NODE){const u=(a.textContent||"").trim();u&&s.push(u)}else if(a instanceof HTMLElement){if(a instanceof HTMLInputElement||a instanceof HTMLTextAreaElement||a instanceof HTMLSelectElement||a instanceof HTMLButtonElement)continue;const u=(a.textContent||"").trim();u&&s.push(u)}const c=s.join(" ").trim();if(c)return c}const l=e.getAttribute("placeholder");return l?l.trim():""}function ee(e,n){return e.length<=n?e:e.slice(0,n-1)+"…"}function Yr(e){return e&&e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function Gr(e){const n=e.getAttribute("aria-label");if(n)return n.trim().slice(0,80);const i=e.getAttribute("aria-labelledby");if(i){const s=document.getElementById(i);if(s!=null&&s.textContent)return s.textContent.trim().slice(0,80)}const o=e.querySelector('button[type="submit"], input[type="submit"], button:not([type])');if(o){const s=o instanceof HTMLInputElement?o.value:(o.textContent??"").trim();if(s&&s.length<60&&!/^(submit|ok|continue)$/i.test(s))return s}let l=e.parentElement;for(let s=0;l&&s<4;s++,l=l.parentElement){const c=l.querySelector("h1, h2, h3, h4");if(c!=null&&c.textContent){const a=c.textContent.trim();if(a&&a.length<80)return a}}return null}function Ue(e){return e.length}function Hn(e,n={}){const i=n.doc??(typeof document<"u"?document:null);if(!i)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const o=typeof window<"u"&&window.location.href||"",l=typeof window<"u"&&window.location.pathname||"/",s=i.title||"",c=Array.from(i.querySelectorAll("[data-ll-region]")),a=[];for(const x of c){if(a.length>=Br)break;if(ot(x)||!st(x))continue;const A=x.getAttribute("data-ll-region")??"",P=x.getAttribute("data-ll-intent")??void 0,H=ee((x.innerText||x.textContent||"").trim(),dn*2);!A||!H||a.push({id:A,intent:P,text:H})}const u=[],h=["H1","H2","H3","H4","H5","H6"],w=Array.from(i.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const x of w){if(ot(x)||!st(x))continue;const A=(x.textContent||"").trim();A&&u.push(`${x.tagName}: ${ee(A,200)}`)}const g=Array.from(i.querySelectorAll("p, li"));for(const x of g){if(ot(x)||!st(x)||h.includes(x.tagName))continue;const A=(x.textContent||"").trim();A.length>10&&u.push(ee(A,dn))}const p=u.join(`
|
|
2
|
-
`),N=[],_=Array.from(i.querySelectorAll("a[href]"));for(const x of _){if(N.length>=Or)break;if(ot(x)||!st(x))continue;const A=x.getAttribute("href")||"",P=(x.textContent||"").trim();!A||!P||N.push({href:A,text:ee(P,100)})}const v=[],f=Array.from(i.querySelectorAll("input, textarea, select"));for(const x of f){if(v.length>=Fr)break;if(ot(x)||!Rt(x)||!st(x))continue;const A=fn(x),P=x instanceof HTMLInputElement?x.type:x.tagName.toLowerCase();A&&v.push({label:ee(A,100),type:P})}const m=Array.from(i.querySelectorAll("form")),k=[];let E=0;for(const x of m){if(k.length>=Wr)break;if(Mt(x)||x.matches(".ll-widget *, .ll-widget"))continue;const A=x.getAttribute("id")||x.getAttribute("name")||Yr(x.getAttribute("data-ll-intent"))||`form_${E++}`,P=x.getAttribute("data-ll-intent")||Gr(x)||void 0,H=Array.from(x.querySelectorAll("input, textarea, select")),Z=[];let D=0;const F=new Set;for(const S of H){if(Z.length>=qr)break;if(!Rt(S))continue;if(S instanceof HTMLInputElement){const $=S.type;if($==="submit"||$==="button"||$==="reset"||$==="hidden"||$==="image"||$==="file")continue}const K=S.getAttribute("name")||"",ye=S.getAttribute("id")||"";let se=K||ye||`field_${D}`;F.has(se)&&(se=`${se}__${D}`),F.add(se),D++;const Me=fn(S)||se,Te=S instanceof HTMLInputElement?S.type:S.tagName.toLowerCase(),Y={name:se,label:ee(Me,100),type:Te};S.required===!0&&(Y.required=!0);const ke=S.getAttribute("placeholder");if(ke&&(Y.placeholder=ee(ke.trim(),100)),S instanceof HTMLInputElement||S instanceof HTMLTextAreaElement){const $=S.getAttribute("minlength");if($!==null){const W=parseInt($,10);!Number.isNaN(W)&&W>=0&&(Y.minLength=W)}const te=S.getAttribute("maxlength");if(te!==null){const W=parseInt(te,10);!Number.isNaN(W)&&W>=0&&(Y.maxLength=W)}}if(S instanceof HTMLInputElement){const $=S.getAttribute("min");$!==null&&(Y.min=ee($,50));const te=S.getAttribute("max");te!==null&&(Y.max=ee(te,50));const W=S.getAttribute("step");W!==null&&(Y.step=ee(W,20));const le=S.getAttribute("pattern");le!==null&&(Y.pattern=ee(le,200));const U=(S.getAttribute("autocomplete")||"").toLowerCase();U&&U!=="off"&&!U.startsWith("cc-")&&(Y.autocomplete=ee(U,50))}if(S instanceof HTMLSelectElement){const $=[];for(let te=0;te<S.options.length&&!($.length>=Ur);te++){const W=S.options[te];if(!W||W.disabled)continue;const le=W.value||"",U=(W.textContent||"").trim()||le;!le&&!U||$.push({value:le,label:ee(U,60)})}$.length>0&&(Y.options=$)}const ve=typeof S.validationMessage=="string"?S.validationMessage:"";ve&&(Y.validationMessage=ee(ve,200)),Z.push(Y)}k.push({id:A,intent:P,fields:Z})}const j={url:o,title:s,pathname:l,regions:a,visibleText:p,visibleLinks:N,visibleFields:v,forms:k,extras:e};let O=Ue(JSON.stringify(j.regions))+Ue(j.visibleText)+Ue(JSON.stringify(j.visibleLinks))+Ue(JSON.stringify(j.visibleFields));for(;O>gt&&j.visibleFields.length>0;)j.visibleFields.pop(),O=Ue(JSON.stringify(j.visibleFields));for(;O>gt&&j.visibleLinks.length>0;)j.visibleLinks.pop(),O-=80;return Ue(j.visibleText)>gt&&(j.visibleText=ee(j.visibleText,gt-100)),j}let Ve=null;function At(e,n={}){const i=Date.now(),l=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(Ve&&Ve.key===l&&i-Ve.at<1e3)return Ve.ctx;const s=Hn(e,n);return Ve={key:l,at:i,ctx:s},s}function On(){Ve=null}const Kr=200;function Fn(e){const n=String(e.href||"");return{href:n,text:String(e.text??e.title??n),internal:e.internal??!0,title:e.title,description:e.description}}function Jr(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function Bn(e){const n=e??(typeof document<"u"?document:null);if(!n)return[];const i=typeof window<"u"&&window.location.origin||"",o=new Set,l=[],s=Array.from(n.querySelectorAll("a[href]"));for(const c of s){if(l.length>=Kr)break;if(Mt(c))continue;const a=c.getAttribute("href")||"";if(!Jr(a))continue;let u=a,h=!0;try{if(typeof window<"u"){const g=new URL(a,i);h=g.origin===i,h&&a.startsWith("http")&&(u=g.pathname+g.search+g.hash)}}catch{continue}if(o.has(u))continue;o.add(u);const w=(c.textContent||"").trim().slice(0,120);l.push({href:u,text:w,internal:h})}return l}let Ye=null;const Xr=5e3;function yt(){const e=Date.now(),n=typeof window<"u"&&window.location.pathname||"/";if(Ye&&Ye.pathname===n&&e-Ye.at<Xr)return Ye.routes;const i=Bn();return Ye={at:e,pathname:n,routes:i},i}function Wn(){Ye=null}function pn(e){if(e instanceof HTMLInputElement){const n=e.type;if(n==="submit"||n==="button"||n==="reset"||n==="hidden"||n==="image"||n==="file")return!1}return!0}function Zr(e,n){return e.getAttribute("name")||e.getAttribute("id")||`field_${n}`}function Qr(e,n){if(!n)return null;try{const s=e.querySelector(`[name="${n.replace(/"/g,'\\"')}"]`);if(s&&pn(s))return s}catch{}const i=Array.from(e.querySelectorAll("input, textarea, select"));let o=0;const l=new Map;for(const s of i){if(!pn(s))continue;const c=Zr(s,o);let a=c;if(l.has(c)&&(a=`${c}__${o}`),a===n)return s;l.set(c,s),o++}return null}function hn(e,n){const i=Qr(e,n);return i?Rt(i)?{el:i}:{el:null,reason:"private"}:{el:null,reason:"not_found"}}function ei(e,n){const i=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,o=Object.getOwnPropertyDescriptor(i,"value"),l=o==null?void 0:o.set;l?l.call(e,n):e.value=n}function ti(e,n,i={}){const o=i.triggerInput??!0,l=i.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const s=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),c=s==null?void 0:s.set,a=n==="true"||n==="1"||n==="on";c?c.call(e,a):e.checked=a,o&&e.dispatchEvent(new Event("input",{bubbles:!0})),l&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}ei(e,n),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),l&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function mn(e,n){if(!n)return null;const i=n.replace(/"/g,'\\"');try{const c=e.querySelector(`form#${CSS.escape(n)}`);if(c)return c}catch{}const o=e.querySelector(`form[name="${i}"]`);if(o)return o;const l=e.querySelector(`form[data-ll-intent="${i}"]`);if(l)return l;const s=Array.from(e.querySelectorAll("form"));for(const c of s){const a=c.getAttribute("data-ll-intent");if(a&&ni(a)===n)return c}if(/^form_\d+$/.test(n)){const c=parseInt(n.slice(5),10);let a=0;for(const u of s)if(!(u.id||u.getAttribute("name")||u.getAttribute("data-ll-intent"))){if(a===c)return u;a++}}return null}function ni(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function ri(){if(typeof window>"u"||typeof document>"u")return!1;const e=document.scrollingElement||document.documentElement;if(!e||e.scrollHeight<=e.clientHeight+2)return!1;const n=window.getComputedStyle(e);return!(n.overflowY==="hidden"||n.overflowY==="clip")}function ii(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function oi(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let n=null,i=0;for(const o of e){if(!ii(o))continue;const l=o.getBoundingClientRect();if(l.bottom<=0||l.top>=window.innerHeight||l.right<=0||l.left>=window.innerWidth||l.width<=0||l.height<=0||o.closest(".ll-widget"))continue;const s=l.width*l.height;s>i&&(i=s,n=o)}return n}function si(){if(typeof window>"u")return null;if(ri())return window;const e=oi();return e||window}function gn(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function ai(e){var n,i;return e instanceof Window?typeof document>"u"?0:Math.max(((n=document.body)==null?void 0:n.scrollHeight)??0,((i=document.documentElement)==null?void 0:i.scrollHeight)??0):e.scrollHeight-e.clientHeight}const li=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","task_field_updated","task_completed"]),qn=r.forwardRef(function(n,i){var qt,Ut,Vt,Yt,Gt,Kt,Jt;const{agentId:o,apiKey:l,baseUrl:s="https://app.livelayer.studio",sessionEndpoint:c,sessionBody:a,soundEffects:u,experienceMode:h="WIDGET",autoConnect:w=!1,displayMode:g,defaultDisplayMode:p="expanded",onDisplayModeChange:N,position:_="bottom-right",mobileBreakpoint:v=640,persistKey:f="ll-widget",disablePersistence:m=!1,teamMembers:k,currentTeamMemberId:E,onTeamMemberChange:j,idleLoopUrl:O,greeting:x,avatarImageUrl:A,agentName:P,branding:H={},allowCamera:Z=!0,allowScreenShare:D=!0,allowTyping:F=!0,showMinimize:S,showClose:K,chromeless:ye=!1,floatingChromeContainer:se=null,compactControls:Me=!1,transforming:Te=!1,transformingLabel:Y="Transforming…",showOn:ke,hideOn:ve,pathname:$,onNavigate:te,onScrollToSelector:W,getPageContext:le,pageContextExtras:U,getRoutes:Ke,onScrollPage:Je,onClick:at,capabilities:Xe,onConnect:Ce,onDisconnect:Pe,onTranscript:Le,onAgentState:De,onConnectionStateChange:Se,onAgentEvent:Ee,onAgentCommand:je,onCollect:Ne,controlledSession:I,className:xt,style:Re,zIndex:$e=2147483647}=n,ce=Nn($),Ze=In(ce,ke,ve);r.useEffect(()=>{On(),Wn()},[ce]);const Ae=E!==void 0,[ze,wt]=r.useState(()=>{var b;return E??((b=k==null?void 0:k[0])==null?void 0:b.id)}),we=Ae?E:ze,ne=r.useMemo(()=>(k==null?void 0:k.find(b=>b.id===we))??null,[k,we]),Qe=(ne==null?void 0:ne.agentId)??o,ue=h==="EMBEDDED",de=jn(v),[He,Oe]=En({value:g,defaultValue:p,onChange:N,persistKey:f,disablePersistence:ue||m}),re=ue?"expanded":He,fe=ue?()=>{}:Oe,lt=S??!ue,ct=K??!ue,Ie=xn(),ie=wn(),ae=_n(),_e=kn(),et=Cn(),[ut,tt]=r.useState(!1),[pe,be]=r.useState(!1),[Fe,Be]=r.useState(!1),[_t,dt]=r.useState(!1),[y,G]=r.useState(!1),ft=xr({baseUrl:s,config:u}),pt=r.useRef(ft);pt.current=ft;const kt=r.useRef(te),Ct=r.useRef(W),Lt=r.useRef(Je),St=r.useRef(at),Tt=r.useRef(le),Pt=r.useRef(U),Dt=r.useRef(Ke),Et=r.useRef(Xe),he=r.useRef(null);kt.current=te,Ct.current=W,Lt.current=Je,St.current=at,Tt.current=le,Pt.current=U,Dt.current=Ke,Et.current=Xe;function me(b){const d=Et.current;return d?d.includes(b):!0}function ge(b,d){console.warn(`[LiveLayer] Agent command "${b}" blocked — capability "${d}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const nt=r.useCallback(b=>{var V,Q,xe,it;const d=b;if(!(!d.type||typeof d.type!="string")){if(Ee==null||Ee({eventName:d.type,data:b}),d.type==="navigate"){if(!me("navigate")){ge("navigate","navigate");return}const C=typeof d.href=="string"?d.href:null;if(!C){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(pt.current.playPageChange(),kt.current){try{kt.current(C)}catch(R){console.warn(`[LiveLayer] onNavigate threw for "${C}". Falling back. Error:`,R)}return}if(typeof document<"u"){const R=document.querySelector(`a[href="${C.replace(/"/g,'\\"')}"]`);if(R){R.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",C),window.dispatchEvent(new PopStateEvent("popstate"))}catch(R){console.warn(`[LiveLayer] history.pushState fallback failed for "${C}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,R)}return}if(d.type==="scroll_to"){if(!me("scroll")){ge("scroll_to","scroll");return}const C=typeof d.selector=="string"?d.selector:null;if(!C)return;const R=d.behavior==="instant"?"instant":"smooth";if(Ct.current){try{Ct.current(C,R)}catch(z){console.warn("[LiveLayer] onScrollToSelector threw.",z)}return}if(typeof document<"u"){let z=null;try{z=document.querySelector(C)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${C}".`);return}if(!z){console.warn(`[LiveLayer] scroll_to: no element matched "${C}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}z.scrollIntoView({behavior:R,block:"start"})}return}if(d.type==="request_page_context"){if(!me("read_page")){ge("request_page_context","read_page");return}const C=typeof d.requestId=="string"?d.requestId:void 0,R=(V=he.current)==null?void 0:V.call(he),z=q=>{const M=R,X=M==null?void 0:M.localParticipant;if(X!=null&&X.publishData)try{const oe=C?{...q,requestId:C}:q,qe=new TextEncoder().encode(JSON.stringify(oe));X.publishData(qe,{reliable:!0})}catch(oe){console.warn("[LiveLayer] publishData failed.",oe)}},T=Pt.current,B=Tt.current;try{if(B){const q=B(T);if(q instanceof Promise){z({type:"page_context_pending"}),q.then(M=>z({type:"page_context",context:M})).catch(M=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",M),z({type:"page_context",context:At(T)})});return}z({type:"page_context",context:q});return}z({type:"page_context",context:At(T)})}catch(q){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",q),z({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:T}})}return}if(d.type==="scroll_page"){if(!me("scroll")){ge("scroll_page","scroll");return}const C=d.direction;if(C!=="up"&&C!=="down"&&C!=="top"&&C!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(C)}". Expected up | down | top | bottom.`);return}const R=d.behavior==="instant"?"instant":"smooth";if(Lt.current){try{Lt.current(C,R)}catch(M){console.warn("[LiveLayer] onScrollPage threw.",M)}return}if(typeof window>"u")return;const z={behavior:R},T=si(),B=M=>{T instanceof Window?T.scrollBy({top:M,...z}):T.scrollBy({top:M,...z})},q=M=>{T instanceof Window?T.scrollTo({top:M,...z}):T.scrollTo({top:M,...z})};C==="up"?B(-gn(T)):C==="down"?B(gn(T)):q(C==="top"?0:ai(T));return}if(d.type==="click"){if(!me("click")){ge("click","click");return}const C=typeof d.selector=="string"?d.selector:null;if(!C){console.warn("[LiveLayer] click: missing selector.");return}if(St.current){try{St.current(C)}catch(z){console.warn("[LiveLayer] onClick threw.",z)}return}if(typeof document>"u")return;let R=null;try{R=document.querySelector(C)}catch{console.warn(`[LiveLayer] click: invalid selector "${C}".`);return}if(!R){console.warn(`[LiveLayer] click: no element matched "${C}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(Q=R.click)==null||Q.call(R);return}if(d.type==="fill_form"||d.type==="focus_field"){if(!me("fill_forms")){ge(d.type,"fill_forms");return}if(typeof document>"u")return;d.type==="fill_form"&&pt.current.playConfirmation();const C=typeof d.formId=="string"?d.formId:null;if(!C){console.warn(`[LiveLayer] ${d.type}: missing formId.`);return}const R=mn(document,C);if(!R){console.warn(`[LiveLayer] ${d.type}: no <form> matched id="${C}" (or matching name / data-ll-intent slug). Forms are auto-discovered — make sure the form has an \`id\`, \`name\`, or \`data-ll-intent\` attribute the agent observed in PageContext.forms.`);return}if(R.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')){console.warn(`[LiveLayer] ${d.type}: refusing to touch a form in a private / opted-out subtree.`);return}if(d.type==="focus_field"){const T=typeof d.fieldName=="string"?d.fieldName:null;if(!T){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const B=hn(R,T);if(B.el===null){B.reason==="private"?console.warn(`[LiveLayer] focus_field: field "${T}" is privacy-protected and not focusable.`):console.warn(`[LiveLayer] focus_field: no input matching key="${T}" in form "${C}". The agent should use the field.name it observed in PageContext.forms[].fields[].`);return}B.el.focus();return}const z=d.values&&typeof d.values=="object"?d.values:null;if(!z){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[T,B]of Object.entries(z)){if(typeof B!="string")continue;const q=hn(R,T);if(q.el===null){q.reason==="private"?console.warn(`[LiveLayer] fill_form: field "${T}" is privacy-protected (password / cc-* / data-ll-private). Skipping.`):console.warn(`[LiveLayer] fill_form: no input matching key="${T}" in form "${C}". The agent should use the field.name it observed in PageContext.forms[].fields[]. Skipping.`);continue}try{ti(q.el,B)}catch(M){console.warn(`[LiveLayer] fill_form: failed to set "${T}".`,M)}}return}if(d.type==="submit_form"){if(!me("submit_forms")){ge("submit_form","submit_forms");return}if(typeof document>"u")return;const C=typeof d.formId=="string"?d.formId:null;if(!C){console.warn("[LiveLayer] submit_form: missing formId.");return}pt.current.playConfirmation();const R=mn(document,C);if(!R){console.warn(`[LiveLayer] submit_form: no <form> matched id="${C}" (or matching name / data-ll-intent slug).`);return}if(R.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private / opted-out subtree.");return}const z=typeof d.requestId=="string"?d.requestId:void 0,T=(xe=he.current)==null?void 0:xe.call(he),B=X=>{const oe=T,qe=oe==null?void 0:oe.localParticipant;if(qe!=null&&qe.publishData)try{const or=z?{...X,requestId:z}:X,sr=new TextEncoder().encode(JSON.stringify(or));qe.publishData(sr,{reliable:!0})}catch{}};let q=!1;const M=()=>{q=!0,B({type:"form_submitted",formId:C})};R.addEventListener("submit",M,{once:!0});try{typeof R.requestSubmit=="function"?R.requestSubmit():R.submit()}catch(X){console.warn("[LiveLayer] submit_form: requestSubmit threw.",X),R.removeEventListener("submit",M),B({type:"form_submit_blocked",formId:C,reason:"exception"});return}setTimeout(()=>{q||(R.removeEventListener("submit",M),B({type:"form_submit_blocked",formId:C,reason:"validation"}))},500);return}if(d.type==="request_routes"){if(!me("read_page")){ge("request_routes","read_page");return}const C=typeof d.requestId=="string"?d.requestId:void 0,z=(it=he.current)==null?void 0:it.call(he),T=z==null?void 0:z.localParticipant;if(!(T!=null&&T.publishData))return;const B=M=>{try{const X=C?{type:"routes",routes:M,requestId:C}:{type:"routes",routes:M},oe=new TextEncoder().encode(JSON.stringify(X));T.publishData(oe,{reliable:!0})}catch(X){console.warn("[LiveLayer] request_routes: publishData failed.",X)}},q=Dt.current;if(q){try{const M=q(),X=oe=>{if(!Array.isArray(oe)){B([]);return}B(oe.map(Fn).slice(0,200))};M instanceof Promise?M.then(X).catch(oe=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",oe),B(yt())}):X(M)}catch(M){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",M),B(yt())}return}try{B(yt())}catch(M){console.warn("[LiveLayer] request_routes: extractRoutes threw.",M)}return}if(d.type==="task_field_updated"){if(!me("collect_data")){ge("task_field_updated","collect_data");return}const C={phase:"field",fieldId:typeof d.fieldId=="string"?d.fieldId:"",fieldName:typeof d.fieldName=="string"?d.fieldName:typeof d.fieldId=="string"?d.fieldId:"",value:typeof d.value=="string"?d.value:"",kind:typeof d.kind=="string"?d.kind:"text",source:d.source==="slide"?"slide":d.source==="page"?"page":"agent",...typeof d.slideId=="string"?{slideId:d.slideId}:{},...typeof d.formId=="string"?{formId:d.formId}:{}};if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:C}))}catch{}return}if(d.type==="task_completed"){if(!me("collect_data")){ge("task_completed","collect_data");return}const C=d.result;if(!C||typeof C!="object"){console.warn("[LiveLayer] task_completed missing `result` payload.");return}if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:{phase:"complete",result:C}}))}catch{}try{Ne==null||Ne(C)}catch(R){console.warn("[LiveLayer] onCollect threw.",R)}return}li.has(d.type)||je==null||je(d)}},[je,Ee,Ne]),J=bn({agentId:I?"__controlled__":Qe,baseUrl:s,apiKey:l,sessionEndpoint:c,sessionBody:a,onDataMessage:I?void 0:nt});r.useEffect(()=>{if(I!=null&&I.subscribeToDataMessages)return I.subscribeToDataMessages(nt)},[I,nt]),he.current=()=>{var b;return(b=J.getRoom)==null?void 0:b.call(J)},r.useEffect(()=>{var V;if(typeof window>"u")return;const b=((V=window.location)==null?void 0:V.hostname)||"";if(b==="localhost"||b==="127.0.0.1"||b==="0.0.0.0"||b.endsWith(".local")||b.endsWith(".test"))return window.__livelayerSimulateCommand=Q=>{try{nt(Q)}catch(xe){console.warn("[LiveLayer] simulate-command threw:",xe)}},()=>{delete window.__livelayerSimulateCommand}},[nt]);const L=r.useMemo(()=>I?{connectionState:I.connectionState,agentState:I.agentState,transcript:I.transcript,videoElement:I.videoElement,audioElement:I.audioElement,canResume:I.canResume,error:I.error,agentConfig:null,connect:async()=>{await I.onConnect()},disconnect:()=>I.onDisconnect(),getRoom:J.getRoom,isControlled:!0}:{connectionState:J.connectionState,agentState:J.agentState,transcript:J.transcript,videoElement:J.videoElement,audioElement:J.audioElement,canResume:J.canResume,error:J.error,agentConfig:J.agentConfig,connect:J.connect,disconnect:J.disconnect,getRoom:J.getRoom,isControlled:!1},[I,J]),$t=r.useRef(L);$t.current=L;const zt=r.useRef(I);zt.current=I,r.useImperativeHandle(i,()=>({sendData:async b=>{var xe,it;const d=zt.current;if(d!=null&&d.publishData){try{await d.publishData(b)}catch(C){console.warn("[AvatarWidget] sendData (controlled) failed:",C)}return}const V=(it=(xe=$t.current)==null?void 0:xe.getRoom)==null?void 0:it.call(xe),Q=V==null?void 0:V.localParticipant;if(Q!=null&&Q.publishData)try{const C=new TextEncoder().encode(JSON.stringify(b));await Q.publishData(C,{reliable:!0})}catch(C){console.warn("[AvatarWidget] sendData failed:",C)}}}),[]);const Ht=r.useRef(null);r.useEffect(()=>{const b=L.videoElement,d=Ht.current;if(!(!b||!d))return d.appendChild(b),()=>{b.parentNode===d&&d.removeChild(b)}},[L.videoElement]),r.useEffect(()=>{const b=L.audioElement;if(!b)return;const d=document.createElement("div");d.className="ll-audio-sink",d.setAttribute("aria-hidden","true"),d.style.cssText="position:absolute;width:0;height:0;overflow:hidden;clip:rect(0 0 0 0);pointer-events:none;",d.appendChild(b),document.body.appendChild(d),Ie.attach(b);const V=b.play();return V&&typeof V.catch=="function"&&V.catch(Q=>{(Q==null?void 0:Q.name)==="NotAllowedError"&&tt(!0)}),()=>{Ie.detach(),b.parentNode===d&&d.removeChild(b),d.parentNode===document.body&&document.body.removeChild(d)}},[L.audioElement]),r.useEffect(()=>{if(L.isControlled||L.connectionState!=="connected")return;const b=L.getRoom();if(b)return ie.setupMic(b).then(()=>{const d=ie.getMicStream();d&&Ie.attachStream(d,"mic")}).catch(()=>{}),()=>{Ie.detachSlot("mic"),ie.teardownMic()}},[L.isControlled,L.connectionState]),r.useEffect(()=>{var d;if(L.connectionState!=="connected")return;const b=L.isControlled?(d=I==null?void 0:I.getRoom)==null?void 0:d.call(I):L.getRoom();if(b)return ae.attachRoom(b),_e.attachRoom(b),L.isControlled&&ie.attachRoom(b),et.refresh(),()=>{ae.teardown(),_e.teardown()}},[L.isControlled,L.connectionState,I]),r.useEffect(()=>{const b=L.audioElement;b&&(b.muted=y)},[L.audioElement,y]);const Yn=r.useCallback(b=>{const d={type:"user_message",text:b};if(I!=null&&I.publishData){try{I.publishData(d)}catch{}return}const V=L.getRoom();if(V)try{const Q=new TextEncoder().encode(JSON.stringify(d));V.localParticipant.publishData(Q,{reliable:!0})}catch{}},[L,I]),Gn=r.useCallback(()=>{G(b=>!b)},[]);r.useEffect(()=>{Se==null||Se(L.connectionState),L.connectionState==="connected"?Ce==null||Ce():L.connectionState==="disconnected"&&(Pe==null||Pe())},[L.connectionState,Ce,Pe,Se]),r.useEffect(()=>{Le==null||Le(L.transcript)},[L.transcript,Le]),r.useEffect(()=>{De==null||De(L.agentState)},[L.agentState,De]),r.useEffect(()=>{ft.setThinking(L.agentState==="thinking")},[L.agentState,ft]);const Ot=r.useRef(!1);r.useEffect(()=>{!w||Ot.current||Ze&&L.connectionState==="idle"&&(Ot.current=!0,L.connect())},[w,L.connectionState,L,Ze]);const Kn=r.useCallback(b=>{const d=k==null?void 0:k.find(V=>V.id===b);d&&(Be(!1),b!==we&&(be(!0),L.disconnect(),Ae||wt(b),j==null||j(d)))},[k,we,L,Ae,j]);r.useEffect(()=>{pe&&L.connectionState==="connected"&&be(!1)},[L.connectionState,pe]),r.useEffect(()=>{if(!Fe)return;const b=d=>{d.key==="Escape"&&Be(!1)};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[Fe]);const Jn=!!A||!!(ne!=null&&ne.avatarImageUrl)||L.isControlled,rt=Ln(Qe,s,Jn);Xe===void 0&&((qt=rt.info)!=null&&qt.capabilities)&&(Et.current=rt.info.capabilities);const ht=(ne==null?void 0:ne.name)??P??((Ut=L.agentConfig)==null?void 0:Ut.name)??((Vt=rt.info)==null?void 0:Vt.name)??"Live Layer",jt=(ne==null?void 0:ne.avatarImageUrl)??A??((Yt=L.agentConfig)==null?void 0:Yt.avatarImageUrl)??((Gt=rt.info)==null?void 0:Gt.avatarImageUrl)??null,Xn=O??((Kt=L.agentConfig)==null?void 0:Kt.idleLoopUrl)??((Jt=rt.info)==null?void 0:Jt.idleLoopUrl)??null,Zn=x??null,Qn=r.useCallback(()=>fe("expanded"),[fe]),er=r.useCallback(()=>fe("minimized"),[fe]),Ft=r.useCallback(()=>{L.disconnect(),fe("hidden")},[L,fe]),tr=r.useCallback(()=>{const b=L.audioElement;b&&b.play().then(()=>tt(!1)).catch(()=>{})},[L.audioElement]),nr=r.useCallback(()=>{tt(!1),L.connect()},[L]),We={...Re,...ue?{}:{zIndex:$e}};H.primaryColor&&(We["--ll-color-primary"]=H.primaryColor),H.accentColor&&(We["--ll-color-accent"]=H.accentColor),H.backgroundColor&&(We["--ll-color-bg"]=H.backgroundColor),H.textColor&&(We["--ll-color-fg"]=H.textColor);const rr=["ll-widget",`ll-widget--${re}`,`ll-widget--${de?"mobile":"desktop"}`,xt].filter(Boolean).join(" ");if(!Ze)return null;const ir=t.jsx("div",{className:rr,style:We,"data-display-mode":re,"data-position":_,"data-experience-mode":h==="EMBEDDED"?"embedded":"widget",children:re==="expanded"&&t.jsx($r,{position:_,isMobile:de,agentName:ht,avatarImageUrl:jt,idleLoopUrl:Xn,greeting:Zn,branding:H,teamMembers:k,currentTeamMemberId:we,isSwitchingTeamMember:pe,teamSwitcherOpen:Fe,onToggleTeamSwitcher:()=>Be(b=>!b),onSelectTeamMember:Kn,connectionState:L.connectionState,agentState:L.agentState,transcript:L.transcript,isMuted:ie.isMuted,micDevices:et.mics,activeMicId:ie.activeDeviceId,isCameraEnabled:ae.isEnabled,cameraPreviewEl:ae.previewEl,cameraDevices:et.cameras,activeCameraId:ae.activeDeviceId,isScreenShareEnabled:_e.isEnabled,screenPreviewEl:_e.previewEl,isSpeakerMuted:y,allowCamera:Z,allowScreenShare:D,allowTyping:F,showMinimize:lt,showClose:ct,chromeless:ye,compactControls:Me,transforming:Te,transformingLabel:Y,languageMenuOpen:_t,onToggleLanguageMenu:()=>dt(b=>!b),needsUserGesture:ut,canResume:L.canResume,micError:ie.micError,error:L.error,avatarVideoContainerRef:Ht,agentVideoEl:L.videoElement,onConnect:()=>void L.connect(),onDisconnect:()=>L.disconnect(),onRetry:nr,onResumeAudio:tr,onToggleMute:ie.toggleMute,onSwitchMicDevice:b=>void ie.switchDevice(b),onToggleCamera:()=>void ae.toggle(),onSwitchCameraDevice:b=>void ae.switchDevice(b),onToggleScreenShare:()=>void _e.toggle(),onToggleSpeaker:Gn,onSendMessage:Yn,onMinimize:er,onClose:Ft,onClearMicError:ie.clearError})}),Bt=!ue&&(re==="hidden"||re==="minimized")?t.jsxs("div",{className:["ll-widget","ll-widget--floating",`ll-widget--${re}`,`ll-widget--${de?"mobile":"desktop"}`].join(" "),style:We,"data-display-mode":re,"data-position":_,children:[re==="hidden"&&t.jsx(Sr,{position:_,isMobile:de,isSpeaking:L.agentState==="speaking",onExpand:()=>fe("expanded"),label:`Open ${ht} widget`,avatarImageUrl:jt,agentName:ht,containerEl:se}),re==="minimized"&&t.jsx(jr,{position:_,isMobile:de,agentName:ht,avatarImageUrl:jt,agentState:L.agentState,isMuted:ie.isMuted,audioLevel:Ie,onExpand:Qn,onToggleMute:ie.toggleMute,onClose:Ft})]}):null,Wt=se??(typeof document<"u"?document.body:null);return t.jsxs(t.Fragment,{children:[ir,Bt&&Wt&&It.createPortal(Bt,Wt)]})});qn.displayName="AvatarWidgetInner";const Un=r.forwardRef(function(n,i){return t.jsx(vn,{children:t.jsx(qn,{...n,ref:i})})});Un.displayName="AvatarWidget";const ci=({agentId:e,baseUrl:n,apiKey:i,mode:o,onAgentEvent:l,className:s,style:c})=>{const a=r.useRef(null),u=r.useRef(null),h=r.useRef(l);h.current=l;const w=r.useCallback(g=>{var N;const p=g.detail;(N=h.current)==null||N.call(h,p)},[]);return r.useEffect(()=>{const g=a.current;if(!g)return;const p=document.createElement("livelayer-widget");return p.setAttribute("agent-id",e),n&&p.setAttribute("base-url",n),i&&p.setAttribute("api-key",i),o&&p.setAttribute("mode",o),p.addEventListener("agent-event",w),g.appendChild(p),u.current=p,()=>{p.removeEventListener("agent-event",w),g.removeChild(p),u.current=null}},[e]),r.useEffect(()=>{u.current&&(o?u.current.setAttribute("mode",o):u.current.removeAttribute("mode"))},[o]),t.jsx("div",{ref:a,className:s,style:c})},ui=r.forwardRef(function({id:n,intent:i,as:o="div",className:l,style:s,children:c},a){return r.createElement(o,{ref:a,"data-ll-region":n,"data-ll-intent":i,className:l,style:s},c)});function di(e={}){const{onFieldUpdate:n,onComplete:i,source:o="all"}=e,[l,s]=r.useState({}),[c,a]=r.useState(!1),[u,h]=r.useState(null),w=r.useRef(n),g=r.useRef(i),p=r.useRef(o);r.useEffect(()=>{w.current=n,g.current=i,p.current=o},[n,i,o]);const N=r.useCallback(()=>{s({}),a(!1)},[]);return r.useEffect(()=>{if(typeof window>"u")return;const _=v=>{var m,k;const f=v.detail;if(f){if(f.phase==="field"){if(p.current!=="all"&&f.source!==p.current)return;a(!0),s(E=>E[f.fieldName]===f.value?E:{...E,[f.fieldName]:f.value});try{(m=w.current)==null||m.call(w,f)}catch(E){console.warn("[LiveLayer] useCollect onFieldUpdate threw.",E)}return}if(f.phase==="complete"){const E=f.result;if(p.current!=="all"&&E.source!==p.current)return;h(E),a(!1);try{(k=g.current)==null||k.call(g,E)}catch(j){console.warn("[LiveLayer] useCollect onComplete threw.",j)}}}};return document.addEventListener("ll-collected",_),()=>document.removeEventListener("ll-collected",_)},[]),{fields:l,isCollecting:c,lastResult:u,reset:N}}let yn=1;function fi({onMount:e,defaultOpen:n=!1,storageKey:i="ll-debug-open"}){const[o,l]=r.useState(n),[s,c]=r.useState([]),[a,u]=r.useState(""),[h,w]=r.useState(!1),g=r.useRef(new Set),p=r.useRef([]),N=r.useRef(h);N.current=h,r.useEffect(()=>{try{const f=localStorage.getItem(i);f==="1"&&l(!0),f==="0"&&l(!1)}catch{}},[i]),r.useEffect(()=>{try{localStorage.setItem(i,o?"1":"0")}catch{}},[o,i]),r.useEffect(()=>{const f=m=>{(m.metaKey||m.ctrlKey)&&m.shiftKey&&m.key.toLowerCase()==="l"&&(m.preventDefault(),l(k=>!k))};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[]),r.useEffect(()=>{const f=setInterval(()=>{if(p.current.length===0||N.current)return;const m=p.current.splice(0,p.current.length);c(k=>[...m.reverse(),...k].slice(0,200))},100);return()=>clearInterval(f)},[]);const _=r.useRef(!1);if(r.useEffect(()=>{!e||_.current||(_.current=!0,e(f=>{p.current.push({id:yn++,ts:Date.now(),kind:"event",type:f.eventName,data:f.data})}))},[e]),r.useEffect(()=>{const f=console.warn,m=console.log,k=(E,j)=>function(...O){try{const x=typeof O[0]=="string"?O[0]:"";x.startsWith("[LiveLayer]")&&p.current.push({id:yn++,ts:Date.now(),kind:E,type:x.slice(0,120),data:{args:O.slice(1).map(A=>hi(A))}})}catch{}return j.apply(this,O)};return console.warn=k("warn",f),console.log=k("log",m),()=>{console.warn=f,console.log=m}},[]),!o)return t.jsx("button",{type:"button",onClick:()=>l(!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 v=s.filter(f=>{if(!a)return!0;const m=a.toLowerCase();return f.type.toLowerCase().includes(m)||JSON.stringify(f.data||{}).toLowerCase().includes(m)});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:[s.length," event",s.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>w(f=>!f),style:Nt(h?"#f59e0b":"transparent"),title:"Pause / resume capture",children:h?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{c([]),p.current=[]},style:Nt("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>l(!1),style:Nt("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:a,onChange:f=>u(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:v.length===0?t.jsxs("div",{style:{padding:14,fontSize:11,color:"rgba(255,255,255,0.4)",lineHeight:1.5},children:["No events yet. Connect to the agent and trigger a tool call — the events will stream in here. You can also dispatch commands manually in DevTools:",t.jsx("pre",{style:{marginTop:6,background:"rgba(255,255,255,0.04)",padding:6,borderRadius:4,fontSize:10,whiteSpace:"pre-wrap"},children:`window.__livelayerSimulateCommand({
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),r=require("react"),Mt=require("react-dom"),Ge=require("@livelayer/sdk"),yt=require("livekit-client");class bn extends r.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,i){var o,l;(l=(o=this.props).onError)==null||l.call(o,n,i)}render(){var n;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[t.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),t.jsx("p",{className:"ll-error-boundary__message",children:((n=this.state.error)==null?void 0:n.message)||"Something went wrong."}),t.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function xn(e){const[n,i]=r.useState("idle"),[o,l]=r.useState("idle"),[s,c]=r.useState([]),[a,u]=r.useState(null),[h,w]=r.useState(null),[g,p]=r.useState(null),[N,_]=r.useState(!1),[y,f]=r.useState(null),m=r.useRef(null),k=r.useRef(e.onDataMessage);k.current=e.onDataMessage,r.useEffect(()=>{const x={onConnectionStateChange:D=>{i(D),D==="connected"&&f(null)},onAgentStateChange:l,onTranscript:D=>c([...D]),onAgentConfig:u,onAudioTrack:D=>p(D),onVideoTrack:D=>w(D),onVideoTrackRemoved:()=>w(null),onError:D=>f(D),onDataMessage:D=>{var H;(H=k.current)==null||H.call(k,D)},onResumabilityChange:_},A=new Ge.LiveKitSession({agentId:e.agentId,baseUrl:e.baseUrl,apiKey:e.apiKey,sessionEndpoint:e.sessionEndpoint,sessionBody:e.sessionBody},x);return m.current=A,i("idle"),l("idle"),c([]),u(null),w(null),p(null),_(!1),f(null),()=>{var D;(D=A.destroy)==null||D.call(A),m.current=null}},[e.agentId,e.baseUrl,e.apiKey,e.sessionEndpoint,JSON.stringify(e.sessionBody??{})]);const E=r.useCallback(async()=>{const x=m.current;if(x)try{await x.connect()}catch(A){throw f(A instanceof Error?A.message:String(A)),A}},[]),j=r.useCallback(()=>{const x=m.current;x&&x.disconnect()},[]),O=r.useCallback(()=>{var x;return((x=m.current)==null?void 0:x.getRoom())??null},[]);return{connectionState:n,agentState:o,transcript:s,agentConfig:a,videoElement:h,audioElement:g,canResume:N,error:y,connect:E,disconnect:j,getRoom:O,session:m.current}}function wn(){const e=r.useRef(null),n=r.useRef(new Map),i=r.useRef(null),o=r.useRef(new Set),l=r.useCallback(()=>{const _=n.current;if(_.size===0){i.current=null;return}let y=0;for(const{analyser:f,buffer:m}of _.values()){f.getByteFrequencyData(m);let k=0;for(let j=0;j<m.length;j++)k+=m[j];const E=k/m.length/255;E>y&&(y=E)}for(const f of o.current)try{f(y)}catch(m){console.error("[useAudioLevel] subscriber threw:",m)}i.current=requestAnimationFrame(l)},[]),s=r.useCallback(()=>e.current?e.current:typeof window>"u"||typeof AudioContext>"u"?null:(e.current=new AudioContext,e.current),[]),c=r.useCallback(()=>{i.current===null&&n.current.size>0&&(i.current=requestAnimationFrame(l))},[l]),a=r.useCallback(_=>{const y=n.current.get(_);if(y){try{y.node.disconnect()}catch{}try{y.analyser.disconnect()}catch{}n.current.delete(_)}},[]),u=r.useCallback((_,y)=>{const f=s();if(!f)return;a(_);const m=y(f);if(!m)return;const k=f.createAnalyser();k.fftSize=64;try{m.connect(k)}catch(E){console.warn("[useAudioLevel] connect failed for slot",_,E);return}n.current.set(_,{analyser:k,node:m,buffer:new Uint8Array(new ArrayBuffer(k.frequencyBinCount))}),c()},[a,s,c]),h=r.useCallback((_,y="agent")=>{u(y,f=>{try{return f.createMediaElementSource(_)}catch(m){return console.warn("[useAudioLevel] createMediaElementSource failed for slot",y,m),null}})},[u]),w=r.useCallback((_,y="mic")=>{u(y,f=>{try{return f.createMediaStreamSource(_)}catch(m){return console.warn("[useAudioLevel] createMediaStreamSource failed for slot",y,m),null}})},[u]),g=r.useCallback(_=>{a(_),n.current.size===0&&i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[a]),p=r.useCallback(()=>{i.current!==null&&(cancelAnimationFrame(i.current),i.current=null);for(const _ of Array.from(n.current.keys()))a(_)},[a]),N=r.useCallback(_=>(o.current.add(_),()=>{o.current.delete(_)}),[]);return r.useEffect(()=>()=>{if(p(),e.current){try{e.current.close()}catch{}e.current=null}o.current.clear()},[p]),{attach:h,attachStream:w,detach:p,detachSlot:g,subscribe:N}}function cr(e){const n=e==null?void 0:e.mediaStreamTrack;return n?new MediaStream([n]):null}function _n(){const[e,n]=r.useState(!1),[i,o]=r.useState(""),[l,s]=r.useState(null),c=r.useRef(null),a=r.useRef(null),u=r.useCallback(async y=>{var f,m;if(c.current&&a.current){try{await a.current.localParticipant.unpublishTrack(c.current)}catch{}c.current.stop(),c.current=null}a.current=y,s(null);try{const k=await yt.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await y.localParticipant.publishTrack(k),c.current=k,n(k.isMuted);const E=(m=(f=k.mediaStreamTrack)==null?void 0:f.getSettings)==null?void 0:m.call(f);E!=null&&E.deviceId&&o(E.deviceId)}catch(k){const E=k instanceof Error&&k.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw s(E),k}},[]),h=r.useCallback(y=>{a.current=y},[]),w=r.useCallback(async y=>{const f=a.current;if(f)try{await f.switchActiveDevice("audioinput",y),o(y)}catch(m){console.warn("[useMicrophoneState] switchDevice failed:",m)}},[]),g=r.useCallback(async()=>{const y=a.current,f=!e;if(n(f),!!y)try{await y.localParticipant.setMicrophoneEnabled(!f)}catch(m){console.warn("[useMicrophoneState] setMicrophoneEnabled failed:",m),n(!f)}},[e]),p=r.useCallback(()=>{const y=c.current,f=a.current;if(y&&f){try{f.localParticipant.unpublishTrack(y)}catch{}y.stop()}c.current=null,a.current=null,n(!1),o("")},[]),N=r.useCallback(()=>s(null),[]),_=r.useCallback(()=>cr(c.current),[]);return{isMuted:e,activeDeviceId:i,micError:l,toggleMute:g,setupMic:u,attachRoom:h,switchDevice:w,teardownMic:p,clearError:N,getMicStream:_}}const ur={resolution:{width:640,height:480,frameRate:24}};function kn(){const[e,n]=r.useState(!1),[i,o]=r.useState(null),[l,s]=r.useState(null),[c,a]=r.useState(""),u=r.useRef(null),h=r.useRef(null),w=r.useCallback(m=>{u.current=m},[]),g=r.useCallback(()=>{var E;const m=u.current,k=h.current;if(k&&m){const j=m.localParticipant.getTrackPublication(yt.Track.Source.Camera),x=(j==null?void 0:j.track)??k;try{m.localParticipant.unpublishTrack(x)}catch{}try{(E=x.stop)==null||E.call(x)}catch{}}h.current=null,s(null),n(!1)},[]),p=r.useCallback(async m=>{const k=u.current;if(k){o(null);try{const E={...ur};m&&(E.deviceId=m);const j=await yt.createLocalVideoTrack(E);await k.localParticipant.publishTrack(j),h.current=j;const O=j.attach();s(O),n(!0),m&&a(m);try{k.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(E){const j=E instanceof Error&&E.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";o(j)}}},[]),N=r.useCallback(async()=>{e?g():await p(c||void 0)},[e,c,g,p]),_=r.useCallback(async m=>{g(),await p(m)},[g,p]),y=r.useCallback(()=>{g(),u.current=null,o(null),a("")},[g]),f=r.useCallback(()=>o(null),[]);return r.useEffect(()=>()=>{h.current&&h.current.stop()},[]),{isEnabled:e,error:i,previewEl:l,activeDeviceId:c,toggle:N,switchDevice:_,attachRoom:w,teardown:y,clearError:f}}function Cn(){const[e,n]=r.useState(!1),[i,o]=r.useState(null),[l,s]=r.useState(null),c=r.useRef(null),a=r.useCallback(p=>{c.current=p},[]),u=r.useCallback(()=>s(null),[]),h=r.useCallback(async()=>{const p=c.current;if(p){if(e){try{await p.localParticipant.setScreenShareEnabled(!1)}catch{}u(),n(!1);return}o(null);try{await p.localParticipant.setScreenShareEnabled(!0);let N=0;const _=()=>{const y=p.localParticipant.getTrackPublication(yt.Track.Source.ScreenShare);if(y!=null&&y.track){const f=y.track.attach();s(f),n(!0);try{p.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}N++<10?setTimeout(_,100):n(!0)};_()}catch(N){const _=N instanceof Error?N.name:"";_!=="NotAllowedError"&&_!=="AbortError"&&o("Screen share unavailable. Try again."),n(!1)}}},[e,u]),w=r.useCallback(()=>{const p=c.current;if(p&&e)try{p.localParticipant.setScreenShareEnabled(!1)}catch{}u(),n(!1),o(null),c.current=null},[e,u]),g=r.useCallback(()=>o(null),[]);return{isEnabled:e,error:i,previewEl:l,toggle:h,attachRoom:a,teardown:w,clearError:g}}function Ln(){const[e,n]=r.useState([]),[i,o]=r.useState([]),l=r.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const s=await navigator.mediaDevices.enumerateDevices();n(s.filter(c=>c.kind==="audioinput")),o(s.filter(c=>c.kind==="videoinput"))}catch{}},[]);return r.useEffect(()=>{if(l(),typeof navigator>"u"||!navigator.mediaDevices)return;const s=()=>void l();return navigator.mediaDevices.addEventListener("devicechange",s),()=>navigator.mediaDevices.removeEventListener("devicechange",s)},[l]),{mics:e,cameras:i,refresh:l}}function Sn(e,n,i=!1){const[o,l]=r.useState(null),[s,c]=r.useState(null),[a,u]=r.useState(!i&&!!e);return r.useEffect(()=>{if(i||!e){u(!1);return}const h=new AbortController,w=n||"https://app.livelayer.studio";return u(!0),c(null),fetch(`${w}/api/widget/agent/${encodeURIComponent(e)}`,{signal:h.signal}).then(async g=>{if(!g.ok){const p=await g.json().catch(()=>({}));throw new Error(p.error||`HTTP ${g.status}`)}return g.json()}).then(g=>{h.signal.aborted||(l(g),u(!1))}).catch(g=>{h.signal.aborted||(c(g instanceof Error?g.message:"Agent lookup failed"),u(!1))}),()=>h.abort()},[e,n,i]),{info:o,error:s,loading:a}}function dr(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function fr(e,n){if(!(typeof window>"u"))try{window.localStorage.setItem(e,n)}catch{}}function En({value:e,defaultValue:n="expanded",onChange:i}={}){const o=e!==void 0,[l,s]=r.useState(n),c=o?e:l,a=r.useCallback(u=>{u!==c&&(o||s(u),i==null||i(u))},[c,o,i]);return[c,a]}const pr=["hidden","minimized","expanded"];function hr(e){return e&&pr.includes(e)?e:null}function jn({value:e,defaultValue:n="expanded",onChange:i,persistKey:o="ll-widget",disablePersistence:l=!1}={}){const s=`${o}:display-mode`,c=r.useRef(!1),[a,u]=En({value:e,defaultValue:n,onChange:h=>{e===void 0&&!l&&fr(s,h),i==null||i(h)}});return r.useEffect(()=>{if(c.current||(c.current=!0,l||e!==void 0))return;const h=hr(dr(s));h&&h!==a&&u(h)},[]),[a,u]}const mr=640;function Nn(e=mr){const[n,i]=r.useState(!1);return r.useEffect(()=>{if(e===!1){i(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const o=`(max-width: ${e-1}px)`,l=window.matchMedia(o),s=()=>i(l.matches);return s(),typeof l.addEventListener=="function"?(l.addEventListener("change",s),()=>l.removeEventListener("change",s)):(l.addListener(s),()=>{l.removeListener(s)})},[e]),n}const Zt="__llHistoryPatched",vt="ll:pathname";function gr(){if(typeof window>"u"||window.history[Zt])return;const e=window.history.pushState,n=window.history.replaceState;window.history.pushState=function(...i){const o=e.apply(this,i);return window.dispatchEvent(new Event(vt)),o},window.history.replaceState=function(...i){const o=n.apply(this,i);return window.dispatchEvent(new Event(vt)),o},window.history[Zt]=!0}function Qt(){return typeof window>"u"?"/":window.location.pathname||"/"}function Rn(e){const[n,i]=r.useState(()=>e??Qt());return r.useEffect(()=>{if(e!==void 0)return;gr();const o=()=>i(Qt());return o(),window.addEventListener("popstate",o),window.addEventListener(vt,o),()=>{window.removeEventListener("popstate",o),window.removeEventListener(vt,o)}},[e]),e??n}const en=new Map,yr=/[\\^$+?.()|{}[\]]/g;function vr(e){return e.replace(yr,"\\$&")}function br(e){const n=en.get(e);if(n)return n;const i=e.length>1&&e.endsWith("/")?e.slice(0,-1):e,o="",l="",s=i.replace(/\*\*/g,o).replace(/\*/g,l),a=vr(s).replace(new RegExp(`\\/${o}`,"g"),"(?:\\/.*)?").replace(new RegExp(o,"g"),".*").replace(new RegExp(l,"g"),"[^/]+"),u=new RegExp(`^${a}\\/?$`);return en.set(e,u),u}function xr(e,n){const i=n.length>1&&n.endsWith("/")?n.slice(0,-1):n;return br(e).test(i)}function An(e,n){return typeof e=="function"?e(n):e instanceof RegExp?e.test(n):xr(e,n)}function tn(e,n){if(!e||e.length===0)return!1;for(const i of e)if(An(i,n))return!0;return!1}function In(e,n,i){return e===void 0?!0:tn(i,e)?!1:n&&n.length>0?tn(n,e):!0}function Mn(e,n,i){return r.useMemo(()=>In(e,n,i),[e,n,i])}function wr(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 _r(e){const n=r.useMemo(()=>wr(e.config),[e.config]),i=e.baseUrl.replace(/\/+$/,""),o=r.useRef(null),l=r.useCallback(u=>{try{new Audio(`${i}${u}`).play().catch(()=>{})}catch{}},[i]),s=r.useCallback(()=>{n.navigate&&l("/audio/page-change-sound.mp3")},[n.navigate,l]),c=r.useCallback(()=>{n.action&&l("/audio/confirmation-sound.mp3")},[n.action,l]),a=r.useCallback(u=>{if(!n.thinking){if(o.current){try{o.current.pause()}catch{}o.current=null}return}if(u){if(o.current)return;try{const h=new Audio(`${i}/audio/thinking-sound.mp3`);h.loop=!0,h.volume=.3,h.play().catch(()=>{o.current=null}),o.current=h}catch{}}else if(o.current){try{o.current.pause()}catch{}o.current=null}},[i,n.thinking]);return r.useEffect(()=>()=>{if(o.current){try{o.current.pause()}catch{}o.current=null}},[]),r.useMemo(()=>({playPageChange:s,playConfirmation:c,setThinking:a}),[s,c,a])}const nn=({muted:e=!1,className:n})=>e?t.jsxs("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"}),t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):t.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4M12 1a3 3 0 00-3 3v4a3 3 0 006 0V4a3 3 0 00-3-3z"})}),rn=({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"})}),kr=({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"})}),Cr={left:180,right:0,up:-90,down:90},on=({direction:e="right",className:n})=>t.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${Cr[e]}deg)`},"aria-hidden":"true",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function Lr(e){return e==="top-left"||e==="bottom-left"?"left":"right"}const Tn="ll-hidden-tab-center-y",Sr=5,sn=16;function Er(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(Tn);if(!e)return null;const n=Number.parseFloat(e);return Number.isFinite(n)?n:null}catch{return null}}function an(e){if(!(typeof window>"u"))try{window.localStorage.setItem(Tn,String(e))}catch{}}const jr=({position:e,isMobile:n,isSpeaking:i,onExpand:o,label:l="Open widget",avatarImageUrl:s,agentName:c,containerEl:a})=>{const u=Lr(e),h=u==="right"?"left":"right",w=n?80:72,g=!!s,p=!!a,[N,_]=r.useState(null),[y,f]=r.useState(!1),m=r.useRef(null),k=r.useRef(!1),E=r.useCallback($=>{if(typeof window>"u")return $;const F=w/2,S=sn+F,K=window.innerHeight-sn-F;return K<S?Math.max(S,$):Math.max(S,Math.min(K,$))},[w]);r.useEffect(()=>{if(p){_(null);return}const $=Er();_(E($??window.innerHeight/2));const F=()=>{_(S=>S===null?null:E(S))};return window.addEventListener("resize",F),()=>window.removeEventListener("resize",F)},[E,p]);const j=r.useCallback($=>{if(!p&&!($.pointerType==="mouse"&&$.button!==0)&&N!==null){try{$.currentTarget.setPointerCapture($.pointerId)}catch{}m.current={startClientY:$.clientY,startCenterY:N,moved:!1}}},[N,p]),O=r.useCallback($=>{const F=m.current;if(!F)return;const S=$.clientY-F.startClientY;!F.moved&&Math.abs(S)>Sr&&(F.moved=!0,f(!0)),F.moved&&_(E(F.startCenterY+S))},[E]),x=r.useCallback($=>{const F=m.current;if(F){try{$.currentTarget.releasePointerCapture($.pointerId)}catch{}m.current=null,F.moved&&(f(!1),k.current=!0,_(S=>(S!==null&&an(S),S)))}},[]),A=r.useCallback(()=>{if(k.current){k.current=!1;return}o()},[o]),D=r.useCallback($=>{if($.key==="ArrowUp"||$.key==="ArrowDown"){$.preventDefault();const F=$.key==="ArrowUp"?-8:8;_(S=>{if(S===null)return S;const K=E(S+F);return an(K),K})}},[E]),H=["ll-hidden",`ll-hidden--${u}`,n?"ll-hidden--mobile":"ll-hidden--desktop",i?"ll-hidden--speaking":null,y?"is-dragging":null,g?"ll-hidden--with-avatar":null,p?"ll-hidden--scoped":null].filter(Boolean).join(" "),Z=N===null?void 0:{top:`${N-w/2}px`,transform:"none"};return t.jsx("button",{type:"button",className:H,onPointerDown:j,onPointerMove:O,onPointerUp:x,onPointerCancel:x,onClick:A,onKeyDown:D,"aria-label":l,"data-position":e,style:Z,children:g?t.jsxs(t.Fragment,{children:[t.jsx(on,{direction:h,className:"ll-hidden__chevron ll-hidden__chevron--mini"}),t.jsx("img",{src:s,alt:c?`${c} avatar`:"Agent avatar",className:"ll-hidden__avatar",draggable:!1})]}):t.jsx(on,{direction:h,className:"ll-hidden__chevron"})})},Nr=({audioLevel:e,bars:n=20,maxHeight:i=20,minHeight:o=4,className:l,barClassName:s})=>{const c=r.useRef(null),a=r.useRef([]),u=r.useMemo(()=>{const w=(Math.sqrt(5)-1)/2;return Array.from({length:n},(g,p)=>.5+p*w%1*.5)},[n]);r.useEffect(()=>e.subscribe(g=>{for(let p=0;p<n;p++){const N=a.current[p];if(!N)continue;const _=Math.max(o,g*i*u[p]);N.style.height=`${_}px`}}),[e,n,i,o,u]);const h=["ll-waveform",l].filter(Boolean).join(" ");return t.jsx("div",{ref:c,className:h,"aria-hidden":"true",children:Array.from({length:n},(w,g)=>t.jsx("div",{ref:p=>{a.current[g]=p},className:["ll-waveform__bar",s].filter(Boolean).join(" "),style:{height:`${o}px`}},g))})},Rr=({position:e,isMobile:n,agentName:i,avatarImageUrl:o,agentState:l,isMuted:s,audioLevel:c,onExpand:a,onToggleMute:u,onClose:h})=>n?t.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${i} widget`,children:t.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:a,"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(Nr,{audioLevel:c,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:w=>{w.stopPropagation(),u()},onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.stopPropagation(),w.preventDefault(),u())},"aria-label":s?"Unmute microphone":"Mute microphone",children:t.jsx(nn,{muted:s,className:"ll-minimized__icon"})}),t.jsx(rn,{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:l==="speaking"?"Speaking":l==="thinking"?"Thinking":"Listening"})]}),t.jsxs("div",{className:"ll-minimized__controls",children:[t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:u,"aria-label":s?"Unmute microphone":"Mute microphone",children:t.jsx(nn,{muted:s,className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:a,"aria-label":`Expand ${i} widget`,children:t.jsx(rn,{className:"ll-minimized__icon"})}),t.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:h,"aria-label":"Close widget",children:t.jsx(kr,{className:"ll-minimized__icon"})})]})]})}),Ar=({src:e,alt:n,preCannedPlaying:i=!1,className:o,style:l})=>{const[s,c]=r.useState(!1),a=r.useRef(e);if(r.useEffect(()=>{a.current!==e&&(a.current=e,c(!1))},[e]),!e)return null;const u={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:i?"scale(1.02)":"scale(1)",opacity:s?1:0,...l};return t.jsx("img",{src:e,alt:n,className:o,style:u,loading:"eager",fetchPriority:"high",onLoad:()=>c(!0)})},Ir="#E06540";function Mr({size:e=14,className:n,fill:i=Ir}){return t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 52 52",fill:"none",className:n,"aria-hidden":!0,children:[t.jsx("path",{d:"M44.5714 26C44.5714 23.5612 44.0908 21.146 43.1575 18.8928C42.2242 16.6397 40.8565 14.5924 39.132 12.868C37.4076 11.1435 35.3603 9.77577 33.1072 8.84247C30.854 7.90917 28.4388 7.42857 26 7.42857C23.5612 7.42857 21.146 7.90916 18.8928 8.84247C16.6397 9.77577 14.5924 11.1435 12.868 12.868C11.1435 14.5924 9.77577 16.6397 8.84247 18.8928C7.90917 21.146 7.42857 23.5612 7.42857 26C7.42857 28.4388 7.90916 30.854 8.84247 33.1072C9.77577 35.3603 11.1435 37.4076 12.868 39.132C14.5924 40.8565 16.6397 42.2242 18.8928 43.1575C21.146 44.0908 23.5612 44.5714 26 44.5714H48.2857C50.3371 44.5714 52 46.2344 52 48.2857C52 50.3371 50.3371 52 48.2857 52H26C22.5857 52 19.2049 51.3275 16.0505 50.021C12.896 48.7144 10.0293 46.7993 7.61501 44.385C5.20069 41.9707 3.28564 39.104 1.97902 35.9495C0.67247 32.7951 -3.54212e-07 29.4143 0 26C-1.68163e-07 22.5857 0.672469 19.2049 1.97902 16.0505C3.28564 12.896 5.20069 10.0293 7.61501 7.61501C10.0293 5.20069 12.896 3.28564 16.0505 1.97902C19.2049 0.67247 22.5857 0 26 0C29.4143 1.86048e-07 32.7951 0.67247 35.9495 1.97902C39.104 3.28564 41.9707 5.20069 44.385 7.61501C46.7993 10.0293 48.7144 12.896 50.021 16.0505C51.3275 19.2049 52 22.5857 52 26C52 28.0513 50.3371 29.7143 48.2857 29.7143C46.2344 29.7143 44.5714 28.0513 44.5714 26Z",fill:i}),t.jsx("path",{d:"M28.9717 23.7714C28.9717 21.3098 30.9672 19.3143 33.4288 19.3143C35.8904 19.3143 37.886 21.3098 37.886 23.7714C37.886 26.233 35.8904 28.2286 33.4288 28.2286C30.9672 28.2286 28.9717 26.233 28.9717 23.7714Z",fill:i}),t.jsx("path",{d:"M18.5714 19.3143C16.1098 19.3143 14.1143 21.3098 14.1143 23.7714C14.1143 26.233 16.1098 28.2286 18.5714 28.2286C21.033 28.2286 23.0285 26.233 23.0285 23.7714C23.0285 21.3098 21.033 19.3143 18.5714 19.3143Z",fill:i})]})}const Tr=8,ln=8,Pr=({open:e,onClose:n,anchorRef:i,children:o})=>{const l=r.useRef(null),[s,c]=r.useState(null);return r.useLayoutEffect(()=>{if(!e){c(null);return}const a=i.current;if(!a)return;const u=()=>{const h=a.getBoundingClientRect(),w={top:h.top-Tr,left:h.left+h.width/2},g=ln+90,p=window.innerWidth-ln-90;w.left<g&&(w.left=g),w.left>p&&(w.left=p),c(w)};return u(),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[e,i]),r.useEffect(()=>{if(!e)return;const a=h=>{const w=h.target,g=l.current,p=i.current;g&&g.contains(w)||p&&p.contains(w)||n()},u=h=>{h.key==="Escape"&&(h.stopPropagation(),n())};return document.addEventListener("mousedown",a),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",a),document.removeEventListener("keydown",u)}},[e,n,i]),!e||s===null||typeof document>"u"?null:Mt.createPortal(t.jsx("div",{ref:l,className:"ll-overflow-popover",role:"menu",style:{position:"fixed",top:s.top,left:s.left,transform:"translate(-50%, -100%)"},children:o}),document.body)},Dr=({isMuted:e,onToggleMute:n,isCameraEnabled:i,onToggleCamera:o,allowCamera:l,isScreenShareEnabled:s,onToggleScreenShare:c,allowScreenShare:a,isSpeakerMuted:u,onToggleSpeaker:h,allowTyping:w,isTypingOpen:g,onToggleTyping:p,onDisconnect:N})=>{const[_,y]=r.useState(!1),f=r.useRef(null);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ll-toolbar ll-toolbar--compact","data-testid":"compact-toolbar",onClick:m=>m.stopPropagation(),children:[t.jsx("button",{type:"button",className:`ll-tool ${e?"is-muted":""}`,onClick:n,"aria-label":e?"Unmute microphone":"Mute microphone",children:t.jsx($n,{muted:e})}),t.jsx("button",{ref:f,type:"button",className:`ll-tool ${_?"is-on":""}`,onClick:()=>y(m=>!m),"aria-label":"More controls","aria-haspopup":"menu","aria-expanded":_,children:t.jsx($r,{})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:N,"aria-label":"End conversation",children:t.jsx(Hn,{})})]}),t.jsxs(Pr,{open:_,onClose:()=>y(!1),anchorRef:f,children:[l&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${i?"is-on":""}`,onClick:()=>{o(),y(!1)},children:[t.jsx(Dn,{}),t.jsx("span",{children:i?"Stop camera":"Start camera"})]}),a&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${s?"is-on":""}`,onClick:()=>{c(),y(!1)},children:[t.jsx(Pn,{}),t.jsx("span",{children:s?"Stop sharing":"Share screen"})]}),t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${u?"is-on":""}`,onClick:()=>{h(),y(!1)},children:[t.jsx(zn,{muted:u}),t.jsx("span",{children:u?"Unmute speaker":"Mute speaker"})]}),w&&t.jsxs("button",{type:"button",className:`ll-overflow-popover__item ${g?"is-on":""}`,onClick:()=>{p(),y(!1)},children:[t.jsx(zr,{}),t.jsx("span",{children:g?"Hide typing":"Type a message"})]}),t.jsxs("button",{type:"button",className:"ll-overflow-popover__item is-active",disabled:!0,"aria-current":"true",children:[t.jsx("span",{className:"ll-overflow-popover__lang-code",children:"EN"}),t.jsx("span",{children:"English"})]})]})]})};function $r(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:[t.jsx("circle",{cx:"6",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),t.jsx("circle",{cx:"18",cy:"12",r:"1.5"})]})}function zr(){return t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}const Hr=({position:e,isMobile:n,agentName:i,avatarImageUrl:o,idleLoopUrl:l,greeting:s,branding:c,teamMembers:a,currentTeamMemberId:u,isSwitchingTeamMember:h,teamSwitcherOpen:w,onToggleTeamSwitcher:g,onSelectTeamMember:p,languageMenuOpen:N,onToggleLanguageMenu:_,connectionState:y,agentState:f,transcript:m,canResume:k,needsUserGesture:E,error:j,isMuted:O,micError:x,micDevices:A,activeMicId:D,isCameraEnabled:H,cameraPreviewEl:Z,cameraDevices:$,activeCameraId:F,isScreenShareEnabled:S,screenPreviewEl:K,isSpeakerMuted:ye,allowCamera:le,allowScreenShare:Me,allowTyping:Te,showMinimize:Y=!0,showClose:Ce=!0,chromeless:ve=!1,compactControls:T=!1,transforming:ne,transformingLabel:W,avatarVideoContainerRef:ce,agentVideoEl:U,onConnect:Ke,onDisconnect:Je,onRetry:lt,onResumeAudio:Xe,onToggleMute:Le,onSwitchMicDevice:Pe,onToggleCamera:Se,onSwitchCameraDevice:De,onToggleScreenShare:Ee,onToggleSpeaker:je,onSendMessage:Ne,onMinimize:Re,onClose:I,onClearMicError:bt})=>{var Be;const Ae=((a==null?void 0:a.length)??0)>1,$e=y==="connecting"||y==="connected",ue=y==="connected",Ze=y==="idle"||y==="disconnected"||y==="error",[Ie,ze]=r.useState(!1);r.useEffect(()=>{if(!U){ze(!1);return}if(!U.paused&&U.readyState>=2){ze(!0);return}ze(!1);const v=()=>ze(!0);return U.addEventListener("playing",v),U.addEventListener("loadeddata",v),()=>{U.removeEventListener("playing",v),U.removeEventListener("loadeddata",v)}},[U]);const[xt,we]=r.useState(!1);r.useEffect(()=>{if(!ue){we(!1);return}if(Ie)return;const v=setTimeout(()=>we(!0),8e3);return()=>clearTimeout(v)},[ue,Ie]);const re=y==="connecting"||ue&&!!o&&!Ie&&!xt,Qe=r.useRef(null),se=r.useRef(null);r.useEffect(()=>{const v=Qe.current;v&&(v.innerHTML="",Z&&(Z.style.width="100%",Z.style.height="100%",Z.style.objectFit="cover",Z.style.transform="scaleX(-1)",v.appendChild(Z)))},[Z]),r.useEffect(()=>{const v=se.current;v&&(v.innerHTML="",K&&(K.style.width="100%",K.style.height="100%",K.style.objectFit="contain",v.appendChild(K)))},[K]);const[ae,He]=r.useState(!1),[Oe,ie]=r.useState(!1),de=r.useRef(null),ct=r.useRef(null);r.useEffect(()=>{if(!ae&&!Oe&&!N&&!w)return;const v=()=>{He(!1),ie(!1),N&&_(),w&&g()};return document.addEventListener("click",v),()=>document.removeEventListener("click",v)},[ae,Oe,N,w,_,g]);const[ut,wt]=r.useState(!1),_t=r.useCallback(()=>wt(v=>!v),[]),[fe,Q]=r.useState(""),be=r.useCallback(v=>{v.preventDefault();const G=fe.trim();G&&(Ne(G),Q(""))},[fe,Ne]),_e=c.productName||"Live Layer",et=!c.productName;let ke=null,pe=null;for(let v=m.length-1;v>=0;v--){const G=m[v];if(!ke&&G.role==="agent"?ke=G:!pe&&G.role==="user"&&(pe=G),ke&&pe)break}const Fe=ue?(ke==null?void 0:ke.text)||null:s||null,tt=ue&&(pe==null?void 0:pe.text)||null,nt=["ll-expanded",n?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return t.jsxs("div",{className:nt,"data-position":e,"data-state":ue?"connected":$e?"connecting":"idle",role:"dialog","aria-label":`${i} widget`,children:[t.jsxs("div",{className:"ll-expanded__bg",children:[o?t.jsx(Ar,{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:((Be=i==null?void 0:i.charAt(0))==null?void 0:Be.toUpperCase())||"A"})}),l&&!ue&&t.jsx("video",{className:"ll-expanded__bg-idle",src:l,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),t.jsx("div",{ref:ce,className:"ll-expanded__video"}),re&&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:h?"Switching...":"Connecting..."})]}),E&&ue&&t.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:Xe,children:[t.jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:t.jsx("path",{d:"M3 9v6h4l5 5V4L7 9H3zm13.54.12a5 5 0 0 1 0 5.76l-1.41-1.41a3 3 0 0 0 0-2.94L16.54 9.12z"})}),t.jsx("p",{className:"ll-expanded__overlay-text",children:"Tap to enable audio"})]}),ne&&t.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--transforming",role:"status","aria-live":"polite","aria-label":W,children:[t.jsx("div",{className:"ll-expanded__spinner"}),t.jsx("p",{className:"ll-expanded__overlay-text",children:W})]}),$e?t.jsxs(t.Fragment,{children:[!T&&t.jsxs("div",{className:"ll-expanded__topbar",children:[!ve&&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:v=>{Ae&&(v.stopPropagation(),g())},"aria-haspopup":Ae?"listbox":void 0,"aria-expanded":Ae?w:void 0,children:[t.jsx("span",{className:"ll-hpill__label",children:i}),Ae&&t.jsx(ht,{})]}),Ae&&w&&t.jsx("div",{className:"ll-hmenu",onClick:v=>v.stopPropagation(),role:"listbox",children:a==null?void 0:a.map(v=>t.jsxs("button",{type:"button",className:`ll-hmenu__item ${v.id===u?"is-active":""}`,onClick:()=>p(v.id),role:"option","aria-selected":v.id===u,children:[v.avatarImageUrl&&t.jsx("img",{src:v.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),t.jsx("span",{className:"ll-hmenu__name",children:v.name}),v.role&&t.jsx("span",{className:"ll-hmenu__role",children:v.role})]},v.id))})]}),t.jsxs("div",{className:"ll-expanded__pill-wrap",children:[t.jsxs("button",{type:"button",className:"ll-hpill ll-hpill--compact",onClick:v=>{v.stopPropagation(),_()},"aria-haspopup":"listbox","aria-expanded":N,"aria-label":"Language: English",title:"Language: English",children:[t.jsx("span",{className:"ll-hpill__label",children:"EN"}),t.jsx(ht,{})]}),N&&t.jsx("div",{className:"ll-hmenu",onClick:v=>v.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--${f}`,children:f})]}),t.jsxs("div",{className:"ll-expanded__header-actions",children:[Y!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn",onClick:Re,"aria-label":"Minimize widget",title:"Minimize",children:t.jsx(un,{})}),Ce!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:I,"aria-label":"End call",title:"End call",children:t.jsx(cn,{})})]})]}),T&&t.jsxs("div",{className:"ll-compact-status","data-state":f,children:[t.jsx("span",{className:"ll-compact-status__dot","aria-hidden":!0}),t.jsx("span",{className:"ll-compact-status__label",children:f})]})]}):t.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[!T&&(et?t.jsxs("a",{className:"ll-expanded__brand ll-expanded__brand--link",href:"https://livelayer.studio?utm_source=widget&utm_medium=brand-badge",target:"_blank",rel:"noopener noreferrer","aria-label":"Powered by LiveLayer — opens livelayer.studio in a new tab",title:"Powered by LiveLayer — visit livelayer.studio",children:[t.jsx(Mr,{size:14,className:"ll-expanded__brand-mark"}),t.jsx("span",{children:_e})]}):t.jsx("span",{className:"ll-expanded__brand",children:_e})),t.jsxs("div",{className:"ll-expanded__header-actions",children:[!T&&Y!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:Re,"aria-label":"Minimize widget",children:t.jsx(un,{})}),Ce!==!1&&t.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--danger",onClick:I,"aria-label":"Close widget",children:t.jsx(cn,{})})]})]}),Ze&&(()=>{const v=k?"Resume session":y==="disconnected"?"Reconnect to agent":"Start video call",G=!j;return t.jsxs(t.Fragment,{children:[G&&t.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:Ke,"aria-label":v,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&&t.jsx("span",{className:"ll-expanded__play-label",children:v})]}),!T&&t.jsxs("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:[s&&t.jsx("div",{className:"ll-expanded__transcript",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:s})}),t.jsx("button",{type:"button",className:"ll-expanded__cta",onClick:Ke,"aria-label":v,children:v})]})]})})(),t.jsxs("div",{className:`ll-expanded__pip ${$e&&(H||S)?"is-visible":""}`,children:[t.jsx("div",{ref:se,className:S?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),t.jsx("div",{ref:Qe,className:!S&&H?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),$e?t.jsxs("div",{className:"ll-expanded__bottom",children:[!T&&Fe&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--agent","data-role":"agent",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:Fe})}),!T&&tt&&t.jsx("div",{className:"ll-expanded__transcript ll-expanded__transcript--user","data-role":"user",children:t.jsx("p",{className:"ll-expanded__transcript-text",children:tt})}),!ve&&!T&&t.jsxs("div",{className:"ll-toolbar",onClick:v=>v.stopPropagation(),children:[Me&&t.jsx("button",{type:"button",className:`ll-tool ${S?"is-on":""}`,onClick:Ee,"aria-label":S?"Stop sharing screen":"Share screen",title:S?"Stop sharing":"Share screen",children:t.jsx(Pn,{})}),le&&t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${H?"is-on":""}`,onClick:Se,"aria-label":H?"Turn off camera":"Turn on camera",title:H?"Stop camera":"Start camera",children:t.jsx(Dn,{})}),t.jsx("button",{ref:ct,type:"button",className:`ll-tool ll-tool--right ${H?"is-on":""}`,onClick:v=>{v.stopPropagation(),ie(G=>!G),He(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":Oe,children:t.jsx(ht,{})}),Oe&&$.length>0&&t.jsx(dn,{label:"Camera",devices:$,activeId:F,anchorRef:ct,onPick:v=>{ie(!1),De(v)}})]}),t.jsxs("div",{className:"ll-tool-split",children:[t.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${O?"is-muted":""}`,onClick:Le,"aria-label":O?"Unmute microphone":"Mute microphone",title:O?"Unmute":"Mute",children:t.jsx($n,{muted:O})}),t.jsx("button",{ref:de,type:"button",className:`ll-tool ll-tool--right ${O?"is-muted":""}`,onClick:v=>{v.stopPropagation(),He(G=>!G),ie(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":ae,children:t.jsx(ht,{})}),ae&&A.length>0&&t.jsx(dn,{label:"Microphone",devices:A,activeId:D,anchorRef:de,onPick:v=>{He(!1),Pe(v)}})]}),t.jsx("button",{type:"button",className:`ll-tool ${ye?"is-muted":""}`,onClick:je,"aria-label":ye?"Unmute speaker":"Mute speaker",title:ye?"Unmute speaker":"Mute speaker",children:t.jsx(zn,{muted:ye})}),t.jsx("button",{type:"button",className:"ll-tool ll-tool--danger",onClick:Je,"aria-label":"End conversation",title:"End conversation",children:t.jsx(Hn,{})})]}),!ve&&T&&t.jsx(Dr,{isMuted:O,onToggleMute:Le,isCameraEnabled:H,onToggleCamera:Se,allowCamera:le,isScreenShareEnabled:S,onToggleScreenShare:Ee,allowScreenShare:Me,isSpeakerMuted:ye,onToggleSpeaker:je,allowTyping:Te,isTypingOpen:ut,onToggleTyping:_t,onDisconnect:Je}),!ve&&Te&&(T?ut:!0)&&t.jsxs("form",{className:"ll-message-input",onSubmit:be,children:[t.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:fe,onChange:v=>Q(v.target.value),"aria-label":"Message the agent"}),fe.trim()&&t.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:t.jsx(Or,{})})]})]}):null,(()=>{if(x&&y!=="error")return t.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[t.jsx("span",{children:x}),t.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:bt,"aria-label":"Dismiss",children:"×"})]});if(!j||y!=="error")return null;let v="Failed to connect",G="Try again";return j==="MIC_PERMISSION_DENIED"?v="Microphone blocked. Allow access to talk.":j==="MIC_NOT_FOUND"?v="No microphone found. Plug one in + retry.":j==="MIC_UNAVAILABLE"?v="Mic unavailable. Check other apps using it.":j==="AGENT_TIMEOUT"?v="Agent didn't pick up. Try again.":j==="CONNECT_FAILED"?v="Connection failed. Check your network.":j.length<80&&(v=j),t.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[t.jsx("span",{children:v}),t.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:lt,children:G})]})})()]})};function ht(){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 cn(){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 un(){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 Pn(){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 Dn(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M23 7l-7 5 7 5V7z"}),t.jsx("rect",{x:"1",y:"5",width:"15",height:"14",rx:"2"})]})}function $n({muted:e}){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),t.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),t.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),e&&t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function 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 Or(){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 Hn(){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 dn=({label:e,devices:n,activeId:i,onPick:o,anchorRef:l})=>{const[s,c]=r.useState(null);return r.useLayoutEffect(()=>{const a=()=>{const u=l.current;if(!u)return;const h=u.getBoundingClientRect(),w=126,g=window.innerWidth-16-110,p=h.left+h.width/2;c({top:h.top-8,left:Math.max(w,Math.min(g,p))})};return a(),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[l]),s===null||typeof document>"u"?null:Mt.createPortal(t.jsxs("div",{className:"ll-device-menu ll-device-menu--floating",onClick:a=>a.stopPropagation(),role:"listbox",style:{position:"fixed",top:s.top,left:s.left,transform:"translate(-50%, -100%)"},children:[t.jsx("p",{className:"ll-device-menu__label",children:e}),n.map((a,u)=>{const h=i===a.deviceId;return t.jsxs("button",{type:"button",className:`ll-device-menu__item ${h?"is-active":""}`,onClick:()=>o(a.deviceId),role:"option","aria-selected":h,children:[h&&t.jsx("span",{className:"ll-device-menu__dot",children:"●"}),t.jsx("span",{className:"ll-device-menu__name",children:a.label||`${e} ${u+1}`})]},a.deviceId||u)})]}),document.body)},Fr=["[data-ll-private]","[data-ll-skip]",".ll-widget"];function Tt(e){let n=e;for(;n;){for(const i of Fr)if(n.matches(i))return!0;n=n.parentElement}return!1}function At(e){if(Tt(e))return!1;if(e instanceof HTMLInputElement){if(e.type==="password")return!1;const n=(e.getAttribute("autocomplete")||"").toLowerCase();if(n==="off"||n.startsWith("cc-"))return!1}return!0}const mt=4096,Br=20,Wr=20,qr=10,Ur=10,Vr=30,Yr=20,fn=500,Gr=['[data-ll-private="true"]',".ll-widget","script","style","noscript","iframe"];function st(e){if(e.getAttribute("aria-hidden")==="true"||e.hasAttribute("hidden"))return!0;let n=e;for(;n;){for(const i of Gr)if(n.matches(i))return!0;n=n.parentElement}return!1}function at(e){if(typeof window>"u")return!0;const n=e.getBoundingClientRect();if(n.width<=0||n.height<=0)return!1;const i=window.innerHeight||document.documentElement.clientHeight,o=window.innerWidth||document.documentElement.clientWidth;return n.bottom>0&&n.right>0&&n.top<i&&n.left<o}function pn(e){const n=e.getAttribute("id");if(n){const s=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/"/g,'\\"'),c=document.querySelector(`label[for="${s}"]`);if(c!=null&&c.textContent)return c.textContent.trim()}const i=e.getAttribute("aria-label");if(i)return i.trim();const o=e.closest("label");if(o){const s=[];for(const a of Array.from(o.childNodes))if(a.nodeType===Node.TEXT_NODE){const u=(a.textContent||"").trim();u&&s.push(u)}else if(a instanceof HTMLElement){if(a instanceof HTMLInputElement||a instanceof HTMLTextAreaElement||a instanceof HTMLSelectElement||a instanceof HTMLButtonElement)continue;const u=(a.textContent||"").trim();u&&s.push(u)}const c=s.join(" ").trim();if(c)return c}const l=e.getAttribute("placeholder");return l?l.trim():""}function te(e,n){return e.length<=n?e:e.slice(0,n-1)+"…"}function Kr(e){return e&&e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function Jr(e){const n=e.getAttribute("aria-label");if(n)return n.trim().slice(0,80);const i=e.getAttribute("aria-labelledby");if(i){const s=document.getElementById(i);if(s!=null&&s.textContent)return s.textContent.trim().slice(0,80)}const o=e.querySelector('button[type="submit"], input[type="submit"], button:not([type])');if(o){const s=o instanceof HTMLInputElement?o.value:(o.textContent??"").trim();if(s&&s.length<60&&!/^(submit|ok|continue)$/i.test(s))return s}let l=e.parentElement;for(let s=0;l&&s<4;s++,l=l.parentElement){const c=l.querySelector("h1, h2, h3, h4");if(c!=null&&c.textContent){const a=c.textContent.trim();if(a&&a.length<80)return a}}return null}function Ue(e){return e.length}function On(e,n={}){const i=n.doc??(typeof document<"u"?document:null);if(!i)return{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:e};const o=typeof window<"u"&&window.location.href||"",l=typeof window<"u"&&window.location.pathname||"/",s=i.title||"",c=Array.from(i.querySelectorAll("[data-ll-region]")),a=[];for(const x of c){if(a.length>=qr)break;if(st(x)||!at(x))continue;const A=x.getAttribute("data-ll-region")??"",D=x.getAttribute("data-ll-intent")??void 0,H=te((x.innerText||x.textContent||"").trim(),fn*2);!A||!H||a.push({id:A,intent:D,text:H})}const u=[],h=["H1","H2","H3","H4","H5","H6"],w=Array.from(i.querySelectorAll("h1, h2, h3, h4, h5, h6"));for(const x of w){if(st(x)||!at(x))continue;const A=(x.textContent||"").trim();A&&u.push(`${x.tagName}: ${te(A,200)}`)}const g=Array.from(i.querySelectorAll("p, li"));for(const x of g){if(st(x)||!at(x)||h.includes(x.tagName))continue;const A=(x.textContent||"").trim();A.length>10&&u.push(te(A,fn))}const p=u.join(`
|
|
2
|
+
`),N=[],_=Array.from(i.querySelectorAll("a[href]"));for(const x of _){if(N.length>=Br)break;if(st(x)||!at(x))continue;const A=x.getAttribute("href")||"",D=(x.textContent||"").trim();!A||!D||N.push({href:A,text:te(D,100)})}const y=[],f=Array.from(i.querySelectorAll("input, textarea, select"));for(const x of f){if(y.length>=Wr)break;if(st(x)||!At(x)||!at(x))continue;const A=pn(x),D=x instanceof HTMLInputElement?x.type:x.tagName.toLowerCase();A&&y.push({label:te(A,100),type:D})}const m=Array.from(i.querySelectorAll("form")),k=[];let E=0;for(const x of m){if(k.length>=Ur)break;if(Tt(x)||x.matches(".ll-widget *, .ll-widget"))continue;const A=x.getAttribute("id")||x.getAttribute("name")||Kr(x.getAttribute("data-ll-intent"))||`form_${E++}`,D=x.getAttribute("data-ll-intent")||Jr(x)||void 0,H=Array.from(x.querySelectorAll("input, textarea, select")),Z=[];let $=0;const F=new Set;for(const S of H){if(Z.length>=Vr)break;if(!At(S))continue;if(S instanceof HTMLInputElement){const T=S.type;if(T==="submit"||T==="button"||T==="reset"||T==="hidden"||T==="image"||T==="file")continue}const K=S.getAttribute("name")||"",ye=S.getAttribute("id")||"";let le=K||ye||`field_${$}`;F.has(le)&&(le=`${le}__${$}`),F.add(le),$++;const Me=pn(S)||le,Te=S instanceof HTMLInputElement?S.type:S.tagName.toLowerCase(),Y={name:le,label:te(Me,100),type:Te};S.required===!0&&(Y.required=!0);const Ce=S.getAttribute("placeholder");if(Ce&&(Y.placeholder=te(Ce.trim(),100)),S instanceof HTMLInputElement||S instanceof HTMLTextAreaElement){const T=S.getAttribute("minlength");if(T!==null){const W=parseInt(T,10);!Number.isNaN(W)&&W>=0&&(Y.minLength=W)}const ne=S.getAttribute("maxlength");if(ne!==null){const W=parseInt(ne,10);!Number.isNaN(W)&&W>=0&&(Y.maxLength=W)}}if(S instanceof HTMLInputElement){const T=S.getAttribute("min");T!==null&&(Y.min=te(T,50));const ne=S.getAttribute("max");ne!==null&&(Y.max=te(ne,50));const W=S.getAttribute("step");W!==null&&(Y.step=te(W,20));const ce=S.getAttribute("pattern");ce!==null&&(Y.pattern=te(ce,200));const U=(S.getAttribute("autocomplete")||"").toLowerCase();U&&U!=="off"&&!U.startsWith("cc-")&&(Y.autocomplete=te(U,50))}if(S instanceof HTMLSelectElement){const T=[];for(let ne=0;ne<S.options.length&&!(T.length>=Yr);ne++){const W=S.options[ne];if(!W||W.disabled)continue;const ce=W.value||"",U=(W.textContent||"").trim()||ce;!ce&&!U||T.push({value:ce,label:te(U,60)})}T.length>0&&(Y.options=T)}const ve=typeof S.validationMessage=="string"?S.validationMessage:"";ve&&(Y.validationMessage=te(ve,200)),Z.push(Y)}k.push({id:A,intent:D,fields:Z})}const j={url:o,title:s,pathname:l,regions:a,visibleText:p,visibleLinks:N,visibleFields:y,forms:k,extras:e};let O=Ue(JSON.stringify(j.regions))+Ue(j.visibleText)+Ue(JSON.stringify(j.visibleLinks))+Ue(JSON.stringify(j.visibleFields));for(;O>mt&&j.visibleFields.length>0;)j.visibleFields.pop(),O=Ue(JSON.stringify(j.visibleFields));for(;O>mt&&j.visibleLinks.length>0;)j.visibleLinks.pop(),O-=80;return Ue(j.visibleText)>mt&&(j.visibleText=te(j.visibleText,mt-100)),j}let Ve=null;function It(e,n={}){const i=Date.now(),l=`${typeof window<"u"&&window.location.pathname||"/"}::${typeof window<"u"?window.scrollY:0}`;if(Ve&&Ve.key===l&&i-Ve.at<1e3)return Ve.ctx;const s=On(e,n);return Ve={key:l,at:i,ctx:s},s}function Fn(){Ve=null}const Xr=200;function Bn(e){const n=String(e.href||"");return{href:n,text:String(e.text??e.title??n),internal:e.internal??!0,title:e.title,description:e.description}}function Zr(e){return!(!e||e.startsWith("#")||e.startsWith("javascript:")||e.startsWith("mailto:")||e.startsWith("tel:"))}function Wn(e){const n=e??(typeof document<"u"?document:null);if(!n)return[];const i=typeof window<"u"&&window.location.origin||"",o=new Set,l=[],s=Array.from(n.querySelectorAll("a[href]"));for(const c of s){if(l.length>=Xr)break;if(Tt(c))continue;const a=c.getAttribute("href")||"";if(!Zr(a))continue;let u=a,h=!0;try{if(typeof window<"u"){const g=new URL(a,i);h=g.origin===i,h&&a.startsWith("http")&&(u=g.pathname+g.search+g.hash)}}catch{continue}if(o.has(u))continue;o.add(u);const w=(c.textContent||"").trim().slice(0,120);l.push({href:u,text:w,internal:h})}return l}let Ye=null;const Qr=5e3;function gt(){const e=Date.now(),n=typeof window<"u"&&window.location.pathname||"/";if(Ye&&Ye.pathname===n&&e-Ye.at<Qr)return Ye.routes;const i=Wn();return Ye={at:e,pathname:n,routes:i},i}function qn(){Ye=null}function hn(e){if(e instanceof HTMLInputElement){const n=e.type;if(n==="submit"||n==="button"||n==="reset"||n==="hidden"||n==="image"||n==="file")return!1}return!0}function ei(e,n){return e.getAttribute("name")||e.getAttribute("id")||`field_${n}`}function ti(e,n){if(!n)return null;try{const s=e.querySelector(`[name="${n.replace(/"/g,'\\"')}"]`);if(s&&hn(s))return s}catch{}const i=Array.from(e.querySelectorAll("input, textarea, select"));let o=0;const l=new Map;for(const s of i){if(!hn(s))continue;const c=ei(s,o);let a=c;if(l.has(c)&&(a=`${c}__${o}`),a===n)return s;l.set(c,s),o++}return null}function mn(e,n){const i=ti(e,n);return i?At(i)?{el:i}:{el:null,reason:"private"}:{el:null,reason:"not_found"}}function ni(e,n){const i=e instanceof HTMLInputElement?HTMLInputElement.prototype:e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLSelectElement.prototype,o=Object.getOwnPropertyDescriptor(i,"value"),l=o==null?void 0:o.set;l?l.call(e,n):e.value=n}function ri(e,n,i={}){const o=i.triggerInput??!0,l=i.triggerChange??!0;if(e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")){const s=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked"),c=s==null?void 0:s.set,a=n==="true"||n==="1"||n==="on";c?c.call(e,a):e.checked=a,o&&e.dispatchEvent(new Event("input",{bubbles:!0})),l&&e.dispatchEvent(new Event("change",{bubbles:!0}));return}ni(e,n),o&&e.dispatchEvent(new Event("input",{bubbles:!0})),l&&e.dispatchEvent(new Event("change",{bubbles:!0}))}function gn(e,n){if(!n)return null;const i=n.replace(/"/g,'\\"');try{const c=e.querySelector(`form#${CSS.escape(n)}`);if(c)return c}catch{}const o=e.querySelector(`form[name="${i}"]`);if(o)return o;const l=e.querySelector(`form[data-ll-intent="${i}"]`);if(l)return l;const s=Array.from(e.querySelectorAll("form"));for(const c of s){const a=c.getAttribute("data-ll-intent");if(a&&ii(a)===n)return c}if(/^form_\d+$/.test(n)){const c=parseInt(n.slice(5),10);let a=0;for(const u of s)if(!(u.id||u.getAttribute("name")||u.getAttribute("data-ll-intent"))){if(a===c)return u;a++}}return null}function ii(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||null}function oi(){if(typeof window>"u"||typeof document>"u")return!1;const e=document.scrollingElement||document.documentElement;if(!e||e.scrollHeight<=e.clientHeight+2)return!1;const n=window.getComputedStyle(e);return!(n.overflowY==="hidden"||n.overflowY==="clip")}function si(e){if(!(e instanceof HTMLElement))return!1;const i=window.getComputedStyle(e).overflowY;return!(i!=="auto"&&i!=="scroll"||e.scrollHeight<=e.clientHeight+2)}function ai(){if(typeof document>"u")return null;const e=Array.from(document.querySelectorAll("body, body *"));let n=null,i=0;for(const o of e){if(!si(o))continue;const l=o.getBoundingClientRect();if(l.bottom<=0||l.top>=window.innerHeight||l.right<=0||l.left>=window.innerWidth||l.width<=0||l.height<=0||o.closest(".ll-widget"))continue;const s=l.width*l.height;s>i&&(i=s,n=o)}return n}function li(){if(typeof window>"u")return null;if(oi())return window;const e=ai();return e||window}function yn(e){return e instanceof Window?e.innerHeight||0:e.clientHeight||0}function ci(e){var n,i;return e instanceof Window?typeof document>"u"?0:Math.max(((n=document.body)==null?void 0:n.scrollHeight)??0,((i=document.documentElement)==null?void 0:i.scrollHeight)??0):e.scrollHeight-e.clientHeight}const ui=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","task_field_updated","task_completed"]),Un=r.forwardRef(function(n,i){var Ut,Vt,Yt,Gt,Kt,Jt,Xt;const{agentId:o,apiKey:l,baseUrl:s="https://app.livelayer.studio",sessionEndpoint:c,sessionBody:a,soundEffects:u,experienceMode:h="WIDGET",autoConnect:w=!1,displayMode:g,defaultDisplayMode:p="expanded",onDisplayModeChange:N,position:_="bottom-right",mobileBreakpoint:y=640,persistKey:f="ll-widget",disablePersistence:m=!1,teamMembers:k,currentTeamMemberId:E,onTeamMemberChange:j,idleLoopUrl:O,greeting:x,avatarImageUrl:A,agentName:D,branding:H={},allowCamera:Z=!0,allowScreenShare:$=!0,allowTyping:F=!0,showMinimize:S,showClose:K,chromeless:ye=!1,floatingChromeContainer:le=null,compactControls:Me=!1,transforming:Te=!1,transformingLabel:Y="Transforming…",showOn:Ce,hideOn:ve,pathname:T,onNavigate:ne,onScrollToSelector:W,getPageContext:ce,pageContextExtras:U,getRoutes:Ke,onScrollPage:Je,onClick:lt,capabilities:Xe,onConnect:Le,onDisconnect:Pe,onTranscript:Se,onAgentState:De,onConnectionStateChange:Ee,onAgentEvent:je,onAgentCommand:Ne,onCollect:Re,controlledSession:I,className:bt,style:Ae,zIndex:$e=2147483647}=n,ue=Rn(T),Ze=Mn(ue,Ce,ve);r.useEffect(()=>{Fn(),qn()},[ue]);const Ie=E!==void 0,[ze,xt]=r.useState(()=>{var b;return E??((b=k==null?void 0:k[0])==null?void 0:b.id)}),we=Ie?E:ze,re=r.useMemo(()=>(k==null?void 0:k.find(b=>b.id===we))??null,[k,we]),Qe=(re==null?void 0:re.agentId)??o,se=h==="EMBEDDED",ae=Nn(y),[He,Oe]=jn({value:g,defaultValue:p,onChange:N,persistKey:f,disablePersistence:se||m}),ie=se?"expanded":He,de=se?()=>{}:Oe,ct=S??!se,ut=K??!se,wt=ye||!se&&ae,_t=Me||!se&&ae,fe=wn(),Q=_n(),be=kn(),_e=Cn(),et=Ln(),[ke,pe]=r.useState(!1),[Fe,tt]=r.useState(!1),[nt,Be]=r.useState(!1),[v,G]=r.useState(!1),[kt,Gn]=r.useState(!1),dt=_r({baseUrl:s,config:u}),ft=r.useRef(dt);ft.current=dt;const Ct=r.useRef(ne),Lt=r.useRef(W),St=r.useRef(Je),Et=r.useRef(lt),Pt=r.useRef(ce),Dt=r.useRef(U),$t=r.useRef(Ke),jt=r.useRef(Xe),he=r.useRef(null);Ct.current=ne,Lt.current=W,St.current=Je,Et.current=lt,Pt.current=ce,Dt.current=U,$t.current=Ke,jt.current=Xe;function me(b){const d=jt.current;return d?d.includes(b):!0}function ge(b,d){console.warn(`[LiveLayer] Agent command "${b}" blocked — capability "${d}" not in allowlist. See https://livelayer.studio/docs/react/capabilities`)}const rt=r.useCallback(b=>{var V,ee,xe,ot;const d=b;if(!(!d.type||typeof d.type!="string")){if(je==null||je({eventName:d.type,data:b}),d.type==="navigate"){if(!me("navigate")){ge("navigate","navigate");return}const C=typeof d.href=="string"?d.href:null;if(!C){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(ft.current.playPageChange(),Ct.current){try{Ct.current(C)}catch(R){console.warn(`[LiveLayer] onNavigate threw for "${C}". Falling back. Error:`,R)}return}if(typeof document<"u"){const R=document.querySelector(`a[href="${C.replace(/"/g,'\\"')}"]`);if(R){R.click();return}}if(typeof window<"u"&&typeof history<"u")try{history.pushState({},"",C),window.dispatchEvent(new PopStateEvent("popstate"))}catch(R){console.warn(`[LiveLayer] history.pushState fallback failed for "${C}". Pass an onNavigate prop to use your router directly. See https://livelayer.studio/docs/react/navigation`,R)}return}if(d.type==="scroll_to"){if(!me("scroll")){ge("scroll_to","scroll");return}const C=typeof d.selector=="string"?d.selector:null;if(!C)return;const R=d.behavior==="instant"?"instant":"smooth";if(Lt.current){try{Lt.current(C,R)}catch(z){console.warn("[LiveLayer] onScrollToSelector threw.",z)}return}if(typeof document<"u"){let z=null;try{z=document.querySelector(C)}catch{console.warn(`[LiveLayer] scroll_to: invalid selector "${C}".`);return}if(!z){console.warn(`[LiveLayer] scroll_to: no element matched "${C}". The user may be on a different page. See https://livelayer.studio/docs/errors/scroll-no-match`);return}z.scrollIntoView({behavior:R,block:"start"})}return}if(d.type==="request_page_context"){if(!me("read_page")){ge("request_page_context","read_page");return}const C=typeof d.requestId=="string"?d.requestId:void 0,R=(V=he.current)==null?void 0:V.call(he),z=q=>{const M=R,X=M==null?void 0:M.localParticipant;if(X!=null&&X.publishData)try{const oe=C?{...q,requestId:C}:q,qe=new TextEncoder().encode(JSON.stringify(oe));X.publishData(qe,{reliable:!0})}catch(oe){console.warn("[LiveLayer] publishData failed.",oe)}},P=Dt.current,B=Pt.current;try{if(B){const q=B(P);if(q instanceof Promise){z({type:"page_context_pending"}),q.then(M=>z({type:"page_context",context:M})).catch(M=>{console.warn("[LiveLayer] getPageContext rejected; falling back to default walker.",M),z({type:"page_context",context:It(P)})});return}z({type:"page_context",context:q});return}z({type:"page_context",context:It(P)})}catch(q){console.warn("[LiveLayer] page-context extraction threw. Sending empty context.",q),z({type:"page_context",context:{url:"",title:"",pathname:"/",regions:[],visibleText:"",visibleLinks:[],visibleFields:[],forms:[],extras:P}})}return}if(d.type==="scroll_page"){if(!me("scroll")){ge("scroll_page","scroll");return}const C=d.direction;if(C!=="up"&&C!=="down"&&C!=="top"&&C!=="bottom"){console.warn(`[LiveLayer] scroll_page: invalid direction "${String(C)}". Expected up | down | top | bottom.`);return}const R=d.behavior==="instant"?"instant":"smooth";if(St.current){try{St.current(C,R)}catch(M){console.warn("[LiveLayer] onScrollPage threw.",M)}return}if(typeof window>"u")return;const z={behavior:R},P=li(),B=M=>{P instanceof Window?P.scrollBy({top:M,...z}):P.scrollBy({top:M,...z})},q=M=>{P instanceof Window?P.scrollTo({top:M,...z}):P.scrollTo({top:M,...z})};C==="up"?B(-yn(P)):C==="down"?B(yn(P)):q(C==="top"?0:ci(P));return}if(d.type==="click"){if(!me("click")){ge("click","click");return}const C=typeof d.selector=="string"?d.selector:null;if(!C){console.warn("[LiveLayer] click: missing selector.");return}if(Et.current){try{Et.current(C)}catch(z){console.warn("[LiveLayer] onClick threw.",z)}return}if(typeof document>"u")return;let R=null;try{R=document.querySelector(C)}catch{console.warn(`[LiveLayer] click: invalid selector "${C}".`);return}if(!R){console.warn(`[LiveLayer] click: no element matched "${C}". See https://livelayer.studio/docs/errors/click-no-match`);return}if(R.closest('[data-ll-private="true"], .ll-widget')){console.warn("[LiveLayer] click: refusing to click element inside a private subtree.");return}(ee=R.click)==null||ee.call(R);return}if(d.type==="fill_form"||d.type==="focus_field"){if(!me("fill_forms")){ge(d.type,"fill_forms");return}if(typeof document>"u")return;d.type==="fill_form"&&ft.current.playConfirmation();const C=typeof d.formId=="string"?d.formId:null;if(!C){console.warn(`[LiveLayer] ${d.type}: missing formId.`);return}const R=gn(document,C);if(!R){console.warn(`[LiveLayer] ${d.type}: no <form> matched id="${C}" (or matching name / data-ll-intent slug). Forms are auto-discovered — make sure the form has an \`id\`, \`name\`, or \`data-ll-intent\` attribute the agent observed in PageContext.forms.`);return}if(R.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')){console.warn(`[LiveLayer] ${d.type}: refusing to touch a form in a private / opted-out subtree.`);return}if(d.type==="focus_field"){const P=typeof d.fieldName=="string"?d.fieldName:null;if(!P){console.warn("[LiveLayer] focus_field: missing fieldName.");return}const B=mn(R,P);if(B.el===null){B.reason==="private"?console.warn(`[LiveLayer] focus_field: field "${P}" is privacy-protected and not focusable.`):console.warn(`[LiveLayer] focus_field: no input matching key="${P}" in form "${C}". The agent should use the field.name it observed in PageContext.forms[].fields[].`);return}B.el.focus();return}const z=d.values&&typeof d.values=="object"?d.values:null;if(!z){console.warn("[LiveLayer] fill_form: missing or invalid values.");return}for(const[P,B]of Object.entries(z)){if(typeof B!="string")continue;const q=mn(R,P);if(q.el===null){q.reason==="private"?console.warn(`[LiveLayer] fill_form: field "${P}" is privacy-protected (password / cc-* / data-ll-private). Skipping.`):console.warn(`[LiveLayer] fill_form: no input matching key="${P}" in form "${C}". The agent should use the field.name it observed in PageContext.forms[].fields[]. Skipping.`);continue}try{ri(q.el,B)}catch(M){console.warn(`[LiveLayer] fill_form: failed to set "${P}".`,M)}}return}if(d.type==="submit_form"){if(!me("submit_forms")){ge("submit_form","submit_forms");return}if(typeof document>"u")return;const C=typeof d.formId=="string"?d.formId:null;if(!C){console.warn("[LiveLayer] submit_form: missing formId.");return}ft.current.playConfirmation();const R=gn(document,C);if(!R){console.warn(`[LiveLayer] submit_form: no <form> matched id="${C}" (or matching name / data-ll-intent slug).`);return}if(R.closest('[data-ll-private="true"], [data-ll-skip], .ll-widget')){console.warn("[LiveLayer] submit_form: refusing to submit a form in a private / opted-out subtree.");return}const z=typeof d.requestId=="string"?d.requestId:void 0,P=(xe=he.current)==null?void 0:xe.call(he),B=X=>{const oe=P,qe=oe==null?void 0:oe.localParticipant;if(qe!=null&&qe.publishData)try{const ar=z?{...X,requestId:z}:X,lr=new TextEncoder().encode(JSON.stringify(ar));qe.publishData(lr,{reliable:!0})}catch{}};let q=!1;const M=()=>{q=!0,B({type:"form_submitted",formId:C})};R.addEventListener("submit",M,{once:!0});try{typeof R.requestSubmit=="function"?R.requestSubmit():R.submit()}catch(X){console.warn("[LiveLayer] submit_form: requestSubmit threw.",X),R.removeEventListener("submit",M),B({type:"form_submit_blocked",formId:C,reason:"exception"});return}setTimeout(()=>{q||(R.removeEventListener("submit",M),B({type:"form_submit_blocked",formId:C,reason:"validation"}))},500);return}if(d.type==="request_routes"){if(!me("read_page")){ge("request_routes","read_page");return}const C=typeof d.requestId=="string"?d.requestId:void 0,z=(ot=he.current)==null?void 0:ot.call(he),P=z==null?void 0:z.localParticipant;if(!(P!=null&&P.publishData))return;const B=M=>{try{const X=C?{type:"routes",routes:M,requestId:C}:{type:"routes",routes:M},oe=new TextEncoder().encode(JSON.stringify(X));P.publishData(oe,{reliable:!0})}catch(X){console.warn("[LiveLayer] request_routes: publishData failed.",X)}},q=$t.current;if(q){try{const M=q(),X=oe=>{if(!Array.isArray(oe)){B([]);return}B(oe.map(Bn).slice(0,200))};M instanceof Promise?M.then(X).catch(oe=>{console.warn("[LiveLayer] getRoutes rejected; falling back to DOM walker.",oe),B(gt())}):X(M)}catch(M){console.warn("[LiveLayer] getRoutes threw; falling back to DOM walker.",M),B(gt())}return}try{B(gt())}catch(M){console.warn("[LiveLayer] request_routes: extractRoutes threw.",M)}return}if(d.type==="task_field_updated"){if(!me("collect_data")){ge("task_field_updated","collect_data");return}const C={phase:"field",fieldId:typeof d.fieldId=="string"?d.fieldId:"",fieldName:typeof d.fieldName=="string"?d.fieldName:typeof d.fieldId=="string"?d.fieldId:"",value:typeof d.value=="string"?d.value:"",kind:typeof d.kind=="string"?d.kind:"text",source:d.source==="slide"?"slide":d.source==="page"?"page":"agent",...typeof d.slideId=="string"?{slideId:d.slideId}:{},...typeof d.formId=="string"?{formId:d.formId}:{}};if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:C}))}catch{}return}if(d.type==="task_completed"){if(!me("collect_data")){ge("task_completed","collect_data");return}const C=d.result;if(!C||typeof C!="object"){console.warn("[LiveLayer] task_completed missing `result` payload.");return}if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("ll-collected",{detail:{phase:"complete",result:C}}))}catch{}try{Re==null||Re(C)}catch(R){console.warn("[LiveLayer] onCollect threw.",R)}return}ui.has(d.type)||Ne==null||Ne(d)}},[Ne,je,Re]),J=xn({agentId:I?"__controlled__":Qe,baseUrl:s,apiKey:l,sessionEndpoint:c,sessionBody:a,onDataMessage:I?void 0:rt});r.useEffect(()=>{if(I!=null&&I.subscribeToDataMessages)return I.subscribeToDataMessages(rt)},[I,rt]),he.current=()=>{var b;return(b=J.getRoom)==null?void 0:b.call(J)},r.useEffect(()=>{var V;if(typeof window>"u")return;const b=((V=window.location)==null?void 0:V.hostname)||"";if(b==="localhost"||b==="127.0.0.1"||b==="0.0.0.0"||b.endsWith(".local")||b.endsWith(".test"))return window.__livelayerSimulateCommand=ee=>{try{rt(ee)}catch(xe){console.warn("[LiveLayer] simulate-command threw:",xe)}},()=>{delete window.__livelayerSimulateCommand}},[rt]);const L=r.useMemo(()=>I?{connectionState:I.connectionState,agentState:I.agentState,transcript:I.transcript,videoElement:I.videoElement,audioElement:I.audioElement,canResume:I.canResume,error:I.error,agentConfig:null,connect:async()=>{await I.onConnect()},disconnect:()=>I.onDisconnect(),getRoom:J.getRoom,isControlled:!0}:{connectionState:J.connectionState,agentState:J.agentState,transcript:J.transcript,videoElement:J.videoElement,audioElement:J.audioElement,canResume:J.canResume,error:J.error,agentConfig:J.agentConfig,connect:J.connect,disconnect:J.disconnect,getRoom:J.getRoom,isControlled:!1},[I,J]),zt=r.useRef(L);zt.current=L;const Ht=r.useRef(I);Ht.current=I,r.useImperativeHandle(i,()=>({sendData:async b=>{var xe,ot;const d=Ht.current;if(d!=null&&d.publishData){try{await d.publishData(b)}catch(C){console.warn("[AvatarWidget] sendData (controlled) failed:",C)}return}const V=(ot=(xe=zt.current)==null?void 0:xe.getRoom)==null?void 0:ot.call(xe),ee=V==null?void 0:V.localParticipant;if(ee!=null&&ee.publishData)try{const C=new TextEncoder().encode(JSON.stringify(b));await ee.publishData(C,{reliable:!0})}catch(C){console.warn("[AvatarWidget] sendData failed:",C)}}}),[]);const Ot=r.useRef(null);r.useEffect(()=>{const b=L.videoElement,d=Ot.current;if(!(!b||!d))return d.appendChild(b),()=>{b.parentNode===d&&d.removeChild(b)}},[L.videoElement]),r.useEffect(()=>{const b=L.audioElement;if(!b)return;const d=document.createElement("div");d.className="ll-audio-sink",d.setAttribute("aria-hidden","true"),d.style.cssText="position:absolute;width:0;height:0;overflow:hidden;clip:rect(0 0 0 0);pointer-events:none;",d.appendChild(b),document.body.appendChild(d),fe.attach(b);const V=b.play();return V&&typeof V.catch=="function"&&V.catch(ee=>{(ee==null?void 0:ee.name)==="NotAllowedError"&&pe(!0)}),()=>{fe.detach(),b.parentNode===d&&d.removeChild(b),d.parentNode===document.body&&document.body.removeChild(d)}},[L.audioElement]),r.useEffect(()=>{if(L.isControlled||L.connectionState!=="connected")return;const b=L.getRoom();if(b)return Q.setupMic(b).then(()=>{const d=Q.getMicStream();d&&fe.attachStream(d,"mic")}).catch(()=>{}),()=>{fe.detachSlot("mic"),Q.teardownMic()}},[L.isControlled,L.connectionState]),r.useEffect(()=>{var d;if(L.connectionState!=="connected")return;const b=L.isControlled?(d=I==null?void 0:I.getRoom)==null?void 0:d.call(I):L.getRoom();if(b)return be.attachRoom(b),_e.attachRoom(b),L.isControlled&&Q.attachRoom(b),et.refresh(),()=>{be.teardown(),_e.teardown()}},[L.isControlled,L.connectionState,I]),r.useEffect(()=>{const b=L.audioElement;b&&(b.muted=kt)},[L.audioElement,kt]);const Kn=r.useCallback(b=>{const d={type:"user_message",text:b};if(I!=null&&I.publishData){try{I.publishData(d)}catch{}return}const V=L.getRoom();if(V)try{const ee=new TextEncoder().encode(JSON.stringify(d));V.localParticipant.publishData(ee,{reliable:!0})}catch{}},[L,I]),Jn=r.useCallback(()=>{Gn(b=>!b)},[]);r.useEffect(()=>{Ee==null||Ee(L.connectionState),L.connectionState==="connected"?Le==null||Le():L.connectionState==="disconnected"&&(Pe==null||Pe())},[L.connectionState,Le,Pe,Ee]),r.useEffect(()=>{Se==null||Se(L.transcript)},[L.transcript,Se]),r.useEffect(()=>{De==null||De(L.agentState)},[L.agentState,De]),r.useEffect(()=>{dt.setThinking(L.agentState==="thinking")},[L.agentState,dt]);const Ft=r.useRef(!1);r.useEffect(()=>{!w||Ft.current||Ze&&L.connectionState==="idle"&&(Ft.current=!0,L.connect())},[w,L.connectionState,L,Ze]);const Xn=r.useCallback(b=>{const d=k==null?void 0:k.find(V=>V.id===b);d&&(Be(!1),b!==we&&(tt(!0),L.disconnect(),Ie||xt(b),j==null||j(d)))},[k,we,L,Ie,j]);r.useEffect(()=>{Fe&&L.connectionState==="connected"&&tt(!1)},[L.connectionState,Fe]),r.useEffect(()=>{if(!nt)return;const b=d=>{d.key==="Escape"&&Be(!1)};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[nt]);const Zn=!!A||!!(re!=null&&re.avatarImageUrl)||L.isControlled,it=Sn(Qe,s,Zn);Xe===void 0&&((Ut=it.info)!=null&&Ut.capabilities)&&(jt.current=it.info.capabilities);const pt=(re==null?void 0:re.name)??D??((Vt=L.agentConfig)==null?void 0:Vt.name)??((Yt=it.info)==null?void 0:Yt.name)??"Live Layer",Nt=(re==null?void 0:re.avatarImageUrl)??A??((Gt=L.agentConfig)==null?void 0:Gt.avatarImageUrl)??((Kt=it.info)==null?void 0:Kt.avatarImageUrl)??null,Qn=O??((Jt=L.agentConfig)==null?void 0:Jt.idleLoopUrl)??((Xt=it.info)==null?void 0:Xt.idleLoopUrl)??null,er=x??null,tr=r.useCallback(()=>de("expanded"),[de]),nr=r.useCallback(()=>de("minimized"),[de]),Bt=r.useCallback(()=>{L.disconnect(),de("hidden")},[L,de]),rr=r.useCallback(()=>{const b=L.audioElement;b&&b.play().then(()=>pe(!1)).catch(()=>{})},[L.audioElement]),ir=r.useCallback(()=>{pe(!1),L.connect()},[L]),We={...Ae,...se?{}:{zIndex:$e}};H.primaryColor&&(We["--ll-color-primary"]=H.primaryColor),H.accentColor&&(We["--ll-color-accent"]=H.accentColor),H.backgroundColor&&(We["--ll-color-bg"]=H.backgroundColor),H.textColor&&(We["--ll-color-fg"]=H.textColor);const or=["ll-widget",`ll-widget--${ie}`,`ll-widget--${ae?"mobile":"desktop"}`,bt].filter(Boolean).join(" ");if(!Ze)return null;const sr=t.jsx("div",{className:or,style:We,"data-display-mode":ie,"data-position":_,"data-experience-mode":h==="EMBEDDED"?"embedded":"widget",children:ie==="expanded"&&t.jsx(Hr,{position:_,isMobile:ae,agentName:pt,avatarImageUrl:Nt,idleLoopUrl:Qn,greeting:er,branding:H,teamMembers:k,currentTeamMemberId:we,isSwitchingTeamMember:Fe,teamSwitcherOpen:nt,onToggleTeamSwitcher:()=>Be(b=>!b),onSelectTeamMember:Xn,connectionState:L.connectionState,agentState:L.agentState,transcript:L.transcript,isMuted:Q.isMuted,micDevices:et.mics,activeMicId:Q.activeDeviceId,isCameraEnabled:be.isEnabled,cameraPreviewEl:be.previewEl,cameraDevices:et.cameras,activeCameraId:be.activeDeviceId,isScreenShareEnabled:_e.isEnabled,screenPreviewEl:_e.previewEl,isSpeakerMuted:kt,allowCamera:Z,allowScreenShare:$,allowTyping:F,showMinimize:ae&&!se?!1:ct,showClose:ut,chromeless:wt,compactControls:_t,transforming:Te,transformingLabel:Y,languageMenuOpen:v,onToggleLanguageMenu:()=>G(b=>!b),needsUserGesture:ke,canResume:L.canResume,micError:Q.micError,error:L.error,avatarVideoContainerRef:Ot,agentVideoEl:L.videoElement,onConnect:()=>void L.connect(),onDisconnect:()=>L.disconnect(),onRetry:ir,onResumeAudio:rr,onToggleMute:Q.toggleMute,onSwitchMicDevice:b=>void Q.switchDevice(b),onToggleCamera:()=>void be.toggle(),onSwitchCameraDevice:b=>void be.switchDevice(b),onToggleScreenShare:()=>void _e.toggle(),onToggleSpeaker:Jn,onSendMessage:Kn,onMinimize:nr,onClose:Bt,onClearMicError:Q.clearError})}),Wt=!se&&(ie==="hidden"||ie==="minimized")?t.jsxs("div",{className:["ll-widget","ll-widget--floating",`ll-widget--${ie}`,`ll-widget--${ae?"mobile":"desktop"}`].join(" "),style:We,"data-display-mode":ie,"data-position":_,children:[ie==="hidden"&&t.jsx(jr,{position:_,isMobile:ae,isSpeaking:L.agentState==="speaking",onExpand:()=>de("expanded"),label:`Open ${pt} widget`,avatarImageUrl:Nt,agentName:pt,containerEl:le}),ie==="minimized"&&t.jsx(Rr,{position:_,isMobile:ae,agentName:pt,avatarImageUrl:Nt,agentState:L.agentState,isMuted:Q.isMuted,audioLevel:fe,onExpand:tr,onToggleMute:Q.toggleMute,onClose:Bt})]}):null,qt=le??(typeof document<"u"?document.body:null);return t.jsxs(t.Fragment,{children:[sr,Wt&&qt&&Mt.createPortal(Wt,qt)]})});Un.displayName="AvatarWidgetInner";const Vn=r.forwardRef(function(n,i){return t.jsx(bn,{children:t.jsx(Un,{...n,ref:i})})});Vn.displayName="AvatarWidget";const di=({agentId:e,baseUrl:n,apiKey:i,mode:o,onAgentEvent:l,className:s,style:c})=>{const a=r.useRef(null),u=r.useRef(null),h=r.useRef(l);h.current=l;const w=r.useCallback(g=>{var N;const p=g.detail;(N=h.current)==null||N.call(h,p)},[]);return r.useEffect(()=>{const g=a.current;if(!g)return;const p=document.createElement("livelayer-widget");return p.setAttribute("agent-id",e),n&&p.setAttribute("base-url",n),i&&p.setAttribute("api-key",i),o&&p.setAttribute("mode",o),p.addEventListener("agent-event",w),g.appendChild(p),u.current=p,()=>{p.removeEventListener("agent-event",w),g.removeChild(p),u.current=null}},[e]),r.useEffect(()=>{u.current&&(o?u.current.setAttribute("mode",o):u.current.removeAttribute("mode"))},[o]),t.jsx("div",{ref:a,className:s,style:c})},fi=r.forwardRef(function({id:n,intent:i,as:o="div",className:l,style:s,children:c},a){return r.createElement(o,{ref:a,"data-ll-region":n,"data-ll-intent":i,className:l,style:s},c)});function pi(e={}){const{onFieldUpdate:n,onComplete:i,source:o="all"}=e,[l,s]=r.useState({}),[c,a]=r.useState(!1),[u,h]=r.useState(null),w=r.useRef(n),g=r.useRef(i),p=r.useRef(o);r.useEffect(()=>{w.current=n,g.current=i,p.current=o},[n,i,o]);const N=r.useCallback(()=>{s({}),a(!1)},[]);return r.useEffect(()=>{if(typeof window>"u")return;const _=y=>{var m,k;const f=y.detail;if(f){if(f.phase==="field"){if(p.current!=="all"&&f.source!==p.current)return;a(!0),s(E=>E[f.fieldName]===f.value?E:{...E,[f.fieldName]:f.value});try{(m=w.current)==null||m.call(w,f)}catch(E){console.warn("[LiveLayer] useCollect onFieldUpdate threw.",E)}return}if(f.phase==="complete"){const E=f.result;if(p.current!=="all"&&E.source!==p.current)return;h(E),a(!1);try{(k=g.current)==null||k.call(g,E)}catch(j){console.warn("[LiveLayer] useCollect onComplete threw.",j)}}}};return document.addEventListener("ll-collected",_),()=>document.removeEventListener("ll-collected",_)},[]),{fields:l,isCollecting:c,lastResult:u,reset:N}}let vn=1;function hi({onMount:e,defaultOpen:n=!1,storageKey:i="ll-debug-open"}){const[o,l]=r.useState(n),[s,c]=r.useState([]),[a,u]=r.useState(""),[h,w]=r.useState(!1),g=r.useRef(new Set),p=r.useRef([]),N=r.useRef(h);N.current=h,r.useEffect(()=>{try{const f=localStorage.getItem(i);f==="1"&&l(!0),f==="0"&&l(!1)}catch{}},[i]),r.useEffect(()=>{try{localStorage.setItem(i,o?"1":"0")}catch{}},[o,i]),r.useEffect(()=>{const f=m=>{(m.metaKey||m.ctrlKey)&&m.shiftKey&&m.key.toLowerCase()==="l"&&(m.preventDefault(),l(k=>!k))};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[]),r.useEffect(()=>{const f=setInterval(()=>{if(p.current.length===0||N.current)return;const m=p.current.splice(0,p.current.length);c(k=>[...m.reverse(),...k].slice(0,200))},100);return()=>clearInterval(f)},[]);const _=r.useRef(!1);if(r.useEffect(()=>{!e||_.current||(_.current=!0,e(f=>{p.current.push({id:vn++,ts:Date.now(),kind:"event",type:f.eventName,data:f.data})}))},[e]),r.useEffect(()=>{const f=console.warn,m=console.log,k=(E,j)=>function(...O){try{const x=typeof O[0]=="string"?O[0]:"";x.startsWith("[LiveLayer]")&&p.current.push({id:vn++,ts:Date.now(),kind:E,type:x.slice(0,120),data:{args:O.slice(1).map(A=>gi(A))}})}catch{}return j.apply(this,O)};return console.warn=k("warn",f),console.log=k("log",m),()=>{console.warn=f,console.log=m}},[]),!o)return t.jsx("button",{type:"button",onClick:()=>l(!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 y=s.filter(f=>{if(!a)return!0;const m=a.toLowerCase();return f.type.toLowerCase().includes(m)||JSON.stringify(f.data||{}).toLowerCase().includes(m)});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:[s.length," event",s.length===1?"":"s"]}),t.jsx("span",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:()=>w(f=>!f),style:Rt(h?"#f59e0b":"transparent"),title:"Pause / resume capture",children:h?"▶ resume":"⏸ pause"}),t.jsx("button",{type:"button",onClick:()=>{c([]),p.current=[]},style:Rt("transparent"),title:"Clear buffer",children:"clear"}),t.jsx("button",{type:"button",onClick:()=>l(!1),style:Rt("transparent"),"aria-label":"Close",title:"Close (Cmd/Ctrl + Shift + L)",children:"✕"})]}),t.jsx("input",{type:"text",value:a,onChange:f=>u(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:y.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
|
+
})`})]}):y.map(f=>t.jsx(mi,{entry:f,expanded:g.current.has(f.id),onToggle:()=>{g.current.has(f.id)?g.current.delete(f.id):g.current.add(f.id),c(m=>[...m])}},f.id))})]})}function mi({entry:e,expanded:n,onToggle:i}){const o=e.kind==="warn"?"#f59e0b":e.type.startsWith("[LiveLayer]")?"#94a3b8":e.type==="navigate"||e.type==="scroll_page"||e.type==="scroll_to"||e.type==="click"?"#22c55e":e.type==="fill_form"||e.type==="submit_form"||e.type==="focus_field"?"#a78bfa":e.type==="request_page_context"||e.type==="request_routes"?"#38bdf8":e.type==="agent_state"?"#facc15":"#cbd5e1",l=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:l}),t.jsx("span",{style:{color:o,fontWeight:600,flexShrink:0},children:e.type.length>50?e.type.slice(0,50)+"…":e.type})]}),n&&e.data&&t.jsx("pre",{style:{marginTop:6,padding:6,background:"rgba(255,255,255,0.04)",borderRadius:4,fontSize:10,overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(e.data,null,2)})]})}function Rt(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 gi(e){try{return e instanceof Error?{message:e.message,stack:e.stack}:(JSON.stringify(e),e)}catch{return String(e)}}function Yn(e){const n=JSON.stringify(e);r.useEffect(()=>Ge.registerFields(e),[n])}function yi({fields:e,children:n}){return Yn(e),t.jsx(t.Fragment,{children:n})}function vi(){const[e,n]=r.useState([]),i=r.useCallback(l=>{n(s=>{const c=s.findIndex(a=>a.id===l.id);if(c>=0){const a=s.slice();return a[c]=l,a}return[...s,l]})},[]),o=r.useCallback(()=>n([]),[]);return{entries:e,pushSegment:i,clear:o,latest:e.length>0?e[e.length-1]:null}}Object.defineProperty(exports,"clearFieldRegistry",{enumerable:!0,get:()=>Ge.clearFieldRegistry});Object.defineProperty(exports,"getRegisteredFields",{enumerable:!0,get:()=>Ge.getRegisteredFields});Object.defineProperty(exports,"registerFields",{enumerable:!0,get:()=>Ge.registerFields});Object.defineProperty(exports,"setFieldValue",{enumerable:!0,get:()=>Ge.setFieldValue});exports.AvatarWidget=Vn;exports.ErrorBoundary=bn;exports.FieldProvider=yi;exports.LiveLayerDebugPanel=hi;exports.LiveLayerRegion=fi;exports.LiveLayerWidget=di;exports.clearPageContextCache=Fn;exports.clearRoutesCache=qn;exports.extractPageContext=On;exports.extractRoutes=Wn;exports.getCachedPageContext=It;exports.getCachedRoutes=gt;exports.matchesPattern=An;exports.normalizeRouteInput=Bn;exports.shouldRenderAtPath=In;exports.useAgentInfo=Sn;exports.useAudioLevel=wn;exports.useCameraState=kn;exports.useCollect=pi;exports.useDisplayMode=En;exports.useDisplayModePersistence=jn;exports.useIsMobile=Nn;exports.useLiveKitSession=xn;exports.useMediaDevices=Ln;exports.useMicrophoneState=_n;exports.usePathname=Rn;exports.useRegisterFields=Yn;exports.useRouteMatch=Mn;exports.useScreenShareState=Cn;exports.useTranscript=vi;
|