@streamoji/avatar-widget 0.3.4 → 0.3.6

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