voicedots-ai-widget 2.1.4 → 2.1.5
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/voicedots-widget.js
CHANGED
|
@@ -39,7 +39,7 @@ return ie(Op,{children:/* @__PURE__ */ie("div",{className:"vd-modal-overlay",chi
|
|
|
39
39
|
/* @__PURE__ */ie(Fe,{size:14}),
|
|
40
40
|
/* @__PURE__ */ie("span",{children:"Confirmed & saved successfully"})]}:{children:[
|
|
41
41
|
/* @__PURE__ */ie(Be,{size:14,className:"vd-spin"}),
|
|
42
|
-
/* @__PURE__ */ie("span",{children:"Waiting for verbal confirmation..."})]})})})]})]})}):null}function Ap({title:e,agentId:t,avatars:n,logo:i,pos:o,mini:s,msg:r}){const[a,c]=_e(s);let d,l="default";t.includes("voicedots")||"agent_6401kktn9d03fncsk4j27psd9gtk"===t?(d=function(){const[e,t]=_e(!1),[n,i]=_e(null),[o,s]=_e(!1),[r,a]=_e(!1),[c,d]=_e(!1),l=ye(!1),[u,h]=_e(null),[p,m]=_e(null),[g,v]=_e(!1),[f,_]=_e(!1),[b,y]=_e(null),[k,w]=_e(!1),C=Ce(async e=>{if(!l.current&&!o&&!r){l.current=!0,a(!0),m(null);try{const n=await fetch(`https://token.voicedots.io/getToken?agent_id=${e}`);if(!n.ok)throw new Error("Failed to fetch token");const{token:o,ws_url:r}=await n.json(),a=new dh({adaptiveStream:!0,dynacast:!0,videoCaptureDefaults:{resolution:Bc.h720.resolution}});a.on(pc.ActiveSpeakersChanged,e=>{const t=e.find(e=>e instanceof ch);d(!!t)}),a.on(pc.TrackSubscribed,e=>{if("audio"===e.kind){const t=e.attach();document.body.appendChild(t)}}),a.on(pc.TrackUnsubscribed,e=>{e.detach().forEach(e=>e.remove())}),a.on(pc.DataReceived,async e=>{try{const t=JSON.parse((new TextDecoder).decode(e));if(console.log("Received data from agent:",t),"TOOL_CALL"===t.type)if("openValidationPopup"===t.function)w(!1),y({name:t.args?.name??"",email:t.args?.email??"",phone:t.args?.phone??""}),_(!0);else if("updateField"===t.function){const e=t.args?.field,n=t.args?.value;e&&void 0!==n&&(console.log(`[Tool] Updating field: ${e} = ${n}`),y(t=>({...t,[e]:n})))}else if("confirmSave"===t.function)console.log("[Tool] Data confirmed by agent — auto-saving"),w(!0),setTimeout(()=>{_(!1),w(!1)},2e3);else if("glowAvatar"===t.function){const e=t.args?.name?.split("_").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ");console.log(`Setting active avatar to: ${e}`),h(e)}else"endCall"===t.function?(console.log("[Tool] Agent initiated end call"),a&&await a.disconnect(),i(null),s(!1),d(!1),h(null),l.current=!1):"appointmentBooked"===t.function
|
|
42
|
+
/* @__PURE__ */ie("span",{children:"Waiting for verbal confirmation..."})]})})})]})]})}):null}function Ap({title:e,agentId:t,avatars:n,logo:i,pos:o,mini:s,msg:r}){const[a,c]=_e(s);let d,l="default";t.includes("voicedots")||"agent_6401kktn9d03fncsk4j27psd9gtk"===t?(d=function(){const[e,t]=_e(!1),[n,i]=_e(null),[o,s]=_e(!1),[r,a]=_e(!1),[c,d]=_e(!1),l=ye(!1),[u,h]=_e(null),[p,m]=_e(null),[g,v]=_e(!1),[f,_]=_e(!1),[b,y]=_e(null),[k,w]=_e(!1),C=Ce(async e=>{if(!l.current&&!o&&!r){l.current=!0,a(!0),m(null);try{const n=await fetch(`https://token.voicedots.io/getToken?agent_id=${e}`);if(!n.ok)throw new Error("Failed to fetch token");const{token:o,ws_url:r}=await n.json(),a=new dh({adaptiveStream:!0,dynacast:!0,videoCaptureDefaults:{resolution:Bc.h720.resolution}});a.on(pc.ActiveSpeakersChanged,e=>{const t=e.find(e=>e instanceof ch);d(!!t)}),a.on(pc.TrackSubscribed,e=>{if("audio"===e.kind){const t=e.attach();document.body.appendChild(t)}}),a.on(pc.TrackUnsubscribed,e=>{e.detach().forEach(e=>e.remove())}),a.on(pc.DataReceived,async e=>{try{const t=JSON.parse((new TextDecoder).decode(e));if(console.log("Received data from agent:",t),"TOOL_CALL"===t.type)if("openValidationPopup"===t.function)w(!1),y({name:t.args?.name??"",email:t.args?.email??"",phone:t.args?.phone??""}),_(!0);else if("updateField"===t.function){const e=t.args?.field,n=t.args?.value;e&&void 0!==n&&(console.log(`[Tool] Updating field: ${e} = ${n}`),y(t=>({...t,[e]:n})))}else if("confirmSave"===t.function)console.log("[Tool] Data confirmed by agent — auto-saving"),w(!0),setTimeout(()=>{_(!1),w(!1)},2e3);else if("glowAvatar"===t.function){const e=t.args?.name?.split("_").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ");console.log(`Setting active avatar to: ${e}`),h(e)}else"endCall"===t.function?(console.log("[Tool] Agent initiated end call"),a&&await a.disconnect(),i(null),s(!1),d(!1),h(null),l.current=!1):"appointmentBooked"===t.function?console.log("[Tool] Appointment booked:",t.args):"externalPageNavigation"===t.function&&(console.log(`[Tool] Navigating user to external page: ${t.args?.url}`),t.args.id?window.location.href=t.args.id:console.warn(`No URL provided for externalPageNavigation: ${JSON.stringify(t.args)}`))}catch(ip){console.error("Error parsing data message",ip)}});const c=r;await a.connect(c,o),await a.localParticipant.setMicrophoneEnabled(!0),t(!1),i(a),s(!0)}catch(n){console.error("LiveKit connection error:",n),m(n.message||"Failed to start conversation")}finally{l.current=!1,a(!1)}}},[o,r]);return{start:C,stop:async()=>{l.current=!1,n&&(await n.disconnect(),i(null)),s(!1),d(!1),h(null)},isConnected:o,isConnecting:r,isSpeaking:c,activeAvatar:u,setActiveAvatar:h,toggleMic:async()=>{if(!n||!n.localParticipant)return;const i=!e;t(i);try{await n.localParticipant.setMicrophoneEnabled(!i)}catch(ip){console.error("Failed to toggle mic",ip)}},micMuted:e,error:p,setError:m,loginOpen:g,setLoginOpen:v,dataCollectionOpen:f,setDataCollectionOpen:_,handleUserDataCollected:async e=>{y(e)},userData:b,setUserData:y,dataConfirmed:k}}(),l="voicedots"):d=Rp();const u=ye({}),[h,p]=_e(360);return be(()=>{const e=d.activeAvatar;e&&(d.isSpeaking?u.current[e]?.startTalking():u.current[e]?.stopTalking())},[d.isSpeaking,d.activeAvatar]),be(()=>{let e;return d.isConnected&&(p(360),e=setInterval(()=>{p(e=>e>0?e-1:0)},1e3)),()=>clearInterval(e)},[d.isConnected]),/* @__PURE__ */ie("div",{className:`vd-widget-container vd-pos-${o}`,children:["voicedots"===l&&/* @__PURE__ */ie(Dp,{isOpen:d.dataCollectionOpen,title:"Verify Information",onClose:()=>d.setDataCollectionOpen(!1),data:d.userData,confirmed:d.dataConfirmed}),"voicedots"!==l&&/* @__PURE__ */ie(Lp,{isOpen:d.dataCollectionOpen,title:"Verify Information",onClose:()=>d.setDataCollectionOpen(!1),data:d.userData,onSubmit:d.handleUserDataCollected}),!a&&/* @__PURE__ */ie("div",{className:"vd-main-card",children:[
|
|
43
43
|
/* @__PURE__ */ie("div",{className:"vd-header",children:[
|
|
44
44
|
/* @__PURE__ */ie("div",{className:"vd-title-group",children:[
|
|
45
45
|
/* @__PURE__ */ie("h3",{children:e}),d.isConnected&&/* @__PURE__ */ie("span",{className:"vd-timer",children:[Math.floor(h/60),":",(h%60).toString().padStart(2,"0")]})]}),
|