@vanira/sdk 0.0.22 → 0.0.23
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
CHANGED
|
@@ -1082,7 +1082,7 @@ overflow: hidden;
|
|
|
1082
1082
|
<div style="position: absolute; bottom: -2px; right: -2px; background: white; border-radius: 50%; padding: 2px; box-shadow: 0 1px 2px rgba(0,0,0,0.1);">
|
|
1083
1083
|
${m.audioLines.replace('width="24"','width="12"').replace('height="24"','height="12"')}
|
|
1084
1084
|
</div>
|
|
1085
|
-
`;const e=t.querySelector("div");if(e){const n=e.querySelector("svg");n&&(n.style.width="12px",n.style.height="12px")}t.onclick=()=>this.onStartCall();const i=this.chatWindow.getElement().querySelector(".chat-input-area"),s=i==null?void 0:i.querySelector(".chat-send-btn");i&&s?i.insertBefore(this.voiceTrigger,s):console.warn("VaniraSDK: Failed to inject voice trigger",{inputArea:i,sendBtn:s})}}class Ae{async sendMessage(t,e,i,s,n,a,r,A){return C.sendChatMessage(e,i,t,s,c=>{a&&a(c)},n,c=>{r&&c&&r(c)},A)}async sendFile(t){throw console.warn("sendFile not implemented for VaniraChatAdapter yet - Incompatible function adapted",t),new Error("Method not implemented.")}async likeDislike(t,e){console.warn("likeDislike not implemented for VaniraChatAdapter yet - Incompatible function adapted",t,e)}}const B=class B extends ${constructor(e){super(e);o(this,"vaniraClient",null);o(this,"currentView",null);o(this,"isPanelOpen",!1);o(this,"callActive",!1);o(this,"eventSource",null);o(this,"floatingButton",null);o(this,"floatingWelcomeChips",null);o(this,"panel",null);o(this,"welcomeChipsData",[]);o(this,"chatAdapter");o(this,"sessionManager",null);o(this,"sessionActive",!1);o(this,"widgetMode","voice_only");o(this,"agentId","");o(this,"prospectGroupId","");o(this,"chatServerUrl","");o(this,"prospectId","");o(this,"chatId",null);o(this,"widgetId","");o(this,"pkKey","");o(this,"primaryColor","#6366f1");o(this,"secondaryColor","#4f46e5");o(this,"gradient",null);o(this,"positionType","fixed");o(this,"position","bottom-right");o(this,"widgetIcon",null);o(this,"chatWelcomeMessage",null);this.chatAdapter=new Ae,this.processConfig(e)}initSessionManager(){const e=this.widgetId||this.agentId||"default";this.sessionManager=new k(e),this.sessionManager.on("tab_took_over",()=>{console.warn("[VaniraAI] Session taken over by another tab."),this.sessionActive=!1,this.showTabConflictBanner("taken_over")}),this.sessionManager.on("session_cleared",()=>{console.log("[VaniraAI] Session cleared externally.")});const i=this.sessionManager.claimSession();return this.sessionActive=i,i}restoreSessionMessages(){var A,c,l;const e=(A=this.sessionManager)==null?void 0:A.getSession();if(!e)return;const i=(l=(c=this.currentView)==null?void 0:c.getChatWindow)==null?void 0:l.call(c);if(!i)return;const s=e.messages.filter(d=>d.content.trim()!==""),n=`vanira_calls_${this.widgetId||this.agentId}`,a=JSON.parse(localStorage.getItem(n)||"[]");if(s.length===0&&a.length===0)return;i.clearMessages();const r=[...s.map((d,g)=>({type:"msg",role:d.role,content:d.content,ts:d.timestamp??g})),...a.map(d=>({type:"call",durationMs:d.durationMs,startedAt:d.startedAt,ts:d.startedAt}))];r.sort((d,g)=>d.ts-g.ts),r.forEach(d=>{d.type==="msg"?i.addMessage(d.role,d.content,d.ts):i.addCallRecord(d.durationMs,d.startedAt)}),console.log(`[VaniraAI] Restored ${s.length} messages + ${a.length} call records from session.`)}showTabConflictBanner(e){var i,s;this.root&&((i=this.root.querySelector(".vanira-tab-conflict-banner"))==null||i.remove(),e==="conflict"&&((s=this.sessionManager)==null||s.forceClaimSession(),this.sessionActive=!0,this.widgetMode.includes("chat")&&this.initializeChatSession(!1)))}playMessageSound(e){try{if(!B.audioContext){const r=window.AudioContext||window.webkitAudioContext;if(!r)return;B.audioContext=new r}const i=B.audioContext;i.state==="suspended"&&i.resume().catch(()=>{});const s=i.createOscillator(),n=i.createGain();s.connect(n),n.connect(i.destination);const a=i.currentTime;e==="send"?(s.type="sine",s.frequency.setValueAtTime(300,a),s.frequency.exponentialRampToValueAtTime(500,a+.05),n.gain.setValueAtTime(0,a),n.gain.linearRampToValueAtTime(.1,a+.01),n.gain.exponentialRampToValueAtTime(.001,a+.1),s.start(a),s.stop(a+.1)):(s.type="sine",s.frequency.setValueAtTime(500,a),s.frequency.exponentialRampToValueAtTime(800,a+.1),n.gain.setValueAtTime(0,a),n.gain.linearRampToValueAtTime(.15,a+.02),n.gain.exponentialRampToValueAtTime(.001,a+.2),s.start(a),s.stop(a+.2))}catch(i){console.warn("[VaniraAI] Audio feedback failed",i)}}handleWelcomePayload(e,i="assistant"){var a,r,A,c,l,d,g,w;if(!e||this.widgetMode==="voice_only")return;e.buttons&&Array.isArray(e.buttons)?this.welcomeChipsData=e.buttons:((a=e.widget)==null?void 0:a.type)==="button_list"&&((r=e.widget.data)!=null&&r.buttons)&&(this.welcomeChipsData=e.widget.data.buttons),this.updateWelcomeChipsVisibility();const s=(c=(A=this.currentView)==null?void 0:A.getChatWindow)==null?void 0:c.call(A);let n=e.text||e.response||e.content||e.message||"";if(!n&&!this.welcomeChipsData.length&&(n="Hey! how can I help you ?"),!n&&typeof e=="string"&&e.trim().startsWith("{"))try{const p=JSON.parse(e);n=p.text||p.response||p.content||p.message||"",((l=p.widget)==null?void 0:l.type)==="button_list"&&((d=p.widget.data)!=null&&d.buttons)&&(this.welcomeChipsData=p.widget.data.buttons)}catch{}if(console.log("[VaniraAI] Processing Welcome Payload:",{hasText:!!n,chipsCount:this.welcomeChipsData.length,hasChatWindow:!!s,mode:this.widgetMode}),s){if(!n&&this.welcomeChipsData.length===0)return;const p=(g=this.sessionManager)==null?void 0:g.getSession();(p==null?void 0:p.messages.some(x=>x.content===n&&x.role===i))||(n&&(s.addMessage(i,n),(w=this.sessionManager)==null||w.pushMessage(i,n)),this.welcomeChipsData.length>0&&s.addButtons(this.welcomeChipsData))}}async initializeChatSession(e=!1){var i,s,n,a,r,A;if(this.sessionActive)try{C.setChatUrl(this.chatServerUrl);const c=(i=this.sessionManager)==null?void 0:i.getSession();if(!e&&(c!=null&&c.prospectId)){this.prospectId=c.prospectId,this.chatId=c.chatId,console.log(`[VaniraAI] Session restored — tab: ${(s=this.sessionManager)==null?void 0:s.getTabId()}, prospect: ${this.prospectId}`),this.restoreSessionMessages(),this.chatId&&!this.eventSource&&(this.eventSource=C.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,p;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(p=this.sessionManager)==null||p.pushMessage("assistant",d),this.playMessageSound("receive")}));return}this.prospectGroupId?this.prospectId=await C.createChatProspect(this.prospectGroupId):this.prospectId=`anon_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;const l=await C.fetchWelcomeMessage(this.agentId,this.prospectId,this.widgetId||void 0);l&&(this.handleWelcomePayload(l),l.chatId&&!this.chatId&&(this.chatId=l.chatId,this.eventSource||(this.eventSource=C.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,p;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(p=this.sessionManager)==null||p.pushMessage("assistant",d),this.playMessageSound("receive")})))),(n=this.sessionManager)==null||n.saveIds(this.prospectId,this.chatId)}catch(c){console.error("[VaniraAI] Chat init failed",c);const l="Hey! how can I help you ?";(r=(a=this.currentView)==null?void 0:a.getChatWindow)==null||r.call(a).addMessage("assistant",l),(A=this.sessionManager)==null||A.pushMessage("assistant",l)}}async initialize(e){await super.initialize(e),this.processConfig(e),this.root&&this.ui_renderer(this.root)}processConfig(e){var i,s;if(this.widgetId=e.widgetId||e.widget_id||"",this.agentId=e.agentId||e.agent_id||"",this.prospectGroupId=e.prospectGroupId||((i=e.client)==null?void 0:i.base_prospect_group_id)||"",this.widgetMode=e.widgetMode||e.mode||"voice_only",this.pkKey=e.pkKey||e.pk_key||"",this.primaryColor=e.primaryColor||e.primary_color||"#6366f1",this.secondaryColor=e.secondaryColor||e.secondary_color||"#a855f7",this.gradient=e.gradient||null,this.position=e.position||"bottom-right",this.positionType=e.positionType||"fixed",this.widgetIcon=e.widgetIcon||e.icon||null,this.chatWelcomeMessage=e.chatWelcomeMessage||e.chat_welcome_message||((s=e.agent)==null?void 0:s.chat_welcome_message)||null,console.log("[VaniraAI] processConfig:",{hasPrimary:!!this.primaryColor,hasSecondary:!!this.secondaryColor,hasWelcome:!!this.chatWelcomeMessage}),typeof this.chatWelcomeMessage=="string")try{this.chatWelcomeMessage=JSON.parse(this.chatWelcomeMessage)}catch(n){console.warn("[VaniraAI] Failed to parse chatWelcomeMessage string",n)}this.chatServerUrl=e.serverUrl||e.chatServerUrl||"https://inboxapi.travelr.club",this.updateWelcomeChipsVisibility()}async create_call(){var e;if(!(this.callActive||!this.agentId)){this.sessionActive||((e=this.sessionManager)==null||e.forceClaimSession(),this.sessionActive=!0);try{this.callActive=!0,this.updateViewCallState(!0),this.updateViewStatus("connecting");const i=await C.createCall(this.agentId,null,this.prospectId||null,this.widgetMode,this.pkKey||void 0),s=new Y({agentId:this.agentId,callId:i.callId,serverUrl:i.workerUrl});s.on("connected",()=>this.updateViewStatus("connected")).on("disconnected",()=>this.end_call()).on("error",n=>{console.error("[VaniraAI Widget] Call error:",n),this.updateViewStatus("error")}).on("transcription",({text:n,isFinal:a})=>{var r,A;(A=(r=this.currentView)==null?void 0:r.setTranscription)==null||A.call(r,n,a)}).on("track",({track:n})=>{var a;this.widgetMode.includes("avatar")&&n.kind==="video"&&((a=this.currentView)!=null&&a.setVideoTrack)&&this.currentView.setVideoTrack(n)}).on("tool_call",n=>{var r,A;const a=new CustomEvent("vaniraai:tool_call",{detail:n,bubbles:!0,composed:!0});(A=(r=this.root)==null?void 0:r.host)==null||A.dispatchEvent(a),console.log("[VaniraAI Widget] Tool call dispatched:",n.name,n.arguments),n.execution_mode}),this.vaniraClient=s,await s.start()}catch(i){console.error("[VaniraAI Widget] Call failed",i),this.updateViewStatus("error")}}}end_call(){this.callActive=!1;const e=this.vaniraClient;this.vaniraClient=null,e&&e.stop(),this.updateViewCallState(!1)}updateViewCallState(e){var i;(i=this.currentView)!=null&&i.setCallActive&&this.currentView.setCallActive(e)}updateViewStatus(e){var i;(i=this.currentView)!=null&&i.setStatus&&this.currentView.setStatus(e)}ui_renderer(e){this.root=e,this.root.innerHTML="",this.root.host&&(this.positionType==="fixed"?this.root.host.classList.add("vanira-portal"):this.root.host.classList.remove("vanira-portal"));const i=document.createElement("style");i.textContent=`@keyframes vanira-slide-up {
|
|
1085
|
+
`;const e=t.querySelector("div");if(e){const n=e.querySelector("svg");n&&(n.style.width="12px",n.style.height="12px")}t.onclick=()=>this.onStartCall();const i=this.chatWindow.getElement().querySelector(".chat-input-area"),s=i==null?void 0:i.querySelector(".chat-send-btn");i&&s?i.insertBefore(this.voiceTrigger,s):console.warn("VaniraSDK: Failed to inject voice trigger",{inputArea:i,sendBtn:s})}}class Ae{async sendMessage(t,e,i,s,n,a,r,A){return C.sendChatMessage(e,i,t,s,c=>{a&&a(c)},n,c=>{r&&c&&r(c)},A)}async sendFile(t){throw console.warn("sendFile not implemented for VaniraChatAdapter yet - Incompatible function adapted",t),new Error("Method not implemented.")}async likeDislike(t,e){console.warn("likeDislike not implemented for VaniraChatAdapter yet - Incompatible function adapted",t,e)}}const B=class B extends ${constructor(e){super(e);o(this,"vaniraClient",null);o(this,"currentView",null);o(this,"isPanelOpen",!1);o(this,"callActive",!1);o(this,"eventSource",null);o(this,"floatingButton",null);o(this,"floatingWelcomeChips",null);o(this,"panel",null);o(this,"welcomeChipsData",[]);o(this,"chatAdapter");o(this,"sessionManager",null);o(this,"sessionActive",!1);o(this,"widgetMode","voice_only");o(this,"agentId","");o(this,"prospectGroupId","");o(this,"chatServerUrl","");o(this,"prospectId","");o(this,"chatId",null);o(this,"widgetId","");o(this,"pkKey","");o(this,"chatInitialized",!1);o(this,"primaryColor","#6366f1");o(this,"secondaryColor","#4f46e5");o(this,"gradient",null);o(this,"positionType","fixed");o(this,"position","bottom-right");o(this,"widgetIcon",null);o(this,"chatWelcomeMessage",null);this.chatAdapter=new Ae,this.processConfig(e)}initSessionManager(){const e=this.widgetId||this.agentId||"default";this.sessionManager=new k(e),this.sessionManager.on("tab_took_over",()=>{console.warn("[VaniraAI] Session taken over by another tab."),this.sessionActive=!1,this.showTabConflictBanner("taken_over")}),this.sessionManager.on("session_cleared",()=>{console.log("[VaniraAI] Session cleared externally.")});const i=this.sessionManager.claimSession();return this.sessionActive=i,i}restoreSessionMessages(){var A,c,l;const e=(A=this.sessionManager)==null?void 0:A.getSession();if(!e)return;const i=(l=(c=this.currentView)==null?void 0:c.getChatWindow)==null?void 0:l.call(c);if(!i)return;const s=e.messages.filter(d=>d.content.trim()!==""),n=`vanira_calls_${this.widgetId||this.agentId}`,a=JSON.parse(localStorage.getItem(n)||"[]");if(s.length===0&&a.length===0)return;i.clearMessages();const r=[...s.map((d,g)=>({type:"msg",role:d.role,content:d.content,ts:d.timestamp??g})),...a.map(d=>({type:"call",durationMs:d.durationMs,startedAt:d.startedAt,ts:d.startedAt}))];r.sort((d,g)=>d.ts-g.ts),r.forEach(d=>{d.type==="msg"?i.addMessage(d.role,d.content,d.ts):i.addCallRecord(d.durationMs,d.startedAt)}),console.log(`[VaniraAI] Restored ${s.length} messages + ${a.length} call records from session.`)}showTabConflictBanner(e){var i,s;this.root&&((i=this.root.querySelector(".vanira-tab-conflict-banner"))==null||i.remove(),e==="conflict"&&((s=this.sessionManager)==null||s.forceClaimSession(),this.sessionActive=!0,this.widgetMode.includes("chat")&&this.initializeChatSession(!1)))}playMessageSound(e){try{if(!B.audioContext){const r=window.AudioContext||window.webkitAudioContext;if(!r)return;B.audioContext=new r}const i=B.audioContext;i.state==="suspended"&&i.resume().catch(()=>{});const s=i.createOscillator(),n=i.createGain();s.connect(n),n.connect(i.destination);const a=i.currentTime;e==="send"?(s.type="sine",s.frequency.setValueAtTime(300,a),s.frequency.exponentialRampToValueAtTime(500,a+.05),n.gain.setValueAtTime(0,a),n.gain.linearRampToValueAtTime(.1,a+.01),n.gain.exponentialRampToValueAtTime(.001,a+.1),s.start(a),s.stop(a+.1)):(s.type="sine",s.frequency.setValueAtTime(500,a),s.frequency.exponentialRampToValueAtTime(800,a+.1),n.gain.setValueAtTime(0,a),n.gain.linearRampToValueAtTime(.15,a+.02),n.gain.exponentialRampToValueAtTime(.001,a+.2),s.start(a),s.stop(a+.2))}catch(i){console.warn("[VaniraAI] Audio feedback failed",i)}}handleWelcomePayload(e,i="assistant"){var a,r,A,c,l,d,g,w;if(!e||this.widgetMode==="voice_only")return;e.buttons&&Array.isArray(e.buttons)?this.welcomeChipsData=e.buttons:((a=e.widget)==null?void 0:a.type)==="button_list"&&((r=e.widget.data)!=null&&r.buttons)&&(this.welcomeChipsData=e.widget.data.buttons),this.updateWelcomeChipsVisibility();const s=(c=(A=this.currentView)==null?void 0:A.getChatWindow)==null?void 0:c.call(A);let n=e.text||e.response||e.content||e.message||"";if(!n&&!this.welcomeChipsData.length&&(n="Hey! how can I help you ?"),!n&&typeof e=="string"&&e.trim().startsWith("{"))try{const p=JSON.parse(e);n=p.text||p.response||p.content||p.message||"",((l=p.widget)==null?void 0:l.type)==="button_list"&&((d=p.widget.data)!=null&&d.buttons)&&(this.welcomeChipsData=p.widget.data.buttons)}catch{}if(console.log("[VaniraAI] Processing Welcome Payload:",{hasText:!!n,chipsCount:this.welcomeChipsData.length,hasChatWindow:!!s,mode:this.widgetMode}),s){if(!n&&this.welcomeChipsData.length===0)return;const p=(g=this.sessionManager)==null?void 0:g.getSession();(p==null?void 0:p.messages.some(x=>x.content===n&&x.role===i))||(n&&(s.addMessage(i,n),(w=this.sessionManager)==null||w.pushMessage(i,n)),this.welcomeChipsData.length>0&&s.addButtons(this.welcomeChipsData))}}async initializeChatSession(e=!1){var i,s,n,a,r,A;if(this.sessionActive&&!this.chatInitialized){this.chatInitialized=!0;try{C.setChatUrl(this.chatServerUrl);const c=(i=this.sessionManager)==null?void 0:i.getSession();if(!e&&(c!=null&&c.prospectId)){this.prospectId=c.prospectId,this.chatId=c.chatId,console.log(`[VaniraAI] Session restored — tab: ${(s=this.sessionManager)==null?void 0:s.getTabId()}, prospect: ${this.prospectId}`),this.restoreSessionMessages(),this.chatId&&!this.eventSource&&(this.eventSource=C.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,p;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(p=this.sessionManager)==null||p.pushMessage("assistant",d),this.playMessageSound("receive")}));return}this.prospectGroupId?this.prospectId=await C.createChatProspect(this.prospectGroupId):this.prospectId=`anon_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;const l=await C.fetchWelcomeMessage(this.agentId,this.prospectId,this.widgetId||void 0);l&&(this.handleWelcomePayload(l),l.chatId&&!this.chatId&&(this.chatId=l.chatId,this.eventSource||(this.eventSource=C.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,p;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(p=this.sessionManager)==null||p.pushMessage("assistant",d),this.playMessageSound("receive")})))),(n=this.sessionManager)==null||n.saveIds(this.prospectId,this.chatId)}catch(c){console.error("[VaniraAI] Chat init failed",c);const l="Hey! how can I help you ?";(r=(a=this.currentView)==null?void 0:a.getChatWindow)==null||r.call(a).addMessage("assistant",l),(A=this.sessionManager)==null||A.pushMessage("assistant",l)}}}async initialize(e){await super.initialize(e),this.processConfig(e),this.root&&this.ui_renderer(this.root)}processConfig(e){var i,s;if(this.widgetId=e.widgetId||e.widget_id||"",this.agentId=e.agentId||e.agent_id||"",this.prospectGroupId=e.prospectGroupId||((i=e.client)==null?void 0:i.base_prospect_group_id)||"",this.widgetMode=e.widgetMode||e.mode||"voice_only",this.pkKey=e.pkKey||e.pk_key||"",this.primaryColor=e.primaryColor||e.primary_color||"#6366f1",this.secondaryColor=e.secondaryColor||e.secondary_color||"#a855f7",this.gradient=e.gradient||null,this.position=e.position||"bottom-right",this.positionType=e.positionType||"fixed",this.widgetIcon=e.widgetIcon||e.icon||null,this.chatWelcomeMessage=e.chatWelcomeMessage||e.chat_welcome_message||((s=e.agent)==null?void 0:s.chat_welcome_message)||null,console.log("[VaniraAI] processConfig:",{hasPrimary:!!this.primaryColor,hasSecondary:!!this.secondaryColor,hasWelcome:!!this.chatWelcomeMessage}),typeof this.chatWelcomeMessage=="string")try{this.chatWelcomeMessage=JSON.parse(this.chatWelcomeMessage)}catch(n){console.warn("[VaniraAI] Failed to parse chatWelcomeMessage string",n)}this.chatServerUrl=e.serverUrl||e.chatServerUrl||"https://inboxapi.travelr.club",this.updateWelcomeChipsVisibility()}async create_call(){var e;if(!(this.callActive||!this.agentId)){this.sessionActive||((e=this.sessionManager)==null||e.forceClaimSession(),this.sessionActive=!0);try{this.callActive=!0,this.updateViewCallState(!0),this.updateViewStatus("connecting");const i=await C.createCall(this.agentId,null,this.prospectId||null,this.widgetMode,this.pkKey||void 0),s=new Y({agentId:this.agentId,callId:i.callId,serverUrl:i.workerUrl});s.on("connected",()=>this.updateViewStatus("connected")).on("disconnected",()=>this.end_call()).on("error",n=>{console.error("[VaniraAI Widget] Call error:",n),this.updateViewStatus("error")}).on("transcription",({text:n,isFinal:a})=>{var r,A;(A=(r=this.currentView)==null?void 0:r.setTranscription)==null||A.call(r,n,a)}).on("track",({track:n})=>{var a;this.widgetMode.includes("avatar")&&n.kind==="video"&&((a=this.currentView)!=null&&a.setVideoTrack)&&this.currentView.setVideoTrack(n)}).on("tool_call",n=>{var r,A;const a=new CustomEvent("vaniraai:tool_call",{detail:n,bubbles:!0,composed:!0});(A=(r=this.root)==null?void 0:r.host)==null||A.dispatchEvent(a),console.log("[VaniraAI Widget] Tool call dispatched:",n.name,n.arguments),n.execution_mode}),this.vaniraClient=s,await s.start()}catch(i){console.error("[VaniraAI Widget] Call failed",i),this.updateViewStatus("error")}}}end_call(){this.callActive=!1;const e=this.vaniraClient;this.vaniraClient=null,e&&e.stop(),this.updateViewCallState(!1)}updateViewCallState(e){var i;(i=this.currentView)!=null&&i.setCallActive&&this.currentView.setCallActive(e)}updateViewStatus(e){var i;(i=this.currentView)!=null&&i.setStatus&&this.currentView.setStatus(e)}ui_renderer(e){this.root=e,this.root.innerHTML="",this.root.host&&(this.positionType==="fixed"?this.root.host.classList.add("vanira-portal"):this.root.host.classList.remove("vanira-portal"));const i=document.createElement("style");i.textContent=`@keyframes vanira-slide-up {
|
|
1086
1086
|
from { opacity:0; transform:translateY(16px); }
|
|
1087
1087
|
to { opacity:1; transform:translateY(0); }
|
|
1088
1088
|
}`,this.root.appendChild(i);const s=document.createElement("style");s.textContent=`
|
package/dist/vanira-sdk.js
CHANGED
|
@@ -1082,7 +1082,7 @@ overflow: hidden;
|
|
|
1082
1082
|
<div style="position: absolute; bottom: -2px; right: -2px; background: white; border-radius: 50%; padding: 2px; box-shadow: 0 1px 2px rgba(0,0,0,0.1);">
|
|
1083
1083
|
${u.audioLines.replace('width="24"','width="12"').replace('height="24"','height="12"')}
|
|
1084
1084
|
</div>
|
|
1085
|
-
`;const e=t.querySelector("div");if(e){const n=e.querySelector("svg");n&&(n.style.width="12px",n.style.height="12px")}t.onclick=()=>this.onStartCall();const i=this.chatWindow.getElement().querySelector(".chat-input-area"),s=i==null?void 0:i.querySelector(".chat-send-btn");i&&s?i.insertBefore(this.voiceTrigger,s):console.warn("VaniraSDK: Failed to inject voice trigger",{inputArea:i,sendBtn:s})}}class ce{async sendMessage(t,e,i,s,n,a,r,l){return v.sendChatMessage(e,i,t,s,c=>{a&&a(c)},n,c=>{r&&c&&r(c)},l)}async sendFile(t){throw console.warn("sendFile not implemented for VaniraChatAdapter yet - Incompatible function adapted",t),new Error("Method not implemented.")}async likeDislike(t,e){console.warn("likeDislike not implemented for VaniraChatAdapter yet - Incompatible function adapted",t,e)}}const I=class I extends _{constructor(e){super(e);o(this,"vaniraClient",null);o(this,"currentView",null);o(this,"isPanelOpen",!1);o(this,"callActive",!1);o(this,"eventSource",null);o(this,"floatingButton",null);o(this,"floatingWelcomeChips",null);o(this,"panel",null);o(this,"welcomeChipsData",[]);o(this,"chatAdapter");o(this,"sessionManager",null);o(this,"sessionActive",!1);o(this,"widgetMode","voice_only");o(this,"agentId","");o(this,"prospectGroupId","");o(this,"chatServerUrl","");o(this,"prospectId","");o(this,"chatId",null);o(this,"widgetId","");o(this,"pkKey","");o(this,"primaryColor","#6366f1");o(this,"secondaryColor","#4f46e5");o(this,"gradient",null);o(this,"positionType","fixed");o(this,"position","bottom-right");o(this,"widgetIcon",null);o(this,"chatWelcomeMessage",null);this.chatAdapter=new ce,this.processConfig(e)}initSessionManager(){const e=this.widgetId||this.agentId||"default";this.sessionManager=new S(e),this.sessionManager.on("tab_took_over",()=>{console.warn("[VaniraAI] Session taken over by another tab."),this.sessionActive=!1,this.showTabConflictBanner("taken_over")}),this.sessionManager.on("session_cleared",()=>{console.log("[VaniraAI] Session cleared externally.")});const i=this.sessionManager.claimSession();return this.sessionActive=i,i}restoreSessionMessages(){var l,c,A;const e=(l=this.sessionManager)==null?void 0:l.getSession();if(!e)return;const i=(A=(c=this.currentView)==null?void 0:c.getChatWindow)==null?void 0:A.call(c);if(!i)return;const s=e.messages.filter(d=>d.content.trim()!==""),n=`vanira_calls_${this.widgetId||this.agentId}`,a=JSON.parse(localStorage.getItem(n)||"[]");if(s.length===0&&a.length===0)return;i.clearMessages();const r=[...s.map((d,g)=>({type:"msg",role:d.role,content:d.content,ts:d.timestamp??g})),...a.map(d=>({type:"call",durationMs:d.durationMs,startedAt:d.startedAt,ts:d.startedAt}))];r.sort((d,g)=>d.ts-g.ts),r.forEach(d=>{d.type==="msg"?i.addMessage(d.role,d.content,d.ts):i.addCallRecord(d.durationMs,d.startedAt)}),console.log(`[VaniraAI] Restored ${s.length} messages + ${a.length} call records from session.`)}showTabConflictBanner(e){var i,s;this.root&&((i=this.root.querySelector(".vanira-tab-conflict-banner"))==null||i.remove(),e==="conflict"&&((s=this.sessionManager)==null||s.forceClaimSession(),this.sessionActive=!0,this.widgetMode.includes("chat")&&this.initializeChatSession(!1)))}playMessageSound(e){try{if(!I.audioContext){const r=window.AudioContext||window.webkitAudioContext;if(!r)return;I.audioContext=new r}const i=I.audioContext;i.state==="suspended"&&i.resume().catch(()=>{});const s=i.createOscillator(),n=i.createGain();s.connect(n),n.connect(i.destination);const a=i.currentTime;e==="send"?(s.type="sine",s.frequency.setValueAtTime(300,a),s.frequency.exponentialRampToValueAtTime(500,a+.05),n.gain.setValueAtTime(0,a),n.gain.linearRampToValueAtTime(.1,a+.01),n.gain.exponentialRampToValueAtTime(.001,a+.1),s.start(a),s.stop(a+.1)):(s.type="sine",s.frequency.setValueAtTime(500,a),s.frequency.exponentialRampToValueAtTime(800,a+.1),n.gain.setValueAtTime(0,a),n.gain.linearRampToValueAtTime(.15,a+.02),n.gain.exponentialRampToValueAtTime(.001,a+.2),s.start(a),s.stop(a+.2))}catch(i){console.warn("[VaniraAI] Audio feedback failed",i)}}handleWelcomePayload(e,i="assistant"){var a,r,l,c,A,d,g,w;if(!e||this.widgetMode==="voice_only")return;e.buttons&&Array.isArray(e.buttons)?this.welcomeChipsData=e.buttons:((a=e.widget)==null?void 0:a.type)==="button_list"&&((r=e.widget.data)!=null&&r.buttons)&&(this.welcomeChipsData=e.widget.data.buttons),this.updateWelcomeChipsVisibility();const s=(c=(l=this.currentView)==null?void 0:l.getChatWindow)==null?void 0:c.call(l);let n=e.text||e.response||e.content||e.message||"";if(!n&&!this.welcomeChipsData.length&&(n="Hey! how can I help you ?"),!n&&typeof e=="string"&&e.trim().startsWith("{"))try{const p=JSON.parse(e);n=p.text||p.response||p.content||p.message||"",((A=p.widget)==null?void 0:A.type)==="button_list"&&((d=p.widget.data)!=null&&d.buttons)&&(this.welcomeChipsData=p.widget.data.buttons)}catch{}if(console.log("[VaniraAI] Processing Welcome Payload:",{hasText:!!n,chipsCount:this.welcomeChipsData.length,hasChatWindow:!!s,mode:this.widgetMode}),s){if(!n&&this.welcomeChipsData.length===0)return;const p=(g=this.sessionManager)==null?void 0:g.getSession();(p==null?void 0:p.messages.some(x=>x.content===n&&x.role===i))||(n&&(s.addMessage(i,n),(w=this.sessionManager)==null||w.pushMessage(i,n)),this.welcomeChipsData.length>0&&s.addButtons(this.welcomeChipsData))}}async initializeChatSession(e=!1){var i,s,n,a,r,l;if(this.sessionActive)try{v.setChatUrl(this.chatServerUrl);const c=(i=this.sessionManager)==null?void 0:i.getSession();if(!e&&(c!=null&&c.prospectId)){this.prospectId=c.prospectId,this.chatId=c.chatId,console.log(`[VaniraAI] Session restored — tab: ${(s=this.sessionManager)==null?void 0:s.getTabId()}, prospect: ${this.prospectId}`),this.restoreSessionMessages(),this.chatId&&!this.eventSource&&(this.eventSource=v.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,p;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(p=this.sessionManager)==null||p.pushMessage("assistant",d),this.playMessageSound("receive")}));return}this.prospectGroupId?this.prospectId=await v.createChatProspect(this.prospectGroupId):this.prospectId=`anon_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;const A=await v.fetchWelcomeMessage(this.agentId,this.prospectId,this.widgetId||void 0);A&&(this.handleWelcomePayload(A),A.chatId&&!this.chatId&&(this.chatId=A.chatId,this.eventSource||(this.eventSource=v.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,p;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(p=this.sessionManager)==null||p.pushMessage("assistant",d),this.playMessageSound("receive")})))),(n=this.sessionManager)==null||n.saveIds(this.prospectId,this.chatId)}catch(c){console.error("[VaniraAI] Chat init failed",c);const A="Hey! how can I help you ?";(r=(a=this.currentView)==null?void 0:a.getChatWindow)==null||r.call(a).addMessage("assistant",A),(l=this.sessionManager)==null||l.pushMessage("assistant",A)}}async initialize(e){await super.initialize(e),this.processConfig(e),this.root&&this.ui_renderer(this.root)}processConfig(e){var i,s;if(this.widgetId=e.widgetId||e.widget_id||"",this.agentId=e.agentId||e.agent_id||"",this.prospectGroupId=e.prospectGroupId||((i=e.client)==null?void 0:i.base_prospect_group_id)||"",this.widgetMode=e.widgetMode||e.mode||"voice_only",this.pkKey=e.pkKey||e.pk_key||"",this.primaryColor=e.primaryColor||e.primary_color||"#6366f1",this.secondaryColor=e.secondaryColor||e.secondary_color||"#a855f7",this.gradient=e.gradient||null,this.position=e.position||"bottom-right",this.positionType=e.positionType||"fixed",this.widgetIcon=e.widgetIcon||e.icon||null,this.chatWelcomeMessage=e.chatWelcomeMessage||e.chat_welcome_message||((s=e.agent)==null?void 0:s.chat_welcome_message)||null,console.log("[VaniraAI] processConfig:",{hasPrimary:!!this.primaryColor,hasSecondary:!!this.secondaryColor,hasWelcome:!!this.chatWelcomeMessage}),typeof this.chatWelcomeMessage=="string")try{this.chatWelcomeMessage=JSON.parse(this.chatWelcomeMessage)}catch(n){console.warn("[VaniraAI] Failed to parse chatWelcomeMessage string",n)}this.chatServerUrl=e.serverUrl||e.chatServerUrl||"https://inboxapi.travelr.club",this.updateWelcomeChipsVisibility()}async create_call(){var e;if(!(this.callActive||!this.agentId)){this.sessionActive||((e=this.sessionManager)==null||e.forceClaimSession(),this.sessionActive=!0);try{this.callActive=!0,this.updateViewCallState(!0),this.updateViewStatus("connecting");const i=await v.createCall(this.agentId,null,this.prospectId||null,this.widgetMode,this.pkKey||void 0),s=new G({agentId:this.agentId,callId:i.callId,serverUrl:i.workerUrl});s.on("connected",()=>this.updateViewStatus("connected")).on("disconnected",()=>this.end_call()).on("error",n=>{console.error("[VaniraAI Widget] Call error:",n),this.updateViewStatus("error")}).on("transcription",({text:n,isFinal:a})=>{var r,l;(l=(r=this.currentView)==null?void 0:r.setTranscription)==null||l.call(r,n,a)}).on("track",({track:n})=>{var a;this.widgetMode.includes("avatar")&&n.kind==="video"&&((a=this.currentView)!=null&&a.setVideoTrack)&&this.currentView.setVideoTrack(n)}).on("tool_call",n=>{var r,l;const a=new CustomEvent("vaniraai:tool_call",{detail:n,bubbles:!0,composed:!0});(l=(r=this.root)==null?void 0:r.host)==null||l.dispatchEvent(a),console.log("[VaniraAI Widget] Tool call dispatched:",n.name,n.arguments),n.execution_mode}),this.vaniraClient=s,await s.start()}catch(i){console.error("[VaniraAI Widget] Call failed",i),this.updateViewStatus("error")}}}end_call(){this.callActive=!1;const e=this.vaniraClient;this.vaniraClient=null,e&&e.stop(),this.updateViewCallState(!1)}updateViewCallState(e){var i;(i=this.currentView)!=null&&i.setCallActive&&this.currentView.setCallActive(e)}updateViewStatus(e){var i;(i=this.currentView)!=null&&i.setStatus&&this.currentView.setStatus(e)}ui_renderer(e){this.root=e,this.root.innerHTML="",this.root.host&&(this.positionType==="fixed"?this.root.host.classList.add("vanira-portal"):this.root.host.classList.remove("vanira-portal"));const i=document.createElement("style");i.textContent=`@keyframes vanira-slide-up {
|
|
1085
|
+
`;const e=t.querySelector("div");if(e){const n=e.querySelector("svg");n&&(n.style.width="12px",n.style.height="12px")}t.onclick=()=>this.onStartCall();const i=this.chatWindow.getElement().querySelector(".chat-input-area"),s=i==null?void 0:i.querySelector(".chat-send-btn");i&&s?i.insertBefore(this.voiceTrigger,s):console.warn("VaniraSDK: Failed to inject voice trigger",{inputArea:i,sendBtn:s})}}class ce{async sendMessage(t,e,i,s,n,a,r,l){return v.sendChatMessage(e,i,t,s,c=>{a&&a(c)},n,c=>{r&&c&&r(c)},l)}async sendFile(t){throw console.warn("sendFile not implemented for VaniraChatAdapter yet - Incompatible function adapted",t),new Error("Method not implemented.")}async likeDislike(t,e){console.warn("likeDislike not implemented for VaniraChatAdapter yet - Incompatible function adapted",t,e)}}const I=class I extends _{constructor(e){super(e);o(this,"vaniraClient",null);o(this,"currentView",null);o(this,"isPanelOpen",!1);o(this,"callActive",!1);o(this,"eventSource",null);o(this,"floatingButton",null);o(this,"floatingWelcomeChips",null);o(this,"panel",null);o(this,"welcomeChipsData",[]);o(this,"chatAdapter");o(this,"sessionManager",null);o(this,"sessionActive",!1);o(this,"widgetMode","voice_only");o(this,"agentId","");o(this,"prospectGroupId","");o(this,"chatServerUrl","");o(this,"prospectId","");o(this,"chatId",null);o(this,"widgetId","");o(this,"pkKey","");o(this,"chatInitialized",!1);o(this,"primaryColor","#6366f1");o(this,"secondaryColor","#4f46e5");o(this,"gradient",null);o(this,"positionType","fixed");o(this,"position","bottom-right");o(this,"widgetIcon",null);o(this,"chatWelcomeMessage",null);this.chatAdapter=new ce,this.processConfig(e)}initSessionManager(){const e=this.widgetId||this.agentId||"default";this.sessionManager=new S(e),this.sessionManager.on("tab_took_over",()=>{console.warn("[VaniraAI] Session taken over by another tab."),this.sessionActive=!1,this.showTabConflictBanner("taken_over")}),this.sessionManager.on("session_cleared",()=>{console.log("[VaniraAI] Session cleared externally.")});const i=this.sessionManager.claimSession();return this.sessionActive=i,i}restoreSessionMessages(){var l,c,A;const e=(l=this.sessionManager)==null?void 0:l.getSession();if(!e)return;const i=(A=(c=this.currentView)==null?void 0:c.getChatWindow)==null?void 0:A.call(c);if(!i)return;const s=e.messages.filter(d=>d.content.trim()!==""),n=`vanira_calls_${this.widgetId||this.agentId}`,a=JSON.parse(localStorage.getItem(n)||"[]");if(s.length===0&&a.length===0)return;i.clearMessages();const r=[...s.map((d,g)=>({type:"msg",role:d.role,content:d.content,ts:d.timestamp??g})),...a.map(d=>({type:"call",durationMs:d.durationMs,startedAt:d.startedAt,ts:d.startedAt}))];r.sort((d,g)=>d.ts-g.ts),r.forEach(d=>{d.type==="msg"?i.addMessage(d.role,d.content,d.ts):i.addCallRecord(d.durationMs,d.startedAt)}),console.log(`[VaniraAI] Restored ${s.length} messages + ${a.length} call records from session.`)}showTabConflictBanner(e){var i,s;this.root&&((i=this.root.querySelector(".vanira-tab-conflict-banner"))==null||i.remove(),e==="conflict"&&((s=this.sessionManager)==null||s.forceClaimSession(),this.sessionActive=!0,this.widgetMode.includes("chat")&&this.initializeChatSession(!1)))}playMessageSound(e){try{if(!I.audioContext){const r=window.AudioContext||window.webkitAudioContext;if(!r)return;I.audioContext=new r}const i=I.audioContext;i.state==="suspended"&&i.resume().catch(()=>{});const s=i.createOscillator(),n=i.createGain();s.connect(n),n.connect(i.destination);const a=i.currentTime;e==="send"?(s.type="sine",s.frequency.setValueAtTime(300,a),s.frequency.exponentialRampToValueAtTime(500,a+.05),n.gain.setValueAtTime(0,a),n.gain.linearRampToValueAtTime(.1,a+.01),n.gain.exponentialRampToValueAtTime(.001,a+.1),s.start(a),s.stop(a+.1)):(s.type="sine",s.frequency.setValueAtTime(500,a),s.frequency.exponentialRampToValueAtTime(800,a+.1),n.gain.setValueAtTime(0,a),n.gain.linearRampToValueAtTime(.15,a+.02),n.gain.exponentialRampToValueAtTime(.001,a+.2),s.start(a),s.stop(a+.2))}catch(i){console.warn("[VaniraAI] Audio feedback failed",i)}}handleWelcomePayload(e,i="assistant"){var a,r,l,c,A,d,g,w;if(!e||this.widgetMode==="voice_only")return;e.buttons&&Array.isArray(e.buttons)?this.welcomeChipsData=e.buttons:((a=e.widget)==null?void 0:a.type)==="button_list"&&((r=e.widget.data)!=null&&r.buttons)&&(this.welcomeChipsData=e.widget.data.buttons),this.updateWelcomeChipsVisibility();const s=(c=(l=this.currentView)==null?void 0:l.getChatWindow)==null?void 0:c.call(l);let n=e.text||e.response||e.content||e.message||"";if(!n&&!this.welcomeChipsData.length&&(n="Hey! how can I help you ?"),!n&&typeof e=="string"&&e.trim().startsWith("{"))try{const p=JSON.parse(e);n=p.text||p.response||p.content||p.message||"",((A=p.widget)==null?void 0:A.type)==="button_list"&&((d=p.widget.data)!=null&&d.buttons)&&(this.welcomeChipsData=p.widget.data.buttons)}catch{}if(console.log("[VaniraAI] Processing Welcome Payload:",{hasText:!!n,chipsCount:this.welcomeChipsData.length,hasChatWindow:!!s,mode:this.widgetMode}),s){if(!n&&this.welcomeChipsData.length===0)return;const p=(g=this.sessionManager)==null?void 0:g.getSession();(p==null?void 0:p.messages.some(x=>x.content===n&&x.role===i))||(n&&(s.addMessage(i,n),(w=this.sessionManager)==null||w.pushMessage(i,n)),this.welcomeChipsData.length>0&&s.addButtons(this.welcomeChipsData))}}async initializeChatSession(e=!1){var i,s,n,a,r,l;if(this.sessionActive&&!this.chatInitialized){this.chatInitialized=!0;try{v.setChatUrl(this.chatServerUrl);const c=(i=this.sessionManager)==null?void 0:i.getSession();if(!e&&(c!=null&&c.prospectId)){this.prospectId=c.prospectId,this.chatId=c.chatId,console.log(`[VaniraAI] Session restored — tab: ${(s=this.sessionManager)==null?void 0:s.getTabId()}, prospect: ${this.prospectId}`),this.restoreSessionMessages(),this.chatId&&!this.eventSource&&(this.eventSource=v.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,p;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(p=this.sessionManager)==null||p.pushMessage("assistant",d),this.playMessageSound("receive")}));return}this.prospectGroupId?this.prospectId=await v.createChatProspect(this.prospectGroupId):this.prospectId=`anon_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;const A=await v.fetchWelcomeMessage(this.agentId,this.prospectId,this.widgetId||void 0);A&&(this.handleWelcomePayload(A),A.chatId&&!this.chatId&&(this.chatId=A.chatId,this.eventSource||(this.eventSource=v.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,p;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(p=this.sessionManager)==null||p.pushMessage("assistant",d),this.playMessageSound("receive")})))),(n=this.sessionManager)==null||n.saveIds(this.prospectId,this.chatId)}catch(c){console.error("[VaniraAI] Chat init failed",c);const A="Hey! how can I help you ?";(r=(a=this.currentView)==null?void 0:a.getChatWindow)==null||r.call(a).addMessage("assistant",A),(l=this.sessionManager)==null||l.pushMessage("assistant",A)}}}async initialize(e){await super.initialize(e),this.processConfig(e),this.root&&this.ui_renderer(this.root)}processConfig(e){var i,s;if(this.widgetId=e.widgetId||e.widget_id||"",this.agentId=e.agentId||e.agent_id||"",this.prospectGroupId=e.prospectGroupId||((i=e.client)==null?void 0:i.base_prospect_group_id)||"",this.widgetMode=e.widgetMode||e.mode||"voice_only",this.pkKey=e.pkKey||e.pk_key||"",this.primaryColor=e.primaryColor||e.primary_color||"#6366f1",this.secondaryColor=e.secondaryColor||e.secondary_color||"#a855f7",this.gradient=e.gradient||null,this.position=e.position||"bottom-right",this.positionType=e.positionType||"fixed",this.widgetIcon=e.widgetIcon||e.icon||null,this.chatWelcomeMessage=e.chatWelcomeMessage||e.chat_welcome_message||((s=e.agent)==null?void 0:s.chat_welcome_message)||null,console.log("[VaniraAI] processConfig:",{hasPrimary:!!this.primaryColor,hasSecondary:!!this.secondaryColor,hasWelcome:!!this.chatWelcomeMessage}),typeof this.chatWelcomeMessage=="string")try{this.chatWelcomeMessage=JSON.parse(this.chatWelcomeMessage)}catch(n){console.warn("[VaniraAI] Failed to parse chatWelcomeMessage string",n)}this.chatServerUrl=e.serverUrl||e.chatServerUrl||"https://inboxapi.travelr.club",this.updateWelcomeChipsVisibility()}async create_call(){var e;if(!(this.callActive||!this.agentId)){this.sessionActive||((e=this.sessionManager)==null||e.forceClaimSession(),this.sessionActive=!0);try{this.callActive=!0,this.updateViewCallState(!0),this.updateViewStatus("connecting");const i=await v.createCall(this.agentId,null,this.prospectId||null,this.widgetMode,this.pkKey||void 0),s=new G({agentId:this.agentId,callId:i.callId,serverUrl:i.workerUrl});s.on("connected",()=>this.updateViewStatus("connected")).on("disconnected",()=>this.end_call()).on("error",n=>{console.error("[VaniraAI Widget] Call error:",n),this.updateViewStatus("error")}).on("transcription",({text:n,isFinal:a})=>{var r,l;(l=(r=this.currentView)==null?void 0:r.setTranscription)==null||l.call(r,n,a)}).on("track",({track:n})=>{var a;this.widgetMode.includes("avatar")&&n.kind==="video"&&((a=this.currentView)!=null&&a.setVideoTrack)&&this.currentView.setVideoTrack(n)}).on("tool_call",n=>{var r,l;const a=new CustomEvent("vaniraai:tool_call",{detail:n,bubbles:!0,composed:!0});(l=(r=this.root)==null?void 0:r.host)==null||l.dispatchEvent(a),console.log("[VaniraAI Widget] Tool call dispatched:",n.name,n.arguments),n.execution_mode}),this.vaniraClient=s,await s.start()}catch(i){console.error("[VaniraAI Widget] Call failed",i),this.updateViewStatus("error")}}}end_call(){this.callActive=!1;const e=this.vaniraClient;this.vaniraClient=null,e&&e.stop(),this.updateViewCallState(!1)}updateViewCallState(e){var i;(i=this.currentView)!=null&&i.setCallActive&&this.currentView.setCallActive(e)}updateViewStatus(e){var i;(i=this.currentView)!=null&&i.setStatus&&this.currentView.setStatus(e)}ui_renderer(e){this.root=e,this.root.innerHTML="",this.root.host&&(this.positionType==="fixed"?this.root.host.classList.add("vanira-portal"):this.root.host.classList.remove("vanira-portal"));const i=document.createElement("style");i.textContent=`@keyframes vanira-slide-up {
|
|
1086
1086
|
from { opacity:0; transform:translateY(16px); }
|
|
1087
1087
|
to { opacity:1; transform:translateY(0); }
|
|
1088
1088
|
}`,this.root.appendChild(i);const s=document.createElement("style");s.textContent=`
|