@streamoji/avatar-widget 0.2.8 → 0.2.9
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.
- package/dist/avatar-widget.cjs +2 -2
- package/dist/avatar-widget.cjs.map +1 -1
- package/dist/avatar-widget.css +1 -1
- package/dist/avatar-widget.js +58 -54
- package/dist/avatar-widget.js.map +1 -1
- package/dist/avatar-widget.umd.js +1 -1
- package/dist/avatar-widget.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -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:
|
|
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
|