@streamoji/avatar-widget 0.1.1 → 0.2.1

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