@streamoji/avatar-widget 0.4.2 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),mt=require("@react-three/drei"),Et=require("@react-three/fiber"),t=require("react"),hn=require("three"),fn=require("three/examples/jsm/loaders/GLTFLoader.js");function dn(f){const T=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(f){for(const R in f)if(R!=="default"){const b=Object.getOwnPropertyDescriptor(f,R);Object.defineProperty(T,R,b.get?b:{enumerable:!0,get:()=>f[R]})}}return T.default=f,Object.freeze(T)}const nt=dn(hn),rt="https://ai.streamoji.com",F=(...f)=>{},mn=(...f)=>{},Wt=({analyser:f})=>{const T=t.useRef(null),R=t.useRef(null);return t.useEffect(()=>{const b=T.current;if(!b)return;const x=b.getContext("2d",{alpha:!0});if(!x)return;let $,N=null;f&&(f.fftSize=128,N=new Uint8Array(f.frequencyBinCount));const Pe=()=>{$=requestAnimationFrame(Pe),(b.width!==b.offsetWidth||b.height!==b.offsetHeight)&&(b.width=b.offsetWidth,b.height=b.offsetHeight);const fe=b.width,E=b.height;if(fe===0||E===0)return;const xe=E/2;x.clearRect(0,0,fe,E),x.fillStyle="#1e293b";const ne=2,m=ne+2,re=fe*.95,S=Math.floor(re/m);(!R.current||R.current.length!==S)&&(R.current=new Float32Array(S).fill(2));const ae=S*m,I=(fe-ae)/2;f&&N&&f.getByteFrequencyData(N);const ve=N?N.length:0,ce=Math.floor(ve*.7)/S,we=new Float32Array(S);for(let P=0;P<S;P++){let G=0;if(N&&ce>0){const D=Math.floor(P*ce),O=Math.floor((P+1)*ce);for(let X=D;X<O;X++){const z=N[X]||0;z>G&&(G=z)}}G<10&&(G=0);const Z=G/255,A=G>0?Math.max(2,Math.pow(Z,1.4)*E*.25):2;we[P]=A}for(let P=0;P<S;P++){const G=S-1-P,Z=Math.max(we[P],we[G]),A=R.current[P]+(Z-R.current[P])*.3;R.current[P]=A;const D=I+P*m,O=xe-A/2;x.beginPath(),x.roundRect?x.roundRect(D,O,ne,A,4):x.fillRect(D,O,ne,A),x.fill()}};return Pe(),()=>{cancelAnimationFrame($)}},[f]),u.jsx("canvas",{ref:T,style:{width:"100%",height:"100%",display:"block"}})},pn="https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev",Vt="https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";async function gn(f){const T=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(f));return Array.from(new Uint8Array(T)).map(R=>R.toString(16).padStart(2,"0")).join("")}function bn(f){const[T,R]=t.useState(null);return t.useEffect(()=>{if(!f){R(null);return}let b=!1;return gn(f).then(x=>{if(b)return;const $=`${pn}/${x}.glb`;fetch($,{method:"HEAD"}).then(N=>{b||R(N.ok?$:Vt)}).catch(()=>{b||R(Vt)})}),()=>{b=!0}},[f]),T}const _n=["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"],wn=["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"],Sn=[{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"}],Rn=["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"],yn=["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"],Ln={zoom:.85,position:[.15,-.8,0],scale:1.5,rotation:[.15,.02,0]},xn=[-.45,1.9,.1],vn=[-.45,1.75,.1],kn={browInnerUp:.2},xt=.18,En=1,Tn=.5,$t=3,ht=.55,vt=.12,Ht=2,qt=2,ft=4,Jt=8,Mn=1,Gt=.38,zt=.32,Yt="__branding__",dt={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}},An=[{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:{}}],In={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 Dn(f){if(!f)return[{v:"sil",w:1}];const T=f.toLowerCase();return In[T]??[{v:"sil",w:1}]}function On({target:f}){const{camera:T}=Et.useThree();return t.useEffect(()=>{T.lookAt(...f)},[T,f]),null}function c(f,T,R){if(!f||!f.morphTargetDictionary)return;const b=f,x=b.morphTargetDictionary,$=b.morphTargetInfluences;if($)for(const N in x)N.toLowerCase()===T.toLowerCase()&&($[x[N]]=R)}function kt(f,T=.97){if(!f)return;const R=f;if(R.morphTargetInfluences)for(let b=0;b<R.morphTargetInfluences.length;b++)R.morphTargetInfluences[b]*=T}const Cn=t.memo(({avatarUrl:f,isPlayingRef:T,visemeQueueRef:R,audioContextRef:b,responseAudioStartTimeRef:x,adjustments:$,mood:N,expression:Pe,agentResponse:fe,isSpeaking:E,nextStartTimeRef:xe,stopPlayback:ne,setIsSpeaking:H,expressionUrl:m,onExpressionFinished:re,isNudgeResponse:S,avatarGender:ae})=>{const{scene:I}=mt.useGLTF(f),ve=ae==="female"?wn:_n,Ae=mt.useGLTF(ve),ce=t.useMemo(()=>Ae.flatMap(g=>g.animations),[Ae]),we=ae==="female"?yn:Rn,P=mt.useGLTF(we),G=t.useMemo(()=>P.flatMap(g=>g.animations),[P]),Z=t.useRef(null),A=t.useRef(null),D=t.useRef(null),O=t.useRef(null),X=t.useRef(null),z=t.useRef(null),je=t.useRef([]),[Y]=t.useState(()=>new nt.AnimationMixer(I)),j=t.useRef({}),q=t.useRef(null),Se=t.useRef(0),Re=t.useRef(!1),ye=t.useRef(0),Ie=t.useRef(!1),ue=t.useRef(null),Be=t.useRef($t),We=t.useRef(-1),Ve=t.useRef("left"),st=t.useRef(ft+Math.random()*(Jt-ft)),$e=t.useRef(0),He=t.useRef("smile");t.useEffect(()=>{if(!(!ce||!I)){if(ce.forEach((g,d)=>{const i=`idle_${d}`;if(!j.current[i]){const r=Y.clipAction(g,I);r.name=i,r.setLoop(nt.LoopOnce,1),r.clampWhenFinished=!0,j.current[i]=r}}),G.forEach((g,d)=>{const i=`talk_${d}`;if(!j.current[i]){const r=Y.clipAction(g,I);r.name=i,r.setLoop(nt.LoopOnce,1),r.clampWhenFinished=!0,j.current[i]=r}}),ce.length>0){const g=j.current.idle_0,d=q.current&&Y.existingAction(q.current.getClip());g&&!d&&(g.reset().fadeIn(.5).play(),q.current=g)}return()=>{Y.stopAllAction(),j.current={},q.current=null}}},[ce,G,I,Y]);const ot=t.useRef("");t.useEffect(()=>{if(!m||!I||m===ot.current)return;ot.current=m,ue.current=m,new fn.GLTFLoader().load(m,d=>{if(d.animations&&d.animations.length>0){const i=d.animations[0],r=Y.clipAction(i,I);if(r.name=`EXPR_${m}`,r.setLoop(nt.LoopOnce,1),r.clampWhenFinished=!0,j.current[`EXPR_${m}`]=r,E&&ue.current===m){const h=q.current;r.reset().fadeIn(.3).play(),h&&h!==r&&h.crossFadeTo(r,.3,!0),q.current=r,ue.current=null}}},void 0,d=>{console.error(`[ANIMATION] Failed to load ${m}`,d)})},[m,I,Y,E]),t.useEffect(()=>{const g=d=>{const i=d.action,r=i.name||"";if(r.startsWith("idle_")){const v=(parseInt(r.split("_")[1])+1)%ce.length,K=j.current[`idle_${v}`];K&&(K.reset().fadeIn(.5).play(),i.crossFadeTo(K,.5,!0),q.current=K)}else if(r.startsWith("EXPR_")){if(E){const h=Math.floor(Math.random()*G.length),v=j.current[`talk_${h}`];v&&(v.reset().fadeIn(.5).play(),i.crossFadeTo(v,.5,!0),q.current=v)}else{const h=j.current.idle_0;h&&(h.reset().fadeIn(.5).play(),i.crossFadeTo(h,.5,!0),q.current=h)}re&&re()}else if(r.startsWith("talk_"))if(E&&!S){const v=(parseInt(r.split("_")[1])+1)%G.length,K=j.current[`talk_${v}`];K&&(K.reset().fadeIn(.3).play(),i.crossFadeTo(K,.3,!0),q.current=K)}else{const h=j.current.idle_0;h&&(h.reset().fadeIn(.5).play(),i.crossFadeTo(h,.5,!0),q.current=h)}};return Y.addEventListener("finished",g),()=>Y.removeEventListener("finished",g)},[Y,ce,G,E,S,re]),t.useEffect(()=>{if(E&&I){const g=q.current,d=g?.name||"";if(d.startsWith("idle_")||d.startsWith("talk_")||d===""){const i=ue.current;if(i){const r=j.current[`EXPR_${i}`];if(r){r.reset().fadeIn(.3).play(),g&&g!==r&&g.crossFadeTo(r,.3,!0),q.current=r,ue.current=null;return}}if(d.startsWith("idle_")||d===""){const r=Math.floor(Math.random()*G.length),h=j.current[`talk_${r}`];h&&(h.reset().fadeIn(.5).play(),g&&g.crossFadeTo(h,.5,!0),q.current=h)}}}else if(!E&&I){const g=q.current,d=g?.name||"";if(d.startsWith("talk_")||d.startsWith("EXPR_")){const i=j.current.idle_0;i&&(i.reset().fadeIn(.5).play(),g&&g.crossFadeTo(i,.5,!0),q.current=i)}}},[E,I,m]),t.useEffect(()=>{if(!I)return;I.traverse(i=>{if(i.isMesh&&i.morphTargetDictionary){const r=i.name.toLowerCase();(r.includes("head")||r.includes("avatar"))&&(A.current=i,F(`[ANIMATION] Found head mesh: ${i.name}`)),r.includes("teeth")&&(D.current=i,F(`[ANIMATION] Found teeth mesh: ${i.name}`)),r.includes("beard")&&(O.current=i,F(`[ANIMATION] Found beard mesh: ${i.name}`)),r.includes("eyeleft")&&(X.current=i,F(`[ANIMATION] Found eye left mesh: ${i.name}`)),r.includes("eyeright")&&(z.current=i,F(`[ANIMATION] Found eye right mesh: ${i.name}`))}});const g=A.current?.morphTargetDictionary;g&&Object.keys(g).filter(i=>i.toLowerCase().includes("brow"));const d=[];I.traverse(i=>{if(i.isMesh){const h=i.morphTargetDictionary;h&&Object.keys(h).some(v=>v.toLowerCase().includes("brow"))&&d.push(i)}}),je.current=d,d.length>0&&F("[ANIMATION] Meshes with brow morphs:",d.length)},[I]);const pt=(g,d=1)=>{const i=`viseme_${g}`.toLowerCase(),r=An.find(h=>h.key.toLowerCase()===i);if(r){for(const h in r.mix){const v=r.mix[h]*d;c(A.current,h,v),c(O.current,h,v),(!r.teethMix||!(h in r.teethMix))&&c(D.current,h,v)}if(r.teethMix)for(const h in r.teethMix){const v=r.teethMix[h]*d;c(D.current,h,v)}}},it=g=>{const d=dt[g]??dt.neutral;for(const i in d)c(A.current,i,d[i]),c(D.current,i,d[i]),c(O.current,i,d[i])};return Et.useFrame((g,d)=>{const i=Math.pow(.88,60*d);kt(A.current,i),kt(D.current,i),kt(O.current,i),it(N);const r=g.clock.elapsedTime;let h=0;if(Math.floor(r)%5===0&&Math.floor((r-d)%5)!==0){let _=null;I.traverse(W=>{W.name.toLowerCase().includes("hips")&&(_=W)});const oe=_?`Hips Y: ${_.position.y.toFixed(4)}`:"Hips not found";F(`[ANIMATION] Mixer Time: ${Y.time.toFixed(2)}, ${oe}`)}if(Y.update(d),r>Se.current&&!Re.current&&(Re.current=!0,ye.current=r),Re.current){const _=E?.2:.3,oe=(r-ye.current)/_;if(oe>=1)if(Re.current=!1,Ie.current){const W=E?1:2.5;Se.current=r+W,Ie.current=!1}else Se.current=r+.12,Ie.current=!0;else{const W=oe<.5?oe*2:(1-oe)*2;c(A.current,"eyeBlinkLeft",W),c(A.current,"eyeBlinkRight",W),c(D.current,"eyeBlinkLeft",W),c(D.current,"eyeBlinkRight",W),c(O.current,"eyeBlinkLeft",W),c(O.current,"eyeBlinkRight",W),h=W*kn.browInnerUp}}const v=dt[N]??dt.neutral,K=v.browInnerUp??0,at=v.browOuterUpLeft??0,ze=v.browOuterUpRight??0,De=r*En,Tt=xt*Math.sin(De),gt=xt*.7*Math.sin(De+.7),Ye=xt*.7*Math.sin(De+1.3),w=_=>Math.max(0,Math.min(1,_)),Oe=w(K+Tt),qe=w(at+gt),Je=w(ze+Ye),ee=w(Oe+h);c(A.current,"browInnerUp",ee),c(D.current,"browInnerUp",ee),c(O.current,"browInnerUp",ee),c(A.current,"browOuterUpLeft",qe),c(D.current,"browOuterUpLeft",qe),c(O.current,"browOuterUpLeft",qe),c(A.current,"browOuterUpRight",Je),c(D.current,"browOuterUpRight",Je),c(O.current,"browOuterUpRight",Je);const ge=Be.current,Ce=ge+ht,ct=Ce+vt;r>ct&&(Be.current+=ht+vt+$t);const ke=!E&&r>=ge&&r<Ce,J=!E&&r>=Ce&&r<ct;(ke||J)&&We.current!==ge&&(We.current=ge,Ve.current=Math.random()<.7?"left":"up");const de=ke?r-ge:J?ht:0,le=ke||J?Math.min(1,de/ht):0,Ke=le<=0?0:Math.sin(le*Math.PI),Qe=J?1-(r-Ce)/vt:1,Ue=ke?Ke:J?Ke*Qe:0,Ee=Tn*Ue,U=_=>v[_]??0;if(Ve.current==="up"?(c(X.current,"eyeLookUpLeft",w(U("eyeLookUpLeft")+Ee)),c(X.current,"eyeLookDownLeft",w(U("eyeLookDownLeft"))),c(X.current,"eyeLookOutLeft",w(U("eyeLookOutLeft"))),c(X.current,"eyeLookInLeft",w(U("eyeLookInLeft"))),c(z.current,"eyeLookUpRight",w(U("eyeLookUpRight")+Ee)),c(z.current,"eyeLookDownRight",w(U("eyeLookDownRight"))),c(z.current,"eyeLookOutRight",w(U("eyeLookOutRight"))),c(z.current,"eyeLookInRight",w(U("eyeLookInRight")))):(c(X.current,"eyeLookUpLeft",w(U("eyeLookUpLeft"))),c(X.current,"eyeLookDownLeft",w(U("eyeLookDownLeft"))),c(X.current,"eyeLookOutLeft",w(U("eyeLookOutLeft"))),c(X.current,"eyeLookInLeft",w(U("eyeLookInLeft")+Ee)),c(z.current,"eyeLookUpRight",w(U("eyeLookUpRight"))),c(z.current,"eyeLookDownRight",w(U("eyeLookDownRight"))),c(z.current,"eyeLookOutRight",w(U("eyeLookOutRight")+Ee)),c(z.current,"eyeLookInRight",w(U("eyeLookInRight")))),!E&&r>=st.current){$e.current=r,He.current=Math.random()<.5?"pucker":"smile";const _=He.current==="pucker"?qt:Ht;st.current=r+_+ft+Math.random()*(Jt-ft)}const Xe=He.current==="pucker"?qt:Ht,Ze=!E&&r>=$e.current&&r<$e.current+Xe,se=Ze?(r-$e.current)/Xe:0,he=se<=0?0:se<.5?se*2:(()=>{const _=(se-.5)*2;return 1-_*_*(3-2*_)})(),Te=_=>v[_]??0;if(Ze)if(He.current==="pucker"){const _=w(Te("mouthPucker")+Mn*he);c(A.current,"mouthPucker",_),c(D.current,"mouthPucker",_),c(O.current,"mouthPucker",_)}else{const _=w(Te("mouthSmileLeft")+Gt*he),oe=w(Te("mouthSmileRight")+Gt*he),W=w(Te("mouthDimpleLeft")+zt*he),Me=w(Te("mouthDimpleRight")+zt*he);c(A.current,"mouthSmileLeft",_),c(A.current,"mouthSmileRight",oe),c(A.current,"mouthDimpleLeft",W),c(A.current,"mouthDimpleRight",Me),c(D.current,"mouthSmileLeft",_),c(D.current,"mouthSmileRight",oe),c(D.current,"mouthDimpleLeft",W),c(D.current,"mouthDimpleRight",Me),c(O.current,"mouthSmileLeft",_),c(O.current,"mouthSmileRight",oe),c(O.current,"mouthDimpleLeft",W),c(O.current,"mouthDimpleRight",Me)}if(Z.current){const _=T.current?0:$.rotation[1];Z.current.rotation.y=nt.MathUtils.lerp(Z.current.rotation.y,_,.1),Z.current.position.set(...$.position),Z.current.scale.setScalar($.scale),Z.current.rotation.x=$.rotation[0],Z.current.rotation.z=$.rotation[2]}if(T.current&&b.current){const _=b.current.currentTime,Me=(_-x.current)*1e3- -150;for(let et=0;et<R.current.length;et++){const te=R.current[et];Me>=te.vtime&&Me<te.vtime+te.vduration&&pt(te.viseme,te.weight??1)}_>xe.current+.5&&(ne(),H(!1))}}),u.jsx("group",{ref:Z,children:u.jsx("primitive",{object:I})})});function Un(f){return f?f.charAt(0).toUpperCase()+f.slice(1).toLowerCase():""}function Kt(f){return f.replace(/\*(.*?)\*/g," $1 ").replace(/\[.*?\]/g," ").replace(/<.*?\/>/g," ").replace(/<.*?>.*?<\/.*?>/g," ").replace(/\s+/g," ").trim()}const Fn=({token:f,agentToken:T,onNavigationRequested:R,avatarGender:b,presetUserDetails:x,onAvatarReady:$}={})=>{const N=f??T??"",Pe=bn(N||void 0),[fe,E]=t.useState(""),[xe,ne]=t.useState(""),[H,m]=t.useState("Ready"),[re,S]=t.useState(!1),[ae,I]=t.useState(!1),[ve,Ae]=t.useState([]),[ce,we]=t.useState(""),P=t.useRef(null),[G,Z]=t.useState(()=>typeof window<"u"?window.matchMedia("(max-width: 480px)").matches:!1);t.useEffect(()=>{const e=window.matchMedia("(max-width: 480px)"),n=()=>Z(e.matches);return e.addEventListener("change",n),()=>e.removeEventListener("change",n)},[]);const A=G?80:600,D=t.useRef(!1),O=t.useRef([]),X=t.useRef(0),z=t.useRef(!1),je=t.useRef([]),Y=t.useRef(null),j=t.useRef([]);t.useRef([]);const q=t.useRef([]),Se=t.useRef(0),Re=t.useRef(0),ye=t.useRef(0),Ie=t.useRef(0),ue=t.useRef(!1),[Be,We]=t.useState(null),Ve=t.useRef(null),[st,$e]=t.useState("neutral"),[He,ot]=t.useState(""),[pt,it]=t.useState(""),[g,d]=t.useState("Chat with us"),[i,r]=t.useState(null),[h,v]=t.useState("hidden"),[K,at]=t.useState(""),ze=t.useRef(null),De=t.useRef(h);De.current=h;const[Tt,gt]=t.useState(null),Ye=t.useRef(null),w=t.useRef(null),[Oe,qe]=t.useState(!1),Je=t.useRef(null),[ee,ge]=t.useState("hidden"),[Ce,ct]=t.useState(""),ke=t.useRef(ee);ke.current=ee;const J=t.useRef(""),de=t.useRef(!1),le=t.useRef(""),Ke=t.useRef(Date.now()),Qe=t.useRef([]),Ue=t.useRef(!1),[Ee,U]=t.useState(!1),[Xe,Ze]=t.useState(!1),se=t.useRef(null),he=t.useMemo(()=>Oe?"Try again":H==="Busy"?"Busy":H==="Thinking..."||H==="Processing Voice..."?H:i!=null&&i!==""&&i!=="none"&&i!=="<none>"?`Enter ${Un(i)}`:ee!=="hidden"||!Xe?null:Yt,[H,i,Oe,ee,Xe]),Te=!Oe&&H!=="Busy"&&H!=="Thinking..."&&H!=="Processing Voice..."&&(i==null||i===""||i==="none"||i==="<none>");t.useEffect(()=>{if(ee!=="hidden"||!Te){Ze(!1),se.current!=null&&(clearTimeout(se.current),se.current=null);return}return se.current=setTimeout(()=>{se.current=null,Ze(!0)},400),()=>{se.current!=null&&(clearTimeout(se.current),se.current=null)}},[ee,Te]);const _=he!=null&&he!=="";t.useEffect(()=>{const e=De.current;if(!(e==="exiting"||e==="entering")){if(e==="hidden"){_&&(at(he??""),v("entering"));return}e==="visible"&&(!_||he!==K)&&(ze.current=_?he:null,v("exiting"))}},[_,he,h,K]),t.useEffect(()=>{if(H!=="Busy"){w.current!=null&&(clearTimeout(w.current),w.current=null);return}return w.current=setTimeout(()=>{w.current=null,m("Ready"),qe(!0)},12e3),()=>{w.current!=null&&(clearTimeout(w.current),w.current=null)}},[H]),t.useEffect(()=>{if(!Oe)return;const e=setTimeout(()=>qe(!1),2500);return()=>clearTimeout(e)},[Oe]);const oe=t.useCallback(()=>{const e=De.current;if(e==="exiting"){v("hidden");const n=ze.current;ze.current=null,n!=null&&n!==""&&(at(n),v("entering"))}else e==="entering"&&v("visible")},[]),W=e=>{if(!e)return;if(e.mood!=null){const o=String(e.mood).toLowerCase();$e(o)}if(e.expression!=null){const o=String(e.expression).trim();ot(o);const l=Sn.find(p=>p.name.toLowerCase()===o.toLowerCase());F(`[STREAM] Animation match for "${o}": ${l?l.name:"NONE"}`),it(l?.url??"")}if(e.navigation!=null){const o=String(e.navigation).trim();o!==""&&(R?R(o):window.open(o,"_blank"))}const n=e.ask_for||e.lead_capture?.ask_for,s=n?String(n).trim().toLowerCase():"",a=s==="none"||s==="<none>";if(n&&!a){const o=s;if(x&&(o==="email"&&x.email||o==="name"&&x.name||o==="phone"&&x.phone))return;r(o||null),d(o==="email"?"Enter your email":o==="name"?"Enter your name":o==="phone"?"Enter your phone number":"Chat with us")}else(a||e.ask_for===null||e.lead_capture&&e.lead_capture.ask_for===null||e.ask_for==="none")&&(r(null),g!=="Chat with us"&&d("Chat with us"));e.collected,e.valid},Me=e=>{const n=e.trim();if(!n)return null;if(n.startsWith("{"))try{return JSON.parse(n)}catch{return null}if(n.includes(":")){const s=n.split(":"),a=s[0].trim().toLowerCase(),o=s.slice(1).join(":").trim();return{[a]:o}}return null},et=t.useCallback(()=>{},[]),te="§",bt=()=>{for(;J.current.includes(`
2
- `);){const e=J.current.indexOf(`
3
- `),n=J.current.slice(0,e).trim();J.current=J.current.slice(e+1);const s=Me(n);s&&W(s)}},Mt=e=>{if(de.current)if(e.includes(te)){const n=e.indexOf(te),s=e.slice(0,n),a=e.slice(n+te.length);s&&(le.current+=s,ne(o=>o+s)),de.current=!1,a&&(J.current+=a,bt())}else e===te?de.current=!1:(le.current+=e,ne(n=>n+e));else if(e.includes(te)){const n=e.indexOf(te),s=e.slice(0,n),a=e.slice(n+te.length);J.current+=s,bt(),de.current=!0,a&&(le.current+=a,ne(o=>o+a))}else if(e===te){de.current=!0;return}else J.current+=e,bt()};t.useEffect(()=>{(async()=>{if(!sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID")){const o="secret",l=Math.floor(Date.now()/1e3).toString();try{const p=new TextEncoder,y=await crypto.subtle.importKey("raw",p.encode(o),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),k=await crypto.subtle.sign("HMAC",y,p.encode(l)),L=Array.from(new Uint8Array(k)).map(C=>C.toString(16).padStart(2,"0")).join("");sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",L),F("[SESSION] New HMAC UID generated and saved:",L)}catch(p){console.error("[SESSION] HMAC generation failed:",p);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 a=[];if(s)try{a=JSON.parse(s)}catch{a=[]}a.length===0&&x&&(x.name||x.email)?(a=[{role:"user",content:`PRESET_USER_DETAILS: Name is "${x.name||""}" , Email is "${x.email||""}"`}],sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES",JSON.stringify(a))):s||sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES",JSON.stringify([]))})()},[x]),t.useEffect(()=>{const e=()=>{Ke.current=Date.now(),Ue.current&&(Ue.current=!1,U(!1),Ae([]),we(""),ne(""),I(!1))};window.addEventListener("mousemove",e),window.addEventListener("keydown",e),window.addEventListener("mousedown",e),window.addEventListener("touchstart",e);const n=setInterval(async()=>{if(Date.now()-Ke.current>=3e4&&!ae&&!re&&H==="Ready"&&!Ue.current)if(Ue.current=!0,Qe.current.length>0)U(!0),Ae(Qe.current);else try{const o=`${rt}/nudgeUser`,l={navigationUrl:window.location.href,token:N},p=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(p.ok){const k=(await p.json()).nudge_questions;k&&k.length>0&&(F("[NUDGE] Received nudge questions from API:",k),Qe.current=k,U(!0),Ae(k))}}catch(o){console.error("[NUDGE] Error calling /nudgeUser:",o),Ue.current=!1}},1e3);return()=>{window.removeEventListener("mousemove",e),window.removeEventListener("keydown",e),window.removeEventListener("mousedown",e),window.removeEventListener("touchstart",e),clearInterval(n)}},[N,ae,re,H]),t.useEffect(()=>{if(ve.length===0)return;let e=0,n=0,s=!1,a=100;const o=()=>{const l=ve[e];if(s){const p=l.substring(0,n-1);we(p),n--,a=50}else{const p=l.substring(0,n+1);we(p),n++,a=100}!s&&n===l.length?(s=!0,a=3e3):s&&n===0&&(s=!1,e=(e+1)%ve.length,a=500),P.current=setTimeout(o,a)};return o(),()=>{P.current&&clearTimeout(P.current)}},[ve]);const At=()=>{try{return JSON.parse(sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES")||"[]")}catch{return[]}},Qt=e=>{sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES",JSON.stringify(e))},[_t,wt]=t.useState(!1),[It,St]=t.useState(0),be=t.useRef(null),ut=t.useRef([]),Dt=t.useRef(0),[Ot,Xt]=t.useState(null),[Zt,Rt]=t.useState(null),Le=t.useRef(null),Fe=t.useRef(null),tt=t.useCallback((e=!1)=>{e&&(ue.current=!0,S(!1),m("Ready")),je.current=[],O.current=[],z.current=!1,I(!1),Se.current=0,Re.current=0,ye.current=0,j.current.forEach(n=>{try{n.stop()}catch{}}),Ye.current&&(clearTimeout(Ye.current),Ye.current=null),gt(null),it(""),j.current=[]},[]),en=async()=>{try{const e=await navigator.mediaDevices.getUserMedia({audio:!0}),n=window.AudioContext||window.webkitAudioContext,s=new n,a=s.createMediaStreamSource(e),o=s.createAnalyser();o.fftSize=64,a.connect(o),Le.current=s,Fe.current=a,Rt(o);const l=new MediaRecorder(e);be.current=l,ut.current=[],l.ondataavailable=p=>{p.data.size>0&&ut.current.push(p.data)},l.onstop=async()=>{const p=Date.now()-Dt.current;if(Rt(null),Fe.current&&(Fe.current.disconnect(),Fe.current=null),Le.current&&Le.current.state!=="closed"&&(Le.current.close(),Le.current=null),p<1e3){m("Recording too short. Hold or click longer."),S(!1);return}const y=new Blob(ut.current,{type:"audio/wav"});await sn(y)},Dt.current=Date.now(),l.start(100),wt(!0),m("Listening...")}catch(e){console.error("Error accessing microphone:",e),m("Mic Access Error")}},tn=()=>{be.current&&be.current.state!=="inactive"&&(be.current.stop(),be.current.stream.getTracks().forEach(e=>e.stop()),wt(!1))},nn=()=>{be.current&&be.current.state!=="inactive"&&(be.current.onstop=null,be.current.stop(),be.current.stream.getTracks().forEach(e=>e.stop()),Rt(null),Fe.current&&(Fe.current.disconnect(),Fe.current=null),Le.current&&Le.current.state!=="closed"&&(Le.current.close(),Le.current=null),wt(!1),ut.current=[],m("Ready"))};t.useEffect(()=>{if(!ae)return;const e=()=>{const n=ye.current;if(n<=0)return;const s=Y.current,a=Se.current;if(!s)return;const o=s.currentTime-a,l=Math.min(Math.max(0,o),n),y=Kt(xe).trim().length;if(y<=0)return;const k=Math.min(Math.round(l/n*y),y);We(k)};return clearInterval(Ve.current??void 0),Ve.current=setInterval(e,90),()=>clearInterval(Ve.current??void 0)},[ae,xe,ye.current]),t.useEffect(()=>{let e;return _t?(St(0),e=window.setInterval(()=>{St(n=>n+1)},1e3)):St(0),()=>clearInterval(e)},[_t]);const rn=e=>{const n=e.numberOfChannels,s=e.length*n*2+44,a=new ArrayBuffer(s),o=new DataView(a);let l=0;const p=L=>{o.setUint16(l,L,!0),l+=2},y=L=>{o.setUint32(l,L,!0),l+=4};y(1179011410),y(s-8),y(1163280727),y(544501094),y(16),p(1),p(n),y(e.sampleRate),y(e.sampleRate*2*n),p(n*2),p(16),y(1635017060),y(s-l-4);const k=[];for(let L=0;L<n;L++)k.push(e.getChannelData(L));let M=0;for(;l<s;){for(let L=0;L<n;L++){let C=Math.max(-1,Math.min(1,k[L][M]));C=C<0?C*32768:C*32767,o.setInt16(l,C,!0),l+=2}M++}return new Blob([a],{type:"audio/wav"})},yt=async(e,n,s=!1)=>{if(!ue.current){if(D.current){O.current.push({audio:e,visemes:n,isNewSegment:s});return}D.current=!0;try{const a=window.AudioContext||window.webkitAudioContext,o=Y.current??new a;o.state==="suspended"&&await o.resume(),Y.current=o;const l=window.atob(e),p=new Uint8Array(l.length);for(let V=0;V<l.length;V++)p[V]=l.charCodeAt(V);const y=await o.decodeAudioData(p.buffer.slice(0));ye.current+=y.duration;const k=o.currentTime;let M=Re.current;const L=!z.current;M<k&&(M=k+.1),Re.current=M+y.duration;const C=o.createBufferSource();C.buffer=y;let Q=Ot;if((!Q||Q.context!==o)&&(Q=o.createAnalyser(),Q.fftSize=64,Q.connect(o.destination),Xt(Q)),C.connect(Q),j.current.push(C),ue.current){j.current=j.current.filter(V=>V!==C);return}if(L){z.current=!0,I(!0),F(`[AUDIO] setIsSpeaking(true) - First chunk starting at ${M.toFixed(3)}`),Se.current=M;const V=(M-k)*1e3;X.current=performance.now()+V,F(`[AUDIO] Response started. Initial startTime: ${M.toFixed(3)}, CT: ${k.toFixed(3)}`)}C.start(M);const ie=(M-Se.current)*1e3;s&&(Ie.current=ie,F(`[AUDIO] New segment detected at +${ie.toFixed(0)}ms. Resetting segment offset.`)),n.forEach((V,me)=>{const B=V.symbol??"";if(B){const pe=Dn(B),_e=Math.round(V.start*1e3),Ne=Math.round((V.duration??0)*1e3),jt=Ie.current+_e;me<3&&F(`[AUDIO] Viseme "${B}": segment_relative=${_e}ms, segment_offset=${Ie.current.toFixed(0)}ms => vtime=${jt}ms`),pe.forEach(Bt=>{je.current.push({viseme:Bt.v,weight:Bt.w,vtime:jt,vduration:Ne})})}}),m("Speaking...")}finally{if(D.current=!1,O.current.length>0){const a=O.current.shift();a&&yt(a.audio,a.visemes,a.isNewSegment)}}}},sn=async e=>{try{S(!0),U(!1),le.current="",ne(""),m("Processing Voice...");const n=await e.arrayBuffer(),a=await new(window.AudioContext||window.webkitAudioContext)().decodeAudioData(n),o=rn(a),l=new FileReader;l.readAsDataURL(o),l.onloadend=async()=>{const p=l.result.split(",")[1];tt(),E(""),J.current="",de.current=!1;const y=`${rt}/stt?token=${encodeURIComponent(N)}`,k=await fetch(y,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({audio_base64:p,audio_format:"wav"})});if(k.status===429){try{const me=await k.text(),B=JSON.parse(me);F("[STT] 429 agent at capacity:",B?.detail)}catch{}E(""),m("Busy"),S(!1);return}if(!k.ok){const me=await k.text();let B="STT Failed";try{B=JSON.parse(me).error||B}catch{me&&(B=me.slice(0,200))}throw new Error(B)}const M=k.body;if(F("this is body"+M),!M){m("STT Failed"),S(!1);return}const L=M.getReader();ue.current=!1;const C=new TextDecoder;let Q="",ie=!1;const V=async(me,B)=>{switch(me){case"transcript":B.transcript!=null&&E(String(B.transcript));break;case"text":{const pe=B.delta??B.text??"";pe&&Mt(pe);break}case"audio":{const pe=B.chunk,_e=B.visemes??[],Ne=!!B.is_new_segment;pe&&await yt(pe,_e,Ne);break}case"done":{ie=!0,m("Ready"),S(!1);break}case"error":{ie=!0,m("STT Failed"),S(!1);break}default:break}};for(;;){const{done:me,value:B}=await L.read();B&&(Q+=C.decode(B,{stream:!0}));const pe=Q.split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),gt=require("@react-three/drei"),It=require("@react-three/fiber"),t=require("react"),wn=require("three"),Sn=require("three/examples/jsm/loaders/GLTFLoader.js");function yn(f){const w=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(f){for(const b in f)if(b!=="default"){const S=Object.getOwnPropertyDescriptor(f,b);Object.defineProperty(w,b,S.get?S:{enumerable:!0,get:()=>f[b]})}}return w.default=f,Object.freeze(w)}const rt=yn(wn),Xe="https://ai.streamoji.com",U=(...f)=>{},Rn=(...f)=>{},Gt=({analyser:f})=>{const w=t.useRef(null),b=t.useRef(null);return t.useEffect(()=>{const S=w.current;if(!S)return;const V=S.getContext("2d",{alpha:!0});if(!V)return;let Y,X=null;f&&(f.fftSize=128,X=new Uint8Array(f.frequencyBinCount));const Ye=()=>{Y=requestAnimationFrame(Ye),(S.width!==S.offsetWidth||S.height!==S.offsetHeight)&&(S.width=S.offsetWidth,S.height=S.offsetHeight);const Fe=S.width,C=S.height;if(Fe===0||C===0)return;const Ze=C/2;V.clearRect(0,0,Fe,C),V.fillStyle="#1e293b";const Se=2,$=Se+2,xe=Fe*.95,G=Math.floor(xe/$);(!b.current||b.current.length!==G)&&(b.current=new Float32Array(G).fill(2));const oe=G*$,M=(Fe-oe)/2;f&&X&&f.getByteFrequencyData(X);const le=X?X.length:0,_=Math.floor(le*.7)/G,ne=new Float32Array(G);for(let p=0;p<G;p++){let D=0;if(X&&_>0){const A=Math.floor(p*_),F=Math.floor((p+1)*_);for(let q=A;q<F;q++){const K=X[q]||0;K>D&&(D=K)}}D<10&&(D=0);const J=D/255,E=D>0?Math.max(2,Math.pow(J,1.4)*C*.25):2;ne[p]=E}for(let p=0;p<G;p++){const D=G-1-p,J=Math.max(ne[p],ne[D]),E=b.current[p]+(J-b.current[p])*.3;b.current[p]=E;const A=M+p*$,F=Ze-E/2;V.beginPath(),V.roundRect?V.roundRect(A,F,Se,E,4):V.fillRect(A,F,Se,E),V.fill()}};return Ye(),()=>{cancelAnimationFrame(Y)}},[f]),l.jsx("canvas",{ref:w,style:{width:"100%",height:"100%",display:"block"}})},Ln="https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev",Jt="https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";function vn(f){const[w,b]=t.useState(null);return t.useEffect(()=>{if(!f){b(null);return}let S=!1;const V=`${Ln}/${f}.glb`;return fetch(V,{method:"HEAD"}).then(Y=>{S||b(Y.ok?V:Jt)}).catch(()=>{S||b(Jt)}),()=>{S=!0}},[f]),w}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"],kn=["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"],En=[{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"}],Tn=["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"],Mn=["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"],An={zoom:.85,position:[.15,-.8,0],scale:1.5,rotation:[.15,.02,0]},In=[-.45,1.9,.1],Dn=[-.45,1.75,.1],On={browInnerUp:.2},Et=.18,Cn=1,Un=.5,qt=3,dt=.55,Tt=.12,zt=2,Yt=2,mt=4,Kt=8,Fn=1,Qt=.38,Xt=.32,Zt="__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}},Nn=[{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:{}}],Pn={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 jn(f){if(!f)return[{v:"sil",w:1}];const w=f.toLowerCase();return Pn[w]??[{v:"sil",w:1}]}function Bn({target:f}){const{camera:w}=It.useThree();return t.useEffect(()=>{w.lookAt(...f)},[w,f]),null}function u(f,w,b){if(!f||!f.morphTargetDictionary)return;const S=f,V=S.morphTargetDictionary,Y=S.morphTargetInfluences;if(Y)for(const X in V)X.toLowerCase()===w.toLowerCase()&&(Y[V[X]]=b)}function Mt(f,w=.97){if(!f)return;const b=f;if(b.morphTargetInfluences)for(let S=0;S<b.morphTargetInfluences.length;S++)b.morphTargetInfluences[S]*=w}const Wn=t.memo(({avatarUrl:f,isPlayingRef:w,visemeQueueRef:b,audioContextRef:S,responseAudioStartTimeRef:V,adjustments:Y,mood:X,expression:Ye,agentResponse:Fe,isSpeaking:C,nextStartTimeRef:Ze,stopPlayback:Se,setIsSpeaking:Ne,expressionUrl:$,onExpressionFinished:xe,isNudgeResponse:G,avatarGender:oe})=>{const{scene:M}=gt.useGLTF(f),le=oe==="female"?kn:xn,W=gt.useGLTF(le),_=t.useMemo(()=>W.flatMap(g=>g.animations),[W]),ne=oe==="female"?Mn:Tn,p=gt.useGLTF(ne),D=t.useMemo(()=>p.flatMap(g=>g.animations),[p]),J=t.useRef(null),E=t.useRef(null),A=t.useRef(null),F=t.useRef(null),q=t.useRef(null),K=t.useRef(null),bt=t.useRef([]),[Z]=t.useState(()=>new rt.AnimationMixer(M)),H=t.useRef({}),j=t.useRef(null),ke=t.useRef(0),Ke=t.useRef(!1),Pe=t.useRef(0),Ee=t.useRef(!1),ge=t.useRef(null),Te=t.useRef(qt),st=t.useRef(-1),Me=t.useRef("left"),je=t.useRef(mt+Math.random()*(Kt-mt)),fe=t.useRef(0),Ae=t.useRef("smile");t.useEffect(()=>{if(!(!_||!M)){if(_.forEach((g,h)=>{const c=`idle_${h}`;if(!H.current[c]){const o=Z.clipAction(g,M);o.name=c,o.setLoop(rt.LoopOnce,1),o.clampWhenFinished=!0,H.current[c]=o}}),D.forEach((g,h)=>{const c=`talk_${h}`;if(!H.current[c]){const o=Z.clipAction(g,M);o.name=c,o.setLoop(rt.LoopOnce,1),o.clampWhenFinished=!0,H.current[c]=o}}),_.length>0){const g=H.current.idle_0,h=j.current&&Z.existingAction(j.current.getClip());g&&!h&&(g.reset().fadeIn(.5).play(),j.current=g)}return()=>{Z.stopAllAction(),H.current={},j.current=null}}},[_,D,M,Z]);const ye=t.useRef("");t.useEffect(()=>{if(!$||!M||$===ye.current)return;ye.current=$,ge.current=$,new Sn.GLTFLoader().load($,h=>{if(h.animations&&h.animations.length>0){const c=h.animations[0],o=Z.clipAction(c,M);if(o.name=`EXPR_${$}`,o.setLoop(rt.LoopOnce,1),o.clampWhenFinished=!0,H.current[`EXPR_${$}`]=o,C&&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,C]),t.useEffect(()=>{const g=h=>{const c=h.action,o=c.name||"";if(o.startsWith("idle_")){const I=(parseInt(o.split("_")[1])+1)%_.length,ee=H.current[`idle_${I}`];ee&&(ee.reset().fadeIn(.5).play(),c.crossFadeTo(ee,.5,!0),j.current=ee)}else if(o.startsWith("EXPR_")){if(C){const d=Math.floor(Math.random()*D.length),I=H.current[`talk_${d}`];I&&(I.reset().fadeIn(.5).play(),c.crossFadeTo(I,.5,!0),j.current=I)}else{const d=H.current.idle_0;d&&(d.reset().fadeIn(.5).play(),c.crossFadeTo(d,.5,!0),j.current=d)}xe&&xe()}else if(o.startsWith("talk_"))if(C&&!G){const I=(parseInt(o.split("_")[1])+1)%D.length,ee=H.current[`talk_${I}`];ee&&(ee.reset().fadeIn(.3).play(),c.crossFadeTo(ee,.3,!0),j.current=ee)}else{const d=H.current.idle_0;d&&(d.reset().fadeIn(.5).play(),c.crossFadeTo(d,.5,!0),j.current=d)}};return Z.addEventListener("finished",g),()=>Z.removeEventListener("finished",g)},[Z,_,D,C,G,xe]),t.useEffect(()=>{if(C&&M){const g=j.current,h=g?.name||"";if(h.startsWith("idle_")||h.startsWith("talk_")||h===""){const c=ge.current;if(c){const o=H.current[`EXPR_${c}`];if(o){o.reset().fadeIn(.3).play(),g&&g!==o&&g.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(),g&&g.crossFadeTo(d,.5,!0),j.current=d)}}}else if(!C&&M){const g=j.current,h=g?.name||"";if(h.startsWith("talk_")||h.startsWith("EXPR_")){const c=H.current.idle_0;c&&(c.reset().fadeIn(.5).play(),g&&g.crossFadeTo(c,.5,!0),j.current=c)}}},[C,M,$]),t.useEffect(()=>{if(!M)return;M.traverse(c=>{if(c.isMesh&&c.morphTargetDictionary){const o=c.name.toLowerCase();(o.includes("head")||o.includes("avatar"))&&(E.current=c,U(`[ANIMATION] Found head mesh: ${c.name}`)),o.includes("teeth")&&(A.current=c,U(`[ANIMATION] Found teeth mesh: ${c.name}`)),o.includes("beard")&&(F.current=c,U(`[ANIMATION] Found beard mesh: ${c.name}`)),o.includes("eyeleft")&&(q.current=c,U(`[ANIMATION] Found eye left mesh: ${c.name}`)),o.includes("eyeright")&&(K.current=c,U(`[ANIMATION] Found eye right mesh: ${c.name}`))}});const g=E.current?.morphTargetDictionary;g&&Object.keys(g).filter(c=>c.toLowerCase().includes("brow"));const h=[];M.traverse(c=>{if(c.isMesh){const d=c.morphTargetDictionary;d&&Object.keys(d).some(I=>I.toLowerCase().includes("brow"))&&h.push(c)}}),bt.current=h,h.length>0&&U("[ANIMATION] Meshes with brow morphs:",h.length)},[M]);const et=(g,h=1)=>{const c=`viseme_${g}`.toLowerCase(),o=Nn.find(d=>d.key.toLowerCase()===c);if(o){for(const d in o.mix){const I=o.mix[d]*h;u(E.current,d,I),u(F.current,d,I),(!o.teethMix||!(d in o.teethMix))&&u(A.current,d,I)}if(o.teethMix)for(const d in o.teethMix){const I=o.teethMix[d]*h;u(A.current,d,I)}}},tt=g=>{const h=pt[g]??pt.neutral;for(const c in h)u(E.current,c,h[c]),u(A.current,c,h[c]),u(F.current,c,h[c])};return It.useFrame((g,h)=>{const c=Math.pow(.88,60*h);Mt(E.current,c),Mt(A.current,c),Mt(F.current,c),tt(X);const o=g.clock.elapsedTime;let d=0;if(Math.floor(o)%5===0&&Math.floor((o-h)%5)!==0){let y=null;M.traverse(N=>{N.name.toLowerCase().includes("hips")&&(y=N)});const z=y?`Hips Y: ${y.position.y.toFixed(4)}`:"Hips not found";U(`[ANIMATION] Mixer Time: ${Z.time.toFixed(2)}, ${z}`)}if(Z.update(h),o>ke.current&&!Ke.current&&(Ke.current=!0,Pe.current=o),Ke.current){const y=C?.2:.3,z=(o-Pe.current)/y;if(z>=1)if(Ke.current=!1,Ee.current){const N=C?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;u(E.current,"eyeBlinkLeft",N),u(E.current,"eyeBlinkRight",N),u(A.current,"eyeBlinkLeft",N),u(A.current,"eyeBlinkRight",N),u(F.current,"eyeBlinkLeft",N),u(F.current,"eyeBlinkRight",N),d=N*On.browInnerUp}}const I=pt[X]??pt.neutral,ee=I.browInnerUp??0,_t=I.browOuterUpLeft??0,Be=I.browOuterUpRight??0,te=o*Cn,ot=Et*Math.sin(te),Ie=Et*.7*Math.sin(te+.7),We=Et*.7*Math.sin(te+1.3),v=y=>Math.max(0,Math.min(1,y)),it=v(ee+ot),Ve=v(_t+Ie),$e=v(Be+We),at=v(it+d);u(E.current,"browInnerUp",at),u(A.current,"browInnerUp",at),u(F.current,"browInnerUp",at),u(E.current,"browOuterUpLeft",Ve),u(A.current,"browOuterUpLeft",Ve),u(F.current,"browOuterUpLeft",Ve),u(E.current,"browOuterUpRight",$e),u(A.current,"browOuterUpRight",$e),u(F.current,"browOuterUpRight",$e);const He=Te.current,De=He+dt,he=De+Tt;o>he&&(Te.current+=dt+Tt+qt);const be=!C&&o>=He&&o<De,Oe=!C&&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,Ge=re<=0?0:Math.sin(re*Math.PI),ut=Oe?1-(o-De)/Tt:1,wt=be?Ge:Oe?Ge*ut:0,Ce=Un*wt,x=y=>I[y]??0;if(Me.current==="up"?(u(q.current,"eyeLookUpLeft",v(x("eyeLookUpLeft")+Ce)),u(q.current,"eyeLookDownLeft",v(x("eyeLookDownLeft"))),u(q.current,"eyeLookOutLeft",v(x("eyeLookOutLeft"))),u(q.current,"eyeLookInLeft",v(x("eyeLookInLeft"))),u(K.current,"eyeLookUpRight",v(x("eyeLookUpRight")+Ce)),u(K.current,"eyeLookDownRight",v(x("eyeLookDownRight"))),u(K.current,"eyeLookOutRight",v(x("eyeLookOutRight"))),u(K.current,"eyeLookInRight",v(x("eyeLookInRight")))):(u(q.current,"eyeLookUpLeft",v(x("eyeLookUpLeft"))),u(q.current,"eyeLookDownLeft",v(x("eyeLookDownLeft"))),u(q.current,"eyeLookOutLeft",v(x("eyeLookOutLeft"))),u(q.current,"eyeLookInLeft",v(x("eyeLookInLeft")+Ce)),u(K.current,"eyeLookUpRight",v(x("eyeLookUpRight"))),u(K.current,"eyeLookDownRight",v(x("eyeLookDownRight"))),u(K.current,"eyeLookOutRight",v(x("eyeLookOutRight")+Ce)),u(K.current,"eyeLookInRight",v(x("eyeLookInRight")))),!C&&o>=je.current){fe.current=o,Ae.current=Math.random()<.5?"pucker":"smile";const y=Ae.current==="pucker"?Yt:zt;je.current=o+y+mt+Math.random()*(Kt-mt)}const ie=Ae.current==="pucker"?Yt:zt,ae=!C&&o>=fe.current&&o<fe.current+ie,Je=ae?(o-fe.current)/ie:0,Re=Je<=0?0:Je<.5?Je*2:(()=>{const y=(Je-.5)*2;return 1-y*y*(3-2*y)})(),de=y=>I[y]??0;if(ae)if(Ae.current==="pucker"){const y=v(de("mouthPucker")+Fn*Re);u(E.current,"mouthPucker",y),u(A.current,"mouthPucker",y),u(F.current,"mouthPucker",y)}else{const y=v(de("mouthSmileLeft")+Qt*Re),z=v(de("mouthSmileRight")+Qt*Re),N=v(de("mouthDimpleLeft")+Xt*Re),Le=v(de("mouthDimpleRight")+Xt*Re);u(E.current,"mouthSmileLeft",y),u(E.current,"mouthSmileRight",z),u(E.current,"mouthDimpleLeft",N),u(E.current,"mouthDimpleRight",Le),u(A.current,"mouthSmileLeft",y),u(A.current,"mouthSmileRight",z),u(A.current,"mouthDimpleLeft",N),u(A.current,"mouthDimpleRight",Le),u(F.current,"mouthSmileLeft",y),u(F.current,"mouthSmileRight",z),u(F.current,"mouthDimpleLeft",N),u(F.current,"mouthDimpleRight",Le)}if(J.current){const y=w.current?0:Y.rotation[1];J.current.rotation.y=rt.MathUtils.lerp(J.current.rotation.y,y,.1),J.current.position.set(...Y.position),J.current.scale.setScalar(Y.scale),J.current.rotation.x=Y.rotation[0],J.current.rotation.z=Y.rotation[2]}if(w.current&&S.current){const y=S.current.currentTime,Le=(y-V.current)*1e3- -150;for(let ce=0;ce<b.current.length;ce++){const ue=b.current[ce];Le>=ue.vtime&&Le<ue.vtime+ue.vduration&&et(ue.viseme,ue.weight??1)}y>Ze.current+.5&&(Se(),Ne(!1))}}),l.jsx("group",{ref:J,children:l.jsx("primitive",{object:M})})});function Vn(f){return f?f.charAt(0).toUpperCase()+f.slice(1).toLowerCase():""}function en(f){return f.replace(/\*(.*?)\*/g," $1 ").replace(/\[.*?\]/g," ").replace(/<.*?\/>/g," ").replace(/<.*?>.*?<\/.*?>/g," ").replace(/\s+/g," ").trim()}const At=new Map,$n=({onNavigationRequested:f,agentId:w,presetUserDetails:b,onAvatarReady:S})=>{const[V,Y]=t.useState(""),[X,Ye]=t.useState("male"),[Fe,C]=t.useState(""),[Ze,Se]=t.useState(!1),Ne=V,$=X;t.useEffect(()=>{if(!w){Se(!0);return}let e=!1;return(async()=>{console.log(">> fetchConfig RUNNING for",w);try{const r=`agent_config_${w}`,i=sessionStorage.getItem(r);if(i)try{const a=JSON.parse(i);e||(a.encryptedAgentToken&&Y(a.encryptedAgentToken),a.avatarGender&&Ye(a.avatarGender),a.agent_id&&C(a.agent_id),Se(!0));return}catch(a){console.error("Failed to parse cached avatar config:",a),sessionStorage.removeItem(r)}let n;if(At.has(w))console.log(">> REUSING in-flight fetch for",w),n=await At.get(w);else{const a=(async()=>{console.log(">> INITIATING visitedWebsite fetch for",w);const m={agentId:w},R=await fetch(`${Xe}/visitedWebsite`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m)});if(!R.ok)throw new Error(`Fetch failed: ${R.status}`);const L=await R.json();return sessionStorage.setItem(r,JSON.stringify(L)),L})();At.set(w,a),n=await a}if(e)return;n&&(n.encryptedAgentToken&&Y(n.encryptedAgentToken),n.avatarGender&&Ye(n.avatarGender),n.agent_id&&C(n.agent_id))}catch(r){console.error("Failed to fetch avatar config:",r)}finally{e||Se(!0)}})(),()=>{e=!0}},[w]);const xe=vn(w??Fe),[G,oe]=t.useState(""),[M,le]=t.useState(""),[W,_]=t.useState("Ready"),[ne,p]=t.useState(!1),[D,J]=t.useState(!1),[E,A]=t.useState([]),[F,q]=t.useState(""),K=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)"),s=()=>Z(e.matches);return e.addEventListener("change",s),()=>e.removeEventListener("change",s)},[]);const H=bt?80:600,j=t.useRef(!1),ke=t.useRef([]),Ke=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),ye=t.useRef(!1),[et,tt]=t.useState(null),g=t.useRef(null),[h,c]=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"),[v,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,Ge]=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(""),Je=t.useRef(Date.now()),Re=t.useRef([]),de=t.useRef(!1),[y,z]=t.useState(!1),[N,Le]=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 ${Vn(te)}`:re!=="hidden"||!N?null:Zt,[W,te,be,re,N]),Dt=!be&&W!=="Busy"&&W!=="Thinking..."&&W!=="Processing Voice..."&&(te==null||te===""||te==="none"||te==="<none>");t.useEffect(()=>{if(re!=="hidden"||!Dt){Le(!1),ce.current!=null&&(clearTimeout(ce.current),ce.current=null);return}return ce.current=setTimeout(()=>{ce.current=null,Le(!0)},400),()=>{ce.current!=null&&(clearTimeout(ce.current),ce.current=null)}},[re,Dt]);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!==v)&&(Ve.current=lt?ue:null,We("exiting"))}},[lt,ue,Ie,v]),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 tn=t.useCallback(()=>{const e=$e.current;if(e==="exiting"){We("hidden");const s=Ve.current;Ve.current=null,s!=null&&s!==""&&(it(s),We("entering"))}else e==="entering"&&We("visible")},[]),nn=e=>{if(!e)return;if(e.mood!=null){const n=String(e.mood).toLowerCase();c(n)}if(e.expression!=null){const n=String(e.expression).trim();d(n);const a=En.find(m=>m.name.toLowerCase()===n.toLowerCase());U(`[STREAM] Animation match for "${n}": ${a?a.name:"NONE"}`),ee(a?.url??"")}if(e.navigation!=null){const n=String(e.navigation).trim();n!==""&&(f?f(n):window.open(n,"_blank"))}const s=e.ask_for||e.lead_capture?.ask_for,r=s?String(s).trim().toLowerCase():"",i=r==="none"||r==="<none>";if(s&&!i){const n=r;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},rn=e=>{const s=e.trim();if(!s)return null;if(s.startsWith("{"))try{return JSON.parse(s)}catch{return null}if(s.includes(":")){const r=s.split(":"),i=r[0].trim().toLowerCase(),n=r.slice(1).join(":").trim();return{[i]:n}}return null},sn=t.useCallback(()=>{},[]),Ue="§",St=()=>{for(;x.current.includes(`
2
+ `);){const e=x.current.indexOf(`
3
+ `),s=x.current.slice(0,e).trim();x.current=x.current.slice(e+1);const r=rn(s);r&&nn(r)}},Ot=e=>{if(ie.current)if(e.includes(Ue)){const s=e.indexOf(Ue),r=e.slice(0,s),i=e.slice(s+Ue.length);r&&(ae.current+=r,le(n=>n+r)),ie.current=!1,i&&(x.current+=i,St())}else e===Ue?ie.current=!1:(ae.current+=e,le(s=>s+e));else if(e.includes(Ue)){const s=e.indexOf(Ue),r=e.slice(0,s),i=e.slice(s+Ue.length);x.current+=r,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",a=Math.floor(Date.now()/1e3).toString();try{const m=new TextEncoder,R=await crypto.subtle.importKey("raw",m.encode(n),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),L=await crypto.subtle.sign("HMAC",R,m.encode(a)),k=Array.from(new Uint8Array(L)).map(O=>O.toString(16).padStart(2,"0")).join("");sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",k),U("[SESSION] New HMAC UID generated and saved:",k)}catch(m){console.error("[SESSION] HMAC generation failed:",m);const R=Math.random().toString(36)+Date.now().toString();sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",R)}}const r=sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");let i=[];if(r)try{i=JSON.parse(r)}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))):r||sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES",JSON.stringify([]))})()},[b]),t.useEffect(()=>{const e=()=>{Je.current=Date.now(),de.current&&(de.current=!1,z(!1),A([]),q(""),le(""),J(!1))};window.addEventListener("mousemove",e),window.addEventListener("keydown",e),window.addEventListener("mousedown",e),window.addEventListener("touchstart",e);const s=setInterval(async()=>{if(Date.now()-Je.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=`${Xe}/nudgeUser`,a={navigationUrl:window.location.href,token:Ne},m=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(m.ok){const L=(await m.json()).nudge_questions;L&&L.length>0&&(U("[NUDGE] Received nudge questions from API:",L),Re.current=L,z(!0),A(L))}}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(s)}},[Ne,D,ne,W]),t.useEffect(()=>{if(E.length===0)return;let e=0,s=0,r=!1,i=100;const n=()=>{const a=E[e];if(r){const m=a.substring(0,s-1);q(m),s--,i=50}else{const m=a.substring(0,s+1);q(m),s++,i=100}!r&&s===a.length?(r=!0,i=3e3):r&&s===0&&(r=!1,e=(e+1)%E.length,i=500),K.current=setTimeout(n,i)};return n(),()=>{K.current&&clearTimeout(K.current)}},[E]);const Ct=()=>{try{return JSON.parse(sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES")||"[]")}catch{return[]}},on=e=>{sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES",JSON.stringify(e))},[yt,Rt]=t.useState(!1),[Ut,Lt]=t.useState(0),_e=t.useRef(null),ft=t.useRef([]),Ft=t.useRef(0),[Nt,an]=t.useState(null),[cn,vt]=t.useState(null),ve=t.useRef(null),qe=t.useRef(null),nt=t.useCallback((e=!1)=>{e&&(ye.current=!0,p(!1),_("Ready")),Ee.current=[],ke.current=[],Pe.current=!1,J(!1),Me.current=0,je.current=0,fe.current=0,Te.current.forEach(s=>{try{s.stop()}catch{}}),De.current&&(clearTimeout(De.current),De.current=null),He(null),ee(""),Te.current=[]},[]),un=async()=>{try{const e=await navigator.mediaDevices.getUserMedia({audio:!0}),s=window.AudioContext||window.webkitAudioContext,r=new s,i=r.createMediaStreamSource(e),n=r.createAnalyser();n.fftSize=64,i.connect(n),ve.current=r,qe.current=i,vt(n);const a=new MediaRecorder(e);_e.current=a,ft.current=[],a.ondataavailable=m=>{m.data.size>0&&ft.current.push(m.data)},a.onstop=async()=>{const m=Date.now()-Ft.current;if(vt(null),qe.current&&(qe.current.disconnect(),qe.current=null),ve.current&&ve.current.state!=="closed"&&(ve.current.close(),ve.current=null),m<1e3){_("Recording too short. Hold or click longer."),p(!1);return}const R=new Blob(ft.current,{type:"audio/wav"});await dn(R)},Ft.current=Date.now(),a.start(100),Rt(!0),_("Listening...")}catch(e){console.error("Error accessing microphone:",e),_("Mic Access Error")}},ln=()=>{_e.current&&_e.current.state!=="inactive"&&(_e.current.stop(),_e.current.stream.getTracks().forEach(e=>e.stop()),Rt(!1))},fn=()=>{_e.current&&_e.current.state!=="inactive"&&(_e.current.onstop=null,_e.current.stop(),_e.current.stream.getTracks().forEach(e=>e.stop()),vt(null),qe.current&&(qe.current.disconnect(),qe.current=null),ve.current&&ve.current.state!=="closed"&&(ve.current.close(),ve.current=null),Rt(!1),ft.current=[],_("Ready"))};t.useEffect(()=>{if(!D)return;const e=()=>{const s=fe.current;if(s<=0)return;const r=ge.current,i=Me.current;if(!r)return;const n=r.currentTime-i,a=Math.min(Math.max(0,n),s),R=en(M).trim().length;if(R<=0)return;const L=Math.min(Math.round(a/s*R),R);tt(L)};return clearInterval(g.current??void 0),g.current=setInterval(e,90),()=>clearInterval(g.current??void 0)},[D,M,fe.current]),t.useEffect(()=>{let e;return yt?(Lt(0),e=window.setInterval(()=>{Lt(s=>s+1)},1e3)):Lt(0),()=>clearInterval(e)},[yt]);const hn=e=>{const s=e.numberOfChannels,r=e.length*s*2+44,i=new ArrayBuffer(r),n=new DataView(i);let a=0;const m=k=>{n.setUint16(a,k,!0),a+=2},R=k=>{n.setUint32(a,k,!0),a+=4};R(1179011410),R(r-8),R(1163280727),R(544501094),R(16),m(1),m(s),R(e.sampleRate),R(e.sampleRate*2*s),m(s*2),m(16),R(1635017060),R(r-a-4);const L=[];for(let k=0;k<s;k++)L.push(e.getChannelData(k));let T=0;for(;a<r;){for(let k=0;k<s;k++){let O=Math.max(-1,Math.min(1,L[k][T]));O=O<0?O*32768:O*32767,n.setInt16(a,O,!0),a+=2}T++}return new Blob([i],{type:"audio/wav"})},xt=async(e,s,r=!1)=>{if(!ye.current){if(j.current){ke.current.push({audio:e,visemes:s,isNewSegment:r});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 a=window.atob(e),m=new Uint8Array(a.length);for(let B=0;B<a.length;B++)m[B]=a.charCodeAt(B);const R=await n.decodeAudioData(m.buffer.slice(0));fe.current+=R.duration;const L=n.currentTime;let T=je.current;const k=!Pe.current;T<L&&(T=L+.1),je.current=T+R.duration;const O=n.createBufferSource();O.buffer=R;let Q=Nt;if((!Q||Q.context!==n)&&(Q=n.createAnalyser(),Q.fftSize=64,Q.connect(n.destination),an(Q)),O.connect(Q),Te.current.push(O),ye.current){Te.current=Te.current.filter(B=>B!==O);return}if(k){Pe.current=!0,J(!0),U(`[AUDIO] setIsSpeaking(true) - First chunk starting at ${T.toFixed(3)}`),Me.current=T;const B=(T-L)*1e3;Ke.current=performance.now()+B,U(`[AUDIO] Response started. Initial startTime: ${T.toFixed(3)}, CT: ${L.toFixed(3)}`)}O.start(T);const se=(T-Me.current)*1e3;r&&(Ae.current=se,U(`[AUDIO] New segment detected at +${se.toFixed(0)}ms. Resetting segment offset.`)),s.forEach((B,me)=>{const P=B.symbol??"";if(P){const pe=jn(P),we=Math.round(B.start*1e3),ze=Math.round((B.duration??0)*1e3),$t=Ae.current+we;me<3&&U(`[AUDIO] Viseme "${P}": segment_relative=${we}ms, segment_offset=${Ae.current.toFixed(0)}ms => vtime=${$t}ms`),pe.forEach(Ht=>{Ee.current.push({viseme:Ht.v,weight:Ht.w,vtime:$t,vduration:ze})})}}),_("Speaking...")}finally{if(j.current=!1,ke.current.length>0){const i=ke.current.shift();i&&xt(i.audio,i.visemes,i.isNewSegment)}}}},dn=async e=>{try{p(!0),z(!1),ae.current="",le(""),_("Processing Voice...");const s=await e.arrayBuffer(),i=await new(window.AudioContext||window.webkitAudioContext)().decodeAudioData(s),n=hn(i),a=new FileReader;a.readAsDataURL(n),a.onloadend=async()=>{const m=a.result.split(",")[1];nt(),oe(""),x.current="",ie.current=!1;const R=`${Xe}/stt?token=${encodeURIComponent(Ne)}`,L=await fetch(R,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({audio_base64:m,audio_format:"wav",agentId:w})});if(L.status===429){try{const me=await L.text(),P=JSON.parse(me);U("[STT] 429 agent at capacity:",P?.detail)}catch{}oe(""),_("Busy"),p(!1);return}if(!L.ok){const me=await L.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=L.body;if(U("this is body"+T),!T){_("STT Failed"),p(!1);return}const k=T.getReader();ye.current=!1;const O=new TextDecoder;let Q="",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&&Ot(pe);break}case"audio":{const pe=P.chunk,we=P.visemes??[],ze=!!P.is_new_segment;pe&&await xt(pe,we,ze);break}case"done":{se=!0,_("Ready"),p(!1);break}case"error":{se=!0,_("STT Failed"),p(!1);break}default:break}};for(;;){const{done:me,value:P}=await k.read();P&&(Q+=O.decode(P,{stream:!0}));const pe=Q.split(`
4
4
 
5
- `);Q=pe.pop()??"";for(const _e of pe){const Ne=Ge(_e);Ne&&await V(Ne.event,Ne.data)}if(me){if(Q.trim()){const _e=Ge(Q.trim());_e&&await V(_e.event,_e.data)}ie||(m("Ready"),S(!1));break}}}}catch(n){console.error("Audio Submission Error:",n),m("STT Failed"),S(!1)}},on=async e=>{e&&e.preventDefault(),U(!1),le.current="",ne(""),!(!fe||re)&&await an(fe)},Ge=e=>{const n=e.split(/\r?\n/);let s="",a="";for(const l of n)l.startsWith("event:")?s=l.slice(6).trim():l.startsWith("data:")&&(a=l.slice(5).trim());if(!s)return null;let o={};if(a)try{o=JSON.parse(a)}catch{o={raw:a}}return{event:s,data:o}},lt=(e,n)=>{switch(e){case"connected":J.current="",de.current=!1;break;case"text":{const s=n.delta??"";s&&Mt(s);break}case"audio":{const s=n.chunk,a=n.visemes??[];s&&yt(s,a);break}case"done":{const s=At(),a=le.current.trim(),o=[...s,{role:"user",content:fe||"..."},{role:"assistant",content:a}];Qt(o),q.current=[...je.current],m("Ready"),S(!1),E("");break}case"error":{const s=n.message??"Unknown error";le.current=s,ne(s),m("Agent Failed"),S(!1);break}}},Ct=async(e,n)=>{S(!0),m("Thinking..."),le.current="",J.current="",de.current=!1,tt(),ye.current=0,We(0);try{const s=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(s.status===429){m("Busy"),S(!1);return}if(!s.ok)throw new Error("Request failed");const a=s.body;if(!a){m("Failed"),S(!1);return}const o=a.getReader();ue.current=!1;const l=new TextDecoder;let p="";for(;;){const{done:y,value:k}=await o.read();k&&(p+=l.decode(k,{stream:!0}));const M=p.split(`
5
+ `);Q=pe.pop()??"";for(const we of pe){const ze=Qe(we);ze&&await B(ze.event,ze.data)}if(me){if(Q.trim()){const we=Qe(Q.trim());we&&await B(we.event,we.data)}se||(_("Ready"),p(!1));break}}}}catch(s){console.error("Audio Submission Error:",s),_("STT Failed"),p(!1)}},mn=async e=>{e&&e.preventDefault(),z(!1),ae.current="",le(""),!(!G||ne)&&await pn(G)},Qe=e=>{const s=e.split(/\r?\n/);let r="",i="";for(const a of s)a.startsWith("event:")?r=a.slice(6).trim():a.startsWith("data:")&&(i=a.slice(5).trim());if(!r)return null;let n={};if(i)try{n=JSON.parse(i)}catch{n={raw:i}}return{event:r,data:n}},ht=(e,s)=>{switch(e){case"connected":x.current="",ie.current=!1;break;case"text":{const r=s.delta??"";r&&Ot(r);break}case"audio":{const r=s.chunk,i=s.visemes??[];r&&xt(r,i);break}case"done":{const r=Ct(),i=ae.current.trim(),n=[...r,{role:"user",content:G||"..."},{role:"assistant",content:i}];on(n),st.current=[...Ee.current],_("Ready"),p(!1),oe("");break}case"error":{const r=s.message??"Unknown error";ae.current=r,le(r),_("Agent Failed"),p(!1);break}}},Pt=async(e,s)=>{p(!0),_("Thinking..."),ae.current="",x.current="",ie.current=!1,nt(),fe.current=0,tt(0);try{const r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(r.status===429){_("Busy"),p(!1);return}if(!r.ok)throw new Error("Request failed");const i=r.body;if(!i){_("Failed"),p(!1);return}const n=i.getReader();ye.current=!1;const a=new TextDecoder;let m="";for(;;){const{done:R,value:L}=await n.read();L&&(m+=a.decode(L,{stream:!0}));const T=m.split(`
6
6
 
7
- `);p=M.pop()??"";for(const L of M){const C=Ge(L);C&&lt(C.event,C.data)}if(y){if(p.trim()){const L=Ge(p.trim());L&&lt(L.event,L.data)}m("Ready"),S(!1);break}}}catch(s){console.error("Streaming Error:",s),m("Failed"),S(!1)}},Ut=t.useCallback(async(e,n,s)=>{const a=`${rt}/avatar_tts`;await Ct(a,{text:e,userQuery:n,llmPrompt:s})},[]),Ft=t.useCallback(async(e,n,s,a)=>{const o=`${rt}/avatar_ttsWithKnowledge`;await Ct(o,{userQuery:e,llmPrompt:n,knowledge:s,history:a})},[]),Nt=t.useRef(!1);t.useEffect(()=>{$&&!Nt.current&&($({avatarSpeak:Ut,avatarRespond:Ft}),Nt.current=!0)},[$,Ut,Ft]);const an=async e=>{S(!0),m("Thinking..."),le.current="",J.current="",de.current=!1,tt(),ye.current=0,We(0);const n=`${rt}/agent/chat?token=${encodeURIComponent(N)}`;try{const s=At();let a=sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");a||(mn("[CHAT] Session UID missing at send time! Generating emergency backup."),a="emergency-"+Math.random().toString(36).substring(7),sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",a));const o={history:s,question:e,lead_id:a};F("[CHAT] Sending payload:",o);const l=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o),cache:"default"});if(l.status===429){try{const L=await l.json();F("[CHAT] 429 agent at capacity:",L?.detail)}catch{}E(""),m("Busy"),S(!1);return}if(!l.ok)throw new Error("Agent request failed");const p=l.body;if(!p){m("Agent Failed"),S(!1);return}const y=p.getReader();ue.current=!1;const k=new TextDecoder;let M="";for(;;){const{done:L,value:C}=await y.read();F(`[SSE] Chunk received. done=${L}, length=${C?.length||0}`),C&&(M+=k.decode(C,{stream:!0}));const Q=M.split(`
7
+ `);m=T.pop()??"";for(const k of T){const O=Qe(k);O&&ht(O.event,O.data)}if(R){if(m.trim()){const k=Qe(m.trim());k&&ht(k.event,k.data)}_("Ready"),p(!1);break}}}catch(r){console.error("Streaming Error:",r),_("Failed"),p(!1)}},jt=t.useCallback(async(e,s,r)=>{const i=`${Xe}/avatar_tts`;await Pt(i,{text:e,userQuery:s,llmPrompt:r})},[]),Bt=t.useCallback(async(e,s,r,i)=>{const n=`${Xe}/avatar_ttsWithKnowledge`;await Pt(n,{userQuery:e,llmPrompt:s,knowledge:r,history:i})},[]),Wt=t.useRef(!1);t.useEffect(()=>{S&&!Wt.current&&(S({avatarSpeak:jt,avatarRespond:Bt}),Wt.current=!0)},[S,jt,Bt]);const pn=async e=>{p(!0),_("Thinking..."),ae.current="",x.current="",ie.current=!1,nt(),fe.current=0,tt(0);const s=`${Xe}/agent/chat?token=${encodeURIComponent(Ne)}`;try{const r=Ct();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:r,question:e,lead_id:i,agentId:w};U("[CHAT] Sending payload:",n);const a=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n),cache:"default"});if(a.status===429){try{const k=await a.json();U("[CHAT] 429 agent at capacity:",k?.detail)}catch{}oe(""),_("Busy"),p(!1);return}if(!a.ok)throw new Error("Agent request failed");const m=a.body;if(!m){_("Agent Failed"),p(!1);return}const R=m.getReader();ye.current=!1;const L=new TextDecoder;let T="";for(;;){const{done:k,value:O}=await R.read();U(`[SSE] Chunk received. done=${k}, length=${O?.length||0}`),O&&(T+=L.decode(O,{stream:!0}));const Q=T.split(`
8
8
 
9
- `);M=Q.pop()??"";for(const ie of Q){F(`[SSE] Processing block: ${ie.slice(0,50)}...`);const V=Ge(ie);V&&(F(`[SSE] Event: ${V.event}`),lt(V.event,V.data))}if(L){if(F("[SSE] Stream finished"),M.trim()){const ie=Ge(M.trim());ie&&lt(ie.event,ie.data)}m("Ready"),S(!1),E("");break}}}catch(s){console.error("Chat Error:",s),m("Agent Failed"),S(!1)}},cn=xe.trim(),Pt=Kt(cn),Lt=Pt&&ae?Pt.slice(0,Be!=null&&Be>0?Be:0):"";t.useEffect(()=>{const e=ke.current;e!=="exiting"&&(Lt?(ct(Lt),e==="hidden"&&ge("entering")):(e==="visible"||e==="entering")&&ge("exiting"))},[Lt,ee]);const un=t.useCallback(()=>{const e=ke.current;e==="entering"?ge("visible"):e==="exiting"&&ge("hidden")},[]);t.useLayoutEffect(()=>{const e=Je.current;e&&(e.scrollTop=e.scrollHeight)},[Ce]);const ln=b==="female"?vn:xn;return u.jsxs("div",{className:"avatar-widget-container",children:[u.jsxs("div",{className:"avatar-input-area",children:[h!=="hidden"?u.jsx("div",{className:`avatar-thinking-tab${h==="exiting"?" avatar-thinking-tab--exiting":h==="entering"?" avatar-thinking-tab--entering":""}`,onAnimationEnd:oe,children:K===Yt?u.jsx("a",{href:"https://leads.streamoji.com",target:"_blank",rel:"noopener noreferrer",children:"Made by Streamoji Leads"}):K}):null,u.jsx("div",{className:"avatar-input-container",children:u.jsx("div",{style:{display:"flex",alignItems:"center",width:"100%",height:"100%"},children:_t?u.jsxs("div",{className:"avatar-input-recording",children:[u.jsx("button",{type:"button",className:"avatar-recording-cancel",onClick:nn,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(Wt,{analyser:Zt})}),u.jsxs("span",{style:{fontSize:"0.75rem",color:"#64748b",fontWeight:500,marginLeft:"4px",minWidth:"32px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:[Math.floor(It/60),":",String(It%60).padStart(2,"0")]})]}),u.jsx("button",{type:"button",className:"avatar-recording-confirm",onClick:tn,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"})})})]}):ae&&!Ee?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(Wt,{analyser:Ot})}),u.jsx("button",{type:"button",className:"avatar-speaking-stop",onClick:()=>tt(!0),title:"Stop",children:u.jsx("span",{className:"avatar-speaking-stop__icon","aria-hidden":!0})})]}):re?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:on,style:{flex:1,display:"flex",height:"100%",alignItems:"center"},children:[u.jsx("input",{id:"avatar-text-input",type:"text",value:fe,onChange:e=>E(e.target.value),placeholder:H==="Busy"?"Assisting another user":ce||"Ask me anything",disabled:re||H==="Busy",autoComplete:"off",style:{width:"100%",height:"100%"}}),H==="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"})})}):fe.trim()===""?u.jsx("button",{type:"button",className:"mic-button",onClick:en,disabled:re,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:re,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:[ee!=="hidden"&&u.jsx("div",{className:`avatar-bubble${ee==="entering"?" avatar-bubble--entering":ee==="exiting"?" avatar-bubble--exiting":""}`,onAnimationEnd:un,children:u.jsx("div",{ref:Je,className:`avatar-bubble__content${Ee?" avatar-bubble__content--nudge":""}`,children:Ce})}),u.jsx("div",{className:"avatar-canvas-layer",style:{width:A,height:A},children:u.jsxs(Et.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(On,{target:ln}),u.jsx("ambientLight",{intensity:.7}),u.jsx("directionalLight",{position:[0,2,2],intensity:1}),u.jsx(mt.Environment,{preset:"city"}),u.jsx(t.Suspense,{fallback:null,children:Pe!==null&&u.jsx(Cn,{avatarUrl:Pe,isPlayingRef:z,visemeQueueRef:je,audioContextRef:Y,responseAudioStartTimeRef:Se,adjustments:Ln,mood:st,expression:He,agentResponse:xe,isSpeaking:ae,nextStartTimeRef:Re,stopPlayback:tt,setIsSpeaking:I,expressionUrl:pt,onExpressionFinished:et,isNudgeResponse:Ee,avatarGender:b})})]})})]})})]})},Nn=({token:f,avatarGender:T,onNavigationRequested:R,presetUserDetails:b,onAvatarReady:x})=>u.jsx(Fn,{token:f,onNavigationRequested:R,avatarGender:T,presetUserDetails:b,onAvatarReady:x});exports.AvatarWidget=Nn;
9
+ `);T=Q.pop()??"";for(const se of Q){U(`[SSE] Processing block: ${se.slice(0,50)}...`);const B=Qe(se);B&&(U(`[SSE] Event: ${B.event}`),ht(B.event,B.data))}if(k){if(U("[SSE] Stream finished"),T.trim()){const se=Qe(T.trim());se&&ht(se.event,se.data)}_("Ready"),p(!1),oe("");break}}}catch(r){console.error("Chat Error:",r),_("Agent Failed"),p(!1)}},gn=M.trim(),Vt=en(gn),kt=Vt&&D?Vt.slice(0,et!=null&&et>0?et:0):"";t.useEffect(()=>{const e=Ce.current;e!=="exiting"&&(kt?(wt(kt),e==="hidden"&&Ge("entering")):(e==="visible"||e==="entering")&&Ge("exiting"))},[kt,re]);const bn=t.useCallback(()=>{const e=Ce.current;e==="entering"?Ge("visible"):e==="exiting"&&Ge("hidden")},[]);t.useLayoutEffect(()=>{const e=ct.current;e&&(e.scrollTop=e.scrollHeight)},[ut]);const _n=$==="female"?Dn:In;return Ze?l.jsxs("div",{className:"avatar-widget-container",children:[l.jsxs("div",{className:"avatar-input-area",children:[Ie!=="hidden"?l.jsx("div",{className:`avatar-thinking-tab${Ie==="exiting"?" avatar-thinking-tab--exiting":Ie==="entering"?" avatar-thinking-tab--entering":""}`,onAnimationEnd:tn,children:v===Zt?l.jsx("a",{href:"https://leads.streamoji.com",target:"_blank",rel:"noopener noreferrer",children:"Made by Streamoji Leads"}):v}):null,l.jsx("div",{className:"avatar-input-container",children:l.jsx("div",{style:{display:"flex",alignItems:"center",width:"100%",height:"100%"},children:yt?l.jsxs("div",{className:"avatar-input-recording",children:[l.jsx("button",{type:"button",className:"avatar-recording-cancel",onClick:fn,title:"Cancel",children:l.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:[l.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),l.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),l.jsxs("div",{style:{flex:1,height:"100%",position:"relative",display:"flex",alignItems:"center",minWidth:0},children:[l.jsx("div",{style:{flex:1,height:"100%"},children:l.jsx(Gt,{analyser:cn})}),l.jsxs("span",{style:{fontSize:"0.75rem",color:"#64748b",fontWeight:500,marginLeft:"4px",minWidth:"32px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:[Math.floor(Ut/60),":",String(Ut%60).padStart(2,"0")]})]}),l.jsx("button",{type:"button",className:"avatar-recording-confirm",onClick:ln,title:"Send",children:l.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:l.jsx("polyline",{points:"20 6 9 17 4 12"})})})]}):D&&!y?l.jsxs("div",{className:"avatar-input-speaking",children:[l.jsx("div",{style:{flex:1,height:"100%",display:"flex",alignItems:"center",paddingRight:"8px"},children:l.jsx(Gt,{analyser:Nt})}),l.jsx("button",{type:"button",className:"avatar-speaking-stop",onClick:()=>nt(!0),title:"Stop",children:l.jsx("span",{className:"avatar-speaking-stop__icon","aria-hidden":!0})})]}):ne?l.jsx("div",{style:{flex:1,height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx("div",{className:"avatar-input-loader"})}):l.jsxs("form",{onSubmit:mn,style:{flex:1,display:"flex",height:"100%",alignItems:"center"},children:[l.jsx("input",{id:"avatar-text-input",type:"text",value:G,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"?l.jsx("button",{type:"button",className:"mic-button",disabled:!0,style:{backgroundColor:"#1e4a5e"},title:"Agent at capacity",children:l.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:l.jsx("path",{d:"M4 2L20 2L12 10L4 2z M12 14L4 22L20 22L12 14z",fill:"white"})})}):G.trim()===""?l.jsx("button",{type:"button",className:"mic-button",onClick:un,disabled:ne,style:{backgroundColor:"#1e4a5e"},children:l.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[l.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"}),l.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"})]})}):l.jsx("button",{type:"submit",className:"mic-button",disabled:ne,style:{backgroundColor:"#1e4a5e"},title:"Send",children:l.jsx("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:l.jsx("path",{d:"M19 12H5M19 12L14 17M19 12L14 7",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})})})]}),l.jsx("div",{className:"avatar-wrapper",children:l.jsxs("div",{className:"avatar-scene-wrapper",children:[re!=="hidden"&&l.jsx("div",{className:`avatar-bubble${re==="entering"?" avatar-bubble--entering":re==="exiting"?" avatar-bubble--exiting":""}`,onAnimationEnd:bn,children:l.jsx("div",{ref:ct,className:`avatar-bubble__content${y?" avatar-bubble__content--nudge":""}`,children:ut})}),l.jsx("div",{className:"avatar-canvas-layer",style:{width:H,height:H},children:l.jsxs(It.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:[l.jsx(Bn,{target:_n}),l.jsx("ambientLight",{intensity:.7}),l.jsx("directionalLight",{position:[0,2,2],intensity:1}),l.jsx(gt.Environment,{preset:"city"}),l.jsx(t.Suspense,{fallback:null,children:xe!==null&&l.jsx(Wn,{avatarUrl:xe,isPlayingRef:Pe,visemeQueueRef:Ee,audioContextRef:ge,responseAudioStartTimeRef:Me,adjustments:An,mood:h,expression:o,agentResponse:M,isSpeaking:D,nextStartTimeRef:je,stopPlayback:nt,setIsSpeaking:J,expressionUrl:I,onExpressionFinished:sn,isNudgeResponse:y,avatarGender:$})})]})})]})})]}):null},Hn=({agentId:f,onNavigationRequested:w,presetUserDetails:b,onAvatarReady:S})=>l.jsx($n,{agentId:f,onNavigationRequested:w,presetUserDetails:b,onAvatarReady:S});exports.AvatarWidget=Hn;
@@ -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}}