@streamoji/avatar-widget 0.4.1 → 0.4.3

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.
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),Ze=require("@react-three/drei"),ft=require("@react-three/fiber"),t=require("react"),tn=require("three"),nn=require("three/examples/jsm/loaders/GLTFLoader.js");function rn(l){const y=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const _ in l)if(_!=="default"){const g=Object.getOwnPropertyDescriptor(l,_);Object.defineProperty(y,_,g.get?g:{enumerable:!0,get:()=>l[_]})}}return y.default=l,Object.freeze(y)}const He=rn(tn),qe="https://ai.streamoji.com",j=(...l)=>{},sn=(...l)=>{},Ot=({analyser:l})=>{const y=t.useRef(null),_=t.useRef(null);return t.useEffect(()=>{const g=y.current;if(!g)return;const x=g.getContext("2d",{alpha:!0});if(!x)return;let W,M=null;l&&(l.fftSize=128,M=new Uint8Array(l.frequencyBinCount));const Oe=()=>{W=requestAnimationFrame(Oe),(g.width!==g.offsetWidth||g.height!==g.offsetHeight)&&(g.width=g.offsetWidth,g.height=g.offsetHeight);const re=g.width,k=g.height;if(re===0||k===0)return;const be=k/2;x.clearRect(0,0,re,k),x.fillStyle="#1e293b";const z=2,h=z+2,Y=re*.95,b=Math.floor(Y/h);(!_.current||_.current.length!==b)&&(_.current=new Float32Array(b).fill(2));const X=b*h,L=(re-X)/2;l&&M&&l.getByteFrequencyData(M);const _e=M?M.length:0,Z=Math.floor(_e*.7)/b,he=new Float32Array(b);for(let I=0;I<b;I++){let $=0;if(M&&Z>0){const P=Math.floor(I*Z),B=Math.floor((I+1)*Z);for(let Ee=P;Ee<B;Ee++){const F=M[Ee]||0;F>$&&($=F)}}$<10&&($=0);const G=$/255,C=$>0?Math.max(2,Math.pow(G,1.4)*k*.25):2;he[I]=C}for(let I=0;I<b;I++){const $=b-1-I,G=Math.max(he[I],he[$]),C=_.current[I]+(G-_.current[I])*.3;_.current[I]=C;const P=L+I*h,B=be-C/2;x.beginPath(),x.roundRect?x.roundRect(P,B,z,C,4):x.fillRect(P,B,z,C),x.fill()}};return Oe(),()=>{cancelAnimationFrame(W)}},[l]),c.jsx("canvas",{ref:y,style:{width:"100%",height:"100%",display:"block"}})},on="https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev",Ct="https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";async function an(l){const y=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(l));return Array.from(new Uint8Array(y)).map(_=>_.toString(16).padStart(2,"0")).join("")}function cn(l){const[y,_]=t.useState(null);return t.useEffect(()=>{if(!l){_(null);return}let g=!1;return an(l).then(x=>{if(g)return;const W=`${on}/${x}.glb`;fetch(W,{method:"HEAD"}).then(M=>{g||_(M.ok?W:Ct)}).catch(()=>{g||_(Ct)})}),()=>{g=!0}},[l]),y}const un=["https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_001.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_002.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_002.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_005.glb"],ln=["https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_001.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb"],dn=[{id:"m_expr_01",name:"Friendly Wave",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_001.glb"},{id:"m_expr_02",name:"You There",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_002.glb"},{id:"m_expr_04",name:"Awkward Agreement",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_004.glb"},{id:"m_expr_05",name:"What's Going On?",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_005.glb"},{id:"m_expr_06",name:"Tired Stretch",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_006.glb"},{id:"m_expr_07",name:"Conceilied Laughter",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_007.glb"},{id:"m_expr_08",name:"You Come Here",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_008.glb"},{id:"m_expr_09",name:"Come Here Kid",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_009.glb"},{id:"m_expr_10",name:"Come Here Everyone",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_010.glb"},{id:"m_expr_11",name:"No Freaking Way",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_011.glb"},{id:"m_expr_12",name:"Cheerful Approval",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_012.glb"},{id:"m_expr_13",name:"Waving Hello",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_013.glb"},{id:"m_expr_14",name:"Checking Surroundings",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_014.glb"},{id:"m_expr_15",name:"Referee Warning",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_015.glb"},{id:"m_expr_16",name:"You Thumbs Down",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_016.glb"},{id:"m_expr_17",name:"Side Thumbs Down",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_017.glb"},{id:"m_expr_18",name:"You're Finished",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_018.glb"},{id:"m_talk_01",name:"Oh God, Why Me?",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_001.glb"},{id:"m_talk_02",name:"What Are You Doing?",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_002.glb"},{id:"m_talk_03",name:"What Am I doing?",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_003.glb"},{id:"m_talk_04",name:"No Way",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_004.glb"},{id:"m_talk_05",name:"What's Going On?",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb"},{id:"m_talk_06",name:"I have no idea",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_006.glb"},{id:"m_talk_07",name:"What's going on here?",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb"},{id:"m_talk_08",name:"Let's stop",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_008.glb"},{id:"m_talk_09",name:"Fed Up Moment",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_009.glb"},{id:"m_talk_10",name:"What's This? Hold On",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_010.glb"},{id:"f_talk_01",name:"Great Job Clap",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_001.glb"},{id:"f_talk_02",name:"Chill Stretch",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_002.glb"},{id:"f_talk_03",name:"This Is Me",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_003.glb"},{id:"f_talk_04",name:"Empathize",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_004.glb"},{id:"f_talk_05",name:"Loose Hands Stretch",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_005.glb"},{id:"f_talk_06",name:"Take It Easy",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb"}],hn=["https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_006.glb"],fn=["https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_004.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_005.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_002.glb"],mn={zoom:.85,position:[.15,-.8,0],scale:1.5,rotation:[.15,.02,0]},pn=[-.45,1.9,.1],gn=[-.45,1.75,.1],bn={browInnerUp:.2},dt=.18,_n=1,Ft="__branding__",Xe={neutral:{eyeLookDownLeft:.1,eyeLookDownRight:.1},happy:{mouthSmileLeft:.2,mouthSmileRight:.2,eyeLookDownLeft:.1,eyeLookDownRight:.1},sad:{eyeLookDownLeft:.2,eyeLookDownRight:.2,browDownRight:.1,browInnerUp:.6,browOuterUpRight:.2,eyeSquintLeft:.7,eyeSquintRight:.7,mouthFrownLeft:.8,mouthFrownRight:.8,mouthLeft:.2,mouthPucker:.5,mouthRollLower:.2,mouthRollUpper:.2,mouthShrugLower:.2,mouthShrugUpper:.2,mouthStretchLeft:.4},angry:{eyeLookDownLeft:.1,eyeLookDownRight:.1,browDownLeft:.6,browDownRight:.6,jawForward:.3,mouthFrownLeft:.7,mouthFrownRight:.7,mouthRollLower:.2,mouthShrugLower:.3},fear:{browInnerUp:.7,eyeSquintLeft:.5,eyeSquintRight:.5,eyeWideLeft:.6,eyeWideRight:.6,mouthClose:.1,mouthFunnel:.3,mouthShrugLower:.5,mouthShrugUpper:.5},disgust:{browDownLeft:.7,browDownRight:.1,browInnerUp:.3,eyeSquintLeft:1,eyeSquintRight:1,eyeWideLeft:.5,eyeWideRight:.5,mouthLeft:.4,mouthPressLeft:.3,mouthRollLower:.3,mouthShrugLower:.3,mouthShrugUpper:.8,mouthUpperUpLeft:.3,noseSneerLeft:1,noseSneerRight:.7},love:{browInnerUp:.4,browOuterUpLeft:.2,browOuterUpRight:.2,mouthSmileLeft:.2,mouthSmileRight:.2,eyeBlinkLeft:.6,eyeBlinkRight:.6,eyeWideLeft:.7,eyeWideRight:.7,mouthDimpleLeft:.1,mouthDimpleRight:.1,mouthPressLeft:.2,mouthShrugUpper:.2,mouthUpperUpLeft:.1,mouthUpperUpRight:.1}},wn=[{key:"viseme_aa",mix:{jawOpen:.4,mouthSmileLeft:.15,mouthSmileRight:.15},teethMix:{jawOpen:.2,mouthSmileLeft:.15,mouthSmileRight:.15}},{key:"viseme_E",mix:{mouthPressLeft:.65,mouthPressRight:.65,mouthDimpleLeft:1,mouthDimpleRight:1,jawOpen:.25,mouthFunnel:.1},teethMix:{jawOpen:.15,mouthPressLeft:.65,mouthPressRight:.65,mouthDimpleLeft:1,mouthDimpleRight:1,mouthFunnel:.1}},{key:"viseme_I",mix:{mouthPressLeft:.55,mouthPressRight:.55,mouthDimpleLeft:1,mouthDimpleRight:1,jawOpen:.15,mouthFunnel:.05},teethMix:{mouthPressLeft:.55,mouthPressRight:.55,mouthDimpleLeft:1,mouthDimpleRight:1,jawOpen:.15,mouthFunnel:.05}},{key:"viseme_O",mix:{mouthPucker:.7,jawOpen:.4,mouthFunnel:.25},teethMix:{jawForward:.6,jawOpen:.2,mouthPucker:.7,mouthFunnel:.25}},{key:"viseme_U",mix:{mouthFunnel:1,mouthClose:.2},teethMix:{mouthFunnel:1,mouthClose:.2}},{key:"viseme_PP",mix:{mouthDimpleLeft:.5,mouthDimpleRight:.5,mouthStretchLeft:.3,mouthStretchRight:.3,mouthRollLower:.3,mouthRollUpper:.3,mouthPressLeft:.5,mouthPressRight:.5},teethMix:{mouthDimpleLeft:.5,mouthDimpleRight:.5,mouthStretchLeft:.3,mouthStretchRight:.3,mouthRollLower:.3,mouthRollUpper:.3,mouthPressLeft:.5,mouthPressRight:.5}},{key:"viseme_FF",mix:{mouthPucker:1,mouthShrugUpper:1,mouthDimpleLeft:1,mouthDimpleRight:1,mouthStretchLeft:.5,mouthStretchRight:.5,mouthPressLeft:.3,mouthPressRight:.3,mouthRollLower:.1},teethMix:{mouthPucker:1,mouthShrugUpper:1,mouthDimpleLeft:1,mouthDimpleRight:1,mouthStretchLeft:.5,mouthStretchRight:.5,mouthPressLeft:.3,mouthPressRight:.3,mouthRollLower:.1}},{key:"viseme_DD",mix:{mouthShrugUpper:.25,mouthShrugLower:.25,mouthPressLeft:.4,mouthPressRight:.4,mouthFunnel:.7,jawOpen:.1},teethMix:{mouthShrugUpper:.25,mouthShrugLower:.25,mouthPressLeft:.4,mouthPressRight:.4,mouthFunnel:.7,jawOpen:.1}},{key:"viseme_SS",mix:{mouthPressLeft:.8,mouthPressRight:.8,mouthLowerDownLeft:.3,mouthLowerDownRight:.3,jawOpen:.1},teethMix:{mouthPressLeft:.8,mouthPressRight:.8,mouthLowerDownLeft:.3,mouthLowerDownRight:.3,jawOpen:.1}},{key:"viseme_TH",mix:{mouthStretchLeft:.4,mouthStretchRight:.4,mouthDimpleLeft:1,mouthDimpleRight:1,mouthFunnel:.4,jawOpen:.15,mouthShrugLower:.45,mouthShrugUpper:.45},teethMix:{mouthStretchLeft:.4,mouthStretchRight:.4,mouthDimpleLeft:1,mouthDimpleRight:1,mouthFunnel:.4,jawOpen:.15,mouthShrugLower:.45,mouthShrugUpper:.45}},{key:"viseme_CH",mix:{mouthPucker:.8,mouthShrugLower:.7,mouthShrugUpper:.2,mouthLowerDownLeft:.6,mouthLowerDownRight:.6,mouthDimpleLeft:.5,mouthDimpleRight:.5,mouthUpperUpLeft:.8,mouthUpperUpRight:.8,jawOpen:.2},teethMix:{mouthPucker:.8,mouthShrugLower:.7,mouthShrugUpper:.2,mouthLowerDownLeft:.6,mouthLowerDownRight:.6,mouthDimpleLeft:.5,mouthDimpleRight:.5,mouthUpperUpLeft:.8,mouthUpperUpRight:.8,jawOpen:.2}},{key:"viseme_RR",mix:{mouthPucker:.4,jawOpen:.2,mouthShrugUpper:.5,mouthFunnel:.15,mouthDimpleLeft:.5,mouthDimpleRight:.5},teethMix:{mouthPucker:.4,jawOpen:.2,mouthShrugUpper:.5,mouthFunnel:.15,mouthDimpleLeft:.5,mouthDimpleRight:.5}},{key:"viseme_kk",mix:{mouthPucker:.5,jawOpen:.2,mouthShrugUpper:.5,mouthFunnel:.2,mouthDimpleLeft:.5,mouthDimpleRight:.5},teethMix:{mouthPucker:.5,jawOpen:.2,mouthShrugUpper:.5,mouthFunnel:.2,mouthDimpleLeft:.5,mouthDimpleRight:.5}},{key:"viseme_nn",mix:{mouthPucker:.6,jawOpen:.2,mouthShrugUpper:.7,mouthShrugLower:.1,mouthFunnel:.1,mouthDimpleLeft:.8,mouthDimpleRight:.8},teethMix:{mouthPucker:.6,jawOpen:.2,mouthShrugUpper:.7,mouthShrugLower:.1,mouthFunnel:.1,mouthDimpleLeft:.8,mouthDimpleRight:.8}},{key:"viseme_sil",mix:{}}],Sn={aei:[{v:"E",w:.8},{v:"I",w:.2}],ee:[{v:"I",w:1}],oo:[{v:"O",w:1}],u:[{v:"U",w:1}],aa:[{v:"aa",w:1}],ah:[{v:"aa",w:.7},{v:"O",w:.3}],bmp:[{v:"PP",w:1}],fv:[{v:"FF",w:1}],th:[{v:"TH",w:1}],l:[{v:"nn",w:1}],r:[{v:"RR",w:1}],qw:[{v:"U",w:.6},{v:"O",w:.4}],chjsh:[{v:"CH",w:1}],cdgknstxyz:[{v:"DD",w:.6},{v:"SS",w:.4}],sil:[{v:"sil",w:1}]};function xn(l){if(!l)return[{v:"sil",w:1}];const y=l.toLowerCase();return Sn[y]??[{v:"sil",w:1}]}function vn({target:l}){const{camera:y}=ft.useThree();return t.useEffect(()=>{y.lookAt(...l)},[y,l]),null}function A(l,y,_){if(!l||!l.morphTargetDictionary)return;const g=l,x=g.morphTargetDictionary,W=g.morphTargetInfluences;if(W)for(const M in x)M.toLowerCase()===y.toLowerCase()&&(W[x[M]]=_)}function ht(l,y=.97){if(!l)return;const _=l;if(_.morphTargetInfluences)for(let g=0;g<_.morphTargetInfluences.length;g++)_.morphTargetInfluences[g]*=y}const yn=t.memo(({avatarUrl:l,isPlayingRef:y,visemeQueueRef:_,audioContextRef:g,responseAudioStartTimeRef:x,adjustments:W,mood:M,expression:Oe,agentResponse:re,isSpeaking:k,nextStartTimeRef:be,stopPlayback:z,setIsSpeaking:V,expressionUrl:h,onExpressionFinished:Y,isNudgeResponse:b,avatarGender:X})=>{const{scene:L}=Ze.useGLTF(l),_e=X==="female"?ln:un,ke=Ze.useGLTF(_e),Z=t.useMemo(()=>ke.flatMap(m=>m.animations),[ke]),he=X==="female"?fn:hn,I=Ze.useGLTF(he),$=t.useMemo(()=>I.flatMap(m=>m.animations),[I]),G=t.useRef(null),C=t.useRef(null),P=t.useRef(null),B=t.useRef(null),Ee=t.useRef([]),[F]=t.useState(()=>new He.AnimationMixer(L)),N=t.useRef({}),D=t.useRef(null),we=t.useRef(0),Ce=t.useRef(!1),Se=t.useRef(0),ce=t.useRef(null);t.useEffect(()=>{if(!(!Z||!L)){if(Z.forEach((m,d)=>{const o=`idle_${d}`;if(!N.current[o]){const a=F.clipAction(m,L);a.name=o,a.setLoop(He.LoopOnce,1),a.clampWhenFinished=!0,N.current[o]=a}}),$.forEach((m,d)=>{const o=`talk_${d}`;if(!N.current[o]){const a=F.clipAction(m,L);a.name=o,a.setLoop(He.LoopOnce,1),a.clampWhenFinished=!0,N.current[o]=a}}),Z.length>0){const m=N.current.idle_0,d=D.current&&F.existingAction(D.current.getClip());m&&!d&&(m.reset().fadeIn(.5).play(),D.current=m)}return()=>{F.stopAllAction(),N.current={},D.current=null}}},[Z,$,L,F]);const fe=t.useRef("");t.useEffect(()=>{if(!h||!L||h===fe.current)return;fe.current=h,ce.current=h,new nn.GLTFLoader().load(h,d=>{if(d.animations&&d.animations.length>0){const o=d.animations[0],a=F.clipAction(o,L);if(a.name=`EXPR_${h}`,a.setLoop(He.LoopOnce,1),a.clampWhenFinished=!0,N.current[`EXPR_${h}`]=a,k&&ce.current===h){const f=D.current;a.reset().fadeIn(.3).play(),f&&f!==a&&f.crossFadeTo(a,.3,!0),D.current=a,ce.current=null}}},void 0,d=>{console.error(`[ANIMATION] Failed to load ${h}`,d)})},[h,L,F,k]),t.useEffect(()=>{const m=d=>{const o=d.action,a=o.name||"";if(a.startsWith("idle_")){const T=(parseInt(a.split("_")[1])+1)%Z.length,K=N.current[`idle_${T}`];K&&(K.reset().fadeIn(.5).play(),o.crossFadeTo(K,.5,!0),D.current=K)}else if(a.startsWith("EXPR_")){if(k){const f=Math.floor(Math.random()*$.length),T=N.current[`talk_${f}`];T&&(T.reset().fadeIn(.5).play(),o.crossFadeTo(T,.5,!0),D.current=T)}else{const f=N.current.idle_0;f&&(f.reset().fadeIn(.5).play(),o.crossFadeTo(f,.5,!0),D.current=f)}Y&&Y()}else if(a.startsWith("talk_"))if(k&&!b){const T=(parseInt(a.split("_")[1])+1)%$.length,K=N.current[`talk_${T}`];K&&(K.reset().fadeIn(.3).play(),o.crossFadeTo(K,.3,!0),D.current=K)}else{const f=N.current.idle_0;f&&(f.reset().fadeIn(.5).play(),o.crossFadeTo(f,.5,!0),D.current=f)}};return F.addEventListener("finished",m),()=>F.removeEventListener("finished",m)},[F,Z,$,k,b,Y]),t.useEffect(()=>{if(k&&L){const m=D.current,d=m?.name||"";if(d.startsWith("idle_")||d.startsWith("talk_")||d===""){const o=ce.current;if(o){const a=N.current[`EXPR_${o}`];if(a){a.reset().fadeIn(.3).play(),m&&m!==a&&m.crossFadeTo(a,.3,!0),D.current=a,ce.current=null;return}}if(d.startsWith("idle_")||d===""){const a=Math.floor(Math.random()*$.length),f=N.current[`talk_${a}`];f&&(f.reset().fadeIn(.5).play(),m&&m.crossFadeTo(f,.5,!0),D.current=f)}}}else if(!k&&L){const m=D.current,d=m?.name||"";if(d.startsWith("talk_")||d.startsWith("EXPR_")){const o=N.current.idle_0;o&&(o.reset().fadeIn(.5).play(),m&&m.crossFadeTo(o,.5,!0),D.current=o)}}},[k,L,h]),t.useEffect(()=>{if(!L)return;L.traverse(o=>{if(o.isMesh&&o.morphTargetDictionary){const a=o.name.toLowerCase();(a.includes("head")||a.includes("avatar"))&&(C.current=o,j(`[ANIMATION] Found head mesh: ${o.name}`)),a.includes("teeth")&&(P.current=o,j(`[ANIMATION] Found teeth mesh: ${o.name}`)),a.includes("beard")&&(B.current=o,j(`[ANIMATION] Found beard mesh: ${o.name}`))}});const m=C.current?.morphTargetDictionary;m&&Object.keys(m).filter(o=>o.toLowerCase().includes("brow"));const d=[];L.traverse(o=>{if(o.isMesh){const f=o.morphTargetDictionary;f&&Object.keys(f).some(T=>T.toLowerCase().includes("brow"))&&d.push(o)}}),Ee.current=d,d.length>0&&j("[ANIMATION] Meshes with brow morphs:",d.length)},[L]);const Pe=(m,d=1)=>{const o=`viseme_${m}`.toLowerCase(),a=wn.find(f=>f.key.toLowerCase()===o);if(a){for(const f in a.mix){const T=a.mix[f]*d;A(C.current,f,T),A(B.current,f,T),(!a.teethMix||!(f in a.teethMix))&&A(P.current,f,T)}if(a.teethMix)for(const f in a.teethMix){const T=a.teethMix[f]*d;A(P.current,f,T)}}},xe=m=>{const d=Xe[m]??Xe.neutral;for(const o in d)A(C.current,o,d[o]),A(P.current,o,d[o]),A(B.current,o,d[o])};return ft.useFrame((m,d)=>{const o=Math.pow(.88,60*d);ht(C.current,o),ht(P.current,o),ht(B.current,o),xe(M);const a=m.clock.elapsedTime;let f=0;if(Math.floor(a)%5===0&&Math.floor((a-d)%5)!==0){let H=null;L.traverse(J=>{J.name.toLowerCase().includes("hips")&&(H=J)});const ye=H?`Hips Y: ${H.position.y.toFixed(4)}`:"Hips not found";j(`[ANIMATION] Mixer Time: ${F.time.toFixed(2)}, ${ye}`)}if(F.update(d),a>we.current&&!Ce.current&&(Ce.current=!0,Se.current=a),Ce.current){const H=k?.2:.3,ye=(a-Se.current)/H;if(ye>=1){Ce.current=!1;const J=k?1:2.5;we.current=a+J}else{const J=ye<.5?ye*2:(1-ye)*2;A(C.current,"eyeBlinkLeft",J),A(C.current,"eyeBlinkRight",J),A(P.current,"eyeBlinkLeft",J),A(P.current,"eyeBlinkRight",J),A(B.current,"eyeBlinkLeft",J),A(B.current,"eyeBlinkRight",J),f=J*bn.browInnerUp}}const T=Xe[M]??Xe.neutral,K=T.browInnerUp??0,et=T.browOuterUpLeft??0,Je=T.browOuterUpRight??0,Be=a*_n,Te=dt*Math.sin(Be),ee=dt*.7*Math.sin(Be+.7),Ge=dt*.7*Math.sin(Be+1.3),se=H=>Math.max(0,Math.min(1,H)),Ae=se(K+Te),ve=se(et+ee),Fe=se(Je+Ge),Me=se(Ae+f);if(A(C.current,"browInnerUp",Me),A(P.current,"browInnerUp",Me),A(B.current,"browInnerUp",Me),A(C.current,"browOuterUpLeft",ve),A(P.current,"browOuterUpLeft",ve),A(B.current,"browOuterUpLeft",ve),A(C.current,"browOuterUpRight",Fe),A(P.current,"browOuterUpRight",Fe),A(B.current,"browOuterUpRight",Fe),G.current){const H=y.current?0:W.rotation[1];G.current.rotation.y=He.MathUtils.lerp(G.current.rotation.y,H,.1),G.current.position.set(...W.position),G.current.scale.setScalar(W.scale),G.current.rotation.x=W.rotation[0],G.current.rotation.z=W.rotation[2]}if(y.current&&g.current){const H=g.current.currentTime,Ne=(H-x.current)*1e3- -150;for(let te=0;te<_.current.length;te++){const ie=_.current[te];Ne>=ie.vtime&&Ne<ie.vtime+ie.vduration&&Pe(ie.viseme,ie.weight??1)}H>be.current+.5&&(z(),V(!1))}}),c.jsx("group",{ref:G,children:c.jsx("primitive",{object:L})})});function Rn(l){return l?l.charAt(0).toUpperCase()+l.slice(1).toLowerCase():""}function Nt(l){return l.replace(/\*(.*?)\*/g," $1 ").replace(/\[.*?\]/g," ").replace(/<.*?\/>/g," ").replace(/<.*?>.*?<\/.*?>/g," ").replace(/\s+/g," ").trim()}const Ln=({token:l,agentToken:y,onNavigationRequested:_,avatarGender:g,presetUserDetails:x,onAvatarReady:W}={})=>{const M=l??y??"",Oe=cn(M||void 0),[re,k]=t.useState(""),[be,z]=t.useState(""),[V,h]=t.useState("Ready"),[Y,b]=t.useState(!1),[X,L]=t.useState(!1),[_e,ke]=t.useState([]),[Z,he]=t.useState(""),I=t.useRef(null),[$,G]=t.useState(()=>typeof window<"u"?window.matchMedia("(max-width: 480px)").matches:!1);t.useEffect(()=>{const e=window.matchMedia("(max-width: 480px)"),n=()=>G(e.matches);return e.addEventListener("change",n),()=>e.removeEventListener("change",n)},[]);const C=$?80:600,P=t.useRef(!1),B=t.useRef([]),Ee=t.useRef(0),F=t.useRef(!1),N=t.useRef([]),D=t.useRef(null),we=t.useRef([]);t.useRef([]);const Ce=t.useRef([]),Se=t.useRef(0),ce=t.useRef(0),fe=t.useRef(0),Pe=t.useRef(0),xe=t.useRef(!1),[m,d]=t.useState(null),o=t.useRef(null),[a,f]=t.useState("neutral"),[T,K]=t.useState(""),[et,Je]=t.useState(""),[Be,Te]=t.useState("Chat with us"),[ee,Ge]=t.useState(null),[se,Ae]=t.useState("hidden"),[ve,Fe]=t.useState(""),Me=t.useRef(null),H=t.useRef(se);H.current=se;const[ye,J]=t.useState(null),Ne=t.useRef(null),te=t.useRef(null),[ie,mt]=t.useState(!1),pt=t.useRef(null),[ue,ze]=t.useState("hidden"),[gt,Ut]=t.useState(""),tt=t.useRef(ue);tt.current=ue;const ne=t.useRef(""),me=t.useRef(!1),pe=t.useRef(""),bt=t.useRef(Date.now()),nt=t.useRef([]),We=t.useRef(!1),[rt,Ve]=t.useState(!1),[_t,wt]=t.useState(!1),Re=t.useRef(null),Ue=t.useMemo(()=>ie?"Try again":V==="Busy"?"Busy":V==="Thinking..."||V==="Processing Voice..."?V:ee!=null&&ee!==""&&ee!=="none"&&ee!=="<none>"?`Enter ${Rn(ee)}`:ue!=="hidden"||!_t?null:Ft,[V,ee,ie,ue,_t]),St=!ie&&V!=="Busy"&&V!=="Thinking..."&&V!=="Processing Voice..."&&(ee==null||ee===""||ee==="none"||ee==="<none>");t.useEffect(()=>{if(ue!=="hidden"||!St){wt(!1),Re.current!=null&&(clearTimeout(Re.current),Re.current=null);return}return Re.current=setTimeout(()=>{Re.current=null,wt(!0)},400),()=>{Re.current!=null&&(clearTimeout(Re.current),Re.current=null)}},[ue,St]);const Ye=Ue!=null&&Ue!=="";t.useEffect(()=>{const e=H.current;if(!(e==="exiting"||e==="entering")){if(e==="hidden"){Ye&&(Fe(Ue??""),Ae("entering"));return}e==="visible"&&(!Ye||Ue!==ve)&&(Me.current=Ye?Ue:null,Ae("exiting"))}},[Ye,Ue,se,ve]),t.useEffect(()=>{if(V!=="Busy"){te.current!=null&&(clearTimeout(te.current),te.current=null);return}return te.current=setTimeout(()=>{te.current=null,h("Ready"),mt(!0)},12e3),()=>{te.current!=null&&(clearTimeout(te.current),te.current=null)}},[V]),t.useEffect(()=>{if(!ie)return;const e=setTimeout(()=>mt(!1),2500);return()=>clearTimeout(e)},[ie]);const jt=t.useCallback(()=>{const e=H.current;if(e==="exiting"){Ae("hidden");const n=Me.current;Me.current=null,n!=null&&n!==""&&(Fe(n),Ae("entering"))}else e==="entering"&&Ae("visible")},[]),Pt=e=>{if(!e)return;if(e.mood!=null){const s=String(e.mood).toLowerCase();f(s)}if(e.expression!=null){const s=String(e.expression).trim();K(s);const u=dn.find(p=>p.name.toLowerCase()===s.toLowerCase());j(`[STREAM] Animation match for "${s}": ${u?u.name:"NONE"}`),Je(u?.url??"")}if(e.navigation!=null){const s=String(e.navigation).trim();s!==""&&(_?_(s):window.open(s,"_blank"))}const n=e.ask_for||e.lead_capture?.ask_for,r=n?String(n).trim().toLowerCase():"",i=r==="none"||r==="<none>";if(n&&!i){const s=r;if(x&&(s==="email"&&x.email||s==="name"&&x.name||s==="phone"&&x.phone))return;Ge(s||null),Te(s==="email"?"Enter your email":s==="name"?"Enter your name":s==="phone"?"Enter your phone number":"Chat with us")}else(i||e.ask_for===null||e.lead_capture&&e.lead_capture.ask_for===null||e.ask_for==="none")&&(Ge(null),Be!=="Chat with us"&&Te("Chat with us"));e.collected,e.valid},Bt=e=>{const n=e.trim();if(!n)return null;if(n.startsWith("{"))try{return JSON.parse(n)}catch{return null}if(n.includes(":")){const r=n.split(":"),i=r[0].trim().toLowerCase(),s=r.slice(1).join(":").trim();return{[i]:s}}return null},Wt=t.useCallback(()=>{},[]),Le="§",st=()=>{for(;ne.current.includes(`
2
- `);){const e=ne.current.indexOf(`
3
- `),n=ne.current.slice(0,e).trim();ne.current=ne.current.slice(e+1);const r=Bt(n);r&&Pt(r)}},xt=e=>{if(me.current)if(e.includes(Le)){const n=e.indexOf(Le),r=e.slice(0,n),i=e.slice(n+Le.length);r&&(pe.current+=r,z(s=>s+r)),me.current=!1,i&&(ne.current+=i,st())}else e===Le?me.current=!1:(pe.current+=e,z(n=>n+e));else if(e.includes(Le)){const n=e.indexOf(Le),r=e.slice(0,n),i=e.slice(n+Le.length);ne.current+=r,st(),me.current=!0,i&&(pe.current+=i,z(s=>s+i))}else if(e===Le){me.current=!0;return}else ne.current+=e,st()};t.useEffect(()=>{(async()=>{if(!sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID")){const s="secret",u=Math.floor(Date.now()/1e3).toString();try{const p=new TextEncoder,w=await crypto.subtle.importKey("raw",p.encode(s),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),v=await crypto.subtle.sign("HMAC",w,p.encode(u)),S=Array.from(new Uint8Array(v)).map(E=>E.toString(16).padStart(2,"0")).join("");sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",S),j("[SESSION] New HMAC UID generated and saved:",S)}catch(p){console.error("[SESSION] HMAC generation failed:",p);const w=Math.random().toString(36)+Date.now().toString();sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",w)}}const r=sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");let i=[];if(r)try{i=JSON.parse(r)}catch{i=[]}i.length===0&&x&&(x.name||x.email)?(i=[{role:"user",content:`PRESET_USER_DETAILS: Name is "${x.name||""}" , Email is "${x.email||""}"`}],sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES",JSON.stringify(i))):r||sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES",JSON.stringify([]))})()},[x]),t.useEffect(()=>{const e=()=>{bt.current=Date.now(),We.current&&(We.current=!1,Ve(!1),ke([]),he(""),z(""),L(!1))};window.addEventListener("mousemove",e),window.addEventListener("keydown",e),window.addEventListener("mousedown",e),window.addEventListener("touchstart",e);const n=setInterval(async()=>{if(Date.now()-bt.current>=3e4&&!X&&!Y&&V==="Ready"&&!We.current)if(We.current=!0,nt.current.length>0)Ve(!0),ke(nt.current);else try{const s=`${qe}/nudgeUser`,u={navigationUrl:window.location.href,token:M},p=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});if(p.ok){const v=(await p.json()).nudge_questions;v&&v.length>0&&(j("[NUDGE] Received nudge questions from API:",v),nt.current=v,Ve(!0),ke(v))}}catch(s){console.error("[NUDGE] Error calling /nudgeUser:",s),We.current=!1}},1e3);return()=>{window.removeEventListener("mousemove",e),window.removeEventListener("keydown",e),window.removeEventListener("mousedown",e),window.removeEventListener("touchstart",e),clearInterval(n)}},[M,X,Y,V]),t.useEffect(()=>{if(_e.length===0)return;let e=0,n=0,r=!1,i=100;const s=()=>{const u=_e[e];if(r){const p=u.substring(0,n-1);he(p),n--,i=50}else{const p=u.substring(0,n+1);he(p),n++,i=100}!r&&n===u.length?(r=!0,i=3e3):r&&n===0&&(r=!1,e=(e+1)%_e.length,i=500),I.current=setTimeout(s,i)};return s(),()=>{I.current&&clearTimeout(I.current)}},[_e]);const vt=()=>{try{return JSON.parse(sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES")||"[]")}catch{return[]}},Vt=e=>{sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES",JSON.stringify(e))},[it,ot]=t.useState(!1),[yt,at]=t.useState(0),le=t.useRef(null),Ke=t.useRef([]),Rt=t.useRef(0),[Lt,$t]=t.useState(null),[Ht,ct]=t.useState(null),ge=t.useRef(null),Ie=t.useRef(null),$e=t.useCallback((e=!1)=>{e&&(xe.current=!0,b(!1),h("Ready")),N.current=[],B.current=[],F.current=!1,L(!1),Se.current=0,ce.current=0,fe.current=0,we.current.forEach(n=>{try{n.stop()}catch{}}),Ne.current&&(clearTimeout(Ne.current),Ne.current=null),J(null),Je(""),we.current=[]},[]),qt=async()=>{try{const e=await navigator.mediaDevices.getUserMedia({audio:!0}),n=window.AudioContext||window.webkitAudioContext,r=new n,i=r.createMediaStreamSource(e),s=r.createAnalyser();s.fftSize=64,i.connect(s),ge.current=r,Ie.current=i,ct(s);const u=new MediaRecorder(e);le.current=u,Ke.current=[],u.ondataavailable=p=>{p.data.size>0&&Ke.current.push(p.data)},u.onstop=async()=>{const p=Date.now()-Rt.current;if(ct(null),Ie.current&&(Ie.current.disconnect(),Ie.current=null),ge.current&&ge.current.state!=="closed"&&(ge.current.close(),ge.current=null),p<1e3){h("Recording too short. Hold or click longer."),b(!1);return}const w=new Blob(Ke.current,{type:"audio/wav"});await Yt(w)},Rt.current=Date.now(),u.start(100),ot(!0),h("Listening...")}catch(e){console.error("Error accessing microphone:",e),h("Mic Access Error")}},Jt=()=>{le.current&&le.current.state!=="inactive"&&(le.current.stop(),le.current.stream.getTracks().forEach(e=>e.stop()),ot(!1))},Gt=()=>{le.current&&le.current.state!=="inactive"&&(le.current.onstop=null,le.current.stop(),le.current.stream.getTracks().forEach(e=>e.stop()),ct(null),Ie.current&&(Ie.current.disconnect(),Ie.current=null),ge.current&&ge.current.state!=="closed"&&(ge.current.close(),ge.current=null),ot(!1),Ke.current=[],h("Ready"))};t.useEffect(()=>{if(!X)return;const e=()=>{const n=fe.current;if(n<=0)return;const r=D.current,i=Se.current;if(!r)return;const s=r.currentTime-i,u=Math.min(Math.max(0,s),n),w=Nt(be).trim().length;if(w<=0)return;const v=Math.min(Math.round(u/n*w),w);d(v)};return clearInterval(o.current??void 0),o.current=setInterval(e,90),()=>clearInterval(o.current??void 0)},[X,be,fe.current]),t.useEffect(()=>{let e;return it?(at(0),e=window.setInterval(()=>{at(n=>n+1)},1e3)):at(0),()=>clearInterval(e)},[it]);const zt=e=>{const n=e.numberOfChannels,r=e.length*n*2+44,i=new ArrayBuffer(r),s=new DataView(i);let u=0;const p=S=>{s.setUint16(u,S,!0),u+=2},w=S=>{s.setUint32(u,S,!0),u+=4};w(1179011410),w(r-8),w(1163280727),w(544501094),w(16),p(1),p(n),w(e.sampleRate),w(e.sampleRate*2*n),p(n*2),p(16),w(1635017060),w(r-u-4);const v=[];for(let S=0;S<n;S++)v.push(e.getChannelData(S));let R=0;for(;u<r;){for(let S=0;S<n;S++){let E=Math.max(-1,Math.min(1,v[S][R]));E=E<0?E*32768:E*32767,s.setInt16(u,E,!0),u+=2}R++}return new Blob([i],{type:"audio/wav"})},ut=async(e,n,r=!1)=>{if(!xe.current){if(P.current){B.current.push({audio:e,visemes:n,isNewSegment:r});return}P.current=!0;try{const i=window.AudioContext||window.webkitAudioContext,s=D.current??new i;s.state==="suspended"&&await s.resume(),D.current=s;const u=window.atob(e),p=new Uint8Array(u.length);for(let U=0;U<u.length;U++)p[U]=u.charCodeAt(U);const w=await s.decodeAudioData(p.buffer.slice(0));fe.current+=w.duration;const v=s.currentTime;let R=ce.current;const S=!F.current;R<v&&(R=v+.1),ce.current=R+w.duration;const E=s.createBufferSource();E.buffer=w;let q=Lt;if((!q||q.context!==s)&&(q=s.createAnalyser(),q.fftSize=64,q.connect(s.destination),$t(q)),E.connect(q),we.current.push(E),xe.current){we.current=we.current.filter(U=>U!==E);return}if(S){F.current=!0,L(!0),j(`[AUDIO] setIsSpeaking(true) - First chunk starting at ${R.toFixed(3)}`),Se.current=R;const U=(R-v)*1e3;Ee.current=performance.now()+U,j(`[AUDIO] Response started. Initial startTime: ${R.toFixed(3)}, CT: ${v.toFixed(3)}`)}E.start(R);const Q=(R-Se.current)*1e3;r&&(Pe.current=Q,j(`[AUDIO] New segment detected at +${Q.toFixed(0)}ms. Resetting segment offset.`)),n.forEach((U,oe)=>{const O=U.symbol??"";if(O){const ae=xn(O),de=Math.round(U.start*1e3),De=Math.round((U.duration??0)*1e3),It=Pe.current+de;oe<3&&j(`[AUDIO] Viseme "${O}": segment_relative=${de}ms, segment_offset=${Pe.current.toFixed(0)}ms => vtime=${It}ms`),ae.forEach(Dt=>{N.current.push({viseme:Dt.v,weight:Dt.w,vtime:It,vduration:De})})}}),h("Speaking...")}finally{if(P.current=!1,B.current.length>0){const i=B.current.shift();i&&ut(i.audio,i.visemes,i.isNewSegment)}}}},Yt=async e=>{try{b(!0),Ve(!1),pe.current="",z(""),h("Processing Voice...");const n=await e.arrayBuffer(),i=await new(window.AudioContext||window.webkitAudioContext)().decodeAudioData(n),s=zt(i),u=new FileReader;u.readAsDataURL(s),u.onloadend=async()=>{const p=u.result.split(",")[1];$e(),k(""),ne.current="",me.current=!1;const w=`${qe}/stt?token=${encodeURIComponent(M)}`,v=await fetch(w,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({audio_base64:p,audio_format:"wav"})});if(v.status===429){try{const oe=await v.text(),O=JSON.parse(oe);j("[STT] 429 agent at capacity:",O?.detail)}catch{}k(""),h("Busy"),b(!1);return}if(!v.ok){const oe=await v.text();let O="STT Failed";try{O=JSON.parse(oe).error||O}catch{oe&&(O=oe.slice(0,200))}throw new Error(O)}const R=v.body;if(j("this is body"+R),!R){h("STT Failed"),b(!1);return}const S=R.getReader();xe.current=!1;const E=new TextDecoder;let q="",Q=!1;const U=async(oe,O)=>{switch(oe){case"transcript":O.transcript!=null&&k(String(O.transcript));break;case"text":{const ae=O.delta??O.text??"";ae&&xt(ae);break}case"audio":{const ae=O.chunk,de=O.visemes??[],De=!!O.is_new_segment;ae&&await ut(ae,de,De);break}case"done":{Q=!0,h("Ready"),b(!1);break}case"error":{Q=!0,h("STT Failed"),b(!1);break}default:break}};for(;;){const{done:oe,value:O}=await S.read();O&&(q+=E.decode(O,{stream:!0}));const ae=q.split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),gt=require("@react-three/drei"),At=require("@react-three/fiber"),t=require("react"),_n=require("three"),wn=require("three/examples/jsm/loaders/GLTFLoader.js");function Sn(f){const L=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(f){for(const b in f)if(b!=="default"){const w=Object.getOwnPropertyDescriptor(f,b);Object.defineProperty(L,b,w.get?w:{enumerable:!0,get:()=>f[b]})}}return L.default=f,Object.freeze(L)}const rt=Sn(_n),Qe="https://ai.streamoji.com",C=(...f)=>{},Rn=(...f)=>{},Ht=({analyser:f})=>{const L=t.useRef(null),b=t.useRef(null);return t.useEffect(()=>{const w=L.current;if(!w)return;const V=w.getContext("2d",{alpha:!0});if(!V)return;let Q,X=null;f&&(f.fftSize=128,X=new Uint8Array(f.frequencyBinCount));const Xe=()=>{Q=requestAnimationFrame(Xe),(w.width!==w.offsetWidth||w.height!==w.offsetHeight)&&(w.width=w.offsetWidth,w.height=w.offsetHeight);const Fe=w.width,U=w.height;if(Fe===0||U===0)return;const Ze=U/2;V.clearRect(0,0,Fe,U),V.fillStyle="#1e293b";const xe=2,$=xe+2,ve=Fe*.95,q=Math.floor(ve/$);(!b.current||b.current.length!==q)&&(b.current=new Float32Array(q).fill(2));const oe=q*$,M=(Fe-oe)/2;f&&X&&f.getByteFrequencyData(X);const le=X?X.length:0,_=Math.floor(le*.7)/q,ne=new Float32Array(q);for(let m=0;m<q;m++){let D=0;if(X&&_>0){const A=Math.floor(m*_),F=Math.floor((m+1)*_);for(let J=A;J<F;J++){const Y=X[J]||0;Y>D&&(D=Y)}}D<10&&(D=0);const G=D/255,E=D>0?Math.max(2,Math.pow(G,1.4)*U*.25):2;ne[m]=E}for(let m=0;m<q;m++){const D=q-1-m,G=Math.max(ne[m],ne[D]),E=b.current[m]+(G-b.current[m])*.3;b.current[m]=E;const A=M+m*$,F=Ze-E/2;V.beginPath(),V.roundRect?V.roundRect(A,F,xe,E,4):V.fillRect(A,F,xe,E),V.fill()}};return Xe(),()=>{cancelAnimationFrame(Q)}},[f]),u.jsx("canvas",{ref:L,style:{width:"100%",height:"100%",display:"block"}})},yn="https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev",qt="https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";function Ln(f){const[L,b]=t.useState(null);return t.useEffect(()=>{if(!f){b(null);return}let w=!1;const V=`${yn}/${f}.glb`;return fetch(V,{method:"HEAD"}).then(Q=>{w||b(Q.ok?V:qt)}).catch(()=>{w||b(qt)}),()=>{w=!0}},[f]),L}const xn=["https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_001.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_002.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_002.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_005.glb"],vn=["https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_001.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb"],kn=[{id:"m_expr_01",name:"Friendly Wave",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_001.glb"},{id:"m_expr_02",name:"You There",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_002.glb"},{id:"m_expr_04",name:"Awkward Agreement",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_004.glb"},{id:"m_expr_05",name:"What's Going On?",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_005.glb"},{id:"m_expr_06",name:"Tired Stretch",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_006.glb"},{id:"m_expr_07",name:"Conceilied Laughter",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_007.glb"},{id:"m_expr_08",name:"You Come Here",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_008.glb"},{id:"m_expr_09",name:"Come Here Kid",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_009.glb"},{id:"m_expr_10",name:"Come Here Everyone",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_010.glb"},{id:"m_expr_11",name:"No Freaking Way",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_011.glb"},{id:"m_expr_12",name:"Cheerful Approval",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_012.glb"},{id:"m_expr_13",name:"Waving Hello",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_013.glb"},{id:"m_expr_14",name:"Checking Surroundings",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_014.glb"},{id:"m_expr_15",name:"Referee Warning",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_015.glb"},{id:"m_expr_16",name:"You Thumbs Down",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_016.glb"},{id:"m_expr_17",name:"Side Thumbs Down",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_017.glb"},{id:"m_expr_18",name:"You're Finished",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Standing_Expressions_018.glb"},{id:"m_talk_01",name:"Oh God, Why Me?",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_001.glb"},{id:"m_talk_02",name:"What Are You Doing?",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_002.glb"},{id:"m_talk_03",name:"What Am I doing?",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_003.glb"},{id:"m_talk_04",name:"No Way",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_004.glb"},{id:"m_talk_05",name:"What's Going On?",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb"},{id:"m_talk_06",name:"I have no idea",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_006.glb"},{id:"m_talk_07",name:"What's going on here?",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb"},{id:"m_talk_08",name:"Let's stop",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_008.glb"},{id:"m_talk_09",name:"Fed Up Moment",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_009.glb"},{id:"m_talk_10",name:"What's This? Hold On",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_010.glb"},{id:"f_talk_01",name:"Great Job Clap",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_001.glb"},{id:"f_talk_02",name:"Chill Stretch",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_002.glb"},{id:"f_talk_03",name:"This Is Me",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_003.glb"},{id:"f_talk_04",name:"Empathize",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_004.glb"},{id:"f_talk_05",name:"Loose Hands Stretch",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_005.glb"},{id:"f_talk_06",name:"Take It Easy",url:"https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb"}],En=["https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_006.glb"],Tn=["https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_004.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_005.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb","https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_002.glb"],Mn={zoom:.85,position:[.15,-.8,0],scale:1.5,rotation:[.15,.02,0]},An=[-.45,1.9,.1],In=[-.45,1.75,.1],Dn={browInnerUp:.2},Et=.18,On=1,Cn=.5,Gt=3,dt=.55,Tt=.12,Jt=2,zt=2,mt=4,Yt=8,Un=1,Kt=.38,Qt=.32,Xt="__branding__",pt={neutral:{eyeLookDownLeft:.1,eyeLookDownRight:.1},happy:{mouthSmileLeft:.2,mouthSmileRight:.2,eyeLookDownLeft:.1,eyeLookDownRight:.1},sad:{eyeLookDownLeft:.2,eyeLookDownRight:.2,browDownRight:.1,browInnerUp:.6,browOuterUpRight:.2,eyeSquintLeft:.7,eyeSquintRight:.7,mouthFrownLeft:.8,mouthFrownRight:.8,mouthLeft:.2,mouthPucker:.5,mouthRollLower:.2,mouthRollUpper:.2,mouthShrugLower:.2,mouthShrugUpper:.2,mouthStretchLeft:.4},angry:{eyeLookDownLeft:.1,eyeLookDownRight:.1,browDownLeft:.6,browDownRight:.6,jawForward:.3,mouthFrownLeft:.7,mouthFrownRight:.7,mouthRollLower:.2,mouthShrugLower:.3},fear:{browInnerUp:.7,eyeSquintLeft:.5,eyeSquintRight:.5,eyeWideLeft:.6,eyeWideRight:.6,mouthClose:.1,mouthFunnel:.3,mouthShrugLower:.5,mouthShrugUpper:.5},disgust:{browDownLeft:.7,browDownRight:.1,browInnerUp:.3,eyeSquintLeft:1,eyeSquintRight:1,eyeWideLeft:.5,eyeWideRight:.5,mouthLeft:.4,mouthPressLeft:.3,mouthRollLower:.3,mouthShrugLower:.3,mouthShrugUpper:.8,mouthUpperUpLeft:.3,noseSneerLeft:1,noseSneerRight:.7},love:{browInnerUp:.4,browOuterUpLeft:.2,browOuterUpRight:.2,mouthSmileLeft:.2,mouthSmileRight:.2,eyeBlinkLeft:.6,eyeBlinkRight:.6,eyeWideLeft:.7,eyeWideRight:.7,mouthDimpleLeft:.1,mouthDimpleRight:.1,mouthPressLeft:.2,mouthShrugUpper:.2,mouthUpperUpLeft:.1,mouthUpperUpRight:.1}},Fn=[{key:"viseme_aa",mix:{jawOpen:.4,mouthSmileLeft:.15,mouthSmileRight:.15},teethMix:{jawOpen:.2,mouthSmileLeft:.15,mouthSmileRight:.15}},{key:"viseme_E",mix:{mouthPressLeft:.65,mouthPressRight:.65,mouthDimpleLeft:1,mouthDimpleRight:1,jawOpen:.25,mouthFunnel:.1},teethMix:{jawOpen:.15,mouthPressLeft:.65,mouthPressRight:.65,mouthDimpleLeft:1,mouthDimpleRight:1,mouthFunnel:.1}},{key:"viseme_I",mix:{mouthPressLeft:.55,mouthPressRight:.55,mouthDimpleLeft:1,mouthDimpleRight:1,jawOpen:.15,mouthFunnel:.05},teethMix:{mouthPressLeft:.55,mouthPressRight:.55,mouthDimpleLeft:1,mouthDimpleRight:1,jawOpen:.15,mouthFunnel:.05}},{key:"viseme_O",mix:{mouthPucker:.7,jawOpen:.4,mouthFunnel:.25},teethMix:{jawForward:.6,jawOpen:.2,mouthPucker:.7,mouthFunnel:.25}},{key:"viseme_U",mix:{mouthFunnel:1,mouthClose:.2},teethMix:{mouthFunnel:1,mouthClose:.2}},{key:"viseme_PP",mix:{mouthDimpleLeft:.5,mouthDimpleRight:.5,mouthStretchLeft:.3,mouthStretchRight:.3,mouthRollLower:.3,mouthRollUpper:.3,mouthPressLeft:.5,mouthPressRight:.5},teethMix:{mouthDimpleLeft:.5,mouthDimpleRight:.5,mouthStretchLeft:.3,mouthStretchRight:.3,mouthRollLower:.3,mouthRollUpper:.3,mouthPressLeft:.5,mouthPressRight:.5}},{key:"viseme_FF",mix:{mouthPucker:1,mouthShrugUpper:1,mouthDimpleLeft:1,mouthDimpleRight:1,mouthStretchLeft:.5,mouthStretchRight:.5,mouthPressLeft:.3,mouthPressRight:.3,mouthRollLower:.1},teethMix:{mouthPucker:1,mouthShrugUpper:1,mouthDimpleLeft:1,mouthDimpleRight:1,mouthStretchLeft:.5,mouthStretchRight:.5,mouthPressLeft:.3,mouthPressRight:.3,mouthRollLower:.1}},{key:"viseme_DD",mix:{mouthShrugUpper:.25,mouthShrugLower:.25,mouthPressLeft:.4,mouthPressRight:.4,mouthFunnel:.7,jawOpen:.1},teethMix:{mouthShrugUpper:.25,mouthShrugLower:.25,mouthPressLeft:.4,mouthPressRight:.4,mouthFunnel:.7,jawOpen:.1}},{key:"viseme_SS",mix:{mouthPressLeft:.8,mouthPressRight:.8,mouthLowerDownLeft:.3,mouthLowerDownRight:.3,jawOpen:.1},teethMix:{mouthPressLeft:.8,mouthPressRight:.8,mouthLowerDownLeft:.3,mouthLowerDownRight:.3,jawOpen:.1}},{key:"viseme_TH",mix:{mouthStretchLeft:.4,mouthStretchRight:.4,mouthDimpleLeft:1,mouthDimpleRight:1,mouthFunnel:.4,jawOpen:.15,mouthShrugLower:.45,mouthShrugUpper:.45},teethMix:{mouthStretchLeft:.4,mouthStretchRight:.4,mouthDimpleLeft:1,mouthDimpleRight:1,mouthFunnel:.4,jawOpen:.15,mouthShrugLower:.45,mouthShrugUpper:.45}},{key:"viseme_CH",mix:{mouthPucker:.8,mouthShrugLower:.7,mouthShrugUpper:.2,mouthLowerDownLeft:.6,mouthLowerDownRight:.6,mouthDimpleLeft:.5,mouthDimpleRight:.5,mouthUpperUpLeft:.8,mouthUpperUpRight:.8,jawOpen:.2},teethMix:{mouthPucker:.8,mouthShrugLower:.7,mouthShrugUpper:.2,mouthLowerDownLeft:.6,mouthLowerDownRight:.6,mouthDimpleLeft:.5,mouthDimpleRight:.5,mouthUpperUpLeft:.8,mouthUpperUpRight:.8,jawOpen:.2}},{key:"viseme_RR",mix:{mouthPucker:.4,jawOpen:.2,mouthShrugUpper:.5,mouthFunnel:.15,mouthDimpleLeft:.5,mouthDimpleRight:.5},teethMix:{mouthPucker:.4,jawOpen:.2,mouthShrugUpper:.5,mouthFunnel:.15,mouthDimpleLeft:.5,mouthDimpleRight:.5}},{key:"viseme_kk",mix:{mouthPucker:.5,jawOpen:.2,mouthShrugUpper:.5,mouthFunnel:.2,mouthDimpleLeft:.5,mouthDimpleRight:.5},teethMix:{mouthPucker:.5,jawOpen:.2,mouthShrugUpper:.5,mouthFunnel:.2,mouthDimpleLeft:.5,mouthDimpleRight:.5}},{key:"viseme_nn",mix:{mouthPucker:.6,jawOpen:.2,mouthShrugUpper:.7,mouthShrugLower:.1,mouthFunnel:.1,mouthDimpleLeft:.8,mouthDimpleRight:.8},teethMix:{mouthPucker:.6,jawOpen:.2,mouthShrugUpper:.7,mouthShrugLower:.1,mouthFunnel:.1,mouthDimpleLeft:.8,mouthDimpleRight:.8}},{key:"viseme_sil",mix:{}}],Nn={aei:[{v:"E",w:.8},{v:"I",w:.2}],ee:[{v:"I",w:1}],oo:[{v:"O",w:1}],u:[{v:"U",w:1}],aa:[{v:"aa",w:1}],ah:[{v:"aa",w:.7},{v:"O",w:.3}],bmp:[{v:"PP",w:1}],fv:[{v:"FF",w:1}],th:[{v:"TH",w:1}],l:[{v:"nn",w:1}],r:[{v:"RR",w:1}],qw:[{v:"U",w:.6},{v:"O",w:.4}],chjsh:[{v:"CH",w:1}],cdgknstxyz:[{v:"DD",w:.6},{v:"SS",w:.4}],sil:[{v:"sil",w:1}]};function Pn(f){if(!f)return[{v:"sil",w:1}];const L=f.toLowerCase();return Nn[L]??[{v:"sil",w:1}]}function jn({target:f}){const{camera:L}=At.useThree();return t.useEffect(()=>{L.lookAt(...f)},[L,f]),null}function c(f,L,b){if(!f||!f.morphTargetDictionary)return;const w=f,V=w.morphTargetDictionary,Q=w.morphTargetInfluences;if(Q)for(const X in V)X.toLowerCase()===L.toLowerCase()&&(Q[V[X]]=b)}function Mt(f,L=.97){if(!f)return;const b=f;if(b.morphTargetInfluences)for(let w=0;w<b.morphTargetInfluences.length;w++)b.morphTargetInfluences[w]*=L}const Bn=t.memo(({avatarUrl:f,isPlayingRef:L,visemeQueueRef:b,audioContextRef:w,responseAudioStartTimeRef:V,adjustments:Q,mood:X,expression:Xe,agentResponse:Fe,isSpeaking:U,nextStartTimeRef:Ze,stopPlayback:xe,setIsSpeaking:Ne,expressionUrl:$,onExpressionFinished:ve,isNudgeResponse:q,avatarGender:oe})=>{const{scene:M}=gt.useGLTF(f),le=oe==="female"?vn:xn,W=gt.useGLTF(le),_=t.useMemo(()=>W.flatMap(p=>p.animations),[W]),ne=oe==="female"?Tn:En,m=gt.useGLTF(ne),D=t.useMemo(()=>m.flatMap(p=>p.animations),[m]),G=t.useRef(null),E=t.useRef(null),A=t.useRef(null),F=t.useRef(null),J=t.useRef(null),Y=t.useRef(null),bt=t.useRef([]),[Z]=t.useState(()=>new rt.AnimationMixer(M)),H=t.useRef({}),j=t.useRef(null),ke=t.useRef(0),Ye=t.useRef(!1),Pe=t.useRef(0),Ee=t.useRef(!1),ge=t.useRef(null),Te=t.useRef(Gt),st=t.useRef(-1),Me=t.useRef("left"),je=t.useRef(mt+Math.random()*(Yt-mt)),fe=t.useRef(0),Ae=t.useRef("smile");t.useEffect(()=>{if(!(!_||!M)){if(_.forEach((p,h)=>{const a=`idle_${h}`;if(!H.current[a]){const o=Z.clipAction(p,M);o.name=a,o.setLoop(rt.LoopOnce,1),o.clampWhenFinished=!0,H.current[a]=o}}),D.forEach((p,h)=>{const a=`talk_${h}`;if(!H.current[a]){const o=Z.clipAction(p,M);o.name=a,o.setLoop(rt.LoopOnce,1),o.clampWhenFinished=!0,H.current[a]=o}}),_.length>0){const p=H.current.idle_0,h=j.current&&Z.existingAction(j.current.getClip());p&&!h&&(p.reset().fadeIn(.5).play(),j.current=p)}return()=>{Z.stopAllAction(),H.current={},j.current=null}}},[_,D,M,Z]);const Se=t.useRef("");t.useEffect(()=>{if(!$||!M||$===Se.current)return;Se.current=$,ge.current=$,new wn.GLTFLoader().load($,h=>{if(h.animations&&h.animations.length>0){const a=h.animations[0],o=Z.clipAction(a,M);if(o.name=`EXPR_${$}`,o.setLoop(rt.LoopOnce,1),o.clampWhenFinished=!0,H.current[`EXPR_${$}`]=o,U&&ge.current===$){const d=j.current;o.reset().fadeIn(.3).play(),d&&d!==o&&d.crossFadeTo(o,.3,!0),j.current=o,ge.current=null}}},void 0,h=>{console.error(`[ANIMATION] Failed to load ${$}`,h)})},[$,M,Z,U]),t.useEffect(()=>{const p=h=>{const a=h.action,o=a.name||"";if(o.startsWith("idle_")){const I=(parseInt(o.split("_")[1])+1)%_.length,ee=H.current[`idle_${I}`];ee&&(ee.reset().fadeIn(.5).play(),a.crossFadeTo(ee,.5,!0),j.current=ee)}else if(o.startsWith("EXPR_")){if(U){const d=Math.floor(Math.random()*D.length),I=H.current[`talk_${d}`];I&&(I.reset().fadeIn(.5).play(),a.crossFadeTo(I,.5,!0),j.current=I)}else{const d=H.current.idle_0;d&&(d.reset().fadeIn(.5).play(),a.crossFadeTo(d,.5,!0),j.current=d)}ve&&ve()}else if(o.startsWith("talk_"))if(U&&!q){const I=(parseInt(o.split("_")[1])+1)%D.length,ee=H.current[`talk_${I}`];ee&&(ee.reset().fadeIn(.3).play(),a.crossFadeTo(ee,.3,!0),j.current=ee)}else{const d=H.current.idle_0;d&&(d.reset().fadeIn(.5).play(),a.crossFadeTo(d,.5,!0),j.current=d)}};return Z.addEventListener("finished",p),()=>Z.removeEventListener("finished",p)},[Z,_,D,U,q,ve]),t.useEffect(()=>{if(U&&M){const p=j.current,h=p?.name||"";if(h.startsWith("idle_")||h.startsWith("talk_")||h===""){const a=ge.current;if(a){const o=H.current[`EXPR_${a}`];if(o){o.reset().fadeIn(.3).play(),p&&p!==o&&p.crossFadeTo(o,.3,!0),j.current=o,ge.current=null;return}}if(h.startsWith("idle_")||h===""){const o=Math.floor(Math.random()*D.length),d=H.current[`talk_${o}`];d&&(d.reset().fadeIn(.5).play(),p&&p.crossFadeTo(d,.5,!0),j.current=d)}}}else if(!U&&M){const p=j.current,h=p?.name||"";if(h.startsWith("talk_")||h.startsWith("EXPR_")){const a=H.current.idle_0;a&&(a.reset().fadeIn(.5).play(),p&&p.crossFadeTo(a,.5,!0),j.current=a)}}},[U,M,$]),t.useEffect(()=>{if(!M)return;M.traverse(a=>{if(a.isMesh&&a.morphTargetDictionary){const o=a.name.toLowerCase();(o.includes("head")||o.includes("avatar"))&&(E.current=a,C(`[ANIMATION] Found head mesh: ${a.name}`)),o.includes("teeth")&&(A.current=a,C(`[ANIMATION] Found teeth mesh: ${a.name}`)),o.includes("beard")&&(F.current=a,C(`[ANIMATION] Found beard mesh: ${a.name}`)),o.includes("eyeleft")&&(J.current=a,C(`[ANIMATION] Found eye left mesh: ${a.name}`)),o.includes("eyeright")&&(Y.current=a,C(`[ANIMATION] Found eye right mesh: ${a.name}`))}});const p=E.current?.morphTargetDictionary;p&&Object.keys(p).filter(a=>a.toLowerCase().includes("brow"));const h=[];M.traverse(a=>{if(a.isMesh){const d=a.morphTargetDictionary;d&&Object.keys(d).some(I=>I.toLowerCase().includes("brow"))&&h.push(a)}}),bt.current=h,h.length>0&&C("[ANIMATION] Meshes with brow morphs:",h.length)},[M]);const et=(p,h=1)=>{const a=`viseme_${p}`.toLowerCase(),o=Fn.find(d=>d.key.toLowerCase()===a);if(o){for(const d in o.mix){const I=o.mix[d]*h;c(E.current,d,I),c(F.current,d,I),(!o.teethMix||!(d in o.teethMix))&&c(A.current,d,I)}if(o.teethMix)for(const d in o.teethMix){const I=o.teethMix[d]*h;c(A.current,d,I)}}},tt=p=>{const h=pt[p]??pt.neutral;for(const a in h)c(E.current,a,h[a]),c(A.current,a,h[a]),c(F.current,a,h[a])};return At.useFrame((p,h)=>{const a=Math.pow(.88,60*h);Mt(E.current,a),Mt(A.current,a),Mt(F.current,a),tt(X);const o=p.clock.elapsedTime;let d=0;if(Math.floor(o)%5===0&&Math.floor((o-h)%5)!==0){let S=null;M.traverse(N=>{N.name.toLowerCase().includes("hips")&&(S=N)});const z=S?`Hips Y: ${S.position.y.toFixed(4)}`:"Hips not found";C(`[ANIMATION] Mixer Time: ${Z.time.toFixed(2)}, ${z}`)}if(Z.update(h),o>ke.current&&!Ye.current&&(Ye.current=!0,Pe.current=o),Ye.current){const S=U?.2:.3,z=(o-Pe.current)/S;if(z>=1)if(Ye.current=!1,Ee.current){const N=U?1:2.5;ke.current=o+N,Ee.current=!1}else ke.current=o+.12,Ee.current=!0;else{const N=z<.5?z*2:(1-z)*2;c(E.current,"eyeBlinkLeft",N),c(E.current,"eyeBlinkRight",N),c(A.current,"eyeBlinkLeft",N),c(A.current,"eyeBlinkRight",N),c(F.current,"eyeBlinkLeft",N),c(F.current,"eyeBlinkRight",N),d=N*Dn.browInnerUp}}const I=pt[X]??pt.neutral,ee=I.browInnerUp??0,_t=I.browOuterUpLeft??0,Be=I.browOuterUpRight??0,te=o*On,ot=Et*Math.sin(te),Ie=Et*.7*Math.sin(te+.7),We=Et*.7*Math.sin(te+1.3),R=S=>Math.max(0,Math.min(1,S)),it=R(ee+ot),Ve=R(_t+Ie),$e=R(Be+We),at=R(it+d);c(E.current,"browInnerUp",at),c(A.current,"browInnerUp",at),c(F.current,"browInnerUp",at),c(E.current,"browOuterUpLeft",Ve),c(A.current,"browOuterUpLeft",Ve),c(F.current,"browOuterUpLeft",Ve),c(E.current,"browOuterUpRight",$e),c(A.current,"browOuterUpRight",$e),c(F.current,"browOuterUpRight",$e);const He=Te.current,De=He+dt,he=De+Tt;o>he&&(Te.current+=dt+Tt+Gt);const be=!U&&o>=He&&o<De,Oe=!U&&o>=De&&o<he;(be||Oe)&&st.current!==He&&(st.current=He,Me.current=Math.random()<.7?"left":"up");const ct=be?o-He:Oe?dt:0,re=be||Oe?Math.min(1,ct/dt):0,qe=re<=0?0:Math.sin(re*Math.PI),ut=Oe?1-(o-De)/Tt:1,wt=be?qe:Oe?qe*ut:0,Ce=Cn*wt,x=S=>I[S]??0;if(Me.current==="up"?(c(J.current,"eyeLookUpLeft",R(x("eyeLookUpLeft")+Ce)),c(J.current,"eyeLookDownLeft",R(x("eyeLookDownLeft"))),c(J.current,"eyeLookOutLeft",R(x("eyeLookOutLeft"))),c(J.current,"eyeLookInLeft",R(x("eyeLookInLeft"))),c(Y.current,"eyeLookUpRight",R(x("eyeLookUpRight")+Ce)),c(Y.current,"eyeLookDownRight",R(x("eyeLookDownRight"))),c(Y.current,"eyeLookOutRight",R(x("eyeLookOutRight"))),c(Y.current,"eyeLookInRight",R(x("eyeLookInRight")))):(c(J.current,"eyeLookUpLeft",R(x("eyeLookUpLeft"))),c(J.current,"eyeLookDownLeft",R(x("eyeLookDownLeft"))),c(J.current,"eyeLookOutLeft",R(x("eyeLookOutLeft"))),c(J.current,"eyeLookInLeft",R(x("eyeLookInLeft")+Ce)),c(Y.current,"eyeLookUpRight",R(x("eyeLookUpRight"))),c(Y.current,"eyeLookDownRight",R(x("eyeLookDownRight"))),c(Y.current,"eyeLookOutRight",R(x("eyeLookOutRight")+Ce)),c(Y.current,"eyeLookInRight",R(x("eyeLookInRight")))),!U&&o>=je.current){fe.current=o,Ae.current=Math.random()<.5?"pucker":"smile";const S=Ae.current==="pucker"?zt:Jt;je.current=o+S+mt+Math.random()*(Yt-mt)}const ie=Ae.current==="pucker"?zt:Jt,ae=!U&&o>=fe.current&&o<fe.current+ie,Ge=ae?(o-fe.current)/ie:0,Re=Ge<=0?0:Ge<.5?Ge*2:(()=>{const S=(Ge-.5)*2;return 1-S*S*(3-2*S)})(),de=S=>I[S]??0;if(ae)if(Ae.current==="pucker"){const S=R(de("mouthPucker")+Un*Re);c(E.current,"mouthPucker",S),c(A.current,"mouthPucker",S),c(F.current,"mouthPucker",S)}else{const S=R(de("mouthSmileLeft")+Kt*Re),z=R(de("mouthSmileRight")+Kt*Re),N=R(de("mouthDimpleLeft")+Qt*Re),ye=R(de("mouthDimpleRight")+Qt*Re);c(E.current,"mouthSmileLeft",S),c(E.current,"mouthSmileRight",z),c(E.current,"mouthDimpleLeft",N),c(E.current,"mouthDimpleRight",ye),c(A.current,"mouthSmileLeft",S),c(A.current,"mouthSmileRight",z),c(A.current,"mouthDimpleLeft",N),c(A.current,"mouthDimpleRight",ye),c(F.current,"mouthSmileLeft",S),c(F.current,"mouthSmileRight",z),c(F.current,"mouthDimpleLeft",N),c(F.current,"mouthDimpleRight",ye)}if(G.current){const S=L.current?0:Q.rotation[1];G.current.rotation.y=rt.MathUtils.lerp(G.current.rotation.y,S,.1),G.current.position.set(...Q.position),G.current.scale.setScalar(Q.scale),G.current.rotation.x=Q.rotation[0],G.current.rotation.z=Q.rotation[2]}if(L.current&&w.current){const S=w.current.currentTime,ye=(S-V.current)*1e3- -150;for(let ce=0;ce<b.current.length;ce++){const ue=b.current[ce];ye>=ue.vtime&&ye<ue.vtime+ue.vduration&&et(ue.viseme,ue.weight??1)}S>Ze.current+.5&&(xe(),Ne(!1))}}),u.jsx("group",{ref:G,children:u.jsx("primitive",{object:M})})});function Wn(f){return f?f.charAt(0).toUpperCase()+f.slice(1).toLowerCase():""}function Zt(f){return f.replace(/\*(.*?)\*/g," $1 ").replace(/\[.*?\]/g," ").replace(/<.*?\/>/g," ").replace(/<.*?>.*?<\/.*?>/g," ").replace(/\s+/g," ").trim()}const Vn=({onNavigationRequested:f,agentId:L,presetUserDetails:b,onAvatarReady:w})=>{const[V,Q]=t.useState(""),[X,Xe]=t.useState("male"),[Fe,U]=t.useState(""),[Ze,xe]=t.useState(!1),Ne=V,$=X;t.useEffect(()=>{if(!L){xe(!0);return}let e=!1;return(async()=>{try{const s={agentId:L},i=await fetch(`${Qe}/visitedWebsite`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(i.ok){const n=await i.json();if(e)return;n.encryptedAgentToken&&Q(n.encryptedAgentToken),n.avatarGender&&Xe(n.avatarGender),n.agent_id&&U(n.agent_id)}}catch(s){console.error("Failed to fetch avatar config:",s)}finally{e||xe(!0)}})(),()=>{e=!0}},[L]);const ve=Ln(L??Fe),[q,oe]=t.useState(""),[M,le]=t.useState(""),[W,_]=t.useState("Ready"),[ne,m]=t.useState(!1),[D,G]=t.useState(!1),[E,A]=t.useState([]),[F,J]=t.useState(""),Y=t.useRef(null),[bt,Z]=t.useState(()=>typeof window<"u"?window.matchMedia("(max-width: 480px)").matches:!1);t.useEffect(()=>{const e=window.matchMedia("(max-width: 480px)"),r=()=>Z(e.matches);return e.addEventListener("change",r),()=>e.removeEventListener("change",r)},[]);const H=bt?80:600,j=t.useRef(!1),ke=t.useRef([]),Ye=t.useRef(0),Pe=t.useRef(!1),Ee=t.useRef([]),ge=t.useRef(null),Te=t.useRef([]);t.useRef([]);const st=t.useRef([]),Me=t.useRef(0),je=t.useRef(0),fe=t.useRef(0),Ae=t.useRef(0),Se=t.useRef(!1),[et,tt]=t.useState(null),p=t.useRef(null),[h,a]=t.useState("neutral"),[o,d]=t.useState(""),[I,ee]=t.useState(""),[_t,Be]=t.useState("Chat with us"),[te,ot]=t.useState(null),[Ie,We]=t.useState("hidden"),[R,it]=t.useState(""),Ve=t.useRef(null),$e=t.useRef(Ie);$e.current=Ie;const[at,He]=t.useState(null),De=t.useRef(null),he=t.useRef(null),[be,Oe]=t.useState(!1),ct=t.useRef(null),[re,qe]=t.useState("hidden"),[ut,wt]=t.useState(""),Ce=t.useRef(re);Ce.current=re;const x=t.useRef(""),ie=t.useRef(!1),ae=t.useRef(""),Ge=t.useRef(Date.now()),Re=t.useRef([]),de=t.useRef(!1),[S,z]=t.useState(!1),[N,ye]=t.useState(!1),ce=t.useRef(null),ue=t.useMemo(()=>be?"Try again":W==="Busy"?"Busy":W==="Thinking..."||W==="Processing Voice..."?W:te!=null&&te!==""&&te!=="none"&&te!=="<none>"?`Enter ${Wn(te)}`:re!=="hidden"||!N?null:Xt,[W,te,be,re,N]),It=!be&&W!=="Busy"&&W!=="Thinking..."&&W!=="Processing Voice..."&&(te==null||te===""||te==="none"||te==="<none>");t.useEffect(()=>{if(re!=="hidden"||!It){ye(!1),ce.current!=null&&(clearTimeout(ce.current),ce.current=null);return}return ce.current=setTimeout(()=>{ce.current=null,ye(!0)},400),()=>{ce.current!=null&&(clearTimeout(ce.current),ce.current=null)}},[re,It]);const lt=ue!=null&&ue!=="";t.useEffect(()=>{const e=$e.current;if(!(e==="exiting"||e==="entering")){if(e==="hidden"){lt&&(it(ue??""),We("entering"));return}e==="visible"&&(!lt||ue!==R)&&(Ve.current=lt?ue:null,We("exiting"))}},[lt,ue,Ie,R]),t.useEffect(()=>{if(W!=="Busy"){he.current!=null&&(clearTimeout(he.current),he.current=null);return}return he.current=setTimeout(()=>{he.current=null,_("Ready"),Oe(!0)},12e3),()=>{he.current!=null&&(clearTimeout(he.current),he.current=null)}},[W]),t.useEffect(()=>{if(!be)return;const e=setTimeout(()=>Oe(!1),2500);return()=>clearTimeout(e)},[be]);const en=t.useCallback(()=>{const e=$e.current;if(e==="exiting"){We("hidden");const r=Ve.current;Ve.current=null,r!=null&&r!==""&&(it(r),We("entering"))}else e==="entering"&&We("visible")},[]),tn=e=>{if(!e)return;if(e.mood!=null){const n=String(e.mood).toLowerCase();a(n)}if(e.expression!=null){const n=String(e.expression).trim();d(n);const l=kn.find(g=>g.name.toLowerCase()===n.toLowerCase());C(`[STREAM] Animation match for "${n}": ${l?l.name:"NONE"}`),ee(l?.url??"")}if(e.navigation!=null){const n=String(e.navigation).trim();n!==""&&(f?f(n):window.open(n,"_blank"))}const r=e.ask_for||e.lead_capture?.ask_for,s=r?String(r).trim().toLowerCase():"",i=s==="none"||s==="<none>";if(r&&!i){const n=s;if(b&&(n==="email"&&b.email||n==="name"&&b.name||n==="phone"&&b.phone))return;ot(n||null),Be(n==="email"?"Enter your email":n==="name"?"Enter your name":n==="phone"?"Enter your phone number":"Chat with us")}else(i||e.ask_for===null||e.lead_capture&&e.lead_capture.ask_for===null||e.ask_for==="none")&&(ot(null),_t!=="Chat with us"&&Be("Chat with us"));e.collected,e.valid},nn=e=>{const r=e.trim();if(!r)return null;if(r.startsWith("{"))try{return JSON.parse(r)}catch{return null}if(r.includes(":")){const s=r.split(":"),i=s[0].trim().toLowerCase(),n=s.slice(1).join(":").trim();return{[i]:n}}return null},rn=t.useCallback(()=>{},[]),Ue="§",St=()=>{for(;x.current.includes(`
2
+ `);){const e=x.current.indexOf(`
3
+ `),r=x.current.slice(0,e).trim();x.current=x.current.slice(e+1);const s=nn(r);s&&tn(s)}},Dt=e=>{if(ie.current)if(e.includes(Ue)){const r=e.indexOf(Ue),s=e.slice(0,r),i=e.slice(r+Ue.length);s&&(ae.current+=s,le(n=>n+s)),ie.current=!1,i&&(x.current+=i,St())}else e===Ue?ie.current=!1:(ae.current+=e,le(r=>r+e));else if(e.includes(Ue)){const r=e.indexOf(Ue),s=e.slice(0,r),i=e.slice(r+Ue.length);x.current+=s,St(),ie.current=!0,i&&(ae.current+=i,le(n=>n+i))}else if(e===Ue){ie.current=!0;return}else x.current+=e,St()};t.useEffect(()=>{(async()=>{if(!sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID")){const n="secret",l=Math.floor(Date.now()/1e3).toString();try{const g=new TextEncoder,y=await crypto.subtle.importKey("raw",g.encode(n),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),k=await crypto.subtle.sign("HMAC",y,g.encode(l)),v=Array.from(new Uint8Array(k)).map(O=>O.toString(16).padStart(2,"0")).join("");sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",v),C("[SESSION] New HMAC UID generated and saved:",v)}catch(g){console.error("[SESSION] HMAC generation failed:",g);const y=Math.random().toString(36)+Date.now().toString();sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",y)}}const s=sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");let i=[];if(s)try{i=JSON.parse(s)}catch{i=[]}i.length===0&&b&&(b.name||b.email)?(i=[{role:"user",content:`PRESET_USER_DETAILS: Name is "${b.name||""}" , Email is "${b.email||""}"`}],sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES",JSON.stringify(i))):s||sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES",JSON.stringify([]))})()},[b]),t.useEffect(()=>{const e=()=>{Ge.current=Date.now(),de.current&&(de.current=!1,z(!1),A([]),J(""),le(""),G(!1))};window.addEventListener("mousemove",e),window.addEventListener("keydown",e),window.addEventListener("mousedown",e),window.addEventListener("touchstart",e);const r=setInterval(async()=>{if(Date.now()-Ge.current>=3e4&&!D&&!ne&&W==="Ready"&&!de.current)if(de.current=!0,Re.current.length>0)z(!0),A(Re.current);else try{const n=`${Qe}/nudgeUser`,l={navigationUrl:window.location.href,token:Ne},g=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(g.ok){const k=(await g.json()).nudge_questions;k&&k.length>0&&(C("[NUDGE] Received nudge questions from API:",k),Re.current=k,z(!0),A(k))}}catch(n){console.error("[NUDGE] Error calling /nudgeUser:",n),de.current=!1}},1e3);return()=>{window.removeEventListener("mousemove",e),window.removeEventListener("keydown",e),window.removeEventListener("mousedown",e),window.removeEventListener("touchstart",e),clearInterval(r)}},[Ne,D,ne,W]),t.useEffect(()=>{if(E.length===0)return;let e=0,r=0,s=!1,i=100;const n=()=>{const l=E[e];if(s){const g=l.substring(0,r-1);J(g),r--,i=50}else{const g=l.substring(0,r+1);J(g),r++,i=100}!s&&r===l.length?(s=!0,i=3e3):s&&r===0&&(s=!1,e=(e+1)%E.length,i=500),Y.current=setTimeout(n,i)};return n(),()=>{Y.current&&clearTimeout(Y.current)}},[E]);const Ot=()=>{try{return JSON.parse(sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES")||"[]")}catch{return[]}},sn=e=>{sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES",JSON.stringify(e))},[Rt,yt]=t.useState(!1),[Ct,Lt]=t.useState(0),_e=t.useRef(null),ft=t.useRef([]),Ut=t.useRef(0),[Ft,on]=t.useState(null),[an,xt]=t.useState(null),Le=t.useRef(null),Je=t.useRef(null),nt=t.useCallback((e=!1)=>{e&&(Se.current=!0,m(!1),_("Ready")),Ee.current=[],ke.current=[],Pe.current=!1,G(!1),Me.current=0,je.current=0,fe.current=0,Te.current.forEach(r=>{try{r.stop()}catch{}}),De.current&&(clearTimeout(De.current),De.current=null),He(null),ee(""),Te.current=[]},[]),cn=async()=>{try{const e=await navigator.mediaDevices.getUserMedia({audio:!0}),r=window.AudioContext||window.webkitAudioContext,s=new r,i=s.createMediaStreamSource(e),n=s.createAnalyser();n.fftSize=64,i.connect(n),Le.current=s,Je.current=i,xt(n);const l=new MediaRecorder(e);_e.current=l,ft.current=[],l.ondataavailable=g=>{g.data.size>0&&ft.current.push(g.data)},l.onstop=async()=>{const g=Date.now()-Ut.current;if(xt(null),Je.current&&(Je.current.disconnect(),Je.current=null),Le.current&&Le.current.state!=="closed"&&(Le.current.close(),Le.current=null),g<1e3){_("Recording too short. Hold or click longer."),m(!1);return}const y=new Blob(ft.current,{type:"audio/wav"});await hn(y)},Ut.current=Date.now(),l.start(100),yt(!0),_("Listening...")}catch(e){console.error("Error accessing microphone:",e),_("Mic Access Error")}},un=()=>{_e.current&&_e.current.state!=="inactive"&&(_e.current.stop(),_e.current.stream.getTracks().forEach(e=>e.stop()),yt(!1))},ln=()=>{_e.current&&_e.current.state!=="inactive"&&(_e.current.onstop=null,_e.current.stop(),_e.current.stream.getTracks().forEach(e=>e.stop()),xt(null),Je.current&&(Je.current.disconnect(),Je.current=null),Le.current&&Le.current.state!=="closed"&&(Le.current.close(),Le.current=null),yt(!1),ft.current=[],_("Ready"))};t.useEffect(()=>{if(!D)return;const e=()=>{const r=fe.current;if(r<=0)return;const s=ge.current,i=Me.current;if(!s)return;const n=s.currentTime-i,l=Math.min(Math.max(0,n),r),y=Zt(M).trim().length;if(y<=0)return;const k=Math.min(Math.round(l/r*y),y);tt(k)};return clearInterval(p.current??void 0),p.current=setInterval(e,90),()=>clearInterval(p.current??void 0)},[D,M,fe.current]),t.useEffect(()=>{let e;return Rt?(Lt(0),e=window.setInterval(()=>{Lt(r=>r+1)},1e3)):Lt(0),()=>clearInterval(e)},[Rt]);const fn=e=>{const r=e.numberOfChannels,s=e.length*r*2+44,i=new ArrayBuffer(s),n=new DataView(i);let l=0;const g=v=>{n.setUint16(l,v,!0),l+=2},y=v=>{n.setUint32(l,v,!0),l+=4};y(1179011410),y(s-8),y(1163280727),y(544501094),y(16),g(1),g(r),y(e.sampleRate),y(e.sampleRate*2*r),g(r*2),g(16),y(1635017060),y(s-l-4);const k=[];for(let v=0;v<r;v++)k.push(e.getChannelData(v));let T=0;for(;l<s;){for(let v=0;v<r;v++){let O=Math.max(-1,Math.min(1,k[v][T]));O=O<0?O*32768:O*32767,n.setInt16(l,O,!0),l+=2}T++}return new Blob([i],{type:"audio/wav"})},vt=async(e,r,s=!1)=>{if(!Se.current){if(j.current){ke.current.push({audio:e,visemes:r,isNewSegment:s});return}j.current=!0;try{const i=window.AudioContext||window.webkitAudioContext,n=ge.current??new i;n.state==="suspended"&&await n.resume(),ge.current=n;const l=window.atob(e),g=new Uint8Array(l.length);for(let B=0;B<l.length;B++)g[B]=l.charCodeAt(B);const y=await n.decodeAudioData(g.buffer.slice(0));fe.current+=y.duration;const k=n.currentTime;let T=je.current;const v=!Pe.current;T<k&&(T=k+.1),je.current=T+y.duration;const O=n.createBufferSource();O.buffer=y;let K=Ft;if((!K||K.context!==n)&&(K=n.createAnalyser(),K.fftSize=64,K.connect(n.destination),on(K)),O.connect(K),Te.current.push(O),Se.current){Te.current=Te.current.filter(B=>B!==O);return}if(v){Pe.current=!0,G(!0),C(`[AUDIO] setIsSpeaking(true) - First chunk starting at ${T.toFixed(3)}`),Me.current=T;const B=(T-k)*1e3;Ye.current=performance.now()+B,C(`[AUDIO] Response started. Initial startTime: ${T.toFixed(3)}, CT: ${k.toFixed(3)}`)}O.start(T);const se=(T-Me.current)*1e3;s&&(Ae.current=se,C(`[AUDIO] New segment detected at +${se.toFixed(0)}ms. Resetting segment offset.`)),r.forEach((B,me)=>{const P=B.symbol??"";if(P){const pe=Pn(P),we=Math.round(B.start*1e3),ze=Math.round((B.duration??0)*1e3),Vt=Ae.current+we;me<3&&C(`[AUDIO] Viseme "${P}": segment_relative=${we}ms, segment_offset=${Ae.current.toFixed(0)}ms => vtime=${Vt}ms`),pe.forEach($t=>{Ee.current.push({viseme:$t.v,weight:$t.w,vtime:Vt,vduration:ze})})}}),_("Speaking...")}finally{if(j.current=!1,ke.current.length>0){const i=ke.current.shift();i&&vt(i.audio,i.visemes,i.isNewSegment)}}}},hn=async e=>{try{m(!0),z(!1),ae.current="",le(""),_("Processing Voice...");const r=await e.arrayBuffer(),i=await new(window.AudioContext||window.webkitAudioContext)().decodeAudioData(r),n=fn(i),l=new FileReader;l.readAsDataURL(n),l.onloadend=async()=>{const g=l.result.split(",")[1];nt(),oe(""),x.current="",ie.current=!1;const y=`${Qe}/stt?token=${encodeURIComponent(Ne)}`,k=await fetch(y,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({audio_base64:g,audio_format:"wav",agentId:L})});if(k.status===429){try{const me=await k.text(),P=JSON.parse(me);C("[STT] 429 agent at capacity:",P?.detail)}catch{}oe(""),_("Busy"),m(!1);return}if(!k.ok){const me=await k.text();let P="STT Failed";try{P=JSON.parse(me).error||P}catch{me&&(P=me.slice(0,200))}throw new Error(P)}const T=k.body;if(C("this is body"+T),!T){_("STT Failed"),m(!1);return}const v=T.getReader();Se.current=!1;const O=new TextDecoder;let K="",se=!1;const B=async(me,P)=>{switch(me){case"transcript":P.transcript!=null&&oe(String(P.transcript));break;case"text":{const pe=P.delta??P.text??"";pe&&Dt(pe);break}case"audio":{const pe=P.chunk,we=P.visemes??[],ze=!!P.is_new_segment;pe&&await vt(pe,we,ze);break}case"done":{se=!0,_("Ready"),m(!1);break}case"error":{se=!0,_("STT Failed"),m(!1);break}default:break}};for(;;){const{done:me,value:P}=await v.read();P&&(K+=O.decode(P,{stream:!0}));const pe=K.split(`
4
4
 
5
- `);q=ae.pop()??"";for(const de of ae){const De=je(de);De&&await U(De.event,De.data)}if(oe){if(q.trim()){const de=je(q.trim());de&&await U(de.event,de.data)}Q||(h("Ready"),b(!1));break}}}}catch(n){console.error("Audio Submission Error:",n),h("STT Failed"),b(!1)}},Kt=async e=>{e&&e.preventDefault(),Ve(!1),pe.current="",z(""),!(!re||Y)&&await Qt(re)},je=e=>{const n=e.split(/\r?\n/);let r="",i="";for(const u of n)u.startsWith("event:")?r=u.slice(6).trim():u.startsWith("data:")&&(i=u.slice(5).trim());if(!r)return null;let s={};if(i)try{s=JSON.parse(i)}catch{s={raw:i}}return{event:r,data:s}},Qe=(e,n)=>{switch(e){case"connected":ne.current="",me.current=!1;break;case"text":{const r=n.delta??"";r&&xt(r);break}case"audio":{const r=n.chunk,i=n.visemes??[];r&&ut(r,i);break}case"done":{const r=vt(),i=pe.current.trim(),s=[...r,{role:"user",content:re||"..."},{role:"assistant",content:i}];Vt(s),Ce.current=[...N.current],h("Ready"),b(!1),k("");break}case"error":{const r=n.message??"Unknown error";pe.current=r,z(r),h("Agent Failed"),b(!1);break}}},kt=async(e,n)=>{b(!0),h("Thinking..."),pe.current="",ne.current="",me.current=!1,$e(),fe.current=0,d(0);try{const r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(r.status===429){h("Busy"),b(!1);return}if(!r.ok)throw new Error("Request failed");const i=r.body;if(!i){h("Failed"),b(!1);return}const s=i.getReader();xe.current=!1;const u=new TextDecoder;let p="";for(;;){const{done:w,value:v}=await s.read();v&&(p+=u.decode(v,{stream:!0}));const R=p.split(`
5
+ `);K=pe.pop()??"";for(const we of pe){const ze=Ke(we);ze&&await B(ze.event,ze.data)}if(me){if(K.trim()){const we=Ke(K.trim());we&&await B(we.event,we.data)}se||(_("Ready"),m(!1));break}}}}catch(r){console.error("Audio Submission Error:",r),_("STT Failed"),m(!1)}},dn=async e=>{e&&e.preventDefault(),z(!1),ae.current="",le(""),!(!q||ne)&&await mn(q)},Ke=e=>{const r=e.split(/\r?\n/);let s="",i="";for(const l of r)l.startsWith("event:")?s=l.slice(6).trim():l.startsWith("data:")&&(i=l.slice(5).trim());if(!s)return null;let n={};if(i)try{n=JSON.parse(i)}catch{n={raw:i}}return{event:s,data:n}},ht=(e,r)=>{switch(e){case"connected":x.current="",ie.current=!1;break;case"text":{const s=r.delta??"";s&&Dt(s);break}case"audio":{const s=r.chunk,i=r.visemes??[];s&&vt(s,i);break}case"done":{const s=Ot(),i=ae.current.trim(),n=[...s,{role:"user",content:q||"..."},{role:"assistant",content:i}];sn(n),st.current=[...Ee.current],_("Ready"),m(!1),oe("");break}case"error":{const s=r.message??"Unknown error";ae.current=s,le(s),_("Agent Failed"),m(!1);break}}},Nt=async(e,r)=>{m(!0),_("Thinking..."),ae.current="",x.current="",ie.current=!1,nt(),fe.current=0,tt(0);try{const s=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(s.status===429){_("Busy"),m(!1);return}if(!s.ok)throw new Error("Request failed");const i=s.body;if(!i){_("Failed"),m(!1);return}const n=i.getReader();Se.current=!1;const l=new TextDecoder;let g="";for(;;){const{done:y,value:k}=await n.read();k&&(g+=l.decode(k,{stream:!0}));const T=g.split(`
6
6
 
7
- `);p=R.pop()??"";for(const S of R){const E=je(S);E&&Qe(E.event,E.data)}if(w){if(p.trim()){const S=je(p.trim());S&&Qe(S.event,S.data)}h("Ready"),b(!1);break}}}catch(r){console.error("Streaming Error:",r),h("Failed"),b(!1)}},Et=t.useCallback(async(e,n,r)=>{const i=`${qe}/avatar_tts`;await kt(i,{text:e,userQuery:n,llmPrompt:r})},[]),Tt=t.useCallback(async(e,n,r,i)=>{const s=`${qe}/avatar_ttsWithKnowledge`;await kt(s,{userQuery:e,llmPrompt:n,knowledge:r,history:i})},[]),At=t.useRef(!1);t.useEffect(()=>{W&&!At.current&&(W({avatarSpeak:Et,avatarRespond:Tt}),At.current=!0)},[W,Et,Tt]);const Qt=async e=>{b(!0),h("Thinking..."),pe.current="",ne.current="",me.current=!1,$e(),fe.current=0,d(0);const n=`${qe}/agent/chat?token=${encodeURIComponent(M)}`;try{const r=vt();let i=sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");i||(sn("[CHAT] Session UID missing at send time! Generating emergency backup."),i="emergency-"+Math.random().toString(36).substring(7),sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",i));const s={history:r,question:e,lead_id:i};j("[CHAT] Sending payload:",s);const u=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s),cache:"default"});if(u.status===429){try{const S=await u.json();j("[CHAT] 429 agent at capacity:",S?.detail)}catch{}k(""),h("Busy"),b(!1);return}if(!u.ok)throw new Error("Agent request failed");const p=u.body;if(!p){h("Agent Failed"),b(!1);return}const w=p.getReader();xe.current=!1;const v=new TextDecoder;let R="";for(;;){const{done:S,value:E}=await w.read();j(`[SSE] Chunk received. done=${S}, length=${E?.length||0}`),E&&(R+=v.decode(E,{stream:!0}));const q=R.split(`
7
+ `);g=T.pop()??"";for(const v of T){const O=Ke(v);O&&ht(O.event,O.data)}if(y){if(g.trim()){const v=Ke(g.trim());v&&ht(v.event,v.data)}_("Ready"),m(!1);break}}}catch(s){console.error("Streaming Error:",s),_("Failed"),m(!1)}},Pt=t.useCallback(async(e,r,s)=>{const i=`${Qe}/avatar_tts`;await Nt(i,{text:e,userQuery:r,llmPrompt:s})},[]),jt=t.useCallback(async(e,r,s,i)=>{const n=`${Qe}/avatar_ttsWithKnowledge`;await Nt(n,{userQuery:e,llmPrompt:r,knowledge:s,history:i})},[]),Bt=t.useRef(!1);t.useEffect(()=>{w&&!Bt.current&&(w({avatarSpeak:Pt,avatarRespond:jt}),Bt.current=!0)},[w,Pt,jt]);const mn=async e=>{m(!0),_("Thinking..."),ae.current="",x.current="",ie.current=!1,nt(),fe.current=0,tt(0);const r=`${Qe}/agent/chat?token=${encodeURIComponent(Ne)}`;try{const s=Ot();let i=sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");i||(Rn("[CHAT] Session UID missing at send time! Generating emergency backup."),i="emergency-"+Math.random().toString(36).substring(7),sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",i));const n={history:s,question:e,lead_id:i,agentId:L};C("[CHAT] Sending payload:",n);const l=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n),cache:"default"});if(l.status===429){try{const v=await l.json();C("[CHAT] 429 agent at capacity:",v?.detail)}catch{}oe(""),_("Busy"),m(!1);return}if(!l.ok)throw new Error("Agent request failed");const g=l.body;if(!g){_("Agent Failed"),m(!1);return}const y=g.getReader();Se.current=!1;const k=new TextDecoder;let T="";for(;;){const{done:v,value:O}=await y.read();C(`[SSE] Chunk received. done=${v}, length=${O?.length||0}`),O&&(T+=k.decode(O,{stream:!0}));const K=T.split(`
8
8
 
9
- `);R=q.pop()??"";for(const Q of q){j(`[SSE] Processing block: ${Q.slice(0,50)}...`);const U=je(Q);U&&(j(`[SSE] Event: ${U.event}`),Qe(U.event,U.data))}if(S){if(j("[SSE] Stream finished"),R.trim()){const Q=je(R.trim());Q&&Qe(Q.event,Q.data)}h("Ready"),b(!1),k("");break}}}catch(r){console.error("Chat Error:",r),h("Agent Failed"),b(!1)}},Xt=be.trim(),Mt=Nt(Xt),lt=Mt&&X?Mt.slice(0,m!=null&&m>0?m:0):"";t.useEffect(()=>{const e=tt.current;e!=="exiting"&&(lt?(Ut(lt),e==="hidden"&&ze("entering")):(e==="visible"||e==="entering")&&ze("exiting"))},[lt,ue]);const Zt=t.useCallback(()=>{const e=tt.current;e==="entering"?ze("visible"):e==="exiting"&&ze("hidden")},[]);t.useLayoutEffect(()=>{const e=pt.current;e&&(e.scrollTop=e.scrollHeight)},[gt]);const en=g==="female"?gn:pn;return c.jsxs("div",{className:"avatar-widget-container",children:[c.jsxs("div",{className:"avatar-input-area",children:[se!=="hidden"?c.jsx("div",{className:`avatar-thinking-tab${se==="exiting"?" avatar-thinking-tab--exiting":se==="entering"?" avatar-thinking-tab--entering":""}`,onAnimationEnd:jt,children:ve===Ft?c.jsx("a",{href:"https://leads.streamoji.com",target:"_blank",rel:"noopener noreferrer",children:"Made by Streamoji Leads"}):ve}):null,c.jsx("div",{className:"avatar-input-container",children:c.jsx("div",{style:{display:"flex",alignItems:"center",width:"100%",height:"100%"},children:it?c.jsxs("div",{className:"avatar-input-recording",children:[c.jsx("button",{type:"button",className:"avatar-recording-cancel",onClick:Gt,title:"Cancel",children:c.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block"},children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),c.jsxs("div",{style:{flex:1,height:"100%",position:"relative",display:"flex",alignItems:"center",minWidth:0},children:[c.jsx("div",{style:{flex:1,height:"100%"},children:c.jsx(Ot,{analyser:Ht})}),c.jsxs("span",{style:{fontSize:"0.75rem",color:"#64748b",fontWeight:500,marginLeft:"4px",minWidth:"32px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:[Math.floor(yt/60),":",String(yt%60).padStart(2,"0")]})]}),c.jsx("button",{type:"button",className:"avatar-recording-confirm",onClick:Jt,title:"Send",children:c.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block"},children:c.jsx("polyline",{points:"20 6 9 17 4 12"})})})]}):X&&!rt?c.jsxs("div",{className:"avatar-input-speaking",children:[c.jsx("div",{style:{flex:1,height:"100%",display:"flex",alignItems:"center",paddingRight:"8px"},children:c.jsx(Ot,{analyser:Lt})}),c.jsx("button",{type:"button",className:"avatar-speaking-stop",onClick:()=>$e(!0),title:"Stop",children:c.jsx("span",{className:"avatar-speaking-stop__icon","aria-hidden":!0})})]}):Y?c.jsx("div",{style:{flex:1,height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:c.jsx("div",{className:"avatar-input-loader"})}):c.jsxs("form",{onSubmit:Kt,style:{flex:1,display:"flex",height:"100%",alignItems:"center"},children:[c.jsx("input",{id:"avatar-text-input",type:"text",value:re,onChange:e=>k(e.target.value),placeholder:V==="Busy"?"Assisting another user":Z||"Ask me anything",disabled:Y||V==="Busy",autoComplete:"off",style:{width:"100%",height:"100%"}}),V==="Busy"?c.jsx("button",{type:"button",className:"mic-button",disabled:!0,style:{backgroundColor:"#1e4a5e"},title:"Agent at capacity",children:c.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:c.jsx("path",{d:"M4 2L20 2L12 10L4 2z M12 14L4 22L20 22L12 14z",fill:"white"})})}):re.trim()===""?c.jsx("button",{type:"button",className:"mic-button",onClick:qt,disabled:Y,style:{backgroundColor:"#1e4a5e"},children:c.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[c.jsx("path",{d:"M12 14C13.66 14 15 12.66 15 11V5C15 3.34 13.66 2 12 2C10.34 2 9 3.34 9 5V11C9 12.66 10.34 14 12 14Z",fill:"white"}),c.jsx("path",{d:"M17 11C17 13.76 14.76 16 12 16C9.24 16 7 13.76 7 11H5C5 14.53 7.61 17.43 11 17.93V21H13V17.93C16.39 17.43 19 14.53 19 11H17Z",fill:"white"})]})}):c.jsx("button",{type:"submit",className:"mic-button",disabled:Y,style:{backgroundColor:"#1e4a5e"},title:"Send",children:c.jsx("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:c.jsx("path",{d:"M19 12H5M19 12L14 17M19 12L14 7",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})})})]}),c.jsx("div",{className:"avatar-wrapper",children:c.jsxs("div",{className:"avatar-scene-wrapper",children:[ue!=="hidden"&&c.jsx("div",{className:`avatar-bubble${ue==="entering"?" avatar-bubble--entering":ue==="exiting"?" avatar-bubble--exiting":""}`,onAnimationEnd:Zt,children:c.jsx("div",{ref:pt,className:`avatar-bubble__content${rt?" avatar-bubble__content--nudge":""}`,children:gt})}),c.jsx("div",{className:"avatar-canvas-layer",style:{width:C,height:C},children:c.jsxs(ft.Canvas,{shadows:!0,camera:{position:[.2,1.4,3],fov:42},gl:{alpha:!0},dpr:1.8,style:{pointerEvents:"none",width:"100%",height:"100%"},children:[c.jsx(vn,{target:en}),c.jsx("ambientLight",{intensity:.7}),c.jsx("directionalLight",{position:[0,2,2],intensity:1}),c.jsx(Ze.Environment,{preset:"city"}),c.jsx(t.Suspense,{fallback:null,children:Oe!==null&&c.jsx(yn,{avatarUrl:Oe,isPlayingRef:F,visemeQueueRef:N,audioContextRef:D,responseAudioStartTimeRef:Se,adjustments:mn,mood:a,expression:T,agentResponse:be,isSpeaking:X,nextStartTimeRef:ce,stopPlayback:$e,setIsSpeaking:L,expressionUrl:et,onExpressionFinished:Wt,isNudgeResponse:rt,avatarGender:g})})]})})]})})]})},kn=({token:l,avatarGender:y,onNavigationRequested:_,presetUserDetails:g,onAvatarReady:x})=>c.jsx(Ln,{token:l,onNavigationRequested:_,avatarGender:y,presetUserDetails:g,onAvatarReady:x});exports.AvatarWidget=kn;
9
+ `);T=K.pop()??"";for(const se of K){C(`[SSE] Processing block: ${se.slice(0,50)}...`);const B=Ke(se);B&&(C(`[SSE] Event: ${B.event}`),ht(B.event,B.data))}if(v){if(C("[SSE] Stream finished"),T.trim()){const se=Ke(T.trim());se&&ht(se.event,se.data)}_("Ready"),m(!1),oe("");break}}}catch(s){console.error("Chat Error:",s),_("Agent Failed"),m(!1)}},pn=M.trim(),Wt=Zt(pn),kt=Wt&&D?Wt.slice(0,et!=null&&et>0?et:0):"";t.useEffect(()=>{const e=Ce.current;e!=="exiting"&&(kt?(wt(kt),e==="hidden"&&qe("entering")):(e==="visible"||e==="entering")&&qe("exiting"))},[kt,re]);const gn=t.useCallback(()=>{const e=Ce.current;e==="entering"?qe("visible"):e==="exiting"&&qe("hidden")},[]);t.useLayoutEffect(()=>{const e=ct.current;e&&(e.scrollTop=e.scrollHeight)},[ut]);const bn=$==="female"?In:An;return Ze?u.jsxs("div",{className:"avatar-widget-container",children:[u.jsxs("div",{className:"avatar-input-area",children:[Ie!=="hidden"?u.jsx("div",{className:`avatar-thinking-tab${Ie==="exiting"?" avatar-thinking-tab--exiting":Ie==="entering"?" avatar-thinking-tab--entering":""}`,onAnimationEnd:en,children:R===Xt?u.jsx("a",{href:"https://leads.streamoji.com",target:"_blank",rel:"noopener noreferrer",children:"Made by Streamoji Leads"}):R}):null,u.jsx("div",{className:"avatar-input-container",children:u.jsx("div",{style:{display:"flex",alignItems:"center",width:"100%",height:"100%"},children:Rt?u.jsxs("div",{className:"avatar-input-recording",children:[u.jsx("button",{type:"button",className:"avatar-recording-cancel",onClick:ln,title:"Cancel",children:u.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block"},children:[u.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),u.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),u.jsxs("div",{style:{flex:1,height:"100%",position:"relative",display:"flex",alignItems:"center",minWidth:0},children:[u.jsx("div",{style:{flex:1,height:"100%"},children:u.jsx(Ht,{analyser:an})}),u.jsxs("span",{style:{fontSize:"0.75rem",color:"#64748b",fontWeight:500,marginLeft:"4px",minWidth:"32px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:[Math.floor(Ct/60),":",String(Ct%60).padStart(2,"0")]})]}),u.jsx("button",{type:"button",className:"avatar-recording-confirm",onClick:un,title:"Send",children:u.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block"},children:u.jsx("polyline",{points:"20 6 9 17 4 12"})})})]}):D&&!S?u.jsxs("div",{className:"avatar-input-speaking",children:[u.jsx("div",{style:{flex:1,height:"100%",display:"flex",alignItems:"center",paddingRight:"8px"},children:u.jsx(Ht,{analyser:Ft})}),u.jsx("button",{type:"button",className:"avatar-speaking-stop",onClick:()=>nt(!0),title:"Stop",children:u.jsx("span",{className:"avatar-speaking-stop__icon","aria-hidden":!0})})]}):ne?u.jsx("div",{style:{flex:1,height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:u.jsx("div",{className:"avatar-input-loader"})}):u.jsxs("form",{onSubmit:dn,style:{flex:1,display:"flex",height:"100%",alignItems:"center"},children:[u.jsx("input",{id:"avatar-text-input",type:"text",value:q,onChange:e=>oe(e.target.value),placeholder:W==="Busy"?"Assisting another user":F||"Ask me anything",disabled:ne||W==="Busy",autoComplete:"off",style:{width:"100%",height:"100%"}}),W==="Busy"?u.jsx("button",{type:"button",className:"mic-button",disabled:!0,style:{backgroundColor:"#1e4a5e"},title:"Agent at capacity",children:u.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:u.jsx("path",{d:"M4 2L20 2L12 10L4 2z M12 14L4 22L20 22L12 14z",fill:"white"})})}):q.trim()===""?u.jsx("button",{type:"button",className:"mic-button",onClick:cn,disabled:ne,style:{backgroundColor:"#1e4a5e"},children:u.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[u.jsx("path",{d:"M12 14C13.66 14 15 12.66 15 11V5C15 3.34 13.66 2 12 2C10.34 2 9 3.34 9 5V11C9 12.66 10.34 14 12 14Z",fill:"white"}),u.jsx("path",{d:"M17 11C17 13.76 14.76 16 12 16C9.24 16 7 13.76 7 11H5C5 14.53 7.61 17.43 11 17.93V21H13V17.93C16.39 17.43 19 14.53 19 11H17Z",fill:"white"})]})}):u.jsx("button",{type:"submit",className:"mic-button",disabled:ne,style:{backgroundColor:"#1e4a5e"},title:"Send",children:u.jsx("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:u.jsx("path",{d:"M19 12H5M19 12L14 17M19 12L14 7",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})})})]}),u.jsx("div",{className:"avatar-wrapper",children:u.jsxs("div",{className:"avatar-scene-wrapper",children:[re!=="hidden"&&u.jsx("div",{className:`avatar-bubble${re==="entering"?" avatar-bubble--entering":re==="exiting"?" avatar-bubble--exiting":""}`,onAnimationEnd:gn,children:u.jsx("div",{ref:ct,className:`avatar-bubble__content${S?" avatar-bubble__content--nudge":""}`,children:ut})}),u.jsx("div",{className:"avatar-canvas-layer",style:{width:H,height:H},children:u.jsxs(At.Canvas,{shadows:!0,camera:{position:[.2,1.4,3],fov:42},gl:{alpha:!0},dpr:1.8,style:{pointerEvents:"none",width:"100%",height:"100%"},children:[u.jsx(jn,{target:bn}),u.jsx("ambientLight",{intensity:.7}),u.jsx("directionalLight",{position:[0,2,2],intensity:1}),u.jsx(gt.Environment,{preset:"city"}),u.jsx(t.Suspense,{fallback:null,children:ve!==null&&u.jsx(Bn,{avatarUrl:ve,isPlayingRef:Pe,visemeQueueRef:Ee,audioContextRef:ge,responseAudioStartTimeRef:Me,adjustments:Mn,mood:h,expression:o,agentResponse:M,isSpeaking:D,nextStartTimeRef:je,stopPlayback:nt,setIsSpeaking:G,expressionUrl:I,onExpressionFinished:rn,isNudgeResponse:S,avatarGender:$})})]})})]})})]}):null},$n=({agentId:f,onNavigationRequested:L,presetUserDetails:b,onAvatarReady:w})=>u.jsx(Vn,{agentId:f,onNavigationRequested:L,presetUserDetails:b,onAvatarReady:w});exports.AvatarWidget=$n;
@@ -1 +1 @@
1
- .avatar-widget-container{position:fixed;bottom:0;right:0;z-index:1000;display:flex;flex-direction:column;align-items:flex-end;gap:1rem;width:280px}.avatar-bubble{z-index:10002;background:#fff;padding:.8rem;min-height:3em;border-radius:24px;color:#1e293b;font-family:Inter,system-ui,-apple-system,sans-serif;font-size:1rem;font-weight:500;line-height:1.4;box-shadow:0 10px 25px -5px #0000001a,0 8px 10px -6px #0000001a;border:1px solid rgba(0,0,0,.05);position:absolute;top:64px;left:50%;transform:translate(-50%,-100%);max-width:min(320px,85vw);width:100%;pointer-events:none;-webkit-user-select:text;user-select:text;overflow:visible;word-break:break-word}.avatar-bubble:after{content:"";position:absolute;bottom:0;right:18%;width:29px;height:33px;background-image:url("data:image/svg+xml,%3Csvg width='29' height='33' viewBox='0 0 29 33' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.5%209C3.55459%207.42985%204.13875e-07%208%204.13875e-07%208L0.517701%20-9.50694e-06L28.5%200.995422L28.2689%207.49131C28.2689%207.49131%2023.754%207.83102%2022.2194%208.77706C20.6848%209.7231%2019.1146%2011.6685%2018.5794%2012.6501C18.0442%2013.6317%206.37564%2032.2286%206.37564%2032.2286C6.37564%2032.2286%207.46192%2015.7568%207.53302%2013.7581C7.60412%2011.7594%207.44541%2010.5702%205.5%209Z' fill='white'/%3E%3C/svg%3E");background-size:100% 100%;background-repeat:no-repeat;filter:drop-shadow(0 2px 2px rgba(0,0,0,.08));transform:translateY(78%) rotate(0)}.avatar-bubble__content{max-height:63px;overflow-y:auto;word-break:break-word;scrollbar-width:none;-ms-overflow-style:none}.avatar-bubble__content::-webkit-scrollbar{display:none}.avatar-bubble__content--nudge{max-height:160px!important}.avatar-bubble--entering{animation:avatarBubbleEnter .35s ease-out forwards}.avatar-bubble--exiting{animation:avatarBubbleExit .6s ease-in 2s forwards}@keyframes avatarBubbleEnter{0%{transform:translate(120%,-100%);opacity:0}to{transform:translate(-50%,-100%);opacity:1}}@keyframes avatarBubbleExit{0%{transform:translate(-50%,-100%);opacity:1}to{transform:translate(120%,-100%);opacity:0}}.avatar-wrapper{pointer-events:none;width:300px;height:400px;cursor:pointer;transition:transform .3s ease;z-index:1000}.avatar-wrapper:hover{transform:scale(1.05)}.avatar-circle-bg{width:100%;height:100%;border-radius:50%;border:2px solid white;background:linear-gradient(135deg,#008b8b,#38bdf8);box-shadow:0 4px 20px #0000004d;position:absolute;top:0;left:0;z-index:1}.avatar-circle-bg:before{content:"";position:absolute;inset:0;border-radius:50%;box-shadow:0 0 #ffffffb3;animation:pulse-white 2s infinite;z-index:-1}.avatar-scene-wrapper{z-index:2;pointer-events:none;overflow:visible}.avatar-scene-wrapper .avatar-canvas-layer{position:absolute;bottom:0;right:0;pointer-events:none!important;overflow:visible}.avatar-canvas-layer{width:400px;height:400px;z-index:2;pointer-events:none!important;overflow:visible}.avatar-canvas-layer canvas{pointer-events:none!important}@keyframes pulse-white{0%{transform:scale(.95);box-shadow:0 0 #ffffffb3}70%{transform:scale(1);box-shadow:0 0 0 10px #fff0}to{transform:scale(.95);box-shadow:0 0 #fff0}}@keyframes popIn{0%{opacity:0;transform:scale(.8) translateY(10px)}to{opacity:1;transform:scale(1) translateY(0)}}.avatar-input-area{position:absolute;bottom:4px;right:4px;z-index:10001;display:flex;flex-direction:column;align-items:flex-end;gap:6px}@keyframes thinkingTabPopUp{0%{transform:translateY(28px);opacity:0}to{transform:translateY(0);opacity:1}}@keyframes thinkingTabPopDown{0%{transform:translateY(0);opacity:1}to{transform:translateY(28px);opacity:0}}.avatar-thinking-tab{background:#1e4a5e;color:#fff;font-size:.8rem;font-weight:500;padding:6px 14px;border-radius:12px 12px 0 0;font-family:Inter,system-ui,sans-serif;white-space:nowrap;box-shadow:0 2px 8px #0000001a;position:absolute;bottom:45px;left:25px}.avatar-thinking-tab--entering{animation:thinkingTabPopUp .25s ease-out forwards}.avatar-thinking-tab--exiting{animation:thinkingTabPopDown .25s ease-in forwards}.avatar-thinking-tab a{color:inherit;text-decoration:none}.avatar-thinking-tab a:hover{text-decoration:underline}.avatar-input-container{position:relative;bottom:auto;right:auto;z-index:10001;width:100%;min-width:280px;height:48px;min-height:48px;pointer-events:auto;display:flex;flex-direction:column;justify-content:center;align-items:stretch;overflow:hidden;background:#fff;border-radius:50px;padding:0 6px;box-shadow:0 2px 12px #00000014}.avatar-input-container>div:first-child{display:flex;align-items:center;width:100%;height:100%;min-height:0}.avatar-input-container .avatar-input-loader{height:30px;aspect-ratio:2.5;--_g: no-repeat radial-gradient(farthest-side, #1e4a5e 90%, #0000);background:var(--_g),var(--_g),var(--_g),var(--_g);background-size:20% 50%;animation:avatar-input-l44 1s infinite linear alternate}@keyframes avatar-input-l44{0%,5%{background-position:0% 50%,calc(1*100%/3) 50%,calc(2*100%/3) 50%,100% 50%}12.5%{background-position:0% 0,calc(1*100%/3) 50%,calc(2*100%/3) 50%,100% 50%}25%{background-position:0% 0,calc(1*100%/3) 0,calc(2*100%/3) 50%,100% 50%}37.5%{background-position:0% 100%,calc(1*100%/3) 0,calc(2*100%/3) 0,100% 50%}50%{background-position:0% 100%,calc(1*100%/3) 100%,calc(2*100%/3) 0,100% 0}62.5%{background-position:0% 50%,calc(1*100%/3) 100%,calc(2*100%/3) 100%,100% 0}75%{background-position:0% 50%,calc(1*100%/3) 50%,calc(2*100%/3) 100%,100% 100%}87.5%{background-position:0% 50%,calc(1*100%/3) 50%,calc(2*100%/3) 50%,100% 100%}95%,to{background-position:0% 50%,calc(1*100%/3) 50%,calc(2*100%/3) 50%,100% 50%}}.avatar-input-header{background:#1e4a5e;color:#fff;padding:6px 16px;width:fit-content;min-width:35%;margin-left:8%;border-radius:12px 12px 0 0;font-family:Inter,system-ui,sans-serif;font-size:11px;font-weight:500;letter-spacing:-.01em;text-align:center;white-space:nowrap}.avatar-input-body{background:#fff;padding:6px;border-radius:50px;display:flex;flex-direction:column}.avatar-input-body form{display:flex;align-items:center;width:100%}#avatar-text-input{background:transparent;border:none;color:#334155;font-size:.95rem;line-height:1.25;outline:none;padding:0 2px 0 12px;flex:1;min-width:0;font-family:Inter,system-ui,sans-serif}#avatar-text-input::placeholder{color:#94a3b8}.avatar-input-container .mic-button{background:#1e4a5e;color:#fff;border:none;width:38px;height:38px;border-radius:50%!important;display:flex;justify-content:center;align-items:center;cursor:pointer;transition:all .2s cubic-bezier(.4,0,.2,1);flex-shrink:0;margin-right:0;margin-left:8px}.avatar-input-container .mic-button:hover{background:#163a4a;transform:translateY(-1px)}.avatar-input-recording{flex:1;display:flex;align-items:center;width:100%;height:100%;min-height:36px;gap:8px}.avatar-input-recording .avatar-recording-cancel,.avatar-input-recording .avatar-recording-confirm{width:32px;height:32px;min-width:32px;min-height:32px;border-radius:50%;border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;padding:0;line-height:0;align-self:center;box-sizing:border-box}.avatar-input-recording .avatar-recording-cancel{background:#cbd5e1;color:#fff}.avatar-input-recording .avatar-recording-confirm{background:#1e4a5e;color:#fff}.avatar-input-recording .avatar-recording-cancel:hover,.avatar-input-recording .avatar-recording-confirm:hover{opacity:.9}.avatar-input-speaking{flex:1;display:flex;align-items:center;width:100%;height:100%;min-height:36px;gap:8px}.avatar-input-speaking .avatar-speaking-stop{width:32px;height:32px;min-width:32px;min-height:32px;border-radius:50%;border:2px solid #7dd3fc;background:#1e4a5e;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;padding:0;line-height:0;align-self:center;box-sizing:border-box}.avatar-input-speaking .avatar-speaking-stop:hover{opacity:.9}.avatar-speaking-stop__icon{width:10px;height:10px;background:#cbd5e1;border-radius:2px;display:block}.avatar-status-text{font-size:.75rem;color:#64748b;text-align:center;padding-bottom:4px;font-family:Inter,sans-serif}@media(max-width:480px){.avatar-widget-container{width:100%;left:0;right:0;bottom:0;padding:0 max(16px,env(safe-area-inset-left));padding-right:max(16px,env(safe-area-inset-right));box-sizing:border-box;flex-direction:column-reverse;align-items:flex-end}.avatar-input-area{position:relative;width:100%}.avatar-input-container{width:100%;min-width:0;max-width:100%;right:auto;bottom:auto;filter:drop-shadow(0 5px 15px rgba(0,0,0,.2))}.avatar-wrapper{width:80px;height:80px;align-self:flex-end}.avatar-scene-wrapper{width:80px;height:80px}.avatar-canvas-layer{width:350px!important;height:350px!important;right:-28px!important}.avatar-bubble{left:16px;right:auto;top:40px;transform:translateY(-50%);max-width:calc(100vw - 120px);font-size:.85rem;padding:.8rem;border-radius:18px;line-height:1.6;height:90px;box-shadow:0 6px 22px -4px #00000021,0 2px 7px -2px #00000014}.avatar-bubble--entering{animation:avatarBubbleEnterMobile .35s ease-out forwards}.avatar-bubble--exiting{animation:avatarBubbleExitMobile .6s ease-in 2s forwards}@keyframes avatarBubbleEnterMobile{0%{transform:translate(-20px,-50%);opacity:0}to{transform:translateY(-50%);opacity:1}}@keyframes avatarBubbleExitMobile{0%{transform:translateY(-50%);opacity:1}to{transform:translate(-20px,-50%);opacity:0}}.avatar-bubble:after{left:auto;right:4px;bottom:50%;width:16px;height:18px;background-size:100% 100%;transform:translate(100%,50%) rotate(-90deg)}.avatar-input-header{padding:8px 12px;font-size:14px}}.speech-bubble{background:#fff;border-radius:40px 40px 0/40px 40px 0px;padding:16px 24px;color:#1e293b;font-family:Inter,system-ui,-apple-system,sans-serif;font-size:16px;font-weight:500;line-height:1.4;max-width:320px;width:max-content;box-shadow:0 10px 25px -5px #0000001a,0 8px 10px -6px #0000001a;pointer-events:none;-webkit-user-select:none;user-select:none;position:relative;text-align:center;z-index:10002;transform:translate(-50%,-100%);margin-bottom:20px}@keyframes bubbleFadeIn{0%{opacity:0;transform:translate(-50%) scale(.9)}to{opacity:1;transform:translate(-50%) scale(1)}}.thinking-dots{display:flex;justify-content:center;align-items:center;gap:4px;height:12px}.thinking-dots span{width:6px;height:6px;background-color:#94a3b8;border-radius:50%;display:inline-block;animation:thinking-dot-pulse 1.4s infinite ease-in-out both}.thinking-dots span:nth-child(1){animation-delay:-.32s}.thinking-dots span:nth-child(2){animation-delay:-.16s}@keyframes thinking-dot-pulse{0%,80%,to{transform:scale(0);opacity:.3}40%{transform:scale(1);opacity:1}}
1
+ .avatar-bubble:after{content:"";position:absolute;bottom:0;right:18%;width:29px;height:33px;background-image:url("data:image/svg+xml,%3Csvg width='29' height='33' viewBox='0 0 29 33' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.5%209C3.55459%207.42985%204.13875e-07%208%204.13875e-07%208L0.517701%20-9.50694e-06L28.5%200.995422L28.2689%207.49131C28.2689%207.49131%2023.754%207.83102%2022.2194%208.77706C20.6848%209.7231%2019.1146%2011.6685%2018.5794%2012.6501C18.0442%2013.6317%206.37564%2032.2286%206.37564%2032.2286C6.37564%2032.2286%207.46192%2015.7568%207.53302%2013.7581C7.60412%2011.7594%207.44541%2010.5702%205.5%209Z' fill='white'/%3E%3C/svg%3E");background-size:100% 100%;background-repeat:no-repeat;filter:drop-shadow(0 2px 2px rgba(0,0,0,.08));transform:translateY(78%) rotate(0)}.avatar-widget-container{position:fixed;bottom:0;right:0;z-index:1000;display:flex;flex-direction:column;align-items:flex-end;gap:1rem;width:280px}.avatar-bubble{z-index:10002;background:#fff;padding:.8rem;min-height:3em;border-radius:24px;color:#1e293b;font-family:Inter,system-ui,-apple-system,sans-serif;font-size:1rem;font-weight:500;line-height:1.4;box-shadow:0 10px 25px -5px #0000001a,0 8px 10px -6px #0000001a;border:1px solid rgba(0,0,0,.05);position:absolute;top:64px;left:50%;transform:translate(-50%,-100%);max-width:min(320px,85vw);width:100%;pointer-events:none;-webkit-user-select:text;user-select:text;overflow:visible;word-break:break-word}.avatar-bubble:after{content:"";position:absolute;bottom:0;right:18%;width:29px;height:33px;background-image:url("data:image/svg+xml,%3Csvg width='29' height='33' viewBox='0 0 29 33' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.5%209C3.55459%207.42985%204.13875e-07%208%204.13875e-07%208L0.517701%20-9.50694e-06L28.5%200.995422L28.2689%207.49131C28.2689%207.49131%2023.754%207.83102%2022.2194%208.77706C20.6848%209.7231%2019.1146%2011.6685%2018.5794%2012.6501C18.0442%2013.6317%206.37564%2032.2286%206.37564%2032.2286C6.37564%2032.2286%207.46192%2015.7568%207.53302%2013.7581C7.60412%2011.7594%207.44541%2010.5702%205.5%209Z' fill='white'/%3E%3C/svg%3E");background-size:100% 100%;background-repeat:no-repeat;filter:drop-shadow(0 2px 2px rgba(0,0,0,.08));transform:translateY(78%) rotate(0)}.avatar-bubble__content{max-height:63px;overflow-y:auto;word-break:break-word;scrollbar-width:none;-ms-overflow-style:none}.avatar-bubble__content::-webkit-scrollbar{display:none}.avatar-bubble__content--nudge{max-height:160px!important}.avatar-bubble--entering{animation:avatarBubbleEnter .35s ease-out forwards}.avatar-bubble--exiting{animation:avatarBubbleExit .6s ease-in 2s forwards}@keyframes avatarBubbleEnter{0%{transform:translate(120%,-100%);opacity:0}to{transform:translate(-50%,-100%);opacity:1}}@keyframes avatarBubbleExit{0%{transform:translate(-50%,-100%);opacity:1}to{transform:translate(120%,-100%);opacity:0}}.avatar-wrapper{pointer-events:none;width:300px;height:400px;cursor:pointer;transition:transform .3s ease;z-index:1000}.avatar-wrapper:hover{transform:scale(1.05)}.avatar-circle-bg{width:100%;height:100%;border-radius:50%;border:2px solid white;background:linear-gradient(135deg,#008b8b,#38bdf8);box-shadow:0 4px 20px #0000004d;position:absolute;top:0;left:0;z-index:1}.avatar-circle-bg:before{content:"";position:absolute;inset:0;border-radius:50%;box-shadow:0 0 #ffffffb3;animation:pulse-white 2s infinite;z-index:-1}.avatar-scene-wrapper{z-index:2;pointer-events:none;overflow:visible}.avatar-scene-wrapper .avatar-canvas-layer{position:absolute;bottom:0;right:0;pointer-events:none!important;overflow:visible}.avatar-canvas-layer{width:400px;height:400px;z-index:2;pointer-events:none!important;overflow:visible}.avatar-canvas-layer canvas{pointer-events:none!important}@keyframes pulse-white{0%{transform:scale(.95);box-shadow:0 0 #ffffffb3}70%{transform:scale(1);box-shadow:0 0 0 10px #fff0}to{transform:scale(.95);box-shadow:0 0 #fff0}}@keyframes popIn{0%{opacity:0;transform:scale(.8) translateY(10px)}to{opacity:1;transform:scale(1) translateY(0)}}.avatar-input-area{position:absolute;bottom:4px;right:4px;z-index:10001;display:flex;flex-direction:column;align-items:flex-end;gap:6px}@keyframes thinkingTabPopUp{0%{transform:translateY(28px);opacity:0}to{transform:translateY(0);opacity:1}}@keyframes thinkingTabPopDown{0%{transform:translateY(0);opacity:1}to{transform:translateY(28px);opacity:0}}.avatar-thinking-tab{background:#1e4a5e;color:#fff;font-size:.8rem;font-weight:500;padding:6px 14px;border-radius:12px 12px 0 0;font-family:Inter,system-ui,sans-serif;white-space:nowrap;box-shadow:0 2px 8px #0000001a;position:absolute;bottom:45px;left:25px}.avatar-thinking-tab--entering{animation:thinkingTabPopUp .25s ease-out forwards}.avatar-thinking-tab--exiting{animation:thinkingTabPopDown .25s ease-in forwards}.avatar-thinking-tab a{color:inherit;text-decoration:none}.avatar-thinking-tab a:hover{text-decoration:underline}.avatar-input-container{position:relative;bottom:auto;right:auto;z-index:10001;width:100%;min-width:280px;height:48px;min-height:48px;pointer-events:auto;display:flex;flex-direction:column;justify-content:center;align-items:stretch;overflow:hidden;background:#fff;border-radius:50px;padding:0 6px;box-shadow:0 2px 12px #00000014}.avatar-input-container>div:first-child{display:flex;align-items:center;width:100%;height:100%;min-height:0}.avatar-input-container .avatar-input-loader{height:30px;aspect-ratio:2.5;--_g: no-repeat radial-gradient(farthest-side, #1e4a5e 90%, #0000);background:var(--_g),var(--_g),var(--_g),var(--_g);background-size:20% 50%;animation:avatar-input-l44 1s infinite linear alternate}@keyframes avatar-input-l44{0%,5%{background-position:0% 50%,calc(1*100%/3) 50%,calc(2*100%/3) 50%,100% 50%}12.5%{background-position:0% 0,calc(1*100%/3) 50%,calc(2*100%/3) 50%,100% 50%}25%{background-position:0% 0,calc(1*100%/3) 0,calc(2*100%/3) 50%,100% 50%}37.5%{background-position:0% 100%,calc(1*100%/3) 0,calc(2*100%/3) 0,100% 50%}50%{background-position:0% 100%,calc(1*100%/3) 100%,calc(2*100%/3) 0,100% 0}62.5%{background-position:0% 50%,calc(1*100%/3) 100%,calc(2*100%/3) 100%,100% 0}75%{background-position:0% 50%,calc(1*100%/3) 50%,calc(2*100%/3) 100%,100% 100%}87.5%{background-position:0% 50%,calc(1*100%/3) 50%,calc(2*100%/3) 50%,100% 100%}95%,to{background-position:0% 50%,calc(1*100%/3) 50%,calc(2*100%/3) 50%,100% 50%}}.avatar-input-header{background:#1e4a5e;color:#fff;padding:6px 16px;width:fit-content;min-width:35%;margin-left:8%;border-radius:12px 12px 0 0;font-family:Inter,system-ui,sans-serif;font-size:11px;font-weight:500;letter-spacing:-.01em;text-align:center;white-space:nowrap}.avatar-input-body{background:#fff;padding:6px;border-radius:50px;display:flex;flex-direction:column}.avatar-input-body form{display:flex;align-items:center;width:100%}#avatar-text-input{background:transparent;border:none;color:#334155;font-size:.95rem;line-height:1.25;outline:none;padding:0 2px 0 12px;flex:1;min-width:0;font-family:Inter,system-ui,sans-serif}#avatar-text-input::placeholder{color:#94a3b8}.avatar-input-container .mic-button{background:#1e4a5e;color:#fff;border:none;width:38px;height:38px;border-radius:50%!important;display:flex;justify-content:center;align-items:center;cursor:pointer;transition:all .2s cubic-bezier(.4,0,.2,1);flex-shrink:0;margin-right:0;margin-left:8px}.avatar-input-container .mic-button:hover{background:#163a4a;transform:translateY(-1px)}.avatar-input-recording{flex:1;display:flex;align-items:center;width:100%;height:100%;min-height:36px;gap:8px}.avatar-input-recording .avatar-recording-cancel,.avatar-input-recording .avatar-recording-confirm{width:32px;height:32px;min-width:32px;min-height:32px;border-radius:50%;border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;padding:0;line-height:0;align-self:center;box-sizing:border-box}.avatar-input-recording .avatar-recording-cancel{background:#cbd5e1;color:#fff}.avatar-input-recording .avatar-recording-confirm{background:#1e4a5e;color:#fff}.avatar-input-recording .avatar-recording-cancel:hover,.avatar-input-recording .avatar-recording-confirm:hover{opacity:.9}.avatar-input-speaking{flex:1;display:flex;align-items:center;width:100%;height:100%;min-height:36px;gap:8px}.avatar-input-speaking .avatar-speaking-stop{width:32px;height:32px;min-width:32px;min-height:32px;border-radius:50%;border:2px solid #7dd3fc;background:#1e4a5e;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;padding:0;line-height:0;align-self:center;box-sizing:border-box}.avatar-input-speaking .avatar-speaking-stop:hover{opacity:.9}.avatar-speaking-stop__icon{width:10px;height:10px;background:#cbd5e1;border-radius:2px;display:block}.avatar-status-text{font-size:.75rem;color:#64748b;text-align:center;padding-bottom:4px;font-family:Inter,sans-serif}@media(max-width:480px){.avatar-widget-container{width:100%;left:0;right:0;bottom:0;padding:0 max(16px,env(safe-area-inset-left));padding-right:max(16px,env(safe-area-inset-right));box-sizing:border-box;flex-direction:column-reverse;align-items:flex-end}.avatar-input-area{position:relative;width:100%}.avatar-input-container{width:100%;min-width:0;max-width:100%;right:auto;bottom:auto;filter:drop-shadow(0 5px 15px rgba(0,0,0,.2))}.avatar-wrapper{width:80px;height:80px;align-self:flex-end}.avatar-scene-wrapper{width:80px;height:80px}.avatar-canvas-layer{width:350px!important;height:350px!important;right:-28px!important}.avatar-bubble{left:16px;right:auto;top:40px;transform:translateY(-50%);max-width:calc(100vw - 120px);font-size:.85rem;padding:.8rem;border-radius:18px;line-height:1.6;height:90px;box-shadow:0 6px 22px -4px #00000021,0 2px 7px -2px #00000014}.avatar-bubble--entering{animation:avatarBubbleEnterMobile .35s ease-out forwards}.avatar-bubble--exiting{animation:avatarBubbleExitMobile .6s ease-in 2s forwards}@keyframes avatarBubbleEnterMobile{0%{transform:translate(-20px,-50%);opacity:0}to{transform:translateY(-50%);opacity:1}}@keyframes avatarBubbleExitMobile{0%{transform:translateY(-50%);opacity:1}to{transform:translate(-20px,-50%);opacity:0}}.avatar-bubble:after{left:auto;right:4px;bottom:50%;width:16px;height:18px;background-size:100% 100%;transform:translate(100%,50%) rotate(-90deg)}.avatar-input-header{padding:8px 12px;font-size:14px}}.speech-bubble{background:#fff;border-radius:40px 40px 0/40px 40px 0px;padding:16px 24px;color:#1e293b;font-family:Inter,system-ui,-apple-system,sans-serif;font-size:16px;font-weight:500;line-height:1.4;max-width:320px;width:max-content;box-shadow:0 10px 25px -5px #0000001a,0 8px 10px -6px #0000001a;pointer-events:none;-webkit-user-select:none;user-select:none;position:relative;text-align:center;z-index:10002;transform:translate(-50%,-100%);margin-bottom:20px}@keyframes bubbleFadeIn{0%{opacity:0;transform:translate(-50%) scale(.9)}to{opacity:1;transform:translate(-50%) scale(1)}}.thinking-dots{display:flex;justify-content:center;align-items:center;gap:4px;height:12px}.thinking-dots span{width:6px;height:6px;background-color:#94a3b8;border-radius:50%;display:inline-block;animation:thinking-dot-pulse 1.4s infinite ease-in-out both}.thinking-dots span:nth-child(1){animation-delay:-.32s}.thinking-dots span:nth-child(2){animation-delay:-.16s}@keyframes thinking-dot-pulse{0%,80%,to{transform:scale(0);opacity:.3}40%{transform:scale(1);opacity:1}}