@streamoji/avatar-widget 0.2.8 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),Ge=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 Ue=Gt(qt),at="https://ai.streamoji.com",B=(...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,W=null;l&&(l.fftSize=128,W=new Uint8Array(l.frequencyBinCount));const le=()=>{C=requestAnimationFrame(le),(p.width!==p.offsetWidth||p.height!==p.offsetHeight)&&(p.width=p.offsetWidth,p.height=p.offsetHeight);const Y=p.width,O=p.height;if(Y===0||O===0)return;const de=O/2;_.clearRect(0,0,Y,O),_.fillStyle="#1e293b";const T=2,R=T+2,A=Y*.95,F=Math.floor(A/R);(!g.current||g.current.length!==F)&&(g.current=new Float32Array(F).fill(2));const me=F*R,v=(Y-me)/2;l&&W&&l.getByteFrequencyData(W);const _e=W?W.length:0,q=Math.floor(_e*.7)/F,ie=new Float32Array(F);for(let I=0;I<F;I++){let j=0;if(W&&q>0){const ee=Math.floor(I*q),U=Math.floor((I+1)*q);for(let y=ee;y<U;y++){const x=W[y]||0;x>j&&(j=x)}}j<10&&(j=0);const V=j/255,D=j>0?Math.max(2,Math.pow(V,1.4)*O*.25):2;ie[I]=D}for(let I=0;I<F;I++){const j=F-1-I,V=Math.max(ie[I],ie[j]),D=g.current[I]+(V-g.current[I])*.3;g.current[I]=D;const ee=v+I*R,U=de-D/2;_.beginPath(),_.roundRect?_.roundRect(ee,U,T,D,4):_.fillRect(ee,U,T,D),_.fill()}};return le(),()=>{cancelAnimationFrame(C)}},[l]),a.jsx("canvas",{ref:b,style:{width:"100%",height:"100%",display:"block"}})},Yt="https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev",Et="https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/fullbodyavatarmale.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 Xt(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(W=>{p||g(W.ok?C:Et)}).catch(()=>{p||g(Et)})}),()=>{p=!0}},[l]),b}const Kt=["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"],nn={zoom:.85,position:[.15,-.8,0],scale:1.5,rotation:[.15,.02,0]},rn=[-.45,1.9,.1],sn={browInnerUp:.2},ot=.18,an=1,Lt="__branding__",Je={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}},on=[{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:{}}],cn={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 un(l){if(!l)return[{v:"sil",w:1}];const b=l.toLowerCase();return cn[b]??[{v:"sil",w:1}]}function ln({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 W in _)W.toLowerCase()===b.toLowerCase()&&(C[_[W]]=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 dn=e.memo(({avatarUrl:l,isPlayingRef:b,visemeQueueRef:g,audioContextRef:p,responseAudioStartTimeRef:_,adjustments:C,mood:W,expression:le,agentResponse:Y,isSpeaking:O,nextStartTimeRef:de,stopPlayback:T,setIsSpeaking:S,expressionUrl:R,onExpressionFinished:A,isNudgeResponse:F,avatarGender:me})=>{const{scene:v}=Ge.useGLTF(l),_e=me==="female"?Zt:Kt,Ce=Ge.useGLTF(_e),q=e.useMemo(()=>Ce.flatMap(d=>d.animations),[Ce]),ie=Ge.useGLTF(tn),I=e.useMemo(()=>ie.flatMap(d=>d.animations),[ie]),j=e.useRef(null),V=e.useRef(null),D=e.useRef(null),ee=e.useRef([]),[U]=e.useState(()=>new Ue.AnimationMixer(v)),y=e.useRef({}),x=e.useRef(null),we=e.useRef(0),ae=e.useRef(!1),Pe=e.useRef(0),te=e.useRef(null);e.useEffect(()=>{if(!(!q||!v)){if(q.forEach((d,f)=>{const o=`idle_${f}`;if(!y.current[o]){const s=U.clipAction(d,v);s.name=o,s.setLoop(Ue.LoopOnce,1),s.clampWhenFinished=!0,y.current[o]=s}}),I.forEach((d,f)=>{const o=`talk_${f}`;if(!y.current[o]){const s=U.clipAction(d,v);s.name=o,s.setLoop(Ue.LoopOnce,1),s.clampWhenFinished=!0,y.current[o]=s}}),q.length>0){const d=y.current.idle_0,f=x.current&&U.existingAction(x.current.getClip());d&&!f&&(d.reset().fadeIn(.5).play(),x.current=d)}return()=>{U.stopAllAction(),y.current={},x.current=null}}},[q,I,v,U]);const Se=e.useRef("");e.useEffect(()=>{if(!R||!v||R===Se.current)return;Se.current=R,te.current=R,new Jt.GLTFLoader().load(R,f=>{if(f.animations&&f.animations.length>0){const o=f.animations[0],s=U.clipAction(o,v);if(s.name=`EXPR_${R}`,s.setLoop(Ue.LoopOnce,1),s.clampWhenFinished=!0,y.current[`EXPR_${R}`]=s,O&&te.current===R){const m=x.current;s.reset().fadeIn(.3).play(),m&&m!==s&&m.crossFadeTo(s,.3,!0),x.current=s,te.current=null}}},void 0,f=>{console.error(`[ANIMATION] Failed to load ${R}`,f)})},[R,v,U,O]),e.useEffect(()=>{const d=f=>{const o=f.action,s=o.name||"";if(s.startsWith("idle_")){const J=(parseInt(s.split("_")[1])+1)%q.length,Q=y.current[`idle_${J}`];Q&&(Q.reset().fadeIn(.5).play(),o.crossFadeTo(Q,.5,!0),x.current=Q)}else if(s.startsWith("EXPR_")){if(O){const m=y.current.talk_0;m&&(m.reset().fadeIn(.5).play(),o.crossFadeTo(m,.5,!0),x.current=m)}else{const m=y.current.idle_0;m&&(m.reset().fadeIn(.5).play(),o.crossFadeTo(m,.5,!0),x.current=m)}A&&A()}else if(s.startsWith("talk_"))if(O&&!F){const J=(parseInt(s.split("_")[1])+1)%I.length,Q=y.current[`talk_${J}`];Q&&(Q.reset().fadeIn(.3).play(),o.crossFadeTo(Q,.3,!0),x.current=Q)}else{const m=y.current.idle_0;m&&(m.reset().fadeIn(.5).play(),o.crossFadeTo(m,.5,!0),x.current=m)}};return U.addEventListener("finished",d),()=>U.removeEventListener("finished",d)},[U,q,I,O,F,A]),e.useEffect(()=>{if(O&&v){const d=x.current,f=d?.name||"";if(f.startsWith("idle_")||f.startsWith("talk_")||f===""){const o=te.current;if(o){const s=y.current[`EXPR_${o}`];if(s){s.reset().fadeIn(.3).play(),d&&d!==s&&d.crossFadeTo(s,.3,!0),x.current=s,te.current=null;return}}if(f.startsWith("idle_")||f===""){const s=y.current.talk_0;s&&(s.reset().fadeIn(.5).play(),d&&d.crossFadeTo(s,.5,!0),x.current=s)}}}else if(!O&&v){const d=x.current,f=d?.name||"";if(f.startsWith("talk_")||f.startsWith("EXPR_")){const o=y.current.idle_0;o&&(o.reset().fadeIn(.5).play(),d&&d.crossFadeTo(o,.5,!0),x.current=o)}}},[O,v,R]),e.useEffect(()=>{if(!v)return;v.traverse(o=>{if(o.isMesh&&o.morphTargetDictionary){const s=o.name.toLowerCase();(s.includes("head")||s.includes("avatar"))&&(V.current=o,B(`[ANIMATION] Found head mesh: ${o.name}`)),s.includes("teeth")&&(D.current=o,B(`[ANIMATION] Found teeth mesh: ${o.name}`))}});const d=V.current?.morphTargetDictionary;d&&Object.keys(d).filter(o=>o.toLowerCase().includes("brow"));const f=[];v.traverse(o=>{if(o.isMesh){const m=o.morphTargetDictionary;m&&Object.keys(m).some(J=>J.toLowerCase().includes("brow"))&&f.push(o)}}),ee.current=f,f.length>0&&B("[ANIMATION] Meshes with brow morphs:",f.length)},[v]);const ve=(d,f=1)=>{const o=`viseme_${d}`.toLowerCase(),s=on.find(m=>m.key.toLowerCase()===o);if(s)for(const m in s.mix){const J=s.mix[m]*f;z(V.current,m,J),z(D.current,m,J)}},Oe=d=>{const f=Je[d]??Je.neutral;for(const o in f)z(V.current,o,f[o]),z(D.current,o,f[o])};return ct.useFrame((d,f)=>{const o=Math.pow(.88,60*f);At(V.current,o),At(D.current,o),Oe(W);const s=d.clock.elapsedTime;let m=0;if(Math.floor(s)%5===0&&Math.floor((s-f)%5)!==0){let H=null;v.traverse(Z=>{Z.name.toLowerCase().includes("hips")&&(H=Z)});const ne=H?`Hips Y: ${H.position.y.toFixed(4)}`:"Hips not found";B(`[ANIMATION] Mixer Time: ${U.time.toFixed(2)}, ${ne}`)}if(U.update(f),s>we.current&&!ae.current&&(ae.current=!0,Pe.current=s),ae.current){const H=O?.2:.3,ne=(s-Pe.current)/H;if(ne>=1){ae.current=!1;const Z=O?1:2.5;we.current=s+Z}else{const Z=ne<.5?ne*2:(1-ne)*2;z(V.current,"eyeBlinkLeft",Z),z(V.current,"eyeBlinkRight",Z),z(D.current,"eyeBlinkLeft",Z),z(D.current,"eyeBlinkRight",Z),m=Z*sn.browInnerUp}}const J=Je[W]??Je.neutral,Q=J.browInnerUp??0,ze=J.browOuterUpLeft??0,Ye=J.browOuterUpRight??0,Ae=s*an,Qe=ot*Math.sin(Ae),ye=ot*.7*Math.sin(Ae+.7),K=ot*.7*Math.sin(Ae+1.3),xe=H=>Math.max(0,Math.min(1,H)),pe=xe(Q+Qe),ge=xe(ze+ye),Re=xe(Ye+K),De=xe(pe+m);if(z(V.current,"browInnerUp",De),z(D.current,"browInnerUp",De),z(V.current,"browOuterUpLeft",ge),z(D.current,"browOuterUpLeft",ge),z(V.current,"browOuterUpRight",Re),z(D.current,"browOuterUpRight",Re),j.current){const H=b.current?0:C.rotation[1];j.current.rotation.y=Ue.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,Be=(H-_.current)*1e3- -150;for(let ke=0;ke<g.current.length;ke++){const G=g.current[ke];Be>=G.vtime&&Be<G.vtime+G.vduration&&ve(G.viseme,G.weight??1)}H>de.current+.5&&(T(),S(!1))}}),a.jsx("group",{ref:j,children:a.jsx("primitive",{object:v})})});function fn(l){return l?l.charAt(0).toUpperCase()+l.slice(1).toLowerCase():""}const hn=({token:l,agentToken:b,onNavigationRequested:g,avatarGender:p,presetUserDetails:_}={})=>{const C=l??b??"",W=Xt(C||void 0),[le,Y]=e.useState(""),[O,de]=e.useState(""),[T,S]=e.useState("Ready"),[R,A]=e.useState(!1),[F,me]=e.useState(!1),[v,_e]=e.useState([]),[Ce,q]=e.useState(""),ie=e.useRef(null),[I,j]=e.useState(()=>typeof window<"u"?window.matchMedia("(max-width: 480px)").matches:!1);e.useEffect(()=>{const t=window.matchMedia("(max-width: 480px)"),n=()=>j(t.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const V=I?80:600,D=e.useRef(!1),ee=e.useRef([]),U=e.useRef(0),y=e.useRef(!1),x=e.useRef([]),we=e.useRef(null),ae=e.useRef([]);e.useRef([]);const Pe=e.useRef([]),te=e.useRef(0),Se=e.useRef(0),ve=e.useRef(0),Oe=e.useRef(0),d=e.useRef(!1),[f,o]=e.useState(null),s=e.useRef(null),[m,J]=e.useState("neutral"),[Q,ze]=e.useState(""),[Ye,Ae]=e.useState(""),[Qe,ye]=e.useState("Chat with us"),[K,xe]=e.useState(null),[pe,ge]=e.useState("hidden"),[Re,De]=e.useState(""),H=e.useRef(null),ne=e.useRef(pe);ne.current=pe;const[Z,Be]=e.useState(null),ke=e.useRef(null),G=e.useRef(null),[Ne,ut]=e.useState(!1),lt=e.useRef(null),[oe,We]=e.useState("hidden"),[dt,Tt]=e.useState(""),Xe=e.useRef(oe);Xe.current=oe;const fe=e.useRef(""),Te=e.useRef(!1),Ie=e.useRef(""),ft=e.useRef(Date.now()),Ke=e.useRef([]),Fe=e.useRef(!1),[Ze,je]=e.useState(!1),[ht,mt]=e.useState(!1),be=e.useRef(null),Me=e.useMemo(()=>Ne?"Try again":T==="Busy"?"Busy":T==="Thinking..."||T==="Processing Voice..."?T:K!=null&&K!==""&&K!=="none"&&K!=="<none>"?`Enter ${fn(K)}`:oe!=="hidden"||!ht?null:Lt,[T,K,Ne,oe,ht]),pt=!Ne&&T!=="Busy"&&T!=="Thinking..."&&T!=="Processing Voice..."&&(K==null||K===""||K==="none"||K==="<none>");e.useEffect(()=>{if(oe!=="hidden"||!pt){mt(!1),be.current!=null&&(clearTimeout(be.current),be.current=null);return}return be.current=setTimeout(()=>{be.current=null,mt(!0)},400),()=>{be.current!=null&&(clearTimeout(be.current),be.current=null)}},[oe,pt]);const Ve=Me!=null&&Me!=="";e.useEffect(()=>{const t=ne.current;if(!(t==="exiting"||t==="entering")){if(t==="hidden"){Ve&&(De(Me??""),ge("entering"));return}t==="visible"&&(!Ve||Me!==Re)&&(H.current=Ve?Me:null,ge("exiting"))}},[Ve,Me,pe,Re]),e.useEffect(()=>{if(T!=="Busy"){G.current!=null&&(clearTimeout(G.current),G.current=null);return}return G.current=setTimeout(()=>{G.current=null,S("Ready"),ut(!0)},12e3),()=>{G.current!=null&&(clearTimeout(G.current),G.current=null)}},[T]),e.useEffect(()=>{if(!Ne)return;const t=setTimeout(()=>ut(!1),2500);return()=>clearTimeout(t)},[Ne]);const It=e.useCallback(()=>{const t=ne.current;if(t==="exiting"){ge("hidden");const n=H.current;H.current=null,n!=null&&n!==""&&(De(n),ge("entering"))}else t==="entering"&&ge("visible")},[]),Mt=t=>{if(!t)return;if(t.mood!=null){const r=String(t.mood).toLowerCase();J(r)}if(t.expression!=null){const r=String(t.expression).trim();ze(r);const u=en.find(h=>h.name.toLowerCase()===r.toLowerCase());B(`[STREAM] Animation match for "${r}": ${u?u.name:"NONE"}`),Ae(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,i=n?String(n).trim().toLowerCase():"",c=i==="none"||i==="<none>";if(n&&!c){const r=i;if(_&&(r==="email"&&_.email||r==="name"&&_.name||r==="phone"&&_.phone))return;xe(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")&&(xe(null),Qe!=="Chat with us"&&ye("Chat with us"));t.collected,t.valid},Ct=t=>{const n=t.trim();if(!n)return null;if(n.startsWith("{"))try{return JSON.parse(n)}catch{return null}if(n.includes(":")){const i=n.split(":"),c=i[0].trim().toLowerCase(),r=i.slice(1).join(":").trim();return{[c]:r}}return null},Ot=e.useCallback(()=>{},[]),gt=t=>{if(Te.current)t==="§"?Te.current=!1:(Ie.current+=t,de(n=>n+t));else if(t==="§"){Te.current=!0;return}else for(fe.current+=t;fe.current.includes(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),Ge=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 m=Object.getOwnPropertyDescriptor(l,g);Object.defineProperty(b,g,m.get?m:{enumerable:!0,get:()=>l[g]})}}return b.default=l,Object.freeze(b)}const Ue=Gt(qt),at="https://ai.streamoji.com",B=(...l)=>{},zt=(...l)=>{},kt=({analyser:l})=>{const b=e.useRef(null),g=e.useRef(null);return e.useEffect(()=>{const m=b.current;if(!m)return;const _=m.getContext("2d",{alpha:!0});if(!_)return;let C,W=null;l&&(l.fftSize=128,W=new Uint8Array(l.frequencyBinCount));const le=()=>{C=requestAnimationFrame(le),(m.width!==m.offsetWidth||m.height!==m.offsetHeight)&&(m.width=m.offsetWidth,m.height=m.offsetHeight);const Y=m.width,O=m.height;if(Y===0||O===0)return;const de=O/2;_.clearRect(0,0,Y,O),_.fillStyle="#1e293b";const T=2,R=T+2,A=Y*.95,F=Math.floor(A/R);(!g.current||g.current.length!==F)&&(g.current=new Float32Array(F).fill(2));const me=F*R,v=(Y-me)/2;l&&W&&l.getByteFrequencyData(W);const _e=W?W.length:0,q=Math.floor(_e*.7)/F,ie=new Float32Array(F);for(let I=0;I<F;I++){let j=0;if(W&&q>0){const ee=Math.floor(I*q),U=Math.floor((I+1)*q);for(let y=ee;y<U;y++){const x=W[y]||0;x>j&&(j=x)}}j<10&&(j=0);const V=j/255,D=j>0?Math.max(2,Math.pow(V,1.4)*O*.25):2;ie[I]=D}for(let I=0;I<F;I++){const j=F-1-I,V=Math.max(ie[I],ie[j]),D=g.current[I]+(V-g.current[I])*.3;g.current[I]=D;const ee=v+I*R,U=de-D/2;_.beginPath(),_.roundRect?_.roundRect(ee,U,T,D,4):_.fillRect(ee,U,T,D),_.fill()}};return le(),()=>{cancelAnimationFrame(C)}},[l]),a.jsx("canvas",{ref:b,style:{width:"100%",height:"100%",display:"block"}})},Yt="https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev",Et="https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/fullbodyavatarmale.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 Xt(l){const[b,g]=e.useState(null);return e.useEffect(()=>{if(!l){g(null);return}let m=!1;return Qt(l).then(_=>{if(m)return;const C=`${Yt}/${_}.glb`;fetch(C,{method:"HEAD"}).then(W=>{m||g(W.ok?C:Et)}).catch(()=>{m||g(Et)})}),()=>{m=!0}},[l]),b}const Kt=["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"],nn={zoom:.85,position:[.15,-.8,0],scale:1.5,rotation:[.15,.02,0]},rn=[-.45,1.9,.1],sn={browInnerUp:.2},ot=.18,an=1,Lt="__branding__",Je={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}},on=[{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:{}}],cn={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 un(l){if(!l)return[{v:"sil",w:1}];const b=l.toLowerCase();return cn[b]??[{v:"sil",w:1}]}function ln({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 m=l,_=m.morphTargetDictionary,C=m.morphTargetInfluences;if(C)for(const W in _)W.toLowerCase()===b.toLowerCase()&&(C[_[W]]=g)}function At(l,b=.97){if(!l)return;const g=l;if(g.morphTargetInfluences)for(let m=0;m<g.morphTargetInfluences.length;m++)g.morphTargetInfluences[m]*=b}const dn=e.memo(({avatarUrl:l,isPlayingRef:b,visemeQueueRef:g,audioContextRef:m,responseAudioStartTimeRef:_,adjustments:C,mood:W,expression:le,agentResponse:Y,isSpeaking:O,nextStartTimeRef:de,stopPlayback:T,setIsSpeaking:S,expressionUrl:R,onExpressionFinished:A,isNudgeResponse:F,avatarGender:me})=>{const{scene:v}=Ge.useGLTF(l),_e=me==="female"?Zt:Kt,Ce=Ge.useGLTF(_e),q=e.useMemo(()=>Ce.flatMap(d=>d.animations),[Ce]),ie=Ge.useGLTF(tn),I=e.useMemo(()=>ie.flatMap(d=>d.animations),[ie]),j=e.useRef(null),V=e.useRef(null),D=e.useRef(null),ee=e.useRef([]),[U]=e.useState(()=>new Ue.AnimationMixer(v)),y=e.useRef({}),x=e.useRef(null),we=e.useRef(0),ae=e.useRef(!1),Pe=e.useRef(0),te=e.useRef(null);e.useEffect(()=>{if(!(!q||!v)){if(q.forEach((d,f)=>{const o=`idle_${f}`;if(!y.current[o]){const s=U.clipAction(d,v);s.name=o,s.setLoop(Ue.LoopOnce,1),s.clampWhenFinished=!0,y.current[o]=s}}),I.forEach((d,f)=>{const o=`talk_${f}`;if(!y.current[o]){const s=U.clipAction(d,v);s.name=o,s.setLoop(Ue.LoopOnce,1),s.clampWhenFinished=!0,y.current[o]=s}}),q.length>0){const d=y.current.idle_0,f=x.current&&U.existingAction(x.current.getClip());d&&!f&&(d.reset().fadeIn(.5).play(),x.current=d)}return()=>{U.stopAllAction(),y.current={},x.current=null}}},[q,I,v,U]);const Se=e.useRef("");e.useEffect(()=>{if(!R||!v||R===Se.current)return;Se.current=R,te.current=R,new Jt.GLTFLoader().load(R,f=>{if(f.animations&&f.animations.length>0){const o=f.animations[0],s=U.clipAction(o,v);if(s.name=`EXPR_${R}`,s.setLoop(Ue.LoopOnce,1),s.clampWhenFinished=!0,y.current[`EXPR_${R}`]=s,O&&te.current===R){const p=x.current;s.reset().fadeIn(.3).play(),p&&p!==s&&p.crossFadeTo(s,.3,!0),x.current=s,te.current=null}}},void 0,f=>{console.error(`[ANIMATION] Failed to load ${R}`,f)})},[R,v,U,O]),e.useEffect(()=>{const d=f=>{const o=f.action,s=o.name||"";if(s.startsWith("idle_")){const J=(parseInt(s.split("_")[1])+1)%q.length,Q=y.current[`idle_${J}`];Q&&(Q.reset().fadeIn(.5).play(),o.crossFadeTo(Q,.5,!0),x.current=Q)}else if(s.startsWith("EXPR_")){if(O){const p=y.current.talk_0;p&&(p.reset().fadeIn(.5).play(),o.crossFadeTo(p,.5,!0),x.current=p)}else{const p=y.current.idle_0;p&&(p.reset().fadeIn(.5).play(),o.crossFadeTo(p,.5,!0),x.current=p)}A&&A()}else if(s.startsWith("talk_"))if(O&&!F){const J=(parseInt(s.split("_")[1])+1)%I.length,Q=y.current[`talk_${J}`];Q&&(Q.reset().fadeIn(.3).play(),o.crossFadeTo(Q,.3,!0),x.current=Q)}else{const p=y.current.idle_0;p&&(p.reset().fadeIn(.5).play(),o.crossFadeTo(p,.5,!0),x.current=p)}};return U.addEventListener("finished",d),()=>U.removeEventListener("finished",d)},[U,q,I,O,F,A]),e.useEffect(()=>{if(O&&v){const d=x.current,f=d?.name||"";if(f.startsWith("idle_")||f.startsWith("talk_")||f===""){const o=te.current;if(o){const s=y.current[`EXPR_${o}`];if(s){s.reset().fadeIn(.3).play(),d&&d!==s&&d.crossFadeTo(s,.3,!0),x.current=s,te.current=null;return}}if(f.startsWith("idle_")||f===""){const s=y.current.talk_0;s&&(s.reset().fadeIn(.5).play(),d&&d.crossFadeTo(s,.5,!0),x.current=s)}}}else if(!O&&v){const d=x.current,f=d?.name||"";if(f.startsWith("talk_")||f.startsWith("EXPR_")){const o=y.current.idle_0;o&&(o.reset().fadeIn(.5).play(),d&&d.crossFadeTo(o,.5,!0),x.current=o)}}},[O,v,R]),e.useEffect(()=>{if(!v)return;v.traverse(o=>{if(o.isMesh&&o.morphTargetDictionary){const s=o.name.toLowerCase();(s.includes("head")||s.includes("avatar"))&&(V.current=o,B(`[ANIMATION] Found head mesh: ${o.name}`)),s.includes("teeth")&&(D.current=o,B(`[ANIMATION] Found teeth mesh: ${o.name}`))}});const d=V.current?.morphTargetDictionary;d&&Object.keys(d).filter(o=>o.toLowerCase().includes("brow"));const f=[];v.traverse(o=>{if(o.isMesh){const p=o.morphTargetDictionary;p&&Object.keys(p).some(J=>J.toLowerCase().includes("brow"))&&f.push(o)}}),ee.current=f,f.length>0&&B("[ANIMATION] Meshes with brow morphs:",f.length)},[v]);const ve=(d,f=1)=>{const o=`viseme_${d}`.toLowerCase(),s=on.find(p=>p.key.toLowerCase()===o);if(s)for(const p in s.mix){const J=s.mix[p]*f;z(V.current,p,J),z(D.current,p,J)}},Oe=d=>{const f=Je[d]??Je.neutral;for(const o in f)z(V.current,o,f[o]),z(D.current,o,f[o])};return ct.useFrame((d,f)=>{const o=Math.pow(.88,60*f);At(V.current,o),At(D.current,o),Oe(W);const s=d.clock.elapsedTime;let p=0;if(Math.floor(s)%5===0&&Math.floor((s-f)%5)!==0){let H=null;v.traverse(Z=>{Z.name.toLowerCase().includes("hips")&&(H=Z)});const ne=H?`Hips Y: ${H.position.y.toFixed(4)}`:"Hips not found";B(`[ANIMATION] Mixer Time: ${U.time.toFixed(2)}, ${ne}`)}if(U.update(f),s>we.current&&!ae.current&&(ae.current=!0,Pe.current=s),ae.current){const H=O?.2:.3,ne=(s-Pe.current)/H;if(ne>=1){ae.current=!1;const Z=O?1:2.5;we.current=s+Z}else{const Z=ne<.5?ne*2:(1-ne)*2;z(V.current,"eyeBlinkLeft",Z),z(V.current,"eyeBlinkRight",Z),z(D.current,"eyeBlinkLeft",Z),z(D.current,"eyeBlinkRight",Z),p=Z*sn.browInnerUp}}const J=Je[W]??Je.neutral,Q=J.browInnerUp??0,ze=J.browOuterUpLeft??0,Ye=J.browOuterUpRight??0,Ae=s*an,Qe=ot*Math.sin(Ae),ye=ot*.7*Math.sin(Ae+.7),K=ot*.7*Math.sin(Ae+1.3),xe=H=>Math.max(0,Math.min(1,H)),pe=xe(Q+Qe),ge=xe(ze+ye),Re=xe(Ye+K),De=xe(pe+p);if(z(V.current,"browInnerUp",De),z(D.current,"browInnerUp",De),z(V.current,"browOuterUpLeft",ge),z(D.current,"browOuterUpLeft",ge),z(V.current,"browOuterUpRight",Re),z(D.current,"browOuterUpRight",Re),j.current){const H=b.current?0:C.rotation[1];j.current.rotation.y=Ue.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&&m.current){const H=m.current.currentTime,Be=(H-_.current)*1e3- -150;for(let ke=0;ke<g.current.length;ke++){const G=g.current[ke];Be>=G.vtime&&Be<G.vtime+G.vduration&&ve(G.viseme,G.weight??1)}H>de.current+.5&&(T(),S(!1))}}),a.jsx("group",{ref:j,children:a.jsx("primitive",{object:v})})});function fn(l){return l?l.charAt(0).toUpperCase()+l.slice(1).toLowerCase():""}const hn=({token:l,agentToken:b,onNavigationRequested:g,avatarGender:m,presetUserDetails:_}={})=>{const C=l??b??"",W=Xt(C||void 0),[le,Y]=e.useState(""),[O,de]=e.useState(""),[T,S]=e.useState("Ready"),[R,A]=e.useState(!1),[F,me]=e.useState(!1),[v,_e]=e.useState([]),[Ce,q]=e.useState(""),ie=e.useRef(null),[I,j]=e.useState(()=>typeof window<"u"?window.matchMedia("(max-width: 480px)").matches:!1);e.useEffect(()=>{const t=window.matchMedia("(max-width: 480px)"),n=()=>j(t.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const V=I?80:600,D=e.useRef(!1),ee=e.useRef([]),U=e.useRef(0),y=e.useRef(!1),x=e.useRef([]),we=e.useRef(null),ae=e.useRef([]);e.useRef([]);const Pe=e.useRef([]),te=e.useRef(0),Se=e.useRef(0),ve=e.useRef(0),Oe=e.useRef(0),d=e.useRef(!1),[f,o]=e.useState(null),s=e.useRef(null),[p,J]=e.useState("neutral"),[Q,ze]=e.useState(""),[Ye,Ae]=e.useState(""),[Qe,ye]=e.useState("Chat with us"),[K,xe]=e.useState(null),[pe,ge]=e.useState("hidden"),[Re,De]=e.useState(""),H=e.useRef(null),ne=e.useRef(pe);ne.current=pe;const[Z,Be]=e.useState(null),ke=e.useRef(null),G=e.useRef(null),[Ne,ut]=e.useState(!1),lt=e.useRef(null),[oe,We]=e.useState("hidden"),[dt,Tt]=e.useState(""),Xe=e.useRef(oe);Xe.current=oe;const fe=e.useRef(""),Te=e.useRef(!1),Ie=e.useRef(""),ft=e.useRef(Date.now()),Ke=e.useRef([]),Fe=e.useRef(!1),[Ze,je]=e.useState(!1),[ht,mt]=e.useState(!1),be=e.useRef(null),Me=e.useMemo(()=>Ne?"Try again":T==="Busy"?"Busy":T==="Thinking..."||T==="Processing Voice..."?T:K!=null&&K!==""&&K!=="none"&&K!=="<none>"?`Enter ${fn(K)}`:oe!=="hidden"||!ht?null:Lt,[T,K,Ne,oe,ht]),pt=!Ne&&T!=="Busy"&&T!=="Thinking..."&&T!=="Processing Voice..."&&(K==null||K===""||K==="none"||K==="<none>");e.useEffect(()=>{if(oe!=="hidden"||!pt){mt(!1),be.current!=null&&(clearTimeout(be.current),be.current=null);return}return be.current=setTimeout(()=>{be.current=null,mt(!0)},400),()=>{be.current!=null&&(clearTimeout(be.current),be.current=null)}},[oe,pt]);const Ve=Me!=null&&Me!=="";e.useEffect(()=>{const t=ne.current;if(!(t==="exiting"||t==="entering")){if(t==="hidden"){Ve&&(De(Me??""),ge("entering"));return}t==="visible"&&(!Ve||Me!==Re)&&(H.current=Ve?Me:null,ge("exiting"))}},[Ve,Me,pe,Re]),e.useEffect(()=>{if(T!=="Busy"){G.current!=null&&(clearTimeout(G.current),G.current=null);return}return G.current=setTimeout(()=>{G.current=null,S("Ready"),ut(!0)},12e3),()=>{G.current!=null&&(clearTimeout(G.current),G.current=null)}},[T]),e.useEffect(()=>{if(!Ne)return;const t=setTimeout(()=>ut(!1),2500);return()=>clearTimeout(t)},[Ne]);const It=e.useCallback(()=>{const t=ne.current;if(t==="exiting"){ge("hidden");const n=H.current;H.current=null,n!=null&&n!==""&&(De(n),ge("entering"))}else t==="entering"&&ge("visible")},[]),Mt=t=>{if(!t)return;if(t.mood!=null){const r=String(t.mood).toLowerCase();J(r)}if(t.expression!=null){const r=String(t.expression).trim();ze(r);const u=en.find(h=>h.name.toLowerCase()===r.toLowerCase());B(`[STREAM] Animation match for "${r}": ${u?u.name:"NONE"}`),Ae(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,i=n?String(n).trim().toLowerCase():"",c=i==="none"||i==="<none>";if(n&&!c){const r=i;if(_&&(r==="email"&&_.email||r==="name"&&_.name||r==="phone"&&_.phone))return;xe(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")&&(xe(null),Qe!=="Chat with us"&&ye("Chat with us"));t.collected,t.valid},Ct=t=>{const n=t.trim();if(!n)return null;if(n.startsWith("{"))try{return JSON.parse(n)}catch{return null}if(n.includes(":")){const i=n.split(":"),c=i[0].trim().toLowerCase(),r=i.slice(1).join(":").trim();return{[c]:r}}return null},Ot=e.useCallback(()=>{},[]),gt=t=>{if(Te.current)t==="§"?Te.current=!1:(Ie.current+=t,de(n=>n+t));else if(t==="§"){Te.current=!0;return}else for(fe.current+=t;fe.current.includes(`
2
2
  `);){const n=fe.current.indexOf(`
3
3
  `),i=fe.current.slice(0,n).trim();fe.current=fe.current.slice(n+1);const c=Ct(i);c&&Mt(c)}};e.useEffect(()=>{(async()=>{if(!sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID")){const r="secret",u=Math.floor(Date.now()/1e3).toString();try{const h=new TextEncoder,w=await crypto.subtle.importKey("raw",h.encode(r),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),k=await crypto.subtle.sign("HMAC",w,h.encode(u)),L=Array.from(new Uint8Array(k)).map(P=>P.toString(16).padStart(2,"0")).join("");sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",L),B("[SESSION] New HMAC UID generated and saved:",L)}catch(h){console.error("[SESSION] HMAC generation failed:",h);const w=Math.random().toString(36)+Date.now().toString();sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",w)}}const i=sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");let c=[];if(i)try{c=JSON.parse(i)}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))):i||sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES",JSON.stringify([]))})()},[_]),e.useEffect(()=>{const t=()=>{ft.current=Date.now(),Fe.current&&(Fe.current=!1,je(!1),_e([]),q(""),de(""),me(!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&&!R&&T==="Ready"&&!Fe.current)if(Fe.current=!0,Ke.current.length>0)je(!0),_e(Ke.current);else try{const r=`${at}/nudgeUser`,u={navigationUrl:window.location.href,token:C},h=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});if(h.ok){const k=(await h.json()).nudge_questions;k&&k.length>0&&(B("[NUDGE] Received nudge questions from API:",k),Ke.current=k,je(!0),_e(k))}}catch(r){console.error("[NUDGE] Error calling /nudgeUser:",r),Fe.current=!1}},1e3);return()=>{window.removeEventListener("mousemove",t),window.removeEventListener("keydown",t),window.removeEventListener("mousedown",t),window.removeEventListener("touchstart",t),clearInterval(n)}},[C,F,R,T]),e.useEffect(()=>{if(v.length===0)return;let t=0,n=0,i=!1,c=100;const r=()=>{const u=v[t];if(i){const h=u.substring(0,n-1);q(h),n--,c=50}else{const h=u.substring(0,n+1);q(h),n++,c=100}!i&&n===u.length?(i=!0,c=3e3):i&&n===0&&(i=!1,t=(t+1)%v.length,c=500),ie.current=setTimeout(r,c)};return r(),()=>{ie.current&&clearTimeout(ie.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),ce=e.useRef(null),He=e.useRef([]),wt=e.useRef(0),[St,Nt]=e.useState(null),[Ft,rt]=e.useState(null),he=e.useRef(null),Ee=e.useRef(null),$e=e.useCallback((t=!1)=>{t&&(d.current=!0,A(!1),S("Ready")),x.current=[],ee.current=[],y.current=!1,me(!1),te.current=0,Se.current=0,ve.current=0,ae.current.forEach(n=>{try{n.stop()}catch{}}),ke.current&&(clearTimeout(ke.current),ke.current=null),Be(null),Ae(""),ae.current=[]},[]),jt=async()=>{try{const t=await navigator.mediaDevices.getUserMedia({audio:!0}),n=window.AudioContext||window.webkitAudioContext,i=new n,c=i.createMediaStreamSource(t),r=i.createAnalyser();r.fftSize=64,c.connect(r),he.current=i,Ee.current=c,rt(r);const u=new MediaRecorder(t);ce.current=u,He.current=[],u.ondataavailable=h=>{h.data.size>0&&He.current.push(h.data)},u.onstop=async()=>{const h=Date.now()-wt.current;if(rt(null),Ee.current&&(Ee.current.disconnect(),Ee.current=null),he.current&&he.current.state!=="closed"&&(he.current.close(),he.current=null),h<1e3){S("Recording too short. Hold or click longer."),A(!1);return}const w=new Blob(He.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=()=>{ce.current&&ce.current.state!=="inactive"&&(ce.current.stop(),ce.current.stream.getTracks().forEach(t=>t.stop()),tt(!1))},Pt=()=>{ce.current&&ce.current.state!=="inactive"&&(ce.current.onstop=null,ce.current.stop(),ce.current.stream.getTracks().forEach(t=>t.stop()),rt(null),Ee.current&&(Ee.current.disconnect(),Ee.current=null),he.current&&he.current.state!=="closed"&&(he.current.close(),he.current=null),tt(!1),He.current=[],S("Ready"))};e.useEffect(()=>{if(!F)return;const t=()=>{const n=ve.current;if(n<=0)return;const i=we.current,c=te.current;if(!i)return;const r=i.currentTime-c,u=Math.min(Math.max(0,r),n),h=O.trim().length;if(h<=0)return;const w=Math.min(Math.round(u/n*h),h);o(w)};return clearInterval(s.current??void 0),s.current=setInterval(t,90),()=>clearInterval(s.current??void 0)},[F,O,ve.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,i=t.length*n*2+44,c=new ArrayBuffer(i),r=new DataView(c);let u=0;const h=L=>{r.setUint16(u,L,!0),u+=2},w=L=>{r.setUint32(u,L,!0),u+=4};w(1179011410),w(i-8),w(1163280727),w(544501094),w(16),h(1),h(n),w(t.sampleRate),w(t.sampleRate*2*n),h(n*2),h(16),w(1635017060),w(i-u-4);const k=[];for(let L=0;L<n;L++)k.push(t.getChannelData(L));let E=0;for(;u<i;){for(let L=0;L<n;L++){let P=Math.max(-1,Math.min(1,k[L][E]));P=P<0?P*32768:P*32767,r.setInt16(u,P,!0),u+=2}E++}return new Blob([c],{type:"audio/wav"})},st=async(t,n,i=!1)=>{if(!d.current){if(D.current){ee.current.push({audio:t,visemes:n,isNewSegment:i});return}D.current=!0;try{const c=window.AudioContext||window.webkitAudioContext,r=we.current??new c;r.state==="suspended"&&await r.resume(),we.current=r;const u=window.atob(t),h=new Uint8Array(u.length);for(let N=0;N<u.length;N++)h[N]=u.charCodeAt(N);const w=await r.decodeAudioData(h.buffer.slice(0));ve.current+=w.duration;const k=r.currentTime;let E=Se.current;const L=!y.current;E<k&&(E=k+.1),Se.current=E+w.duration;const P=r.createBufferSource();P.buffer=w;let $=St;if((!$||$.context!==r)&&($=r.createAnalyser(),$.fftSize=64,$.connect(r.destination),Nt($)),P.connect($),ae.current.push(P),d.current){ae.current=ae.current.filter(N=>N!==P);return}if(L){y.current=!0,me(!0),B(`[AUDIO] setIsSpeaking(true) - First chunk starting at ${E.toFixed(3)}`),te.current=E;const N=(E-k)*1e3;U.current=performance.now()+N,B(`[AUDIO] Response started. Initial startTime: ${E.toFixed(3)}, CT: ${k.toFixed(3)}`)}P.start(E);const X=(E-te.current)*1e3;i&&(Oe.current=X,B(`[AUDIO] New segment detected at +${X.toFixed(0)}ms. Resetting segment offset.`)),n.forEach((N,re)=>{const M=N.symbol??"";if(M){const se=un(M),ue=Math.round(N.start*1e3),Le=Math.round((N.duration??0)*1e3),xt=Oe.current+ue;re<3&&B(`[AUDIO] Viseme "${M}": segment_relative=${ue}ms, segment_offset=${Oe.current.toFixed(0)}ms => vtime=${xt}ms`),se.forEach(Rt=>{x.current.push({viseme:Rt.v,weight:Rt.w,vtime:xt,vduration:Le})})}}),S("Speaking...")}finally{if(D.current=!1,ee.current.length>0){const c=ee.current.shift();c&&st(c.audio,c.visemes,c.isNewSegment)}}}},Wt=async t=>{try{A(!0),je(!1),Ie.current="",de(""),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 h=u.result.split(",")[1];$e(),Y(""),fe.current="",Te.current=!1;const w=`${at}/stt?token=${encodeURIComponent(C)}`,k=await fetch(w,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({audio_base64:h,audio_format:"wav"})});if(k.status===429){try{const re=await k.text(),M=JSON.parse(re);B("[STT] 429 agent at capacity:",M?.detail)}catch{}Y(""),S("Busy"),A(!1);return}if(!k.ok){const re=await k.text();let M="STT Failed";try{M=JSON.parse(re).error||M}catch{re&&(M=re.slice(0,200))}throw new Error(M)}const E=k.body;if(B("this is body"+E),!E){S("STT Failed"),A(!1);return}const L=E.getReader();d.current=!1;const P=new TextDecoder;let $="",X=!1;const N=async(re,M)=>{switch(re){case"transcript":M.transcript!=null&&Y(String(M.transcript));break;case"text":{const se=M.delta??M.text??"";se&&gt(se);break}case"audio":{const se=M.chunk,ue=M.visemes??[],Le=!!M.is_new_segment;se&&await st(se,ue,Le);break}case"done":{X=!0,S("Ready"),A(!1);break}case"error":{X=!0,S("STT Failed"),A(!1);break}default:break}};for(;;){const{done:re,value:M}=await L.read();M&&($+=P.decode(M,{stream:!0}));const se=$.split(`
4
4
 
5
5
  `);$=se.pop()??"";for(const ue of se){const Le=qe(ue);Le&&await N(Le.event,Le.data)}if(re){if($.trim()){const ue=qe($.trim());ue&&await N(ue.event,ue.data)}X||(S("Ready"),A(!1));break}}}}catch(n){console.error("Audio Submission Error:",n),S("STT Failed"),A(!1)}},Vt=async t=>{t&&t.preventDefault(),je(!1),Ie.current="",de(""),!(!le||R)&&await Ht(le)},qe=t=>{const n=t.split(/\r?\n/);let i="",c="";for(const u of n)u.startsWith("event:")?i=u.slice(6).trim():u.startsWith("data:")&&(c=u.slice(5).trim());if(!i)return null;let r={};if(c)try{r=JSON.parse(c)}catch{r={raw:c}}return{event:i,data:r}},vt=(t,n)=>{switch(t){case"connected":fe.current="",Te.current=!1;break;case"text":{const i=n.delta??"";i&&gt(i);break}case"audio":{const i=n.chunk,c=n.visemes??[];i&&st(i,c);break}case"done":{const i=bt(),c=Ie.current.trim(),r=[...i,{role:"user",content:le||"..."},{role:"assistant",content:c}];Dt(r),Pe.current=[...x.current],S("Ready"),A(!1),Y("");break}case"error":{const i=n.message??"Unknown error";Ie.current=i,de(i),S("Agent Failed"),A(!1);break}}},Ht=async t=>{A(!0),S("Thinking..."),Ie.current="",fe.current="",Te.current=!1,$e(),ve.current=0,o(0);const n=`${at}/agent/chat?token=${encodeURIComponent(C)}`;try{const i=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:i,question:t,lead_id:c};B("[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 L=await u.json();B("[CHAT] 429 agent at capacity:",L?.detail)}catch{}Y(""),S("Busy"),A(!1);return}if(!u.ok)throw new Error("Agent request failed");const h=u.body;if(!h){S("Agent Failed"),A(!1);return}const w=h.getReader();d.current=!1;const k=new TextDecoder;let E="";for(;;){const{done:L,value:P}=await w.read();B(`[SSE] Chunk received. done=${L}, length=${P?.length||0}`),P&&(E+=k.decode(P,{stream:!0}));const $=E.split(`
6
6
 
7
- `);E=$.pop()??"";for(const X of $){B(`[SSE] Processing block: ${X.slice(0,50)}...`);const N=qe(X);N&&(B(`[SSE] Event: ${N.event}`),vt(N.event,N.data))}if(L){if(B("[SSE] Stream finished"),E.trim()){const X=qe(E.trim());X&&vt(X.event,X.data)}S("Ready"),A(!1),Y("");break}}}catch(i){console.error("Chat Error:",i),S("Agent Failed"),A(!1)}},yt=O.trim(),it=yt&&F?yt.slice(0,f!=null&&f>0?f:0):"";e.useEffect(()=>{const t=Xe.current;t!=="exiting"&&(it?(Tt(it),t==="hidden"&&We("entering")):(t==="visible"||t==="entering")&&We("exiting"))},[it,oe]);const $t=e.useCallback(()=>{const t=Xe.current;t==="entering"?We("visible"):t==="exiting"&&We("hidden")},[]);return e.useLayoutEffect(()=>{const t=lt.current;t&&(t.scrollTop=t.scrollHeight)},[dt]),a.jsxs("div",{className:"avatar-widget-container",children:[a.jsxs("div",{className:"avatar-input-area",children:[pe!=="hidden"?a.jsx("div",{className:`avatar-thinking-tab${pe==="exiting"?" avatar-thinking-tab--exiting":pe==="entering"?" avatar-thinking-tab--entering":""}`,onAnimationEnd:It,children:Re===Lt?a.jsx("a",{href:"https://leads.streamoji.com",target:"_blank",rel:"noopener noreferrer",children:"Made by Streamoji Leads"}):Re}):null,a.jsx("div",{className:"avatar-input-container",children:a.jsx("div",{style:{display:"flex",alignItems:"center",width:"100%",height:"100%"},children:et?a.jsxs("div",{className:"avatar-input-recording",children:[a.jsx("button",{type:"button",className:"avatar-recording-cancel",onClick:Pt,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(kt,{analyser:Ft})}),a.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")]})]}),a.jsx("button",{type:"button",className:"avatar-recording-confirm",onClick:Ut,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"})})})]}):F&&!Ze?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(kt,{analyser:St})}),a.jsx("button",{type:"button",className:"avatar-speaking-stop",onClick:()=>$e(!0),title:"Stop",children:a.jsx("span",{className:"avatar-speaking-stop__icon","aria-hidden":!0})})]}):R?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:Vt,style:{flex:1,display:"flex",height:"100%",alignItems:"center"},children:[a.jsx("input",{id:"avatar-text-input",type:"text",value:le,onChange:t=>Y(t.target.value),placeholder:T==="Busy"?"Assisting another user":Ce||"Ask me anything",disabled:R||T==="Busy",autoComplete:"off",style:{width:"100%",height:"100%"}}),T==="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"})})}):le.trim()===""?a.jsx("button",{type:"button",className:"mic-button",onClick:jt,disabled:R,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:R,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:[oe!=="hidden"&&a.jsx("div",{className:`avatar-bubble${oe==="entering"?" avatar-bubble--entering":oe==="exiting"?" avatar-bubble--exiting":""}`,onAnimationEnd:$t,children:a.jsx("div",{ref:lt,className:`avatar-bubble__content${Ze?" avatar-bubble__content--nudge":""}`,children:dt})}),a.jsx("div",{className:"avatar-canvas-layer",style:{width:V,height:V},children:a.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:[a.jsx(ln,{target:rn}),a.jsx("ambientLight",{intensity:.7}),a.jsx("directionalLight",{position:[0,2,2],intensity:1}),a.jsx(Ge.Environment,{preset:"city"}),a.jsx(e.Suspense,{fallback:null,children:W!==null&&a.jsx(dn,{avatarUrl:W,isPlayingRef:y,visemeQueueRef:x,audioContextRef:we,responseAudioStartTimeRef:te,adjustments:nn,mood:m,expression:Q,agentResponse:O,isSpeaking:F,nextStartTimeRef:Se,stopPlayback:$e,setIsSpeaking:me,expressionUrl:Ye,onExpressionFinished:Ot,isNudgeResponse:Ze,avatarGender:p})})]})})]})})]})},mn=({token:l,onNavigationRequested:b})=>a.jsx(hn,{token:l,onNavigationRequested:b});exports.AvatarWidget=mn;
8
- //# sourceMappingURL=avatar-widget.cjs.map
7
+ `);E=$.pop()??"";for(const X of $){B(`[SSE] Processing block: ${X.slice(0,50)}...`);const N=qe(X);N&&(B(`[SSE] Event: ${N.event}`),vt(N.event,N.data))}if(L){if(B("[SSE] Stream finished"),E.trim()){const X=qe(E.trim());X&&vt(X.event,X.data)}S("Ready"),A(!1),Y("");break}}}catch(i){console.error("Chat Error:",i),S("Agent Failed"),A(!1)}},yt=O.trim(),it=yt&&F?yt.slice(0,f!=null&&f>0?f:0):"";e.useEffect(()=>{const t=Xe.current;t!=="exiting"&&(it?(Tt(it),t==="hidden"&&We("entering")):(t==="visible"||t==="entering")&&We("exiting"))},[it,oe]);const $t=e.useCallback(()=>{const t=Xe.current;t==="entering"?We("visible"):t==="exiting"&&We("hidden")},[]);return e.useLayoutEffect(()=>{const t=lt.current;t&&(t.scrollTop=t.scrollHeight)},[dt]),a.jsxs("div",{className:"avatar-widget-container",children:[a.jsxs("div",{className:"avatar-input-area",children:[pe!=="hidden"?a.jsx("div",{className:`avatar-thinking-tab${pe==="exiting"?" avatar-thinking-tab--exiting":pe==="entering"?" avatar-thinking-tab--entering":""}`,onAnimationEnd:It,children:Re===Lt?a.jsx("a",{href:"https://leads.streamoji.com",target:"_blank",rel:"noopener noreferrer",children:"Made by Streamoji Leads"}):Re}):null,a.jsx("div",{className:"avatar-input-container",children:a.jsx("div",{style:{display:"flex",alignItems:"center",width:"100%",height:"100%"},children:et?a.jsxs("div",{className:"avatar-input-recording",children:[a.jsx("button",{type:"button",className:"avatar-recording-cancel",onClick:Pt,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(kt,{analyser:Ft})}),a.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")]})]}),a.jsx("button",{type:"button",className:"avatar-recording-confirm",onClick:Ut,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"})})})]}):F&&!Ze?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(kt,{analyser:St})}),a.jsx("button",{type:"button",className:"avatar-speaking-stop",onClick:()=>$e(!0),title:"Stop",children:a.jsx("span",{className:"avatar-speaking-stop__icon","aria-hidden":!0})})]}):R?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:Vt,style:{flex:1,display:"flex",height:"100%",alignItems:"center"},children:[a.jsx("input",{id:"avatar-text-input",type:"text",value:le,onChange:t=>Y(t.target.value),placeholder:T==="Busy"?"Assisting another user":Ce||"Ask me anything",disabled:R||T==="Busy",autoComplete:"off",style:{width:"100%",height:"100%"}}),T==="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"})})}):le.trim()===""?a.jsx("button",{type:"button",className:"mic-button",onClick:jt,disabled:R,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:R,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:[oe!=="hidden"&&a.jsx("div",{className:`avatar-bubble${oe==="entering"?" avatar-bubble--entering":oe==="exiting"?" avatar-bubble--exiting":""}`,onAnimationEnd:$t,children:a.jsx("div",{ref:lt,className:`avatar-bubble__content${Ze?" avatar-bubble__content--nudge":""}`,children:dt})}),a.jsx("div",{className:"avatar-canvas-layer",style:{width:V,height:V},children:a.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:[a.jsx(ln,{target:rn}),a.jsx("ambientLight",{intensity:.7}),a.jsx("directionalLight",{position:[0,2,2],intensity:1}),a.jsx(Ge.Environment,{preset:"city"}),a.jsx(e.Suspense,{fallback:null,children:W!==null&&a.jsx(dn,{avatarUrl:W,isPlayingRef:y,visemeQueueRef:x,audioContextRef:we,responseAudioStartTimeRef:te,adjustments:nn,mood:p,expression:Q,agentResponse:O,isSpeaking:F,nextStartTimeRef:Se,stopPlayback:$e,setIsSpeaking:me,expressionUrl:Ye,onExpressionFinished:Ot,isNudgeResponse:Ze,avatarGender:m})})]})})]})})]})},mn=({token:l,avatarGender:b,onNavigationRequested:g,presetUserDetails:m})=>a.jsx(hn,{token:l,onNavigationRequested:g,avatarGender:b,presetUserDetails:m});exports.AvatarWidget=mn;
@@ -1 +1 @@
1
- .avatar-bubble:after{content:"";position:absolute;bottom:0;right:18%;width:29px;height:33px;background-image:url("data:image/svg+xml,%3Csvg width='29' height='33' viewBox='0 0 29 33' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.5%209C3.55459%207.42985%204.13875e-07%208%204.13875e-07%208L0.517701%20-9.50694e-06L28.5%200.995422L28.2689%207.49131C28.2689%207.49131%2023.754%207.83102%2022.2194%208.77706C20.6848%209.7231%2019.1146%2011.6685%2018.5794%2012.6501C18.0442%2013.6317%206.37564%2032.2286%206.37564%2032.2286C6.37564%2032.2286%207.46192%2015.7568%207.53302%2013.7581C7.60412%2011.7594%207.44541%2010.5702%205.5%209Z' fill='white'/%3E%3C/svg%3E");background-size:100% 100%;background-repeat:no-repeat;filter:drop-shadow(0 2px 2px rgba(0,0,0,.08));transform:translateY(78%) rotate(0)}.avatar-widget-container{position:fixed;bottom:0;right:0;z-index:1000;display:flex;flex-direction:column;align-items:flex-end;gap:1rem;width:280px}.avatar-bubble{z-index:10002;background:#fff;padding: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: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}}
@@ -7,12 +7,12 @@ import { GLTFLoader as nn } from "three/examples/jsm/loaders/GLTFLoader.js";
7
7
  const ut = "https://ai.streamoji.com", V = (...f) => {
8
8
  }, rn = (...f) => {
9
9
  }, Et = ({ analyser: f }) => {
10
- const T = a(null), w = a(null);
10
+ const T = a(null), b = a(null);
11
11
  return $(() => {
12
12
  const p = T.current;
13
13
  if (!p) return;
14
- const b = p.getContext("2d", { alpha: !0 });
15
- if (!b) return;
14
+ const _ = p.getContext("2d", { alpha: !0 });
15
+ if (!_) return;
16
16
  let O, H = null;
17
17
  f && (f.fftSize = 128, H = new Uint8Array(f.frequencyBinCount));
18
18
  const he = () => {
@@ -20,9 +20,9 @@ const ut = "https://ai.streamoji.com", V = (...f) => {
20
20
  const X = p.width, D = p.height;
21
21
  if (X === 0 || D === 0) return;
22
22
  const me = D / 2;
23
- b.clearRect(0, 0, X, D), b.fillStyle = "#1e293b";
23
+ _.clearRect(0, 0, X, D), _.fillStyle = "#1e293b";
24
24
  const I = 2, k = I + 2, E = X * 0.95, U = Math.floor(E / k);
25
- (!w.current || w.current.length !== U) && (w.current = new Float32Array(U).fill(2));
25
+ (!b.current || b.current.length !== U) && (b.current = new Float32Array(U).fill(2));
26
26
  const be = U * k, y = (X - be) / 2;
27
27
  f && H && f.getByteFrequencyData(H);
28
28
  const Ie = H ? H.length : 0, G = Math.floor(Ie * 0.7) / U, ce = new Float32Array(U);
@@ -40,10 +40,10 @@ const ut = "https://ai.streamoji.com", V = (...f) => {
40
40
  ce[M] = N;
41
41
  }
42
42
  for (let M = 0; M < U; M++) {
43
- const B = U - 1 - M, j = Math.max(ce[M], ce[B]), N = w.current[M] + (j - w.current[M]) * 0.3;
44
- w.current[M] = N;
43
+ const B = U - 1 - M, j = Math.max(ce[M], ce[B]), N = b.current[M] + (j - b.current[M]) * 0.3;
44
+ b.current[M] = N;
45
45
  const ne = y + M * k, P = me - N / 2;
46
- b.beginPath(), b.roundRect ? b.roundRect(ne, P, I, N, 4) : b.fillRect(ne, P, I, N), b.fill();
46
+ _.beginPath(), _.roundRect ? _.roundRect(ne, P, I, N, 4) : _.fillRect(ne, P, I, N), _.fill();
47
47
  }
48
48
  };
49
49
  return he(), () => {
@@ -62,23 +62,23 @@ async function on(f) {
62
62
  "SHA-256",
63
63
  new TextEncoder().encode(f)
64
64
  );
65
- return Array.from(new Uint8Array(T)).map((w) => w.toString(16).padStart(2, "0")).join("");
65
+ return Array.from(new Uint8Array(T)).map((b) => b.toString(16).padStart(2, "0")).join("");
66
66
  }
67
67
  function an(f) {
68
- const [T, w] = g(null);
68
+ const [T, b] = g(null);
69
69
  return $(() => {
70
70
  if (!f) {
71
- w(null);
71
+ b(null);
72
72
  return;
73
73
  }
74
74
  let p = !1;
75
- return on(f).then((b) => {
75
+ return on(f).then((_) => {
76
76
  if (p) return;
77
- const O = `${sn}/${b}.glb`;
77
+ const O = `${sn}/${_}.glb`;
78
78
  fetch(O, { method: "HEAD" }).then((H) => {
79
- p || w(H.ok ? O : It);
79
+ p || b(H.ok ? O : It);
80
80
  }).catch(() => {
81
- p || w(It);
81
+ p || b(It);
82
82
  });
83
83
  }), () => {
84
84
  p = !0;
@@ -488,28 +488,28 @@ function wn({ target: f }) {
488
488
  T.lookAt(...f);
489
489
  }, [T, f]), null;
490
490
  }
491
- function Q(f, T, w) {
491
+ function Q(f, T, b) {
492
492
  if (!f || !f.morphTargetDictionary)
493
493
  return;
494
- const p = f, b = p.morphTargetDictionary, O = p.morphTargetInfluences;
494
+ const p = f, _ = p.morphTargetDictionary, O = p.morphTargetInfluences;
495
495
  if (O)
496
- for (const H in b)
497
- H.toLowerCase() === T.toLowerCase() && (O[b[H]] = w);
496
+ for (const H in _)
497
+ H.toLowerCase() === T.toLowerCase() && (O[_[H]] = b);
498
498
  }
499
499
  function Ct(f, T = 0.97) {
500
500
  if (!f) return;
501
- const w = f;
502
- if (w.morphTargetInfluences)
503
- for (let p = 0; p < w.morphTargetInfluences.length; p++)
504
- w.morphTargetInfluences[p] *= T;
501
+ const b = f;
502
+ if (b.morphTargetInfluences)
503
+ for (let p = 0; p < b.morphTargetInfluences.length; p++)
504
+ b.morphTargetInfluences[p] *= T;
505
505
  }
506
506
  const vn = Zt(
507
507
  ({
508
508
  avatarUrl: f,
509
509
  isPlayingRef: T,
510
- visemeQueueRef: w,
510
+ visemeQueueRef: b,
511
511
  audioContextRef: p,
512
- responseAudioStartTimeRef: b,
512
+ responseAudioStartTimeRef: _,
513
513
  adjustments: O,
514
514
  mood: H,
515
515
  expression: he,
@@ -694,9 +694,9 @@ const vn = Zt(
694
694
  ), B.current.position.set(...O.position), B.current.scale.setScalar(O.scale), B.current.rotation.x = O.rotation[0], B.current.rotation.z = O.rotation[2];
695
695
  }
696
696
  if (T.current && p.current) {
697
- const J = p.current.currentTime, He = (J - b.current) * 1e3 - -150;
698
- for (let Le = 0; Le < w.current.length; Le++) {
699
- const Y = w.current[Le];
697
+ const J = p.current.currentTime, He = (J - _.current) * 1e3 - -150;
698
+ for (let Le = 0; Le < b.current.length; Le++) {
699
+ const Y = b.current[Le];
700
700
  He >= Y.vtime && He < Y.vtime + Y.vduration && xe(Y.viseme, Y.weight ?? 1);
701
701
  }
702
702
  J > me.current + 0.5 && (I(), v(!1));
@@ -710,9 +710,9 @@ function yn(f) {
710
710
  const Sn = ({
711
711
  token: f,
712
712
  agentToken: T,
713
- onNavigationRequested: w,
713
+ onNavigationRequested: b,
714
714
  avatarGender: p,
715
- presetUserDetails: b
715
+ presetUserDetails: _
716
716
  } = {}) => {
717
717
  const O = f ?? T ?? "", H = an(O || void 0), [he, X] = g(""), [D, me] = g(""), [I, v] = g("Ready"), [k, E] = g(!1), [U, be] = g(!1), [y, Ie] = g([]), [Ne, G] = g(""), ce = a(null), [M, B] = g(
718
718
  () => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
@@ -798,12 +798,12 @@ const Sn = ({
798
798
  }
799
799
  if (e.navigation != null) {
800
800
  const n = String(e.navigation).trim();
801
- n !== "" && (w ? w(n) : window.open(n, "_blank"));
801
+ n !== "" && (b ? b(n) : window.open(n, "_blank"));
802
802
  }
803
803
  const t = e.ask_for || e.lead_capture?.ask_for, i = t ? String(t).trim().toLowerCase() : "", o = i === "none" || i === "<none>";
804
804
  if (t && !o) {
805
805
  const n = i;
806
- if (b && (n === "email" && b.email || n === "name" && b.name || n === "phone" && b.phone))
806
+ if (_ && (n === "email" && _.email || n === "name" && _.name || n === "phone" && _.phone))
807
807
  return;
808
808
  Ae(n || null), ke(n === "email" ? "Enter your email" : n === "name" ? "Enter your name" : n === "phone" ? "Enter your phone number" : "Chat with us");
809
809
  } else (o || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (Ae(null), Ze !== "Chat with us" && ke("Chat with us"));
@@ -846,7 +846,7 @@ const Sn = ({
846
846
  )) {
847
847
  const n = "secret", c = Math.floor(Date.now() / 1e3).toString();
848
848
  try {
849
- const h = new TextEncoder(), _ = await crypto.subtle.importKey(
849
+ const h = new TextEncoder(), w = await crypto.subtle.importKey(
850
850
  "raw",
851
851
  h.encode(n),
852
852
  { name: "HMAC", hash: "SHA-256" },
@@ -854,14 +854,14 @@ const Sn = ({
854
854
  ["sign"]
855
855
  ), A = await crypto.subtle.sign(
856
856
  "HMAC",
857
- _,
857
+ w,
858
858
  h.encode(c)
859
859
  ), L = Array.from(new Uint8Array(A)).map((W) => W.toString(16).padStart(2, "0")).join("");
860
860
  sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", L), V("[SESSION] New HMAC UID generated and saved:", L);
861
861
  } catch (h) {
862
862
  console.error("[SESSION] HMAC generation failed:", h);
863
- const _ = Math.random().toString(36) + Date.now().toString();
864
- sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", _);
863
+ const w = Math.random().toString(36) + Date.now().toString();
864
+ sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", w);
865
865
  }
866
866
  }
867
867
  const i = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
@@ -872,7 +872,7 @@ const Sn = ({
872
872
  } catch {
873
873
  o = [];
874
874
  }
875
- o.length === 0 && b && (b.name || b.email) ? (o = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${b.name || ""}" , Email is "${b.email || ""}"` }], sessionStorage.setItem(
875
+ o.length === 0 && _ && (_.name || _.email) ? (o = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${_.name || ""}" , Email is "${_.email || ""}"` }], sessionStorage.setItem(
876
876
  "STREAMOJI_LEADS_SESSION_MESSAGES",
877
877
  JSON.stringify(o)
878
878
  )) : i || sessionStorage.setItem(
@@ -880,7 +880,7 @@ const Sn = ({
880
880
  JSON.stringify([])
881
881
  );
882
882
  })();
883
- }, [b]), $(() => {
883
+ }, [_]), $(() => {
884
884
  const e = () => {
885
885
  gt.current = Date.now(), Pe.current && (Pe.current = !1, We(!1), Ie([]), G(""), me(""), be(!1));
886
886
  };
@@ -969,10 +969,10 @@ const Sn = ({
969
969
  v("Recording too short. Hold or click longer."), E(!1);
970
970
  return;
971
971
  }
972
- const _ = new Blob(qe.current, {
972
+ const w = new Blob(qe.current, {
973
973
  type: "audio/wav"
974
974
  });
975
- await Jt(_);
975
+ await Jt(w);
976
976
  }, xt.current = Date.now(), c.start(100), it(!0), v("Listening...");
977
977
  } catch (e) {
978
978
  console.error("Error accessing microphone:", e), v("Mic Access Error");
@@ -991,11 +991,11 @@ const Sn = ({
991
991
  if (!i) return;
992
992
  const n = i.currentTime - o, c = Math.min(Math.max(0, n), t), h = D.trim().length;
993
993
  if (h <= 0) return;
994
- const _ = Math.min(
994
+ const w = Math.min(
995
995
  Math.round(c / t * h),
996
996
  h
997
997
  );
998
- s(_);
998
+ s(w);
999
999
  };
1000
1000
  return clearInterval(r.current ?? void 0), r.current = setInterval(e, 90), () => clearInterval(r.current ?? void 0);
1001
1001
  }, [U, D, xe.current]), $(() => {
@@ -1009,10 +1009,10 @@ const Sn = ({
1009
1009
  let c = 0;
1010
1010
  const h = (L) => {
1011
1011
  n.setUint16(c, L, !0), c += 2;
1012
- }, _ = (L) => {
1012
+ }, w = (L) => {
1013
1013
  n.setUint32(c, L, !0), c += 4;
1014
1014
  };
1015
- _(1179011410), _(i - 8), _(1163280727), _(544501094), _(16), h(1), h(t), _(e.sampleRate), _(e.sampleRate * 2 * t), h(t * 2), h(16), _(1635017060), _(i - c - 4);
1015
+ w(1179011410), w(i - 8), w(1163280727), w(544501094), w(16), h(1), h(t), w(e.sampleRate), w(e.sampleRate * 2 * t), h(t * 2), h(16), w(1635017060), w(i - c - 4);
1016
1016
  const A = [];
1017
1017
  for (let L = 0; L < t; L++) A.push(e.getChannelData(L));
1018
1018
  let R = 0;
@@ -1041,14 +1041,14 @@ const Sn = ({
1041
1041
  const c = window.atob(e), h = new Uint8Array(c.length);
1042
1042
  for (let F = 0; F < c.length; F++)
1043
1043
  h[F] = c.charCodeAt(F);
1044
- const _ = await n.decodeAudioData(h.buffer.slice(0));
1045
- xe.current += _.duration;
1044
+ const w = await n.decodeAudioData(h.buffer.slice(0));
1045
+ xe.current += w.duration;
1046
1046
  const A = n.currentTime;
1047
1047
  let R = Se.current;
1048
1048
  const L = !S.current;
1049
- R < A && (R = A + 0.1), Se.current = R + _.duration;
1049
+ R < A && (R = A + 0.1), Se.current = R + w.duration;
1050
1050
  const W = n.createBufferSource();
1051
- W.buffer = _;
1051
+ W.buffer = w;
1052
1052
  let q = kt;
1053
1053
  if ((!q || q.context !== n) && (q = n.createAnalyser(), q.fftSize = 64, q.connect(n.destination), Pt(q)), W.connect(q), le.current.push(W), u.current) {
1054
1054
  le.current = le.current.filter((F) => F !== W);
@@ -1105,9 +1105,9 @@ const Sn = ({
1105
1105
  c.readAsDataURL(n), c.onloadend = async () => {
1106
1106
  const h = c.result.split(",")[1];
1107
1107
  Ge(), X(""), pe.current = "", Ce.current = !1;
1108
- const _ = `${ut}/stt?token=${encodeURIComponent(
1108
+ const w = `${ut}/stt?token=${encodeURIComponent(
1109
1109
  O
1110
- )}`, A = await fetch(_, {
1110
+ )}`, A = await fetch(w, {
1111
1111
  method: "POST",
1112
1112
  headers: { "Content-Type": "application/json" },
1113
1113
  body: JSON.stringify({
@@ -1281,12 +1281,12 @@ const Sn = ({
1281
1281
  v("Agent Failed"), E(!1);
1282
1282
  return;
1283
1283
  }
1284
- const _ = h.getReader();
1284
+ const w = h.getReader();
1285
1285
  u.current = !1;
1286
1286
  const A = new TextDecoder();
1287
1287
  let R = "";
1288
1288
  for (; ; ) {
1289
- const { done: L, value: W } = await _.read();
1289
+ const { done: L, value: W } = await w.read();
1290
1290
  V(
1291
1291
  `[SSE] Chunk received. done=${L}, length=${W?.length || 0}`
1292
1292
  ), W && (R += A.decode(W, { stream: !0 }));
@@ -1656,15 +1656,18 @@ const Sn = ({
1656
1656
  ] });
1657
1657
  }, Tn = ({
1658
1658
  token: f,
1659
- onNavigationRequested: T
1659
+ avatarGender: T,
1660
+ onNavigationRequested: b,
1661
+ presetUserDetails: p
1660
1662
  }) => /* @__PURE__ */ l(
1661
1663
  Sn,
1662
1664
  {
1663
1665
  token: f,
1664
- onNavigationRequested: T
1666
+ onNavigationRequested: b,
1667
+ avatarGender: T,
1668
+ presetUserDetails: p
1665
1669
  }
1666
1670
  );
1667
1671
  export {
1668
1672
  Tn as AvatarWidget
1669
1673
  };
1670
- //# sourceMappingURL=avatar-widget.js.map
@@ -4152,5 +4152,5 @@ void main() {
4152
4152
 
4153
4153
  `);Hn=jn.pop()??"";for(const Zn of jn){const li=he(Zn);li&&await yn(li.event,li.data)}if(xn){if(Hn.trim()){const Zn=he(Hn.trim());Zn&&await yn(Zn.event,Zn.data)}dn||(y("Ready"),b(!1));break}}}}catch(Ge){console.error("Audio Submission Error:",Ge),y("STT Failed"),b(!1)}},fe=async _e=>{_e&&_e.preventDefault(),Be(!1),bt.current="",_(""),!(!h||x)&&await nt(h)},he=_e=>{const Ge=_e.split(/\r?\n/);let Le="",Ye="";for(const Ut of Ge)Ut.startsWith("event:")?Le=Ut.slice(6).trim():Ut.startsWith("data:")&&(Ye=Ut.slice(5).trim());if(!Le)return null;let ot={};if(Ye)try{ot=JSON.parse(Ye)}catch{ot={raw:Ye}}return{event:Le,data:ot}},ce=(_e,Ge)=>{switch(_e){case"connected":Ve.current="",qe.current=!1;break;case"text":{const Le=Ge.delta??"";Le&&br(Le);break}case"audio":{const Le=Ge.chunk,Ye=Ge.visemes??[];Le&&k(Le,Ye);break}case"done":{const Le=zs(),Ye=bt.current.trim(),ot=[...Le,{role:"user",content:h||"..."},{role:"assistant",content:Ye}];Va(ot),H.current=[...$.current],y("Ready"),b(!1),d("");break}case"error":{const Le=Ge.message??"Unknown error";bt.current=Le,_(Le),y("Agent Failed"),b(!1);break}}},nt=async _e=>{b(!0),y("Thinking..."),bt.current="",Ve.current="",qe.current=!1,it(),ye.current=0,le(0);const Ge=`${PS}/agent/chat?token=${encodeURIComponent(o)}`;try{const Le=zs();let Ye=sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");Ye||(wF("[CHAT] Session UID missing at send time! Generating emergency backup."),Ye="emergency-"+Math.random().toString(36).substring(7),sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID",Ye));const ot={history:Le,question:_e,lead_id:Ye};ga("[CHAT] Sending payload:",ot);const Ut=await fetch(Ge,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(ot),cache:"default"});if(Ut.status===429){try{const dt=await Ut.json();ga("[CHAT] 429 agent at capacity:",dt?.detail)}catch{}d(""),y("Busy"),b(!1);return}if(!Ut.ok)throw new Error("Agent request failed");const Ot=Ut.body;if(!Ot){y("Agent Failed"),b(!1);return}const Mt=Ot.getReader();X.current=!1;const ht=new TextDecoder;let wt="";for(;;){const{done:dt,value:an}=await Mt.read();ga(`[SSE] Chunk received. done=${dt}, length=${an?.length||0}`),an&&(wt+=ht.decode(an,{stream:!0}));const Hn=wt.split(`
4154
4154
 
4155
- `);wt=Hn.pop()??"";for(const dn of Hn){ga(`[SSE] Processing block: ${dn.slice(0,50)}...`);const yn=he(dn);yn&&(ga(`[SSE] Event: ${yn.event}`),ce(yn.event,yn.data))}if(dt){if(ga("[SSE] Stream finished"),wt.trim()){const dn=he(wt.trim());dn&&ce(dn.event,dn.data)}y("Ready"),b(!1),d("");break}}}catch(Le){console.error("Chat Error:",Le),y("Agent Failed"),b(!1)}},ft=p.trim(),ut=ft&&R?ft.slice(0,ee!=null&&ee>0?ee:0):"";Me.useEffect(()=>{const _e=qt.current;_e!=="exiting"&&(ut?(zt(ut),_e==="hidden"&&Ht("entering")):(_e==="visible"||_e==="entering")&&Ht("exiting"))},[ut,Ne]);const Tt=Me.useCallback(()=>{const _e=qt.current;_e==="entering"?Ht("visible"):_e==="exiting"&&Ht("hidden")},[]);return Me.useLayoutEffect(()=>{const _e=We.current;_e&&(_e.scrollTop=_e.scrollHeight)},[St]),Vt.jsxs("div",{className:"avatar-widget-container",children:[Vt.jsxs("div",{className:"avatar-input-area",children:[$e!=="hidden"?Vt.jsx("div",{className:`avatar-thinking-tab${$e==="exiting"?" avatar-thinking-tab--exiting":$e==="entering"?" avatar-thinking-tab--entering":""}`,onAnimationEnd:Dn,children:vt===dC?Vt.jsx("a",{href:"https://leads.streamoji.com",target:"_blank",rel:"noopener noreferrer",children:"Made by Streamoji Leads"}):vt}):null,Vt.jsx("div",{className:"avatar-input-container",children:Vt.jsx("div",{style:{display:"flex",alignItems:"center",width:"100%",height:"100%"},children:sa?Vt.jsxs("div",{className:"avatar-input-recording",children:[Vt.jsx("button",{type:"button",className:"avatar-recording-cancel",onClick:_t,title:"Cancel",children:Vt.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:[Vt.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),Vt.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),Vt.jsxs("div",{style:{flex:1,height:"100%",position:"relative",display:"flex",alignItems:"center",minWidth:0},children:[Vt.jsx("div",{style:{flex:1,height:"100%"},children:Vt.jsx(fC,{analyser:Re})}),Vt.jsxs("span",{style:{fontSize:"0.75rem",color:"#64748b",fontWeight:500,marginLeft:"4px",minWidth:"32px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:[Math.floor(Fi/60),":",String(Fi%60).padStart(2,"0")]})]}),Vt.jsx("button",{type:"button",className:"avatar-recording-confirm",onClick:et,title:"Send",children:Vt.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:Vt.jsx("polyline",{points:"20 6 9 17 4 12"})})})]}):R&&!pe?Vt.jsxs("div",{className:"avatar-input-speaking",children:[Vt.jsx("div",{style:{flex:1,height:"100%",display:"flex",alignItems:"center",paddingRight:"8px"},children:Vt.jsx(fC,{analyser:J})}),Vt.jsx("button",{type:"button",className:"avatar-speaking-stop",onClick:()=>it(!0),title:"Stop",children:Vt.jsx("span",{className:"avatar-speaking-stop__icon","aria-hidden":!0})})]}):x?Vt.jsx("div",{style:{flex:1,height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:Vt.jsx("div",{className:"avatar-input-loader"})}):Vt.jsxs("form",{onSubmit:fe,style:{flex:1,display:"flex",height:"100%",alignItems:"center"},children:[Vt.jsx("input",{id:"avatar-text-input",type:"text",value:h,onChange:_e=>d(_e.target.value),placeholder:v==="Busy"?"Assisting another user":D||"Ask me anything",disabled:x||v==="Busy",autoComplete:"off",style:{width:"100%",height:"100%"}}),v==="Busy"?Vt.jsx("button",{type:"button",className:"mic-button",disabled:!0,style:{backgroundColor:"#1e4a5e"},title:"Agent at capacity",children:Vt.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:Vt.jsx("path",{d:"M4 2L20 2L12 10L4 2z M12 14L4 22L20 22L12 14z",fill:"white"})})}):h.trim()===""?Vt.jsx("button",{type:"button",className:"mic-button",onClick:st,disabled:x,style:{backgroundColor:"#1e4a5e"},children:Vt.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[Vt.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"}),Vt.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"})]})}):Vt.jsx("button",{type:"submit",className:"mic-button",disabled:x,style:{backgroundColor:"#1e4a5e"},title:"Send",children:Vt.jsx("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:Vt.jsx("path",{d:"M19 12H5M19 12L14 17M19 12L14 7",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})})})]}),Vt.jsx("div",{className:"avatar-wrapper",children:Vt.jsxs("div",{className:"avatar-scene-wrapper",children:[Ne!=="hidden"&&Vt.jsx("div",{className:`avatar-bubble${Ne==="entering"?" avatar-bubble--entering":Ne==="exiting"?" avatar-bubble--exiting":""}`,onAnimationEnd:Tt,children:Vt.jsx("div",{ref:We,className:`avatar-bubble__content${pe?" avatar-bubble__content--nudge":""}`,children:St})}),Vt.jsx("div",{className:"avatar-canvas-layer",style:{width:V,height:V},children:Vt.jsxs(BO,{shadows:!0,camera:{position:[.2,1.4,3],fov:42},gl:{alpha:!0},dpr:1.8,style:{pointerEvents:"none",width:"100%",height:"100%"},children:[Vt.jsx(XF,{target:HF}),Vt.jsx("ambientLight",{intensity:.7}),Vt.jsx("directionalLight",{position:[0,2,2],intensity:1}),Vt.jsx(qI,{preset:"city"}),Vt.jsx(Me.Suspense,{fallback:null,children:l!==null&&Vt.jsx(YF,{avatarUrl:l,isPlayingRef:ne,visemeQueueRef:$,audioContextRef:ae,responseAudioStartTimeRef:K,adjustments:FF,mood:Pe,expression:Ee,agentResponse:p,isSpeaking:R,nextStartTimeRef:te,stopPlayback:it,setIsSpeaking:T,expressionUrl:Bt,onExpressionFinished:Ba,isNudgeResponse:pe,avatarGender:n})})]})})]})})]})},KF=({token:s,onNavigationRequested:e})=>Vt.jsx(qF,{token:s,onNavigationRequested:e}),mC="streamoji-leads-avatar-widget-root";function gC(s){const{token:e}=s;let t=document.getElementById(mC);if(!t){t=document.createElement("div"),t.id=mC,t.style.cssText="position:fixed;bottom:0;right:0;z-index:9999;pointer-events:none;";const i=document.createElement("div");i.style.cssText="pointer-events:auto;",t.appendChild(i),document.body.appendChild(t),t=i}gR.createRoot(t).render(bM.createElement(KF,{token:e||""}))}return window.StreamojiLeadsAvatarWidget={init:gC},Oy.init=gC,Object.defineProperty(Oy,Symbol.toStringTag,{value:"Module"}),Oy})({});
4155
+ `);wt=Hn.pop()??"";for(const dn of Hn){ga(`[SSE] Processing block: ${dn.slice(0,50)}...`);const yn=he(dn);yn&&(ga(`[SSE] Event: ${yn.event}`),ce(yn.event,yn.data))}if(dt){if(ga("[SSE] Stream finished"),wt.trim()){const dn=he(wt.trim());dn&&ce(dn.event,dn.data)}y("Ready"),b(!1),d("");break}}}catch(Le){console.error("Chat Error:",Le),y("Agent Failed"),b(!1)}},ft=p.trim(),ut=ft&&R?ft.slice(0,ee!=null&&ee>0?ee:0):"";Me.useEffect(()=>{const _e=qt.current;_e!=="exiting"&&(ut?(zt(ut),_e==="hidden"&&Ht("entering")):(_e==="visible"||_e==="entering")&&Ht("exiting"))},[ut,Ne]);const Tt=Me.useCallback(()=>{const _e=qt.current;_e==="entering"?Ht("visible"):_e==="exiting"&&Ht("hidden")},[]);return Me.useLayoutEffect(()=>{const _e=We.current;_e&&(_e.scrollTop=_e.scrollHeight)},[St]),Vt.jsxs("div",{className:"avatar-widget-container",children:[Vt.jsxs("div",{className:"avatar-input-area",children:[$e!=="hidden"?Vt.jsx("div",{className:`avatar-thinking-tab${$e==="exiting"?" avatar-thinking-tab--exiting":$e==="entering"?" avatar-thinking-tab--entering":""}`,onAnimationEnd:Dn,children:vt===dC?Vt.jsx("a",{href:"https://leads.streamoji.com",target:"_blank",rel:"noopener noreferrer",children:"Made by Streamoji Leads"}):vt}):null,Vt.jsx("div",{className:"avatar-input-container",children:Vt.jsx("div",{style:{display:"flex",alignItems:"center",width:"100%",height:"100%"},children:sa?Vt.jsxs("div",{className:"avatar-input-recording",children:[Vt.jsx("button",{type:"button",className:"avatar-recording-cancel",onClick:_t,title:"Cancel",children:Vt.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:[Vt.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),Vt.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),Vt.jsxs("div",{style:{flex:1,height:"100%",position:"relative",display:"flex",alignItems:"center",minWidth:0},children:[Vt.jsx("div",{style:{flex:1,height:"100%"},children:Vt.jsx(fC,{analyser:Re})}),Vt.jsxs("span",{style:{fontSize:"0.75rem",color:"#64748b",fontWeight:500,marginLeft:"4px",minWidth:"32px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:[Math.floor(Fi/60),":",String(Fi%60).padStart(2,"0")]})]}),Vt.jsx("button",{type:"button",className:"avatar-recording-confirm",onClick:et,title:"Send",children:Vt.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:Vt.jsx("polyline",{points:"20 6 9 17 4 12"})})})]}):R&&!pe?Vt.jsxs("div",{className:"avatar-input-speaking",children:[Vt.jsx("div",{style:{flex:1,height:"100%",display:"flex",alignItems:"center",paddingRight:"8px"},children:Vt.jsx(fC,{analyser:J})}),Vt.jsx("button",{type:"button",className:"avatar-speaking-stop",onClick:()=>it(!0),title:"Stop",children:Vt.jsx("span",{className:"avatar-speaking-stop__icon","aria-hidden":!0})})]}):x?Vt.jsx("div",{style:{flex:1,height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:Vt.jsx("div",{className:"avatar-input-loader"})}):Vt.jsxs("form",{onSubmit:fe,style:{flex:1,display:"flex",height:"100%",alignItems:"center"},children:[Vt.jsx("input",{id:"avatar-text-input",type:"text",value:h,onChange:_e=>d(_e.target.value),placeholder:v==="Busy"?"Assisting another user":D||"Ask me anything",disabled:x||v==="Busy",autoComplete:"off",style:{width:"100%",height:"100%"}}),v==="Busy"?Vt.jsx("button",{type:"button",className:"mic-button",disabled:!0,style:{backgroundColor:"#1e4a5e"},title:"Agent at capacity",children:Vt.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:Vt.jsx("path",{d:"M4 2L20 2L12 10L4 2z M12 14L4 22L20 22L12 14z",fill:"white"})})}):h.trim()===""?Vt.jsx("button",{type:"button",className:"mic-button",onClick:st,disabled:x,style:{backgroundColor:"#1e4a5e"},children:Vt.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[Vt.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"}),Vt.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"})]})}):Vt.jsx("button",{type:"submit",className:"mic-button",disabled:x,style:{backgroundColor:"#1e4a5e"},title:"Send",children:Vt.jsx("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:Vt.jsx("path",{d:"M19 12H5M19 12L14 17M19 12L14 7",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})})})]}),Vt.jsx("div",{className:"avatar-wrapper",children:Vt.jsxs("div",{className:"avatar-scene-wrapper",children:[Ne!=="hidden"&&Vt.jsx("div",{className:`avatar-bubble${Ne==="entering"?" avatar-bubble--entering":Ne==="exiting"?" avatar-bubble--exiting":""}`,onAnimationEnd:Tt,children:Vt.jsx("div",{ref:We,className:`avatar-bubble__content${pe?" avatar-bubble__content--nudge":""}`,children:St})}),Vt.jsx("div",{className:"avatar-canvas-layer",style:{width:V,height:V},children:Vt.jsxs(BO,{shadows:!0,camera:{position:[.2,1.4,3],fov:42},gl:{alpha:!0},dpr:1.8,style:{pointerEvents:"none",width:"100%",height:"100%"},children:[Vt.jsx(XF,{target:HF}),Vt.jsx("ambientLight",{intensity:.7}),Vt.jsx("directionalLight",{position:[0,2,2],intensity:1}),Vt.jsx(qI,{preset:"city"}),Vt.jsx(Me.Suspense,{fallback:null,children:l!==null&&Vt.jsx(YF,{avatarUrl:l,isPlayingRef:ne,visemeQueueRef:$,audioContextRef:ae,responseAudioStartTimeRef:K,adjustments:FF,mood:Pe,expression:Ee,agentResponse:p,isSpeaking:R,nextStartTimeRef:te,stopPlayback:it,setIsSpeaking:T,expressionUrl:Bt,onExpressionFinished:Ba,isNudgeResponse:pe,avatarGender:n})})]})})]})})]})},KF=({token:s,avatarGender:e,onNavigationRequested:t,presetUserDetails:n})=>Vt.jsx(qF,{token:s,onNavigationRequested:t,avatarGender:e,presetUserDetails:n}),mC="streamoji-leads-avatar-widget-root";function gC(s){const{token:e}=s;let t=document.getElementById(mC);if(!t){t=document.createElement("div"),t.id=mC,t.style.cssText="position:fixed;bottom:0;right:0;z-index:9999;pointer-events:none;";const i=document.createElement("div");i.style.cssText="pointer-events:auto;",t.appendChild(i),document.body.appendChild(t),t=i}gR.createRoot(t).render(bM.createElement(KF,{token:e||""}))}return window.StreamojiLeadsAvatarWidget={init:gC},Oy.init=gC,Object.defineProperty(Oy,Symbol.toStringTag,{value:"Module"}),Oy})({});
4156
4156
  //# sourceMappingURL=avatar-widget.umd.js.map