@vanira/sdk 0.0.21 → 0.0.22
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/vanira-sdk.es.js +1 -1
- package/dist/vanira-sdk.js +1 -1
- package/dist/vanira-sdk.js.map +1 -1
- package/package.json +1 -1
package/dist/vanira-sdk.es.js
CHANGED
|
@@ -1092,4 +1092,4 @@ overflow: hidden;
|
|
|
1092
1092
|
${O.styles}
|
|
1093
1093
|
${N.styles}
|
|
1094
1094
|
${this.gradient?`.widget-fab { background: ${this.gradient} !important; }`:""}
|
|
1095
|
-
`,this.root.appendChild(s);const n=`vanira_pos_${this.widgetId||this.agentId}`,a=localStorage.getItem(n);let r=null;if(a)try{r=JSON.parse(a)}catch{}this.floatingButton=new R(()=>this.togglePanel(),(c,l)=>{var d,g;(d=this.floatingWelcomeChips)==null||d.updateCoordinates(c,l,l>window.innerHeight/2),this.isPanelOpen&&((g=this.panel)==null||g.updatePosition({left:`${Math.max(20,Math.min(c-170,window.innerWidth-420))}px`,top:l>window.innerHeight/2?"auto":`${l+80}px`,bottom:l>window.innerHeight/2?`${window.innerHeight-l+20}px`:"auto"}))},(c,l)=>{localStorage.setItem(n,JSON.stringify({x:c,y:l}))}),this.floatingButton.setIcon(this.getFabIcon()),r?this.floatingButton.updateCoordinates(r.x,r.y):this.floatingButton.setPosition(this.getPosStyle()),this.floatingWelcomeChips=new O(c=>this.handleFloatingChipClick(c)),r?this.floatingWelcomeChips.updateCoordinates(r.x,r.y,r.y>window.innerHeight/2):this.floatingWelcomeChips.setPosition(this.getPosStyle()),this.panel=new N(()=>this.closePanel(),this.getPanelTitle()),this.root.appendChild(this.floatingWelcomeChips.getElement()),this.root.appendChild(this.floatingButton.getElement()),this.root.appendChild(this.panel.getElement()),this.setupPanelContent(),this.chatWelcomeMessage&&this.handleWelcomePayload(this.chatWelcomeMessage),this.initSessionManager()?this.widgetMode.includes("chat")&&this.initializeChatSession():this.showTabConflictBanner("conflict")}getFabIcon(){return this.widgetIcon&&T[this.widgetIcon]?T[this.widgetIcon]:this.widgetMode.includes("chat")?m.chat:m.voice_orb}getPanelTitle(){return"Assistant"}getPosStyle(){const e={"bottom-right":"bottom: 24px; right: 24px;","bottom-left":"bottom: 24px; left: 24px;","top-right":"top: 24px; right: 24px;","top-left":"top: 24px; left: 24px;"};return e[this.position]||e["bottom-right"]}setupPanelContent(){const e=(i,s)=>{var A,c;const n=(c=(A=this.currentView)==null?void 0:A.getChatWindow)==null?void 0:c.call(A);n&&n.addCallRecord(i,s);const a=`vanira_calls_${this.widgetId||this.agentId}`,r=JSON.parse(localStorage.getItem(a)||"[]");r.push({durationMs:i,startedAt:s}),r.length>50&&r.splice(0,r.length-50),localStorage.setItem(a,JSON.stringify(r))};switch(this.widgetMode){case"chat_only":this.currentView=new oe(i=>this.handleChatSend(i));break;case"chat_voice":this.currentView=new ae(i=>this.handleChatSend(i),()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break;case"avatar_only":this.currentView=new re(()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break;case"chat_avatar":this.currentView=new le(i=>this.handleChatSend(i),()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break;case"voice_only":default:this.currentView=new ne(()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break}this.currentView&&this.panel&&this.panel.setContent(this.currentView.getElement())}async handleChatSend(e){var s,n,a,r,A;if(!e)return;this.sessionActive||((s=this.sessionManager)==null||s.forceClaimSession(),this.sessionActive=!0,this.widgetMode.includes("chat")&&await this.initializeChatSession(!1));const i=(a=(n=this.currentView)==null?void 0:n.getChatWindow)==null?void 0:a.call(n);if(i){this.chatId&&!this.eventSource&&(this.eventSource=C.listenForAdminReplies(this.chatId,this.prospectId,c=>{var l,d,g;(d=(l=this.currentView)==null?void 0:l.getChatWindow)==null||d.call(l).addMessage("assistant",c),(g=this.sessionManager)==null||g.pushMessage("assistant",c),this.playMessageSound("receive")})),i.addMessage("user",e),(r=this.sessionManager)==null||r.pushMessage("user",e),i.setTyping(!0),(A=this.sessionManager)==null||A.pushMessage("assistant","");try{let c=!1;await this.chatAdapter.sendMessage(e,this.agentId,this.prospectId,this.chatId,l=>{var d;c||(this.playMessageSound("receive"),c=!0),i.setTyping(!1),(l==null?void 0:l.type)==="button_list"&&((d=l.data)!=null&&d.buttons)&&(i.addButtons(l.data.buttons),this.welcomeChipsData=l.data.buttons,this.updateWelcomeChipsVisibility())},l=>{var d;c||(this.playMessageSound("receive"),c=!0),i.setTyping(!1),i.updateLastAssistantMessage(l),(d=this.sessionManager)==null||d.updateLastAssistantMessage(l)},l=>{var d;l&&(this.chatId=l,(d=this.sessionManager)==null||d.saveIds(this.prospectId,l))})}catch(c){i.setTyping(!1),console.error("[VaniraAI] Send message failed",c),i.addMessage("assistant","Error sending message.")}}}togglePanel(){this.isPanelOpen?this.closePanel():this.openPanel()}openPanel(){var i,s,n,a;this.isPanelOpen=!0,this.updateWelcomeChipsVisibility();const e=(i=this.floatingButton)==null?void 0:i.getElement().getBoundingClientRect();if(e){const r=e.top>window.innerHeight/2;(s=this.panel)==null||s.open({left:`${Math.max(20,Math.min(e.left-170,window.innerWidth-420))}px`,bottom:r?`${window.innerHeight-e.top+20}px`:void 0,top:r?void 0:`${e.top+80}px`})}else(n=this.panel)==null||n.open({bottom:this.position.includes("bottom")?"100px":void 0,top:this.position.includes("top")?"100px":void 0,right:this.position.includes("right")?"24px":void 0,left:this.position.includes("left")?"24px":void 0});(a=this.root)!=null&&a.host&&this.root.host.classList.add("vanira-panel-open")}closePanel(){var e,i;this.isPanelOpen=!1,this.updateWelcomeChipsVisibility(),(e=this.panel)==null||e.close(),(i=this.root)!=null&&i.host&&this.root.host.classList.remove("vanira-panel-open")}updateWelcomeChipsVisibility(){if(!this.floatingWelcomeChips)return;const e=!this.isPanelOpen&&this.welcomeChipsData.length>0;console.log("[VaniraAI] updateWelcomeChipsVisibility:",{visible:e,isPanelOpen:this.isPanelOpen,chipsCount:this.welcomeChipsData.length}),e?(this.floatingWelcomeChips.setChips(this.welcomeChipsData),this.floatingWelcomeChips.getElement().style.display="flex"):this.floatingWelcomeChips.getElement().style.display="none"}handleFloatingChipClick(e){this.openPanel(),this.handleChatSend(e)}};o(B,"audioContext",null);let S=B;class ce{static getProvider(t){return new S(t)}}class de extends HTMLElement{constructor(){super();o(this,"shadow");o(this,"provider",null);o(this,"widgetId","");o(this,"agentId","");o(this,"pkKey","");o(this,"serverUrl","https://inboxapi.travelr.club");o(this,"position","bottom-right");o(this,"primaryColor","#000000");o(this,"secondaryColor","#000000");o(this,"gradient",null);o(this,"positionType","fixed");this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["widget-id","agent-id","position","primary-color","secondary-color","server-url","gradient","position-type","pk-key"]}connectedCallback(){console.log("[VaniraAI Widget] Initializing..."),this.readAttributes();const e={widgetId:this.widgetId,agentId:this.agentId,pkKey:this.pkKey,serverUrl:this.serverUrl,position:this.position,primaryColor:this.primaryColor,secondaryColor:this.secondaryColor,gradient:this.gradient,positionType:this.positionType};this.provider=ce.getProvider(e),this.provider&&this.provider.ui_renderer(this.shadow),this.widgetId&&!this.agentId&&this.initializeExpandedConfig()}readAttributes(){this.widgetId=this.getAttribute("widget-id")||"",this.agentId=this.getAttribute("agent-id")||"",this.pkKey=this.getAttribute("pk-key")||"",this.serverUrl=this.getAttribute("server-url")||"https://inboxapi.travelr.club",this.position=this.getAttribute("position")||"bottom-right",this.primaryColor=this.getAttribute("primary-color")||"#000000",this.secondaryColor=this.getAttribute("secondary-color")||this.primaryColor,this.gradient=this.getAttribute("gradient"),this.positionType=this.getAttribute("position-type")||"fixed"}async initializeExpandedConfig(){try{const e=await G.fetchWidgetConfig(this.widgetId,this.pkKey||void 0);this.provider&&await this.provider.initialize(e)}catch(e){console.error("[VaniraAI Widget] Config failed:",e)}}}u.ChatService=C,u.ConfigService=G,u.SessionManager=k,u.VaniraAI=Y,u.VaniraWidget=de,u.WebRTCClient=v,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
1095
|
+
`,this.root.appendChild(s);const n=`vanira_pos_${this.widgetId||this.agentId}`,a=localStorage.getItem(n);let r=null;if(a)try{r=JSON.parse(a)}catch{}this.floatingButton=new R(()=>this.togglePanel(),(c,l)=>{var d,g;(d=this.floatingWelcomeChips)==null||d.updateCoordinates(c,l,l>window.innerHeight/2),this.isPanelOpen&&((g=this.panel)==null||g.updatePosition({left:`${Math.max(20,Math.min(c-170,window.innerWidth-420))}px`,top:l>window.innerHeight/2?"auto":`${l+80}px`,bottom:l>window.innerHeight/2?`${window.innerHeight-l+20}px`:"auto"}))},(c,l)=>{localStorage.setItem(n,JSON.stringify({x:c,y:l}))}),this.floatingButton.setIcon(this.getFabIcon()),r?this.floatingButton.updateCoordinates(r.x,r.y):this.floatingButton.setPosition(this.getPosStyle()),this.floatingWelcomeChips=new O(c=>this.handleFloatingChipClick(c)),r?this.floatingWelcomeChips.updateCoordinates(r.x,r.y,r.y>window.innerHeight/2):this.floatingWelcomeChips.setPosition(this.getPosStyle()),this.panel=new N(()=>this.closePanel(),this.getPanelTitle()),this.root.appendChild(this.floatingWelcomeChips.getElement()),this.root.appendChild(this.floatingButton.getElement()),this.root.appendChild(this.panel.getElement()),this.setupPanelContent(),this.chatWelcomeMessage&&!this.widgetMode.includes("chat")&&this.handleWelcomePayload(this.chatWelcomeMessage),this.initSessionManager()?this.widgetMode.includes("chat")&&this.initializeChatSession():this.showTabConflictBanner("conflict")}getFabIcon(){return this.widgetIcon&&T[this.widgetIcon]?T[this.widgetIcon]:this.widgetMode.includes("chat")?m.chat:m.voice_orb}getPanelTitle(){return"Assistant"}getPosStyle(){const e={"bottom-right":"bottom: 24px; right: 24px;","bottom-left":"bottom: 24px; left: 24px;","top-right":"top: 24px; right: 24px;","top-left":"top: 24px; left: 24px;"};return e[this.position]||e["bottom-right"]}setupPanelContent(){const e=(i,s)=>{var A,c;const n=(c=(A=this.currentView)==null?void 0:A.getChatWindow)==null?void 0:c.call(A);n&&n.addCallRecord(i,s);const a=`vanira_calls_${this.widgetId||this.agentId}`,r=JSON.parse(localStorage.getItem(a)||"[]");r.push({durationMs:i,startedAt:s}),r.length>50&&r.splice(0,r.length-50),localStorage.setItem(a,JSON.stringify(r))};switch(this.widgetMode){case"chat_only":this.currentView=new oe(i=>this.handleChatSend(i));break;case"chat_voice":this.currentView=new ae(i=>this.handleChatSend(i),()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break;case"avatar_only":this.currentView=new re(()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break;case"chat_avatar":this.currentView=new le(i=>this.handleChatSend(i),()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break;case"voice_only":default:this.currentView=new ne(()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break}this.currentView&&this.panel&&this.panel.setContent(this.currentView.getElement())}async handleChatSend(e){var s,n,a,r,A;if(!e)return;this.sessionActive||((s=this.sessionManager)==null||s.forceClaimSession(),this.sessionActive=!0,this.widgetMode.includes("chat")&&await this.initializeChatSession(!1));const i=(a=(n=this.currentView)==null?void 0:n.getChatWindow)==null?void 0:a.call(n);if(i){this.chatId&&!this.eventSource&&(this.eventSource=C.listenForAdminReplies(this.chatId,this.prospectId,c=>{var l,d,g;(d=(l=this.currentView)==null?void 0:l.getChatWindow)==null||d.call(l).addMessage("assistant",c),(g=this.sessionManager)==null||g.pushMessage("assistant",c),this.playMessageSound("receive")})),i.addMessage("user",e),(r=this.sessionManager)==null||r.pushMessage("user",e),i.setTyping(!0),(A=this.sessionManager)==null||A.pushMessage("assistant","");try{let c=!1;await this.chatAdapter.sendMessage(e,this.agentId,this.prospectId,this.chatId,l=>{var d;c||(this.playMessageSound("receive"),c=!0),i.setTyping(!1),(l==null?void 0:l.type)==="button_list"&&((d=l.data)!=null&&d.buttons)&&(i.addButtons(l.data.buttons),this.welcomeChipsData=l.data.buttons,this.updateWelcomeChipsVisibility())},l=>{var d;c||(this.playMessageSound("receive"),c=!0),i.setTyping(!1),i.updateLastAssistantMessage(l),(d=this.sessionManager)==null||d.updateLastAssistantMessage(l)},l=>{var d;l&&(this.chatId=l,(d=this.sessionManager)==null||d.saveIds(this.prospectId,l))})}catch(c){i.setTyping(!1),console.error("[VaniraAI] Send message failed",c),i.addMessage("assistant","Error sending message.")}}}togglePanel(){this.isPanelOpen?this.closePanel():this.openPanel()}openPanel(){var i,s,n,a;this.isPanelOpen=!0,this.updateWelcomeChipsVisibility();const e=(i=this.floatingButton)==null?void 0:i.getElement().getBoundingClientRect();if(e){const r=e.top>window.innerHeight/2;(s=this.panel)==null||s.open({left:`${Math.max(20,Math.min(e.left-170,window.innerWidth-420))}px`,bottom:r?`${window.innerHeight-e.top+20}px`:void 0,top:r?void 0:`${e.top+80}px`})}else(n=this.panel)==null||n.open({bottom:this.position.includes("bottom")?"100px":void 0,top:this.position.includes("top")?"100px":void 0,right:this.position.includes("right")?"24px":void 0,left:this.position.includes("left")?"24px":void 0});(a=this.root)!=null&&a.host&&this.root.host.classList.add("vanira-panel-open")}closePanel(){var e,i;this.isPanelOpen=!1,this.updateWelcomeChipsVisibility(),(e=this.panel)==null||e.close(),(i=this.root)!=null&&i.host&&this.root.host.classList.remove("vanira-panel-open")}updateWelcomeChipsVisibility(){if(!this.floatingWelcomeChips)return;const e=!this.isPanelOpen&&this.welcomeChipsData.length>0;console.log("[VaniraAI] updateWelcomeChipsVisibility:",{visible:e,isPanelOpen:this.isPanelOpen,chipsCount:this.welcomeChipsData.length}),e?(this.floatingWelcomeChips.setChips(this.welcomeChipsData),this.floatingWelcomeChips.getElement().style.display="flex"):this.floatingWelcomeChips.getElement().style.display="none"}handleFloatingChipClick(e){this.openPanel(),this.handleChatSend(e)}};o(B,"audioContext",null);let S=B;class ce{static getProvider(t){return new S(t)}}class de extends HTMLElement{constructor(){super();o(this,"shadow");o(this,"provider",null);o(this,"widgetId","");o(this,"agentId","");o(this,"pkKey","");o(this,"serverUrl","https://inboxapi.travelr.club");o(this,"position","bottom-right");o(this,"primaryColor","#000000");o(this,"secondaryColor","#000000");o(this,"gradient",null);o(this,"positionType","fixed");this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["widget-id","agent-id","position","primary-color","secondary-color","server-url","gradient","position-type","pk-key"]}connectedCallback(){console.log("[VaniraAI Widget] Initializing..."),this.readAttributes();const e={widgetId:this.widgetId,agentId:this.agentId,pkKey:this.pkKey,serverUrl:this.serverUrl,position:this.position,primaryColor:this.primaryColor,secondaryColor:this.secondaryColor,gradient:this.gradient,positionType:this.positionType};this.provider=ce.getProvider(e),this.provider&&this.provider.ui_renderer(this.shadow),this.widgetId&&!this.agentId&&this.initializeExpandedConfig()}readAttributes(){this.widgetId=this.getAttribute("widget-id")||"",this.agentId=this.getAttribute("agent-id")||"",this.pkKey=this.getAttribute("pk-key")||"",this.serverUrl=this.getAttribute("server-url")||"https://inboxapi.travelr.club",this.position=this.getAttribute("position")||"bottom-right",this.primaryColor=this.getAttribute("primary-color")||"#000000",this.secondaryColor=this.getAttribute("secondary-color")||this.primaryColor,this.gradient=this.getAttribute("gradient"),this.positionType=this.getAttribute("position-type")||"fixed"}async initializeExpandedConfig(){try{const e=await G.fetchWidgetConfig(this.widgetId,this.pkKey||void 0);this.provider&&await this.provider.initialize(e)}catch(e){console.error("[VaniraAI Widget] Config failed:",e)}}}u.ChatService=C,u.ConfigService=G,u.SessionManager=k,u.VaniraAI=Y,u.VaniraWidget=de,u.WebRTCClient=v,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/dist/vanira-sdk.js
CHANGED
|
@@ -1092,5 +1092,5 @@ overflow: hidden;
|
|
|
1092
1092
|
${O.styles}
|
|
1093
1093
|
${N.styles}
|
|
1094
1094
|
${this.gradient?`.widget-fab { background: ${this.gradient} !important; }`:""}
|
|
1095
|
-
`,this.root.appendChild(s);const n=`vanira_pos_${this.widgetId||this.agentId}`,a=localStorage.getItem(n);let r=null;if(a)try{r=JSON.parse(a)}catch{}this.floatingButton=new R(()=>this.togglePanel(),(c,A)=>{var d,g;(d=this.floatingWelcomeChips)==null||d.updateCoordinates(c,A,A>window.innerHeight/2),this.isPanelOpen&&((g=this.panel)==null||g.updatePosition({left:`${Math.max(20,Math.min(c-170,window.innerWidth-420))}px`,top:A>window.innerHeight/2?"auto":`${A+80}px`,bottom:A>window.innerHeight/2?`${window.innerHeight-A+20}px`:"auto"}))},(c,A)=>{localStorage.setItem(n,JSON.stringify({x:c,y:A}))}),this.floatingButton.setIcon(this.getFabIcon()),r?this.floatingButton.updateCoordinates(r.x,r.y):this.floatingButton.setPosition(this.getPosStyle()),this.floatingWelcomeChips=new O(c=>this.handleFloatingChipClick(c)),r?this.floatingWelcomeChips.updateCoordinates(r.x,r.y,r.y>window.innerHeight/2):this.floatingWelcomeChips.setPosition(this.getPosStyle()),this.panel=new N(()=>this.closePanel(),this.getPanelTitle()),this.root.appendChild(this.floatingWelcomeChips.getElement()),this.root.appendChild(this.floatingButton.getElement()),this.root.appendChild(this.panel.getElement()),this.setupPanelContent(),this.chatWelcomeMessage&&this.handleWelcomePayload(this.chatWelcomeMessage),this.initSessionManager()?this.widgetMode.includes("chat")&&this.initializeChatSession():this.showTabConflictBanner("conflict")}getFabIcon(){return this.widgetIcon&&T[this.widgetIcon]?T[this.widgetIcon]:this.widgetMode.includes("chat")?u.chat:u.voice_orb}getPanelTitle(){return"Assistant"}getPosStyle(){const e={"bottom-right":"bottom: 24px; right: 24px;","bottom-left":"bottom: 24px; left: 24px;","top-right":"top: 24px; right: 24px;","top-left":"top: 24px; left: 24px;"};return e[this.position]||e["bottom-right"]}setupPanelContent(){const e=(i,s)=>{var l,c;const n=(c=(l=this.currentView)==null?void 0:l.getChatWindow)==null?void 0:c.call(l);n&&n.addCallRecord(i,s);const a=`vanira_calls_${this.widgetId||this.agentId}`,r=JSON.parse(localStorage.getItem(a)||"[]");r.push({durationMs:i,startedAt:s}),r.length>50&&r.splice(0,r.length-50),localStorage.setItem(a,JSON.stringify(r))};switch(this.widgetMode){case"chat_only":this.currentView=new ae(i=>this.handleChatSend(i));break;case"chat_voice":this.currentView=new re(i=>this.handleChatSend(i),()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break;case"avatar_only":this.currentView=new le(()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break;case"chat_avatar":this.currentView=new Ae(i=>this.handleChatSend(i),()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break;case"voice_only":default:this.currentView=new oe(()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break}this.currentView&&this.panel&&this.panel.setContent(this.currentView.getElement())}async handleChatSend(e){var s,n,a,r,l;if(!e)return;this.sessionActive||((s=this.sessionManager)==null||s.forceClaimSession(),this.sessionActive=!0,this.widgetMode.includes("chat")&&await this.initializeChatSession(!1));const i=(a=(n=this.currentView)==null?void 0:n.getChatWindow)==null?void 0:a.call(n);if(i){this.chatId&&!this.eventSource&&(this.eventSource=v.listenForAdminReplies(this.chatId,this.prospectId,c=>{var A,d,g;(d=(A=this.currentView)==null?void 0:A.getChatWindow)==null||d.call(A).addMessage("assistant",c),(g=this.sessionManager)==null||g.pushMessage("assistant",c),this.playMessageSound("receive")})),i.addMessage("user",e),(r=this.sessionManager)==null||r.pushMessage("user",e),i.setTyping(!0),(l=this.sessionManager)==null||l.pushMessage("assistant","");try{let c=!1;await this.chatAdapter.sendMessage(e,this.agentId,this.prospectId,this.chatId,A=>{var d;c||(this.playMessageSound("receive"),c=!0),i.setTyping(!1),(A==null?void 0:A.type)==="button_list"&&((d=A.data)!=null&&d.buttons)&&(i.addButtons(A.data.buttons),this.welcomeChipsData=A.data.buttons,this.updateWelcomeChipsVisibility())},A=>{var d;c||(this.playMessageSound("receive"),c=!0),i.setTyping(!1),i.updateLastAssistantMessage(A),(d=this.sessionManager)==null||d.updateLastAssistantMessage(A)},A=>{var d;A&&(this.chatId=A,(d=this.sessionManager)==null||d.saveIds(this.prospectId,A))})}catch(c){i.setTyping(!1),console.error("[VaniraAI] Send message failed",c),i.addMessage("assistant","Error sending message.")}}}togglePanel(){this.isPanelOpen?this.closePanel():this.openPanel()}openPanel(){var i,s,n,a;this.isPanelOpen=!0,this.updateWelcomeChipsVisibility();const e=(i=this.floatingButton)==null?void 0:i.getElement().getBoundingClientRect();if(e){const r=e.top>window.innerHeight/2;(s=this.panel)==null||s.open({left:`${Math.max(20,Math.min(e.left-170,window.innerWidth-420))}px`,bottom:r?`${window.innerHeight-e.top+20}px`:void 0,top:r?void 0:`${e.top+80}px`})}else(n=this.panel)==null||n.open({bottom:this.position.includes("bottom")?"100px":void 0,top:this.position.includes("top")?"100px":void 0,right:this.position.includes("right")?"24px":void 0,left:this.position.includes("left")?"24px":void 0});(a=this.root)!=null&&a.host&&this.root.host.classList.add("vanira-panel-open")}closePanel(){var e,i;this.isPanelOpen=!1,this.updateWelcomeChipsVisibility(),(e=this.panel)==null||e.close(),(i=this.root)!=null&&i.host&&this.root.host.classList.remove("vanira-panel-open")}updateWelcomeChipsVisibility(){if(!this.floatingWelcomeChips)return;const e=!this.isPanelOpen&&this.welcomeChipsData.length>0;console.log("[VaniraAI] updateWelcomeChipsVisibility:",{visible:e,isPanelOpen:this.isPanelOpen,chipsCount:this.welcomeChipsData.length}),e?(this.floatingWelcomeChips.setChips(this.welcomeChipsData),this.floatingWelcomeChips.getElement().style.display="flex"):this.floatingWelcomeChips.getElement().style.display="none"}handleFloatingChipClick(e){this.openPanel(),this.handleChatSend(e)}};o(I,"audioContext",null);let P=I;class de{static getProvider(t){return new P(t)}}class X extends HTMLElement{constructor(){super();o(this,"shadow");o(this,"provider",null);o(this,"widgetId","");o(this,"agentId","");o(this,"pkKey","");o(this,"serverUrl","https://inboxapi.travelr.club");o(this,"position","bottom-right");o(this,"primaryColor","#000000");o(this,"secondaryColor","#000000");o(this,"gradient",null);o(this,"positionType","fixed");this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["widget-id","agent-id","position","primary-color","secondary-color","server-url","gradient","position-type","pk-key"]}connectedCallback(){console.log("[VaniraAI Widget] Initializing..."),this.readAttributes();const e={widgetId:this.widgetId,agentId:this.agentId,pkKey:this.pkKey,serverUrl:this.serverUrl,position:this.position,primaryColor:this.primaryColor,secondaryColor:this.secondaryColor,gradient:this.gradient,positionType:this.positionType};this.provider=de.getProvider(e),this.provider&&this.provider.ui_renderer(this.shadow),this.widgetId&&!this.agentId&&this.initializeExpandedConfig()}readAttributes(){this.widgetId=this.getAttribute("widget-id")||"",this.agentId=this.getAttribute("agent-id")||"",this.pkKey=this.getAttribute("pk-key")||"",this.serverUrl=this.getAttribute("server-url")||"https://inboxapi.travelr.club",this.position=this.getAttribute("position")||"bottom-right",this.primaryColor=this.getAttribute("primary-color")||"#000000",this.secondaryColor=this.getAttribute("secondary-color")||this.primaryColor,this.gradient=this.getAttribute("gradient"),this.positionType=this.getAttribute("position-type")||"fixed"}async initializeExpandedConfig(){try{const e=await b.fetchWidgetConfig(this.widgetId,this.pkKey||void 0);this.provider&&await this.provider.initialize(e)}catch(e){console.error("[VaniraAI Widget] Config failed:",e)}}}customElements.get("vanira-convai")||customElements.define("vanira-convai",X),typeof window<"u"&&(window.VaniraConvAI=X,window.VaniraAI=G);const m=document.currentScript;if(m){const h=m.getAttribute("data-widget-id")||m.getAttribute("widget-id"),t=m.getAttribute("data-agent-id")||m.getAttribute("agent-id");if(h||t){const e=m.getAttribute("data-position")||"bottom-right",i=m.getAttribute("data-primary-color")||m.getAttribute("primary-color")||"#6366f1",s=m.getAttribute("data-secondary-color")||m.getAttribute("secondary-color"),n=m.getAttribute("data-gradient")||m.getAttribute("gradient"),a=m.getAttribute("data-server-url")||m.getAttribute("server-url"),r=m.getAttribute("data-pk-key")||m.getAttribute("pk-key"),l=document.createElement("vanira-convai");h&&l.setAttribute("widget-id",h),t&&l.setAttribute("agent-id",t),r&&l.setAttribute("pk-key",r),l.setAttribute("position",e),l.setAttribute("primary-color",i),s&&l.setAttribute("secondary-color",s),n&&l.setAttribute("gradient",n),a&&l.setAttribute("server-url",a),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>document.body.appendChild(l)):document.body.appendChild(l),l.addEventListener("vaniraai:tool_call",c=>{const A=c.detail;console.log("[VaniraAI Widget] Tool call received by host page:",A.name,A.arguments),typeof window.__vaniraai_tool_handler=="function"&&window.__vaniraai_tool_handler(A,{sendResult:d=>{console.log("[VaniraAI] sendResult called:",d)}})})}}})();
|
|
1095
|
+
`,this.root.appendChild(s);const n=`vanira_pos_${this.widgetId||this.agentId}`,a=localStorage.getItem(n);let r=null;if(a)try{r=JSON.parse(a)}catch{}this.floatingButton=new R(()=>this.togglePanel(),(c,A)=>{var d,g;(d=this.floatingWelcomeChips)==null||d.updateCoordinates(c,A,A>window.innerHeight/2),this.isPanelOpen&&((g=this.panel)==null||g.updatePosition({left:`${Math.max(20,Math.min(c-170,window.innerWidth-420))}px`,top:A>window.innerHeight/2?"auto":`${A+80}px`,bottom:A>window.innerHeight/2?`${window.innerHeight-A+20}px`:"auto"}))},(c,A)=>{localStorage.setItem(n,JSON.stringify({x:c,y:A}))}),this.floatingButton.setIcon(this.getFabIcon()),r?this.floatingButton.updateCoordinates(r.x,r.y):this.floatingButton.setPosition(this.getPosStyle()),this.floatingWelcomeChips=new O(c=>this.handleFloatingChipClick(c)),r?this.floatingWelcomeChips.updateCoordinates(r.x,r.y,r.y>window.innerHeight/2):this.floatingWelcomeChips.setPosition(this.getPosStyle()),this.panel=new N(()=>this.closePanel(),this.getPanelTitle()),this.root.appendChild(this.floatingWelcomeChips.getElement()),this.root.appendChild(this.floatingButton.getElement()),this.root.appendChild(this.panel.getElement()),this.setupPanelContent(),this.chatWelcomeMessage&&!this.widgetMode.includes("chat")&&this.handleWelcomePayload(this.chatWelcomeMessage),this.initSessionManager()?this.widgetMode.includes("chat")&&this.initializeChatSession():this.showTabConflictBanner("conflict")}getFabIcon(){return this.widgetIcon&&T[this.widgetIcon]?T[this.widgetIcon]:this.widgetMode.includes("chat")?u.chat:u.voice_orb}getPanelTitle(){return"Assistant"}getPosStyle(){const e={"bottom-right":"bottom: 24px; right: 24px;","bottom-left":"bottom: 24px; left: 24px;","top-right":"top: 24px; right: 24px;","top-left":"top: 24px; left: 24px;"};return e[this.position]||e["bottom-right"]}setupPanelContent(){const e=(i,s)=>{var l,c;const n=(c=(l=this.currentView)==null?void 0:l.getChatWindow)==null?void 0:c.call(l);n&&n.addCallRecord(i,s);const a=`vanira_calls_${this.widgetId||this.agentId}`,r=JSON.parse(localStorage.getItem(a)||"[]");r.push({durationMs:i,startedAt:s}),r.length>50&&r.splice(0,r.length-50),localStorage.setItem(a,JSON.stringify(r))};switch(this.widgetMode){case"chat_only":this.currentView=new ae(i=>this.handleChatSend(i));break;case"chat_voice":this.currentView=new re(i=>this.handleChatSend(i),()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break;case"avatar_only":this.currentView=new le(()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break;case"chat_avatar":this.currentView=new Ae(i=>this.handleChatSend(i),()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break;case"voice_only":default:this.currentView=new oe(()=>this.create_call(),()=>this.end_call(),this.primaryColor,this.secondaryColor,e);break}this.currentView&&this.panel&&this.panel.setContent(this.currentView.getElement())}async handleChatSend(e){var s,n,a,r,l;if(!e)return;this.sessionActive||((s=this.sessionManager)==null||s.forceClaimSession(),this.sessionActive=!0,this.widgetMode.includes("chat")&&await this.initializeChatSession(!1));const i=(a=(n=this.currentView)==null?void 0:n.getChatWindow)==null?void 0:a.call(n);if(i){this.chatId&&!this.eventSource&&(this.eventSource=v.listenForAdminReplies(this.chatId,this.prospectId,c=>{var A,d,g;(d=(A=this.currentView)==null?void 0:A.getChatWindow)==null||d.call(A).addMessage("assistant",c),(g=this.sessionManager)==null||g.pushMessage("assistant",c),this.playMessageSound("receive")})),i.addMessage("user",e),(r=this.sessionManager)==null||r.pushMessage("user",e),i.setTyping(!0),(l=this.sessionManager)==null||l.pushMessage("assistant","");try{let c=!1;await this.chatAdapter.sendMessage(e,this.agentId,this.prospectId,this.chatId,A=>{var d;c||(this.playMessageSound("receive"),c=!0),i.setTyping(!1),(A==null?void 0:A.type)==="button_list"&&((d=A.data)!=null&&d.buttons)&&(i.addButtons(A.data.buttons),this.welcomeChipsData=A.data.buttons,this.updateWelcomeChipsVisibility())},A=>{var d;c||(this.playMessageSound("receive"),c=!0),i.setTyping(!1),i.updateLastAssistantMessage(A),(d=this.sessionManager)==null||d.updateLastAssistantMessage(A)},A=>{var d;A&&(this.chatId=A,(d=this.sessionManager)==null||d.saveIds(this.prospectId,A))})}catch(c){i.setTyping(!1),console.error("[VaniraAI] Send message failed",c),i.addMessage("assistant","Error sending message.")}}}togglePanel(){this.isPanelOpen?this.closePanel():this.openPanel()}openPanel(){var i,s,n,a;this.isPanelOpen=!0,this.updateWelcomeChipsVisibility();const e=(i=this.floatingButton)==null?void 0:i.getElement().getBoundingClientRect();if(e){const r=e.top>window.innerHeight/2;(s=this.panel)==null||s.open({left:`${Math.max(20,Math.min(e.left-170,window.innerWidth-420))}px`,bottom:r?`${window.innerHeight-e.top+20}px`:void 0,top:r?void 0:`${e.top+80}px`})}else(n=this.panel)==null||n.open({bottom:this.position.includes("bottom")?"100px":void 0,top:this.position.includes("top")?"100px":void 0,right:this.position.includes("right")?"24px":void 0,left:this.position.includes("left")?"24px":void 0});(a=this.root)!=null&&a.host&&this.root.host.classList.add("vanira-panel-open")}closePanel(){var e,i;this.isPanelOpen=!1,this.updateWelcomeChipsVisibility(),(e=this.panel)==null||e.close(),(i=this.root)!=null&&i.host&&this.root.host.classList.remove("vanira-panel-open")}updateWelcomeChipsVisibility(){if(!this.floatingWelcomeChips)return;const e=!this.isPanelOpen&&this.welcomeChipsData.length>0;console.log("[VaniraAI] updateWelcomeChipsVisibility:",{visible:e,isPanelOpen:this.isPanelOpen,chipsCount:this.welcomeChipsData.length}),e?(this.floatingWelcomeChips.setChips(this.welcomeChipsData),this.floatingWelcomeChips.getElement().style.display="flex"):this.floatingWelcomeChips.getElement().style.display="none"}handleFloatingChipClick(e){this.openPanel(),this.handleChatSend(e)}};o(I,"audioContext",null);let P=I;class de{static getProvider(t){return new P(t)}}class X extends HTMLElement{constructor(){super();o(this,"shadow");o(this,"provider",null);o(this,"widgetId","");o(this,"agentId","");o(this,"pkKey","");o(this,"serverUrl","https://inboxapi.travelr.club");o(this,"position","bottom-right");o(this,"primaryColor","#000000");o(this,"secondaryColor","#000000");o(this,"gradient",null);o(this,"positionType","fixed");this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["widget-id","agent-id","position","primary-color","secondary-color","server-url","gradient","position-type","pk-key"]}connectedCallback(){console.log("[VaniraAI Widget] Initializing..."),this.readAttributes();const e={widgetId:this.widgetId,agentId:this.agentId,pkKey:this.pkKey,serverUrl:this.serverUrl,position:this.position,primaryColor:this.primaryColor,secondaryColor:this.secondaryColor,gradient:this.gradient,positionType:this.positionType};this.provider=de.getProvider(e),this.provider&&this.provider.ui_renderer(this.shadow),this.widgetId&&!this.agentId&&this.initializeExpandedConfig()}readAttributes(){this.widgetId=this.getAttribute("widget-id")||"",this.agentId=this.getAttribute("agent-id")||"",this.pkKey=this.getAttribute("pk-key")||"",this.serverUrl=this.getAttribute("server-url")||"https://inboxapi.travelr.club",this.position=this.getAttribute("position")||"bottom-right",this.primaryColor=this.getAttribute("primary-color")||"#000000",this.secondaryColor=this.getAttribute("secondary-color")||this.primaryColor,this.gradient=this.getAttribute("gradient"),this.positionType=this.getAttribute("position-type")||"fixed"}async initializeExpandedConfig(){try{const e=await b.fetchWidgetConfig(this.widgetId,this.pkKey||void 0);this.provider&&await this.provider.initialize(e)}catch(e){console.error("[VaniraAI Widget] Config failed:",e)}}}customElements.get("vanira-convai")||customElements.define("vanira-convai",X),typeof window<"u"&&(window.VaniraConvAI=X,window.VaniraAI=G);const m=document.currentScript;if(m){const h=m.getAttribute("data-widget-id")||m.getAttribute("widget-id"),t=m.getAttribute("data-agent-id")||m.getAttribute("agent-id");if(h||t){const e=m.getAttribute("data-position")||"bottom-right",i=m.getAttribute("data-primary-color")||m.getAttribute("primary-color")||"#6366f1",s=m.getAttribute("data-secondary-color")||m.getAttribute("secondary-color"),n=m.getAttribute("data-gradient")||m.getAttribute("gradient"),a=m.getAttribute("data-server-url")||m.getAttribute("server-url"),r=m.getAttribute("data-pk-key")||m.getAttribute("pk-key"),l=document.createElement("vanira-convai");h&&l.setAttribute("widget-id",h),t&&l.setAttribute("agent-id",t),r&&l.setAttribute("pk-key",r),l.setAttribute("position",e),l.setAttribute("primary-color",i),s&&l.setAttribute("secondary-color",s),n&&l.setAttribute("gradient",n),a&&l.setAttribute("server-url",a),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>document.body.appendChild(l)):document.body.appendChild(l),l.addEventListener("vaniraai:tool_call",c=>{const A=c.detail;console.log("[VaniraAI Widget] Tool call received by host page:",A.name,A.arguments),typeof window.__vaniraai_tool_handler=="function"&&window.__vaniraai_tool_handler(A,{sendResult:d=>{console.log("[VaniraAI] sendResult called:",d)}})})}}})();
|
|
1096
1096
|
//# sourceMappingURL=vanira-sdk.js.map
|