@livelayer/react 0.2.0 → 0.2.1
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.d.ts +57 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1336 -823
- package/dist/styles.css +671 -261
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,19 @@ export declare interface AgentEventDetail {
|
|
|
31
31
|
data: Record<string, unknown>;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
export declare interface AgentInfo {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
avatarImageUrl: string;
|
|
38
|
+
idleLoopUrl: string | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export declare interface AgentInfoHandle {
|
|
42
|
+
info: AgentInfo | null;
|
|
43
|
+
error: string | null;
|
|
44
|
+
loading: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
34
47
|
export { AgentState }
|
|
35
48
|
|
|
36
49
|
export declare interface AudioLevelHandle {
|
|
@@ -106,6 +119,24 @@ export declare interface BrandingConfig {
|
|
|
106
119
|
textColor?: string;
|
|
107
120
|
}
|
|
108
121
|
|
|
122
|
+
export declare interface CameraStateHandle {
|
|
123
|
+
isEnabled: boolean;
|
|
124
|
+
/** Human-readable error if getUserMedia was denied, else null. */
|
|
125
|
+
error: string | null;
|
|
126
|
+
/** The <video> element displaying the local camera preview (or null). */
|
|
127
|
+
previewEl: HTMLVideoElement | null;
|
|
128
|
+
/** The active device id, or "" if using default. */
|
|
129
|
+
activeDeviceId: string;
|
|
130
|
+
toggle: () => Promise<void>;
|
|
131
|
+
/** Switch to a different camera device (keeps camera enabled). */
|
|
132
|
+
switchDevice: (deviceId: string) => Promise<void>;
|
|
133
|
+
/** Attach the Room once it's connected. */
|
|
134
|
+
attachRoom: (room: Room) => void;
|
|
135
|
+
/** Unpublish, stop the track, and clear state. */
|
|
136
|
+
teardown: () => void;
|
|
137
|
+
clearError: () => void;
|
|
138
|
+
}
|
|
139
|
+
|
|
109
140
|
export { ConnectionState }
|
|
110
141
|
|
|
111
142
|
/**
|
|
@@ -189,6 +220,12 @@ export declare interface LiveLayerWidgetProps {
|
|
|
189
220
|
style?: React.CSSProperties;
|
|
190
221
|
}
|
|
191
222
|
|
|
223
|
+
export declare interface MediaDevicesHandle {
|
|
224
|
+
mics: MediaDeviceInfo[];
|
|
225
|
+
cameras: MediaDeviceInfo[];
|
|
226
|
+
refresh: () => Promise<void>;
|
|
227
|
+
}
|
|
228
|
+
|
|
192
229
|
export declare interface MicrophoneStateHandle {
|
|
193
230
|
isMuted: boolean;
|
|
194
231
|
/** Human-readable error when mic publish failed, else null. */
|
|
@@ -228,6 +265,16 @@ declare interface Props {
|
|
|
228
265
|
fallback?: ReactNode;
|
|
229
266
|
}
|
|
230
267
|
|
|
268
|
+
export declare interface ScreenShareStateHandle {
|
|
269
|
+
isEnabled: boolean;
|
|
270
|
+
error: string | null;
|
|
271
|
+
previewEl: HTMLVideoElement | null;
|
|
272
|
+
toggle: () => Promise<void>;
|
|
273
|
+
attachRoom: (room: Room) => void;
|
|
274
|
+
teardown: () => void;
|
|
275
|
+
clearError: () => void;
|
|
276
|
+
}
|
|
277
|
+
|
|
231
278
|
declare interface State {
|
|
232
279
|
hasError: boolean;
|
|
233
280
|
error: Error | null;
|
|
@@ -266,8 +313,14 @@ export declare interface TranscriptHandle {
|
|
|
266
313
|
latest: TranscriptEntry_2 | null;
|
|
267
314
|
}
|
|
268
315
|
|
|
316
|
+
export declare function useAgentInfo(agentId: string, baseUrl: string | undefined,
|
|
317
|
+
/** Skip the fetch (e.g. when consumer has passed avatarImageUrl as a prop). */
|
|
318
|
+
skip?: boolean): AgentInfoHandle;
|
|
319
|
+
|
|
269
320
|
export declare function useAudioLevel(): AudioLevelHandle;
|
|
270
321
|
|
|
322
|
+
export declare function useCameraState(): CameraStateHandle;
|
|
323
|
+
|
|
271
324
|
export declare function useDisplayMode({ value, defaultValue, onChange, }?: Options): [DisplayMode_2, (next: DisplayMode_2) => void];
|
|
272
325
|
|
|
273
326
|
export declare function useDisplayModePersistence({ value, defaultValue, onChange, persistKey, disablePersistence, }?: Options_2): [DisplayMode_2, (next: DisplayMode_2) => void];
|
|
@@ -306,8 +359,12 @@ export declare interface UseLiveKitSessionResult {
|
|
|
306
359
|
session: LiveKitSession | null;
|
|
307
360
|
}
|
|
308
361
|
|
|
362
|
+
export declare function useMediaDevices(): MediaDevicesHandle;
|
|
363
|
+
|
|
309
364
|
export declare function useMicrophoneState(): MicrophoneStateHandle;
|
|
310
365
|
|
|
366
|
+
export declare function useScreenShareState(): ScreenShareStateHandle;
|
|
367
|
+
|
|
311
368
|
export declare function useTranscript(): TranscriptHandle;
|
|
312
369
|
|
|
313
370
|
export declare type WidgetPosition = "top-left" | "top-right" | "bottom-left" | "bottom-right" | "custom";
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),ze=require("@livelayer/sdk"),Ae=require("livekit-client");class pe extends t.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,l){var a,s;(s=(a=this.props).onError)==null||s.call(a,r,l)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback:e.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[e.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),e.jsx("p",{className:"ll-error-boundary__message",children:((r=this.state.error)==null?void 0:r.message)||"Something went wrong."}),e.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function fe(n){const[r,l]=t.useState("idle"),[a,s]=t.useState("idle"),[i,p]=t.useState([]),[m,f]=t.useState(null),[_,u]=t.useState(null),[c,o]=t.useState(null),[x,v]=t.useState(!1),[C,N]=t.useState(null),S=t.useRef(null),M=t.useRef(n.onDataMessage);M.current=n.onDataMessage,t.useEffect(()=>{const b={onConnectionStateChange:g=>{l(g),g==="connected"&&N(null)},onAgentStateChange:s,onTranscript:g=>p([...g]),onAgentConfig:f,onAudioTrack:g=>o(g),onVideoTrack:g=>u(g),onVideoTrackRemoved:()=>u(null),onError:g=>N(g),onDataMessage:g=>{var R;(R=M.current)==null||R.call(M,g)},onResumabilityChange:v},k=new ze.LiveKitSession({agentId:n.agentId,baseUrl:n.baseUrl,apiKey:n.apiKey,sessionEndpoint:n.sessionEndpoint,sessionBody:n.sessionBody},b);return S.current=k,l("idle"),s("idle"),p([]),f(null),u(null),o(null),v(!1),N(null),()=>{var g;(g=k.destroy)==null||g.call(k),S.current=null}},[n.agentId,n.baseUrl,n.apiKey,n.sessionEndpoint,JSON.stringify(n.sessionBody??{})]);const T=t.useCallback(async()=>{const b=S.current;if(b)try{await b.connect()}catch(k){throw N(k instanceof Error?k.message:String(k)),k}},[]),B=t.useCallback(()=>{const b=S.current;b&&b.disconnect()},[]),w=t.useCallback(()=>{var b;return((b=S.current)==null?void 0:b.getRoom())??null},[]);return{connectionState:r,agentState:a,transcript:i,agentConfig:m,videoElement:_,audioElement:c,canResume:x,error:C,connect:T,disconnect:B,getRoom:w,session:S.current}}function he(){const n=t.useRef(null),r=t.useRef(null),l=t.useRef(null),a=t.useRef(null),s=t.useRef(new Set),i=t.useRef(null),p=t.useCallback(()=>{const c=r.current;if(!c){a.current=null;return}(!i.current||i.current.length!==c.frequencyBinCount)&&(i.current=new Uint8Array(new ArrayBuffer(c.frequencyBinCount)));const o=i.current;c.getByteFrequencyData(o);let x=0;for(let C=0;C<o.length;C++)x+=o[C];const v=x/o.length/255;for(const C of s.current)try{C(v)}catch(N){console.error("[useAudioLevel] subscriber threw:",N)}a.current=requestAnimationFrame(p)},[]),m=t.useCallback(()=>{if(n.current||typeof window>"u"||typeof AudioContext>"u")return;const c=new AudioContext,o=c.createAnalyser();o.fftSize=64,o.connect(c.destination),n.current=c,r.current=o},[]),f=t.useCallback(c=>{if(m(),!(!n.current||!r.current)){if(l.current){try{l.current.disconnect()}catch{}l.current=null}try{const o=n.current.createMediaElementSource(c);o.connect(r.current),l.current=o}catch(o){console.warn("[useAudioLevel] createMediaElementSource failed:",o);return}a.current===null&&(a.current=requestAnimationFrame(p))}},[m,p]),_=t.useCallback(()=>{if(a.current!==null&&(cancelAnimationFrame(a.current),a.current=null),l.current){try{l.current.disconnect()}catch{}l.current=null}},[]),u=t.useCallback(c=>(s.current.add(c),()=>{s.current.delete(c)}),[]);return t.useEffect(()=>()=>{if(_(),r.current){try{r.current.disconnect()}catch{}r.current=null}if(n.current){try{n.current.close()}catch{}n.current=null}s.current.clear(),i.current=null},[_]),{attach:f,detach:_,subscribe:u}}function xe(){const[n,r]=t.useState(!1),[l,a]=t.useState(null),s=t.useRef(null),i=t.useRef(null),p=t.useCallback(async u=>{if(s.current&&i.current){try{await i.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}i.current=u,a(null);try{const c=await Ae.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await u.localParticipant.publishTrack(c),s.current=c,r(c.isMuted)}catch(c){const o=c instanceof Error&&c.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw a(o),c}},[]),m=t.useCallback(()=>{const u=s.current;u&&(u.isMuted?(u.unmute(),r(!1)):(u.mute(),r(!0)))},[]),f=t.useCallback(()=>{const u=s.current,c=i.current;if(u&&c){try{c.localParticipant.unpublishTrack(u)}catch{}u.stop()}s.current=null,i.current=null,r(!1)},[]),_=t.useCallback(()=>a(null),[]);return{isMuted:n,micError:l,toggleMute:m,setupMic:p,teardownMic:f,clearError:_}}function Ie(n){if(typeof window>"u")return null;try{return window.localStorage.getItem(n)}catch{return null}}function Te(n,r){if(!(typeof window>"u"))try{window.localStorage.setItem(n,r)}catch{}}function _e({value:n,defaultValue:r="expanded",onChange:l}={}){const a=n!==void 0,[s,i]=t.useState(r),p=a?n:s,m=t.useCallback(f=>{f!==p&&(a||i(f),l==null||l(f))},[p,a,l]);return[p,m]}const Be=["hidden","minimized","expanded"];function De(n){return n&&Be.includes(n)?n:null}function ge({value:n,defaultValue:r="expanded",onChange:l,persistKey:a="ll-widget",disablePersistence:s=!1}={}){const i=`${a}:display-mode`,p=t.useRef(!1),[m,f]=_e({value:n,defaultValue:r,onChange:_=>{n===void 0&&!s&&Te(i,_),l==null||l(_)}});return t.useEffect(()=>{if(p.current||(p.current=!0,s||n!==void 0))return;const _=De(Ie(i));_&&_!==m&&f(_)},[]),[m,f]}const Pe=640;function ve(n=Pe){const[r,l]=t.useState(!1);return t.useEffect(()=>{if(n===!1){l(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const a=`(max-width: ${n-1}px)`,s=window.matchMedia(a),i=()=>l(s.matches);return i(),typeof s.addEventListener=="function"?(s.addEventListener("change",i),()=>s.removeEventListener("change",i)):(s.addListener(i),()=>{s.removeListener(i)})},[n]),r}const te=({muted:n=!1,className:r})=>n?e.jsxs("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e.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"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):e.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e.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"})}),ue=({className:n})=>e.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e.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"})}),me=({className:n})=>e.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})}),ye=({className:n})=>e.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),Ue={left:180,right:0,up:-90,down:90},$e=({direction:n="right",className:r})=>e.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${Ue[n]}deg)`},"aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}),Ve=({muted:n=!1,className:r})=>e.jsxs("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 9v6m3-9v12M9 5l-3 4H3v6h3l3 4V5z"}),n&&e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 20L20 4"})]}),We=({className:n})=>e.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"})});function qe(n){return n==="top-left"||n==="bottom-left"?"left":"right"}const Ke=({position:n,isMobile:r,isSpeaking:l,onExpand:a,label:s="Open widget"})=>{const i=qe(n),p=i==="right"?"left":"right",m=["ll-hidden",`ll-hidden--${i}`,r?"ll-hidden--mobile":"ll-hidden--desktop",l?"ll-hidden--speaking":null].filter(Boolean).join(" ");return e.jsx("button",{type:"button",className:m,onClick:a,"aria-label":s,"data-position":n,children:e.jsx($e,{direction:p,className:"ll-hidden__chevron"})})},Oe=({audioLevel:n,bars:r=20,maxHeight:l=20,minHeight:a=4,className:s,barClassName:i})=>{const p=t.useRef(null),m=t.useRef([]),f=t.useMemo(()=>{const u=(Math.sqrt(5)-1)/2;return Array.from({length:r},(c,o)=>.5+o*u%1*.5)},[r]);t.useEffect(()=>n.subscribe(c=>{for(let o=0;o<r;o++){const x=m.current[o];if(!x)continue;const v=Math.max(a,c*l*f[o]);x.style.height=`${v}px`}}),[n,r,l,a,f]);const _=["ll-waveform",s].filter(Boolean).join(" ");return e.jsx("div",{ref:p,className:_,"aria-hidden":"true",children:Array.from({length:r},(u,c)=>e.jsx("div",{ref:o=>{m.current[c]=o},className:["ll-waveform__bar",i].filter(Boolean).join(" "),style:{height:`${a}px`}},c))})},Fe=({position:n,isMobile:r,agentName:l,avatarImageUrl:a,agentState:s,isMuted:i,audioLevel:p,onExpand:m,onToggleMute:f,onClose:_})=>r?e.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${l} widget`,children:e.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:m,"aria-label":`Expand ${l} widget`,children:[a?e.jsx("img",{src:a,alt:l,className:"ll-minimized__avatar"}):e.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),e.jsx(Oe,{audioLevel:p,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),e.jsx("span",{className:"ll-minimized__name",children:l}),e.jsxs("div",{className:"ll-minimized__controls",children:[e.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:u=>{u.stopPropagation(),f()},onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.stopPropagation(),u.preventDefault(),f())},"aria-label":i?"Unmute microphone":"Mute microphone",children:e.jsx(te,{muted:i,className:"ll-minimized__icon"})}),e.jsx(ue,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):e.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":n,role:"region","aria-label":`${l} widget`,children:e.jsxs("div",{className:"ll-minimized__surface",children:[a?e.jsx("img",{src:a,alt:l,className:"ll-minimized__avatar"}):e.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),e.jsxs("div",{className:"ll-minimized__meta",children:[e.jsx("span",{className:"ll-minimized__name",children:l}),e.jsx("span",{className:"ll-minimized__state",children:s==="speaking"?"Speaking":s==="thinking"?"Thinking":"Listening"})]}),e.jsxs("div",{className:"ll-minimized__controls",children:[e.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:f,"aria-label":i?"Unmute microphone":"Mute microphone",children:e.jsx(te,{muted:i,className:"ll-minimized__icon"})}),e.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:m,"aria-label":`Expand ${l} widget`,children:e.jsx(ue,{className:"ll-minimized__icon"})}),e.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:_,"aria-label":"Close widget",children:e.jsx(ye,{className:"ll-minimized__icon"})})]})]})}),He=({src:n,alt:r,preCannedPlaying:l=!1,className:a,style:s})=>{const[i,p]=t.useState(!1),m=t.useRef(n);if(t.useEffect(()=>{m.current!==n&&(m.current=n,p(!1))},[n]),!n)return null;const f={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:l?"scale(1.02)":"scale(1)",opacity:i?1:0,...s};return e.jsx("img",{src:n,alt:r,className:a,style:f,loading:"eager",fetchpriority:"high",onLoad:()=>p(!0)})},Ye={idle:"Idle",listening:"Listening",thinking:"Thinking",speaking:"Speaking"},Ge=({state:n,className:r})=>{const l=["ll-pill",`ll-pill--${n}`,r].filter(Boolean).join(" ");return e.jsxs("div",{className:l,"data-agent-state":n,children:[e.jsx("span",{className:"ll-pill__dot"}),e.jsx("span",{className:"ll-pill__label",children:Ye[n]})]})},Je=({position:n,isMobile:r,agentName:l,avatarImageUrl:a,idleLoopUrl:s,greeting:i,branding:p,teamMembers:m,currentTeamMemberId:f,isSwitchingTeamMember:_,teamSwitcherOpen:u,onToggleTeamSwitcher:c,onSelectTeamMember:o,connectionState:x,agentState:v,transcript:C,isMuted:N,needsUserGesture:S,canResume:M,micError:T,error:B,avatarVideoContainerRef:w,onConnect:b,onDisconnect:k,onRetry:g,onResumeAudio:R,onToggleMute:D,onMinimize:P,onClose:U,onClearMicError:y})=>{const O=C.length>0?C[C.length-1]:null,F=((m==null?void 0:m.length)??0)>1,Y=p.productName||"Live Layer",$=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return e.jsxs("div",{className:$,"data-position":n,role:"dialog","aria-label":`${l} widget`,children:[e.jsxs("div",{className:"ll-expanded__header",children:[e.jsxs("div",{className:"ll-expanded__header-left",children:[p.logoUrl&&e.jsx("img",{src:p.logoUrl,alt:Y,className:"ll-expanded__logo"}),F?e.jsxs("button",{type:"button",className:"ll-expanded__team-trigger",onClick:c,"aria-expanded":u,"aria-label":"Change team member",children:[e.jsx("span",{children:l}),e.jsx(me,{className:`ll-expanded__team-chevron ${u?"ll-expanded__team-chevron--open":""}`})]}):e.jsx("span",{className:"ll-expanded__name",children:l})]}),e.jsxs("div",{className:"ll-expanded__header-right",children:[e.jsx("button",{type:"button",className:"ll-expanded__icon-btn",onClick:D,"aria-label":N?"Unmute microphone":"Mute microphone",title:N?"Unmute":"Mute",children:e.jsx(Ve,{muted:N,className:"ll-expanded__icon"})}),r?null:e.jsx("button",{type:"button",className:"ll-expanded__icon-btn",onClick:P,"aria-label":"Minimize widget",title:"Minimize",children:e.jsx(me,{className:"ll-expanded__icon"})}),e.jsx("button",{type:"button",className:"ll-expanded__icon-btn",onClick:U,"aria-label":"Close widget",title:"Close",children:e.jsx(ye,{className:"ll-expanded__icon"})})]})]}),F&&u&&e.jsx("div",{className:"ll-expanded__team-menu",role:"menu",children:m.map(L=>e.jsxs("button",{type:"button",role:"menuitem",className:`ll-expanded__team-item ${L.id===f?"ll-expanded__team-item--active":""}`,onClick:()=>o(L.id),children:[L.avatarImageUrl&&e.jsx("img",{src:L.avatarImageUrl,alt:"",className:"ll-expanded__team-item-avatar"}),e.jsxs("div",{className:"ll-expanded__team-item-meta",children:[e.jsx("span",{className:"ll-expanded__team-item-name",children:L.name}),L.role&&e.jsx("span",{className:"ll-expanded__team-item-role",children:L.role})]})]},L.id))}),e.jsxs("div",{className:"ll-expanded__avatar-surface",children:[a&&e.jsx(He,{src:a,alt:l,className:"ll-expanded__avatar-image"}),s&&e.jsx("video",{className:"ll-expanded__avatar-idle-loop",src:s,loop:!0,muted:!0,playsInline:!0,autoPlay:!0}),e.jsx("div",{ref:w,className:"ll-expanded__avatar-live"}),x==="connecting"&&e.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--connecting",children:[e.jsx("div",{className:"ll-expanded__spinner"}),e.jsx("p",{className:"ll-expanded__overlay-text",children:"Connecting..."})]}),S&&e.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:R,children:[e.jsx("div",{className:"ll-expanded__play-circle",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M8 5v14l11-7L8 5z"})})}),e.jsx("p",{className:"ll-expanded__overlay-text",children:"Tap to enable audio"}),e.jsx("p",{className:"ll-expanded__overlay-subtext",children:"Your agent is ready"})]}),!S&&(x==="idle"||x==="disconnected"||x==="error")&&e.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--play",onClick:b,"aria-label":M?"Restart paused session":x==="disconnected"?"Reconnect to agent":"Start video call",children:[e.jsx("div",{className:"ll-expanded__play-circle",children:e.jsx("svg",{width:"26",height:"26",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("polygon",{points:"6 3 20 12 6 21 6 3"})})}),e.jsx("p",{className:"ll-expanded__overlay-text",children:M?"Restart session":x==="disconnected"?"Click to reconnect":i||"Start video call"}),M&&e.jsx("p",{className:"ll-expanded__overlay-subtext",children:"Pick up where you left off"})]}),_&&e.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--switching",children:[e.jsx("div",{className:"ll-expanded__spinner"}),e.jsxs("p",{className:"ll-expanded__overlay-text",children:["Connecting to ",l,"..."]})]}),x==="connected"&&e.jsx("div",{className:"ll-expanded__state-pill-wrap",children:e.jsx(Ge,{state:v})}),T&&x==="connected"&&e.jsxs("div",{className:"ll-expanded__mic-error",role:"alert",children:[e.jsx("p",{children:T}),e.jsx("button",{type:"button",onClick:()=>{y(),g()},children:"Retry"})]}),x==="connected"&&O&&e.jsx("div",{className:"ll-expanded__transcript","aria-live":"polite",children:e.jsx("p",{children:O.text})})]}),e.jsxs("div",{className:"ll-expanded__footer",children:[x==="idle"&&e.jsxs("button",{type:"button",className:"ll-expanded__cta ll-expanded__cta--primary",onClick:b,children:[e.jsx(We,{className:"ll-expanded__cta-icon"}),e.jsx("span",{children:"Start Video Call"})]}),x==="connecting"&&e.jsxs("button",{type:"button",className:"ll-expanded__cta ll-expanded__cta--loading",disabled:!0,children:[e.jsx("div",{className:"ll-expanded__spinner ll-expanded__spinner--small"}),e.jsx("span",{children:"Connecting..."})]}),x==="connected"&&e.jsx("button",{type:"button",className:"ll-expanded__cta ll-expanded__cta--danger",onClick:k,children:"End conversation"}),(x==="error"||x==="disconnected")&&e.jsxs("div",{className:"ll-expanded__retry",children:[B&&e.jsx("p",{className:"ll-expanded__error-text",children:B}),e.jsxs("button",{type:"button",className:"ll-expanded__cta ll-expanded__cta--primary",onClick:g,children:[e.jsx(te,{muted:!1,className:"ll-expanded__cta-icon"}),e.jsx("span",{children:"Try again"})]})]})]})]})},Qe=new Set(["agent_state","avatar_stream_ready","avatar_active","avatar_idle","bot_ready","agent_error","idle_warning","idle_timeout"]);function Xe(n){var oe,ce,de;const{agentId:r,apiKey:l,baseUrl:a="https://app.livelayer.studio",sessionEndpoint:s,sessionBody:i,autoConnect:p=!1,displayMode:m,defaultDisplayMode:f="expanded",onDisplayModeChange:_,position:u="bottom-right",mobileBreakpoint:c=640,persistKey:o="ll-widget",disablePersistence:x=!1,teamMembers:v,currentTeamMemberId:C,onTeamMemberChange:N,idleLoopUrl:S,greeting:M,avatarImageUrl:T,agentName:B,branding:w={},onConnect:b,onDisconnect:k,onTranscript:g,onAgentState:R,onConnectionStateChange:D,onAgentEvent:P,onAgentCommand:U,controlledSession:y,className:O,style:F,zIndex:Y=2147483647}=n,$=C!==void 0,[L,je]=t.useState(()=>{var h;return C??((h=v==null?void 0:v[0])==null?void 0:h.id)}),V=$?C:L,z=t.useMemo(()=>(v==null?void 0:v.find(h=>h.id===V))??null,[v,V]),be=(z==null?void 0:z.agentId)??r,[W,I]=ge({value:m,defaultValue:f,onChange:_,persistKey:o,disablePersistence:x}),H=ve(c),G=he(),A=xe(),[ke,J]=t.useState(!1),[Q,re]=t.useState(!1),[X,Z]=t.useState(!1),ee=t.useCallback(h=>{const j=h;!j.type||typeof j.type!="string"||(P==null||P({eventName:j.type,data:h}),Qe.has(j.type)||U==null||U(j))},[U,P]),E=fe({agentId:y?"__controlled__":be,baseUrl:a,apiKey:l,sessionEndpoint:s,sessionBody:i,onDataMessage:y?void 0:ee});t.useEffect(()=>{if(y!=null&&y.subscribeToDataMessages)return y.subscribeToDataMessages(ee)},[y,ee]);const d=t.useMemo(()=>y?{connectionState:y.connectionState,agentState:y.agentState,transcript:y.transcript,videoElement:y.videoElement,audioElement:y.audioElement,canResume:y.canResume,error:y.error,agentConfig:null,connect:async()=>{await y.onConnect()},disconnect:()=>y.onDisconnect(),getRoom:E.getRoom,isControlled:!0}:{connectionState:E.connectionState,agentState:E.agentState,transcript:E.transcript,videoElement:E.videoElement,audioElement:E.audioElement,canResume:E.canResume,error:E.error,agentConfig:E.agentConfig,connect:E.connect,disconnect:E.disconnect,getRoom:E.getRoom,isControlled:!1},[y,E]),le=t.useRef(null);t.useEffect(()=>{const h=d.videoElement,j=le.current;if(!(!h||!j))return j.appendChild(h),()=>{h.parentNode===j&&j.removeChild(h)}},[d.videoElement]),t.useEffect(()=>{const h=d.audioElement;if(!h)return;G.attach(h);const j=h.play();return j&&typeof j.catch=="function"&&j.catch(K=>{(K==null?void 0:K.name)==="NotAllowedError"&&J(!0)}),()=>{G.detach()}},[d.audioElement]),t.useEffect(()=>{if(d.isControlled||d.connectionState!=="connected")return;const h=d.getRoom();if(h)return A.setupMic(h).catch(()=>{}),()=>{A.teardownMic()}},[d.isControlled,d.connectionState]),t.useEffect(()=>{D==null||D(d.connectionState),d.connectionState==="connected"?b==null||b():d.connectionState==="disconnected"&&(k==null||k())},[d.connectionState,b,k,D]),t.useEffect(()=>{g==null||g(d.transcript)},[d.transcript,g]),t.useEffect(()=>{R==null||R(d.agentState)},[d.agentState,R]);const se=t.useRef(!1);t.useEffect(()=>{d.isControlled||!p||se.current||d.connectionState==="idle"&&(se.current=!0,d.connect())},[p,d.connectionState,d]);const Ce=t.useCallback(h=>{const j=v==null?void 0:v.find(K=>K.id===h);j&&(Z(!1),h!==V&&(re(!0),d.disconnect(),$||je(h),N==null||N(j)))},[v,V,d,$,N]);t.useEffect(()=>{Q&&d.connectionState==="connected"&&re(!1)},[d.connectionState,Q]),t.useEffect(()=>{if(!X)return;const h=j=>{j.key==="Escape"&&Z(!1)};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[X]);const ne=(z==null?void 0:z.name)??B??((oe=d.agentConfig)==null?void 0:oe.name)??"Live Layer",ae=(z==null?void 0:z.avatarImageUrl)??T??((ce=d.agentConfig)==null?void 0:ce.avatarImageUrl)??null,Ne=S??((de=d.agentConfig)==null?void 0:de.idleLoopUrl)??null,we=M??null,Ee=t.useCallback(()=>I("expanded"),[I]),Se=t.useCallback(()=>I("minimized"),[I]),ie=t.useCallback(()=>I("hidden"),[I]),Me=t.useCallback(()=>{const h=d.audioElement;h&&h.play().then(()=>J(!1)).catch(()=>{})},[d.audioElement]),Le=t.useCallback(()=>{J(!1),d.connect()},[d]),q={...F,zIndex:Y};w.primaryColor&&(q["--ll-color-primary"]=w.primaryColor),w.accentColor&&(q["--ll-color-accent"]=w.accentColor),w.backgroundColor&&(q["--ll-color-bg"]=w.backgroundColor),w.textColor&&(q["--ll-color-fg"]=w.textColor);const Re=["ll-widget",`ll-widget--${W}`,`ll-widget--${H?"mobile":"desktop"}`,O].filter(Boolean).join(" ");return e.jsxs("div",{className:Re,style:q,"data-display-mode":W,"data-position":u,children:[W==="hidden"&&e.jsx(Ke,{position:u,isMobile:H,isSpeaking:d.agentState==="speaking",onExpand:()=>I("minimized"),label:`Open ${ne} widget`}),W==="minimized"&&e.jsx(Fe,{position:u,isMobile:H,agentName:ne,avatarImageUrl:ae,agentState:d.agentState,isMuted:A.isMuted,audioLevel:G,onExpand:Ee,onToggleMute:A.toggleMute,onClose:ie}),W==="expanded"&&e.jsx(Je,{position:u,isMobile:H,agentName:ne,avatarImageUrl:ae,idleLoopUrl:Ne,greeting:we,branding:w,teamMembers:v,currentTeamMemberId:V,isSwitchingTeamMember:Q,teamSwitcherOpen:X,onToggleTeamSwitcher:()=>Z(h=>!h),onSelectTeamMember:Ce,connectionState:d.connectionState,agentState:d.agentState,transcript:d.transcript,isMuted:A.isMuted,needsUserGesture:ke,canResume:d.canResume,micError:A.micError,error:d.error,avatarVideoContainerRef:le,onConnect:()=>void d.connect(),onDisconnect:()=>d.disconnect(),onRetry:Le,onResumeAudio:Me,onToggleMute:A.toggleMute,onMinimize:Se,onClose:ie,onClearMicError:A.clearError})]})}function Ze(n){return e.jsx(pe,{children:e.jsx(Xe,{...n})})}const en=({agentId:n,baseUrl:r,apiKey:l,mode:a,onAgentEvent:s,className:i,style:p})=>{const m=t.useRef(null),f=t.useRef(null),_=t.useRef(s);_.current=s;const u=t.useCallback(c=>{var x;const o=c.detail;(x=_.current)==null||x.call(_,o)},[]);return t.useEffect(()=>{const c=m.current;if(!c)return;const o=document.createElement("livelayer-widget");return o.setAttribute("agent-id",n),r&&o.setAttribute("base-url",r),l&&o.setAttribute("api-key",l),a&&o.setAttribute("mode",a),o.addEventListener("agent-event",u),c.appendChild(o),f.current=o,()=>{o.removeEventListener("agent-event",u),c.removeChild(o),f.current=null}},[n]),t.useEffect(()=>{f.current&&(a?f.current.setAttribute("mode",a):f.current.removeAttribute("mode"))},[a]),e.jsx("div",{ref:m,className:i,style:p})};function nn(){const[n,r]=t.useState([]),l=t.useCallback(s=>{r(i=>{const p=i.findIndex(m=>m.id===s.id);if(p>=0){const m=i.slice();return m[p]=s,m}return[...i,s]})},[]),a=t.useCallback(()=>r([]),[]);return{entries:n,pushSegment:l,clear:a,latest:n.length>0?n[n.length-1]:null}}exports.AvatarWidget=Ze;exports.ErrorBoundary=pe;exports.LiveLayerWidget=en;exports.useAudioLevel=he;exports.useDisplayMode=_e;exports.useDisplayModePersistence=ge;exports.useIsMobile=ve;exports.useLiveKitSession=fe;exports.useMicrophoneState=xe;exports.useTranscript=nn;
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),st=require("@livelayer/sdk"),xe=require("livekit-client");class Be extends t.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null},this.reset=()=>{this.setState({hasError:!1,error:null})}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,l){var a,s;(s=(a=this.props).onError)==null||s.call(a,r,l)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback:e.jsxs("div",{className:"ll-error-boundary",role:"alert",children:[e.jsx("p",{className:"ll-error-boundary__title",children:"Widget crashed"}),e.jsx("p",{className:"ll-error-boundary__message",children:((r=this.state.error)==null?void 0:r.message)||"Something went wrong."}),e.jsx("button",{type:"button",className:"ll-error-boundary__retry",onClick:this.reset,children:"Reload widget"})]}):this.props.children}}function $e(n){const[r,l]=t.useState("idle"),[a,s]=t.useState("idle"),[o,d]=t.useState([]),[m,u]=t.useState(null),[x,f]=t.useState(null),[c,i]=t.useState(null),[y,b]=t.useState(!1),[j,N]=t.useState(null),C=t.useRef(null),M=t.useRef(n.onDataMessage);M.current=n.onDataMessage,t.useEffect(()=>{const _={onConnectionStateChange:v=>{l(v),v==="connected"&&N(null)},onAgentStateChange:s,onTranscript:v=>d([...v]),onAgentConfig:u,onAudioTrack:v=>i(v),onVideoTrack:v=>f(v),onVideoTrackRemoved:()=>f(null),onError:v=>N(v),onDataMessage:v=>{var E;(E=M.current)==null||E.call(M,v)},onResumabilityChange:b},k=new st.LiveKitSession({agentId:n.agentId,baseUrl:n.baseUrl,apiKey:n.apiKey,sessionEndpoint:n.sessionEndpoint,sessionBody:n.sessionBody},_);return C.current=k,l("idle"),s("idle"),d([]),u(null),f(null),i(null),b(!1),N(null),()=>{var v;(v=k.destroy)==null||v.call(k),C.current=null}},[n.agentId,n.baseUrl,n.apiKey,n.sessionEndpoint,JSON.stringify(n.sessionBody??{})]);const R=t.useCallback(async()=>{const _=C.current;if(_)try{await _.connect()}catch(k){throw N(k instanceof Error?k.message:String(k)),k}},[]),L=t.useCallback(()=>{const _=C.current;_&&_.disconnect()},[]),S=t.useCallback(()=>{var _;return((_=C.current)==null?void 0:_.getRoom())??null},[]);return{connectionState:r,agentState:a,transcript:o,agentConfig:m,videoElement:x,audioElement:c,canResume:y,error:j,connect:R,disconnect:L,getRoom:S,session:C.current}}function Ue(){const n=t.useRef(null),r=t.useRef(null),l=t.useRef(null),a=t.useRef(null),s=t.useRef(new Set),o=t.useRef(null),d=t.useCallback(()=>{const c=r.current;if(!c){a.current=null;return}(!o.current||o.current.length!==c.frequencyBinCount)&&(o.current=new Uint8Array(new ArrayBuffer(c.frequencyBinCount)));const i=o.current;c.getByteFrequencyData(i);let y=0;for(let j=0;j<i.length;j++)y+=i[j];const b=y/i.length/255;for(const j of s.current)try{j(b)}catch(N){console.error("[useAudioLevel] subscriber threw:",N)}a.current=requestAnimationFrame(d)},[]),m=t.useCallback(()=>{if(n.current||typeof window>"u"||typeof AudioContext>"u")return;const c=new AudioContext,i=c.createAnalyser();i.fftSize=64,i.connect(c.destination),n.current=c,r.current=i},[]),u=t.useCallback(c=>{if(m(),!(!n.current||!r.current)){if(l.current){try{l.current.disconnect()}catch{}l.current=null}try{const i=n.current.createMediaElementSource(c);i.connect(r.current),l.current=i}catch(i){console.warn("[useAudioLevel] createMediaElementSource failed:",i);return}a.current===null&&(a.current=requestAnimationFrame(d))}},[m,d]),x=t.useCallback(()=>{if(a.current!==null&&(cancelAnimationFrame(a.current),a.current=null),l.current){try{l.current.disconnect()}catch{}l.current=null}},[]),f=t.useCallback(c=>(s.current.add(c),()=>{s.current.delete(c)}),[]);return t.useEffect(()=>()=>{if(x(),r.current){try{r.current.disconnect()}catch{}r.current=null}if(n.current){try{n.current.close()}catch{}n.current=null}s.current.clear(),o.current=null},[x]),{attach:u,detach:x,subscribe:f}}function Oe(){const[n,r]=t.useState(!1),[l,a]=t.useState(null),s=t.useRef(null),o=t.useRef(null),d=t.useCallback(async f=>{if(s.current&&o.current){try{await o.current.localParticipant.unpublishTrack(s.current)}catch{}s.current.stop(),s.current=null}o.current=f,a(null);try{const c=await xe.createLocalAudioTrack({echoCancellation:!0,noiseSuppression:!0});await f.localParticipant.publishTrack(c),s.current=c,r(c.isMuted)}catch(c){const i=c instanceof Error&&c.name==="NotAllowedError"?"Enable your microphone to talk with the agent.":"Microphone unavailable. Check browser permissions and try again.";throw a(i),c}},[]),m=t.useCallback(()=>{const f=s.current;f&&(f.isMuted?(f.unmute(),r(!1)):(f.mute(),r(!0)))},[]),u=t.useCallback(()=>{const f=s.current,c=o.current;if(f&&c){try{c.localParticipant.unpublishTrack(f)}catch{}f.stop()}s.current=null,o.current=null,r(!1)},[]),x=t.useCallback(()=>a(null),[]);return{isMuted:n,micError:l,toggleMute:m,setupMic:d,teardownMic:u,clearError:x}}const lt={resolution:{width:640,height:480,frameRate:24}};function Ve(){const[n,r]=t.useState(!1),[l,a]=t.useState(null),[s,o]=t.useState(null),[d,m]=t.useState(""),u=t.useRef(null),x=t.useRef(null),f=t.useCallback(C=>{u.current=C},[]),c=t.useCallback(()=>{const C=u.current,M=x.current;if(M&&C){const R=C.localParticipant.getTrackPublication(xe.Track.Source.Camera);if(R!=null&&R.track){try{C.localParticipant.unpublishTrack(R.track)}catch{}R.track.stop()}else M.stop()}x.current=null,o(null),r(!1)},[]),i=t.useCallback(async C=>{const M=u.current;if(M){a(null);try{const R={...lt};C&&(R.deviceId=C);const L=await xe.createLocalVideoTrack(R);await M.localParticipant.publishTrack(L),x.current=L;const S=L.attach();o(S),r(!0),C&&m(C);try{M.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_camera_on"})),{reliable:!0})}catch{}}catch(R){const L=R instanceof Error&&R.name==="NotAllowedError"?"Enable your camera in the browser to share video.":"Camera unavailable. Check permissions and try again.";a(L)}}},[]),y=t.useCallback(async()=>{n?c():await i(d||void 0)},[n,d,c,i]),b=t.useCallback(async C=>{c(),await i(C)},[c,i]),j=t.useCallback(()=>{c(),u.current=null,a(null),m("")},[c]),N=t.useCallback(()=>a(null),[]);return t.useEffect(()=>()=>{x.current&&x.current.stop()},[]),{isEnabled:n,error:l,previewEl:s,activeDeviceId:d,toggle:y,switchDevice:b,attachRoom:f,teardown:j,clearError:N}}function We(){const[n,r]=t.useState(!1),[l,a]=t.useState(null),[s,o]=t.useState(null),d=t.useRef(null),m=t.useCallback(i=>{d.current=i},[]),u=t.useCallback(()=>o(null),[]),x=t.useCallback(async()=>{const i=d.current;if(i){if(n){try{await i.localParticipant.setScreenShareEnabled(!1)}catch{}u(),r(!1);return}a(null);try{await i.localParticipant.setScreenShareEnabled(!0);let y=0;const b=()=>{const j=i.localParticipant.getTrackPublication(xe.Track.Source.ScreenShare);if(j!=null&&j.track){const N=j.track.attach();o(N),r(!0);try{i.localParticipant.publishData(new TextEncoder().encode(JSON.stringify({type:"user_screen_share_on"})),{reliable:!0})}catch{}return}y++<10?setTimeout(b,100):r(!0)};b()}catch(y){const b=y instanceof Error?y.name:"";b!=="NotAllowedError"&&b!=="AbortError"&&a("Screen share unavailable. Try again."),r(!1)}}},[n,u]),f=t.useCallback(()=>{const i=d.current;if(i&&n)try{i.localParticipant.setScreenShareEnabled(!1)}catch{}u(),r(!1),a(null),d.current=null},[n,u]),c=t.useCallback(()=>a(null),[]);return{isEnabled:n,error:l,previewEl:s,toggle:x,attachRoom:m,teardown:f,clearError:c}}function Fe(){const[n,r]=t.useState([]),[l,a]=t.useState([]),s=t.useCallback(async()=>{if(!(typeof navigator>"u"||!navigator.mediaDevices))try{const o=await navigator.mediaDevices.enumerateDevices();r(o.filter(d=>d.kind==="audioinput")),a(o.filter(d=>d.kind==="videoinput"))}catch{}},[]);return t.useEffect(()=>{if(s(),typeof navigator>"u"||!navigator.mediaDevices)return;const o=()=>void s();return navigator.mediaDevices.addEventListener("devicechange",o),()=>navigator.mediaDevices.removeEventListener("devicechange",o)},[s]),{mics:n,cameras:l,refresh:s}}function Ke(n,r,l=!1){const[a,s]=t.useState(null),[o,d]=t.useState(null),[m,u]=t.useState(!l&&!!n),x=t.useRef("");return t.useEffect(()=>{if(l||!n){u(!1);return}const f=`${r||""}::${n}`;if(x.current===f)return;x.current=f;const c=new AbortController,i=r||"https://app.livelayer.studio";return u(!0),d(null),fetch(`${i}/api/widget/agent/${encodeURIComponent(n)}`,{signal:c.signal}).then(async y=>{if(!y.ok){const b=await y.json().catch(()=>({}));throw new Error(b.error||`HTTP ${y.status}`)}return y.json()}).then(y=>{s(y),u(!1)}).catch(y=>{c.signal.aborted||(d(y instanceof Error?y.message:"Agent lookup failed"),u(!1))}),()=>c.abort()},[n,r,l]),{info:a,error:o,loading:m}}function at(n){if(typeof window>"u")return null;try{return window.localStorage.getItem(n)}catch{return null}}function it(n,r){if(!(typeof window>"u"))try{window.localStorage.setItem(n,r)}catch{}}function qe({value:n,defaultValue:r="expanded",onChange:l}={}){const a=n!==void 0,[s,o]=t.useState(r),d=a?n:s,m=t.useCallback(u=>{u!==d&&(a||o(u),l==null||l(u))},[d,a,l]);return[d,m]}const ot=["hidden","minimized","expanded"];function ct(n){return n&&ot.includes(n)?n:null}function Ge({value:n,defaultValue:r="expanded",onChange:l,persistKey:a="ll-widget",disablePersistence:s=!1}={}){const o=`${a}:display-mode`,d=t.useRef(!1),[m,u]=qe({value:n,defaultValue:r,onChange:x=>{n===void 0&&!s&&it(o,x),l==null||l(x)}});return t.useEffect(()=>{if(d.current||(d.current=!0,s||n!==void 0))return;const x=ct(at(o));x&&x!==m&&u(x)},[]),[m,u]}const dt=640;function Ye(n=dt){const[r,l]=t.useState(!1);return t.useEffect(()=>{if(n===!1){l(!1);return}if(typeof window>"u"||typeof window.matchMedia>"u")return;const a=`(max-width: ${n-1}px)`,s=window.matchMedia(a),o=()=>l(s.matches);return o(),typeof s.addEventListener=="function"?(s.addEventListener("change",o),()=>s.removeEventListener("change",o)):(s.addListener(o),()=>{s.removeListener(o)})},[n]),r}const Ie=({muted:n=!1,className:r})=>n?e.jsxs("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:[e.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"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"})]}):e.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e.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"})}),Ae=({className:n})=>e.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e.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"})}),ut=({className:n})=>e.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),ft={left:180,right:0,up:-90,down:90},ht=({direction:n="right",className:r})=>e.jsx("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:{transform:`rotate(${ft[n]}deg)`},"aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 6l6 6-6 6"})});function pt(n){return n==="top-left"||n==="bottom-left"?"left":"right"}const He="ll-hidden-tab-center-y",mt=5,De=16;function xt(){if(typeof window>"u")return null;try{const n=window.localStorage.getItem(He);if(!n)return null;const r=Number.parseFloat(n);return Number.isFinite(r)?r:null}catch{return null}}function Te(n){if(!(typeof window>"u"))try{window.localStorage.setItem(He,String(n))}catch{}}const gt=({position:n,isMobile:r,isSpeaking:l,onExpand:a,label:s="Open widget"})=>{const o=pt(n),d=o==="right"?"left":"right",m=r?80:72,[u,x]=t.useState(null),[f,c]=t.useState(!1),i=t.useRef(null),y=t.useRef(!1),b=t.useCallback(_=>{if(typeof window>"u")return _;const k=m/2,v=De+k,E=window.innerHeight-De-k;return E<v?Math.max(v,_):Math.max(v,Math.min(E,_))},[m]);t.useEffect(()=>{const _=xt();x(b(_??window.innerHeight/2));const k=()=>{x(v=>v===null?null:b(v))};return window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[b]);const j=t.useCallback(_=>{if(!(_.pointerType==="mouse"&&_.button!==0)&&u!==null){try{_.currentTarget.setPointerCapture(_.pointerId)}catch{}i.current={startClientY:_.clientY,startCenterY:u,moved:!1}}},[u]),N=t.useCallback(_=>{const k=i.current;if(!k)return;const v=_.clientY-k.startClientY;!k.moved&&Math.abs(v)>mt&&(k.moved=!0,c(!0)),k.moved&&x(b(k.startCenterY+v))},[b]),C=t.useCallback(_=>{const k=i.current;if(k){try{_.currentTarget.releasePointerCapture(_.pointerId)}catch{}i.current=null,k.moved&&(c(!1),y.current=!0,x(v=>(v!==null&&Te(v),v)))}},[]),M=t.useCallback(()=>{if(y.current){y.current=!1;return}a()},[a]),R=t.useCallback(_=>{if(_.key==="ArrowUp"||_.key==="ArrowDown"){_.preventDefault();const k=_.key==="ArrowUp"?-8:8;x(v=>{if(v===null)return v;const E=b(v+k);return Te(E),E})}},[b]),L=["ll-hidden",`ll-hidden--${o}`,r?"ll-hidden--mobile":"ll-hidden--desktop",l?"ll-hidden--speaking":null,f?"is-dragging":null].filter(Boolean).join(" "),S=u===null?void 0:{top:`${u-m/2}px`,transform:"none"};return e.jsx("button",{type:"button",className:L,onPointerDown:j,onPointerMove:N,onPointerUp:C,onPointerCancel:C,onClick:M,onKeyDown:R,"aria-label":s,"data-position":n,style:S,children:e.jsx(ht,{direction:d,className:"ll-hidden__chevron"})})},vt=({audioLevel:n,bars:r=20,maxHeight:l=20,minHeight:a=4,className:s,barClassName:o})=>{const d=t.useRef(null),m=t.useRef([]),u=t.useMemo(()=>{const f=(Math.sqrt(5)-1)/2;return Array.from({length:r},(c,i)=>.5+i*f%1*.5)},[r]);t.useEffect(()=>n.subscribe(c=>{for(let i=0;i<r;i++){const y=m.current[i];if(!y)continue;const b=Math.max(a,c*l*u[i]);y.style.height=`${b}px`}}),[n,r,l,a,u]);const x=["ll-waveform",s].filter(Boolean).join(" ");return e.jsx("div",{ref:d,className:x,"aria-hidden":"true",children:Array.from({length:r},(f,c)=>e.jsx("div",{ref:i=>{m.current[c]=i},className:["ll-waveform__bar",o].filter(Boolean).join(" "),style:{height:`${a}px`}},c))})},bt=({position:n,isMobile:r,agentName:l,avatarImageUrl:a,agentState:s,isMuted:o,audioLevel:d,onExpand:m,onToggleMute:u,onClose:x})=>r?e.jsx("div",{className:"ll-minimized ll-minimized--mobile",role:"region","aria-label":`${l} widget`,children:e.jsxs("button",{type:"button",className:"ll-minimized__surface",onClick:m,"aria-label":`Expand ${l} widget`,children:[a?e.jsx("img",{src:a,alt:l,className:"ll-minimized__avatar"}):e.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),e.jsx(vt,{audioLevel:d,bars:16,maxHeight:18,className:"ll-minimized__waveform"}),e.jsx("span",{className:"ll-minimized__name",children:l}),e.jsxs("div",{className:"ll-minimized__controls",children:[e.jsx("span",{className:"ll-minimized__btn",role:"button",tabIndex:0,onClick:f=>{f.stopPropagation(),u()},onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&(f.stopPropagation(),f.preventDefault(),u())},"aria-label":o?"Unmute microphone":"Mute microphone",children:e.jsx(Ie,{muted:o,className:"ll-minimized__icon"})}),e.jsx(Ae,{className:"ll-minimized__icon ll-minimized__icon--expand"})]})]})}):e.jsx("div",{className:"ll-minimized ll-minimized--desktop","data-position":n,role:"region","aria-label":`${l} widget`,children:e.jsxs("div",{className:"ll-minimized__surface",children:[a?e.jsx("img",{src:a,alt:l,className:"ll-minimized__avatar"}):e.jsx("div",{className:"ll-minimized__avatar ll-minimized__avatar--placeholder"}),e.jsxs("div",{className:"ll-minimized__meta",children:[e.jsx("span",{className:"ll-minimized__name",children:l}),e.jsx("span",{className:"ll-minimized__state",children:s==="speaking"?"Speaking":s==="thinking"?"Thinking":"Listening"})]}),e.jsxs("div",{className:"ll-minimized__controls",children:[e.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:u,"aria-label":o?"Unmute microphone":"Mute microphone",children:e.jsx(Ie,{muted:o,className:"ll-minimized__icon"})}),e.jsx("button",{type:"button",className:"ll-minimized__btn",onClick:m,"aria-label":`Expand ${l} widget`,children:e.jsx(Ae,{className:"ll-minimized__icon"})}),e.jsx("button",{type:"button",className:"ll-minimized__btn ll-minimized__btn--close",onClick:x,"aria-label":"Close widget",children:e.jsx(ut,{className:"ll-minimized__icon"})})]})]})}),yt=({src:n,alt:r,preCannedPlaying:l=!1,className:a,style:s})=>{const[o,d]=t.useState(!1),m=t.useRef(n);if(t.useEffect(()=>{m.current!==n&&(m.current=n,d(!1))},[n]),!n)return null;const u={position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",objectPosition:"top",transition:"opacity 500ms ease, transform 500ms ease",transform:l?"scale(1.02)":"scale(1)",opacity:o?1:0,...s};return e.jsx("img",{src:n,alt:r,className:a,style:u,loading:"eager",fetchpriority:"high",onLoad:()=>d(!0)})},_t=({position:n,isMobile:r,agentName:l,avatarImageUrl:a,idleLoopUrl:s,greeting:o,branding:d,teamMembers:m,currentTeamMemberId:u,isSwitchingTeamMember:x,teamSwitcherOpen:f,onToggleTeamSwitcher:c,onSelectTeamMember:i,languageMenuOpen:y,onToggleLanguageMenu:b,connectionState:j,agentState:N,transcript:C,canResume:M,needsUserGesture:R,error:L,isMuted:S,micError:_,micDevices:k,isCameraEnabled:v,cameraPreviewEl:E,cameraDevices:G,activeCameraId:Q,isScreenShareEnabled:T,screenPreviewEl:z,isSpeakerMuted:U,allowCamera:Z,allowScreenShare:I,allowTyping:ge,avatarVideoContainerRef:ve,onConnect:fe,onDisconnect:ae,onRetry:be,onResumeAudio:ye,onToggleMute:Y,onToggleCamera:D,onSwitchCameraDevice:he,onToggleScreenShare:H,onToggleSpeaker:O,onSendMessage:J,onMinimize:ie,onClose:P,onClearMicError:V})=>{var pe;const B=C.length>0?C[C.length-1]:null,W=((m==null?void 0:m.length)??0)>1,ee=j==="connecting"||j==="connected",F=j==="connected",oe=j==="idle"||j==="disconnected"||j==="error",ce=t.useRef(null),te=t.useRef(null);t.useEffect(()=>{const h=ce.current;h&&(h.innerHTML="",E&&(E.style.width="100%",E.style.height="100%",E.style.objectFit="cover",E.style.transform="scaleX(-1)",h.appendChild(E)))},[E]),t.useEffect(()=>{const h=te.current;h&&(h.innerHTML="",z&&(z.style.width="100%",z.style.height="100%",z.style.objectFit="contain",h.appendChild(z)))},[z]);const[K,ne]=t.useState(!1),[re,q]=t.useState(!1);t.useEffect(()=>{if(!K&&!re&&!y&&!f)return;const h=()=>{ne(!1),q(!1),y&&b(),f&&c()};return document.addEventListener("click",h),()=>document.removeEventListener("click",h)},[K,re,y,f,b,c]);const[se,le]=t.useState(""),A=t.useCallback(h=>{h.preventDefault();const $=se.trim();$&&(J($),le(""))},[se,J]),p=d.productName||"Live Layer",de=F&&(B!=null&&B.text)?B.text:o||"",_e=["ll-expanded",r?"ll-expanded--mobile":"ll-expanded--desktop"].join(" ");return e.jsxs("div",{className:_e,"data-position":n,"data-state":F?"connected":ee?"connecting":"idle",role:"dialog","aria-label":`${l} widget`,children:[e.jsxs("div",{className:"ll-expanded__bg",children:[a?e.jsx(yt,{src:a,alt:l,className:"ll-expanded__bg-img"}):e.jsx("div",{className:"ll-expanded__bg-fallback",children:e.jsx("span",{className:"ll-expanded__bg-initial",children:((pe=l==null?void 0:l.charAt(0))==null?void 0:pe.toUpperCase())||"A"})}),s&&!F&&e.jsx("video",{className:"ll-expanded__bg-idle",src:s,autoPlay:!0,loop:!0,muted:!0,playsInline:!0})]}),e.jsx("div",{ref:ve,className:"ll-expanded__video"}),j==="connecting"&&e.jsxs("div",{className:"ll-expanded__overlay ll-expanded__overlay--connecting",children:[e.jsx("div",{className:"ll-expanded__spinner"}),e.jsx("p",{className:"ll-expanded__overlay-text",children:x?"Switching...":"Connecting..."})]}),R&&F&&e.jsxs("button",{type:"button",className:"ll-expanded__overlay ll-expanded__overlay--gesture",onClick:ye,children:[e.jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:e.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"})}),e.jsx("p",{className:"ll-expanded__overlay-text",children:"Tap to enable audio"})]}),ee?e.jsxs("div",{className:"ll-expanded__topbar",children:[e.jsxs("div",{className:"ll-expanded__topbar-left",children:[e.jsxs("div",{className:"ll-expanded__pill-wrap",children:[e.jsxs("button",{type:"button",className:"ll-hpill",onClick:h=>{W&&(h.stopPropagation(),c())},"aria-haspopup":W?"listbox":void 0,"aria-expanded":W?f:void 0,children:[e.jsx("span",{className:"ll-hpill__label",children:l}),W&&e.jsx(me,{})]}),W&&f&&e.jsx("div",{className:"ll-hmenu",onClick:h=>h.stopPropagation(),role:"listbox",children:m==null?void 0:m.map(h=>e.jsxs("button",{type:"button",className:`ll-hmenu__item ${h.id===u?"is-active":""}`,onClick:()=>i(h.id),role:"option","aria-selected":h.id===u,children:[h.avatarImageUrl&&e.jsx("img",{src:h.avatarImageUrl,alt:"",className:"ll-hmenu__avatar"}),e.jsx("span",{className:"ll-hmenu__name",children:h.name}),h.role&&e.jsx("span",{className:"ll-hmenu__role",children:h.role})]},h.id))})]}),e.jsxs("div",{className:"ll-expanded__pill-wrap",children:[e.jsxs("button",{type:"button",className:"ll-hpill",onClick:h=>{h.stopPropagation(),b()},"aria-haspopup":"listbox","aria-expanded":y,children:[e.jsx("span",{className:"ll-hpill__label",children:"English"}),e.jsx(me,{})]}),y&&e.jsx("div",{className:"ll-hmenu",onClick:h=>h.stopPropagation(),role:"listbox",children:e.jsx("button",{type:"button",className:"ll-hmenu__item is-active",role:"option","aria-selected":!0,children:e.jsx("span",{className:"ll-hmenu__name",children:"English"})})})]}),e.jsx("span",{className:`ll-expanded__state ll-expanded__state--${N}`,children:N})]}),e.jsx("button",{type:"button",className:"ll-hbtn",onClick:P,"aria-label":"Close widget",title:"Close",children:e.jsx(ze,{})})]}):e.jsxs("div",{className:"ll-expanded__header ll-expanded__header--idle",children:[e.jsx("span",{className:"ll-expanded__brand",children:p}),e.jsxs("div",{className:"ll-expanded__header-actions",children:[e.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:ie,"aria-label":"Minimize widget",children:e.jsx(kt,{})}),e.jsx("button",{type:"button",className:"ll-hbtn ll-hbtn--ghost",onClick:P,"aria-label":"Close widget",children:e.jsx(ze,{})})]})]}),oe&&e.jsxs("button",{type:"button",className:"ll-expanded__play",onClick:fe,"aria-label":M?"Resume session":"Start video call",children:[e.jsx("div",{className:"ll-expanded__play-circle",children:e.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:e.jsx("polygon",{points:"6 3 20 12 6 21 6 3"})})}),e.jsx("span",{className:"ll-expanded__play-label",children:M?"Restart session":"Start video call"}),M&&e.jsx("span",{className:"ll-expanded__play-sublabel",children:"Pick up where you left off"})]}),e.jsxs("div",{className:`ll-expanded__pip ${ee&&(v||T)?"is-visible":""}`,children:[e.jsx("div",{ref:te,className:T?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"}),e.jsx("div",{ref:ce,className:!T&&v?"ll-expanded__pip-host":"ll-expanded__pip-host is-hidden"})]}),ee?e.jsxs("div",{className:"ll-expanded__bottom",children:[de&&e.jsx("div",{className:"ll-expanded__transcript",children:e.jsx("p",{className:"ll-expanded__transcript-text",children:de})}),e.jsxs("div",{className:"ll-toolbar",onClick:h=>h.stopPropagation(),children:[I&&e.jsx("button",{type:"button",className:`ll-tool ${T?"is-on":""}`,onClick:H,"aria-label":T?"Stop sharing screen":"Share screen",title:T?"Stop sharing":"Share screen",children:e.jsx(jt,{})}),Z&&e.jsxs("div",{className:"ll-tool-split",children:[e.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${v?"is-on":""}`,onClick:D,"aria-label":v?"Turn off camera":"Turn on camera",title:v?"Stop camera":"Start camera",children:e.jsx(Ct,{})}),e.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${v?"is-on":""}`,onClick:h=>{h.stopPropagation(),q($=>!$),ne(!1)},"aria-label":"Camera devices","aria-haspopup":"listbox","aria-expanded":re,children:e.jsx(me,{})}),re&&G.length>0&&e.jsx(Pe,{label:"Camera",devices:G,activeId:Q,onPick:h=>{q(!1),he(h)}})]}),e.jsxs("div",{className:"ll-tool-split",children:[e.jsx("button",{type:"button",className:`ll-tool ll-tool--left ${S?"is-muted":""}`,onClick:Y,"aria-label":S?"Unmute microphone":"Mute microphone",title:S?"Unmute":"Mute",children:e.jsx(wt,{muted:S})}),e.jsx("button",{type:"button",className:`ll-tool ll-tool--right ${S?"is-muted":""}`,onClick:h=>{h.stopPropagation(),ne($=>!$),q(!1)},"aria-label":"Microphone devices","aria-haspopup":"listbox","aria-expanded":K,children:e.jsx(me,{})}),K&&k.length>0&&e.jsx(Pe,{label:"Microphone",devices:k,activeId:"",onPick:()=>ne(!1)})]}),e.jsx("button",{type:"button",className:`ll-tool ${U?"is-muted":""}`,onClick:O,"aria-label":U?"Unmute speaker":"Mute speaker",title:U?"Unmute speaker":"Mute speaker",children:e.jsx(St,{muted:U})})]}),ge&&e.jsxs("form",{className:"ll-message-input",onSubmit:A,children:[e.jsx("input",{type:"text",className:"ll-message-input__field",placeholder:"Message...",value:se,onChange:h=>le(h.target.value),"aria-label":"Message the agent"}),se.trim()&&e.jsx("button",{type:"submit",className:"ll-message-input__send","aria-label":"Send message",children:e.jsx(Et,{})})]}),e.jsx("button",{type:"button",className:"ll-expanded__end",onClick:ae,children:"End conversation"})]}):o&&e.jsx("div",{className:"ll-expanded__bottom ll-expanded__bottom--idle",children:e.jsx("div",{className:"ll-expanded__transcript",children:e.jsx("p",{className:"ll-expanded__transcript-text",children:o})})}),(()=>{if(_&&j!=="error")return e.jsxs("div",{className:"ll-expanded__banner",role:"alert",children:[e.jsx("span",{children:_}),e.jsx("button",{type:"button",className:"ll-expanded__banner-x",onClick:V,"aria-label":"Dismiss",children:"×"})]});if(!L||j!=="error")return null;let h="Failed to connect",$="Try again";return L==="MIC_PERMISSION_DENIED"?h="Microphone blocked. Allow access to talk.":L==="MIC_NOT_FOUND"?h="No microphone found. Plug one in + retry.":L==="MIC_UNAVAILABLE"?h="Mic unavailable. Check other apps using it.":L==="AGENT_TIMEOUT"?h="Agent didn't pick up. Try again.":L==="CONNECT_FAILED"?h="Connection failed. Check your network.":L.length<80&&(h=L),e.jsxs("div",{className:"ll-expanded__banner ll-expanded__banner--error",role:"alert",children:[e.jsx("span",{children:h}),e.jsx("button",{type:"button",className:"ll-expanded__banner-retry",onClick:be,children:$})]})})()]})};function me(){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":!0,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}function ze(){return e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function kt(){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round","aria-hidden":!0,children:e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function jt(){return e.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:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),e.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function Ct(){return e.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:[e.jsx("path",{d:"M23 7l-7 5 7 5V7z"}),e.jsx("rect",{x:"1",y:"5",width:"15",height:"14",rx:"2"})]})}function wt({muted:n}){return e.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:[e.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),e.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),n&&e.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function St({muted:n}){return e.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:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),n?e.jsx("line",{x1:"23",y1:"9",x2:"17",y2:"15"}):e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"}),e.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]})]})}function Et(){return e.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:[e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),e.jsx("polyline",{points:"12 5 19 12 12 19"})]})}const Pe=({label:n,devices:r,activeId:l,onPick:a})=>e.jsxs("div",{className:"ll-device-menu",onClick:s=>s.stopPropagation(),role:"listbox",children:[e.jsx("p",{className:"ll-device-menu__label",children:n}),r.map((s,o)=>{const d=l===s.deviceId;return e.jsxs("button",{type:"button",className:`ll-device-menu__item ${d?"is-active":""}`,onClick:()=>a(s.deviceId),role:"option","aria-selected":d,children:[d&&e.jsx("span",{className:"ll-device-menu__dot",children:"●"}),e.jsx("span",{className:"ll-device-menu__name",children:s.label||`${n} ${o+1}`})]},s.deviceId||o)})]}),Nt=new Set(["agent_state","avatar_stream_ready","avatar_active","avatar_idle","bot_ready","agent_error","idle_warning","idle_timeout"]);function Mt(n){var Se,Ee,Ne,Me,Re,Le;const{agentId:r,apiKey:l,baseUrl:a="https://app.livelayer.studio",sessionEndpoint:s,sessionBody:o,autoConnect:d=!1,displayMode:m,defaultDisplayMode:u="expanded",onDisplayModeChange:x,position:f="bottom-right",mobileBreakpoint:c=640,persistKey:i="ll-widget",disablePersistence:y=!1,teamMembers:b,currentTeamMemberId:j,onTeamMemberChange:N,idleLoopUrl:C,greeting:M,avatarImageUrl:R,agentName:L,branding:S={},allowCamera:_=!0,allowScreenShare:k=!0,allowTyping:v=!0,onConnect:E,onDisconnect:G,onTranscript:Q,onAgentState:T,onConnectionStateChange:z,onAgentEvent:U,onAgentCommand:Z,controlledSession:I,className:ge,style:ve,zIndex:fe=2147483647}=n,ae=j!==void 0,[be,ye]=t.useState(()=>{var g;return j??((g=b==null?void 0:b[0])==null?void 0:g.id)}),Y=ae?j:be,D=t.useMemo(()=>(b==null?void 0:b.find(g=>g.id===Y))??null,[b,Y]),he=(D==null?void 0:D.agentId)??r,[H,O]=Ge({value:m,defaultValue:u,onChange:x,persistKey:i,disablePersistence:y}),J=Ye(c),ie=Ue(),P=Oe(),V=Ve(),B=We(),W=Fe(),[ee,F]=t.useState(!1),[oe,ce]=t.useState(!1),[te,K]=t.useState(!1),[ne,re]=t.useState(!1),[q,se]=t.useState(!1),le=t.useCallback(g=>{const w=g;!w.type||typeof w.type!="string"||(U==null||U({eventName:w.type,data:g}),Nt.has(w.type)||Z==null||Z(w))},[Z,U]),A=$e({agentId:I?"__controlled__":he,baseUrl:a,apiKey:l,sessionEndpoint:s,sessionBody:o,onDataMessage:I?void 0:le});t.useEffect(()=>{if(I!=null&&I.subscribeToDataMessages)return I.subscribeToDataMessages(le)},[I,le]);const p=t.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:A.getRoom,isControlled:!0}:{connectionState:A.connectionState,agentState:A.agentState,transcript:A.transcript,videoElement:A.videoElement,audioElement:A.audioElement,canResume:A.canResume,error:A.error,agentConfig:A.agentConfig,connect:A.connect,disconnect:A.disconnect,getRoom:A.getRoom,isControlled:!1},[I,A]),de=t.useRef(null);t.useEffect(()=>{const g=p.videoElement,w=de.current;if(!(!g||!w))return w.appendChild(g),()=>{g.parentNode===w&&w.removeChild(g)}},[p.videoElement]),t.useEffect(()=>{const g=p.audioElement;if(!g)return;ie.attach(g);const w=g.play();return w&&typeof w.catch=="function"&&w.catch(X=>{(X==null?void 0:X.name)==="NotAllowedError"&&F(!0)}),()=>{ie.detach()}},[p.audioElement]),t.useEffect(()=>{if(p.isControlled||p.connectionState!=="connected")return;const g=p.getRoom();if(g)return P.setupMic(g).catch(()=>{}),V.attachRoom(g),B.attachRoom(g),W.refresh(),()=>{P.teardownMic(),V.teardown(),B.teardown()}},[p.isControlled,p.connectionState]),t.useEffect(()=>{const g=p.audioElement;g&&(g.muted=q)},[p.audioElement,q]);const _e=t.useCallback(g=>{const w=p.getRoom();if(w)try{const X=new TextEncoder().encode(JSON.stringify({type:"user_message",text:g}));w.localParticipant.publishData(X,{reliable:!0})}catch{}},[p]),pe=t.useCallback(()=>{se(g=>!g)},[]);t.useEffect(()=>{z==null||z(p.connectionState),p.connectionState==="connected"?E==null||E():p.connectionState==="disconnected"&&(G==null||G())},[p.connectionState,E,G,z]),t.useEffect(()=>{Q==null||Q(p.transcript)},[p.transcript,Q]),t.useEffect(()=>{T==null||T(p.agentState)},[p.agentState,T]);const h=t.useRef(!1);t.useEffect(()=>{p.isControlled||!d||h.current||p.connectionState==="idle"&&(h.current=!0,p.connect())},[d,p.connectionState,p]);const $=t.useCallback(g=>{const w=b==null?void 0:b.find(X=>X.id===g);w&&(K(!1),g!==Y&&(ce(!0),p.disconnect(),ae||ye(g),N==null||N(w)))},[b,Y,p,ae,N]);t.useEffect(()=>{oe&&p.connectionState==="connected"&&ce(!1)},[p.connectionState,oe]),t.useEffect(()=>{if(!te)return;const g=w=>{w.key==="Escape"&&K(!1)};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[te]);const Je=!!R||!!(D!=null&&D.avatarImageUrl)||p.isControlled,ke=Ke(he,a,Je),je=(D==null?void 0:D.name)??L??((Se=p.agentConfig)==null?void 0:Se.name)??((Ee=ke.info)==null?void 0:Ee.name)??"Live Layer",Ce=(D==null?void 0:D.avatarImageUrl)??R??((Ne=p.agentConfig)==null?void 0:Ne.avatarImageUrl)??((Me=ke.info)==null?void 0:Me.avatarImageUrl)??null,Xe=C??((Re=p.agentConfig)==null?void 0:Re.idleLoopUrl)??((Le=ke.info)==null?void 0:Le.idleLoopUrl)??null,Qe=M??null,Ze=t.useCallback(()=>O("expanded"),[O]),et=t.useCallback(()=>O("minimized"),[O]),we=t.useCallback(()=>O("hidden"),[O]),tt=t.useCallback(()=>{const g=p.audioElement;g&&g.play().then(()=>F(!1)).catch(()=>{})},[p.audioElement]),nt=t.useCallback(()=>{F(!1),p.connect()},[p]),ue={...ve,zIndex:fe};S.primaryColor&&(ue["--ll-color-primary"]=S.primaryColor),S.accentColor&&(ue["--ll-color-accent"]=S.accentColor),S.backgroundColor&&(ue["--ll-color-bg"]=S.backgroundColor),S.textColor&&(ue["--ll-color-fg"]=S.textColor);const rt=["ll-widget",`ll-widget--${H}`,`ll-widget--${J?"mobile":"desktop"}`,ge].filter(Boolean).join(" ");return e.jsxs("div",{className:rt,style:ue,"data-display-mode":H,"data-position":f,children:[H==="hidden"&&e.jsx(gt,{position:f,isMobile:J,isSpeaking:p.agentState==="speaking",onExpand:()=>O("expanded"),label:`Open ${je} widget`}),H==="minimized"&&e.jsx(bt,{position:f,isMobile:J,agentName:je,avatarImageUrl:Ce,agentState:p.agentState,isMuted:P.isMuted,audioLevel:ie,onExpand:Ze,onToggleMute:P.toggleMute,onClose:we}),H==="expanded"&&e.jsx(_t,{position:f,isMobile:J,agentName:je,avatarImageUrl:Ce,idleLoopUrl:Xe,greeting:Qe,branding:S,teamMembers:b,currentTeamMemberId:Y,isSwitchingTeamMember:oe,teamSwitcherOpen:te,onToggleTeamSwitcher:()=>K(g=>!g),onSelectTeamMember:$,connectionState:p.connectionState,agentState:p.agentState,transcript:p.transcript,isMuted:P.isMuted,micDevices:W.mics,isCameraEnabled:V.isEnabled,cameraPreviewEl:V.previewEl,cameraDevices:W.cameras,activeCameraId:V.activeDeviceId,isScreenShareEnabled:B.isEnabled,screenPreviewEl:B.previewEl,isSpeakerMuted:q,allowCamera:_,allowScreenShare:k,allowTyping:v,languageMenuOpen:ne,onToggleLanguageMenu:()=>re(g=>!g),needsUserGesture:ee,canResume:p.canResume,micError:P.micError,error:p.error,avatarVideoContainerRef:de,onConnect:()=>void p.connect(),onDisconnect:()=>p.disconnect(),onRetry:nt,onResumeAudio:tt,onToggleMute:P.toggleMute,onToggleCamera:()=>void V.toggle(),onSwitchCameraDevice:g=>void V.switchDevice(g),onToggleScreenShare:()=>void B.toggle(),onToggleSpeaker:pe,onSendMessage:_e,onMinimize:et,onClose:we,onClearMicError:P.clearError})]})}function Rt(n){return e.jsx(Be,{children:e.jsx(Mt,{...n})})}const Lt=({agentId:n,baseUrl:r,apiKey:l,mode:a,onAgentEvent:s,className:o,style:d})=>{const m=t.useRef(null),u=t.useRef(null),x=t.useRef(s);x.current=s;const f=t.useCallback(c=>{var y;const i=c.detail;(y=x.current)==null||y.call(x,i)},[]);return t.useEffect(()=>{const c=m.current;if(!c)return;const i=document.createElement("livelayer-widget");return i.setAttribute("agent-id",n),r&&i.setAttribute("base-url",r),l&&i.setAttribute("api-key",l),a&&i.setAttribute("mode",a),i.addEventListener("agent-event",f),c.appendChild(i),u.current=i,()=>{i.removeEventListener("agent-event",f),c.removeChild(i),u.current=null}},[n]),t.useEffect(()=>{u.current&&(a?u.current.setAttribute("mode",a):u.current.removeAttribute("mode"))},[a]),e.jsx("div",{ref:m,className:o,style:d})};function It(){const[n,r]=t.useState([]),l=t.useCallback(s=>{r(o=>{const d=o.findIndex(m=>m.id===s.id);if(d>=0){const m=o.slice();return m[d]=s,m}return[...o,s]})},[]),a=t.useCallback(()=>r([]),[]);return{entries:n,pushSegment:l,clear:a,latest:n.length>0?n[n.length-1]:null}}exports.AvatarWidget=Rt;exports.ErrorBoundary=Be;exports.LiveLayerWidget=Lt;exports.useAgentInfo=Ke;exports.useAudioLevel=Ue;exports.useCameraState=Ve;exports.useDisplayMode=qe;exports.useDisplayModePersistence=Ge;exports.useIsMobile=Ye;exports.useLiveKitSession=$e;exports.useMediaDevices=Fe;exports.useMicrophoneState=Oe;exports.useScreenShareState=We;exports.useTranscript=It;
|