@vanira/sdk 0.0.15 → 0.0.17

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.
@@ -8,6 +8,7 @@ export declare class VaniraWidget extends HTMLElement {
8
8
  private primaryColor;
9
9
  private secondaryColor;
10
10
  private gradient;
11
+ private positionType;
11
12
  static get observedAttributes(): string[];
12
13
  constructor();
13
14
  connectedCallback(): void;
@@ -24,6 +24,7 @@ export declare class VaniraInternalProvider extends AbstractWidgetProvider {
24
24
  private primaryColor;
25
25
  private secondaryColor;
26
26
  private gradient;
27
+ private positionType;
27
28
  private position;
28
29
  private widgetIcon;
29
30
  private chatWelcomeMessage;
@@ -1 +1 @@
1
- export declare const widgetStyles = "\n :host {\n display: block;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n box-sizing: border-box;\n overflow: visible !important;\n contain: none !important;\n \n /* Default Theme Variables */\n --primary: #6366f1;\n --primary-hover: #4f46e5;\n --primary-rgb: 99, 102, 241;\n --secondary: #4f46e5;\n --secondary-rgb: 79, 70, 229;\n --bg: #ffffff;\n --text: #1f2937;\n --text-muted: #6b7280;\n --border: #e5e7eb;\n --shadow: 0 10px 40px rgba(0, 0, 0, 0.1);\n --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.15);\n }\n\n :host * {\n box-sizing: border-box;\n }\n\n \n @keyframes fadeInScale {\n from { opacity: 0; transform: scale(0.8); }\n to { opacity: 1; transform: scale(1); }\n }\n\n @keyframes pulse {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.5; }\n }\n\n @keyframes wave {\n 0%, 100% { transform: translateY(0); }\n 50% { transform: translateY(-4px); }\n }\n\n @keyframes wave-rotate-1 {\n 0% { transform: rotate(0deg) scale(1); border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }\n 25% { transform: rotate(90deg) scale(1.02); border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%; }\n 50% { transform: rotate(180deg) scale(1); border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }\n 75% { transform: rotate(270deg) scale(0.98); border-radius: 40% 60% 70% 30% / 40% 40% 60% 50%; }\n 100% { transform: rotate(360deg) scale(1); border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }\n }\n\n @keyframes wave-rotate-2 {\n 0% { transform: rotate(60deg) scale(1.02); border-radius: 40% 60% 60% 40% / 60% 40% 60% 40%; }\n 33% { transform: rotate(180deg) scale(0.98); border-radius: 60% 40% 40% 60% / 40% 60% 40% 60%; }\n 66% { transform: rotate(300deg) scale(1.02); border-radius: 50% 50% 40% 60% / 60% 40% 50% 50%; }\n 100% { transform: rotate(420deg) scale(1.02); border-radius: 40% 60% 60% 40% / 60% 40% 60% 40%; }\n }\n\n @keyframes wave-rotate-3 {\n 0% { transform: rotate(120deg) scale(1); border-radius: 50% 50% 50% 50%; }\n 50% { transform: rotate(300deg) scale(1.05); border-radius: 40% 60% 50% 50% / 50% 50% 60% 40%; }\n 100% { transform: rotate(480deg) scale(1); border-radius: 50% 50% 50% 50%; }\n }\n\n @keyframes clickBounce {\n 0% { transform: scale(1); }\n 25% { transform: scale(0.9) rotate(-5deg); }\n 50% { transform: scale(1.15) rotate(5deg); }\n 75% { transform: scale(0.95) rotate(-2deg); }\n 100% { transform: scale(1) rotate(0deg); }\n }\n\n @keyframes pulseGlow {\n 0%, 100% { box-shadow: 0 4px 16px rgba(239, 68, 68, 0.4); }\n 50% { box-shadow: 0 4px 24px rgba(239, 68, 68, 0.6), 0 0 32px rgba(239, 68, 68, 0.3); }\n }\n\n @keyframes typingBounce {\n 0%, 80%, 100% { transform: translateY(0); }\n 40% { transform: translateY(-6px); }\n }\n\n @keyframes floatOrb {\n 0%, 100% { transform: translateY(0); }\n 50% { transform: translateY(-10px); }\n }\n\n @keyframes pulseGlowIdle {\n 0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.4; }\n 50% { transform: translate(-50%, -50%) scale(1.1); opacity: 0.2; }\n }\n\n @keyframes spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n }\n\n @keyframes voice-bars-orb {\n 0%, 100% { transform: scaleY(1); opacity: 0.7; }\n 50% { transform: scaleY(1.8); opacity: 1; }\n }\n\n\n .widget-fab {\n position: fixed;\n z-index: 9999;\n width: 64px;\n height: 64px;\n border-radius: 50%;\n background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n box-shadow: var(--shadow);\n transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);\n animation: fadeInScale 0.4s ease-out;\n }\n\n .widget-fab:hover {\n transform: scale(1.1);\n box-shadow: var(--shadow-lg);\n }\n\n .widget-fab:active {\n transform: scale(0.95);\n }\n\n .widget-fab svg {\n width: 28px;\n height: 28px;\n color: white;\n }\n\n .widget-panel {\n position: fixed;\n z-index: 10000; /* Higher than FAB */\n background: rgba(255, 255, 255, 0.98);\n backdrop-filter: blur(20px);\n -webkit-backdrop-filter: blur(20px);\n border: 1px solid #d1d5db; /* Solid light gray border for better differentiation */\n border-radius: 28px;\n box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.08);\n overflow: hidden;\n display: flex;\n flex-direction: column;\n transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n \n /* Default Dimensions */\n width: 400px;\n height: 600px;\n max-height: 90vh;\n max-width: 95vw;\n }\n\n .widget-panel.maximized {\n width: 90vw !important;\n height: 90vh !important;\n top: 5vh !important;\n left: 5vw !important;\n right: 5vw !important;\n bottom: 5vh !important;\n margin: auto;\n }\n\n .widget-panel.maximized {\n width: 800px;\n max-width: calc(100vw - 40px);\n height: 80vh;\n }\n\n .widget-body {\n padding: 0;\n flex: 1;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n min-height: 0;\n }\n\n .widget-panel.hidden {\n opacity: 0;\n pointer-events: none;\n transform: translateY(20px) scale(0.95);\n }\n/* ... rest of the content is redundant if I use replace or overwrite, but I will overwrite to include everything properly */\n .widget-header {\n background: #1f2937;\n color: white;\n padding: 14px 20px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n }\n\n .widget-title {\n font-size: 18px;\n font-weight: 600;\n margin: 0;\n letter-spacing: 0.3px;\n }\n\n .close-btn {\n background: rgba(255, 255, 255, 0.15);\n border: none;\n width: 36px;\n height: 36px;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n transition: all 0.2s;\n backdrop-filter: blur(10px);\n }\n\n .close-btn:hover {\n background: rgba(255, 255, 255, 0.25);\n transform: scale(1.1);\n }\n\n .close-btn.maximize-btn {\n display: flex;\n }\n\n .close-btn svg {\n width: 18px;\n height: 18px;\n color: white;\n flex-shrink: 0;\n }\n\n .widget-body {\n padding: 0;\n flex: 1;\n display: flex;\n flex-direction: column;\n }\n\n .status-indicator {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 16px;\n background: #f9fafb;\n border-radius: 12px;\n margin-bottom: 20px;\n }\n\n .status-dot {\n width: 10px;\n height: 10px;\n border-radius: 50%;\n background: #10b981;\n animation: pulse 2s infinite;\n }\n\n .status-text {\n font-size: 14px;\n color: var(--text-muted);\n margin: 0;\n }\n\n .controls {\n display: flex;\n gap: 12px;\n justify-content: center;\n }\n\n .control-btn {\n flex: 1;\n padding: 14px 20px;\n border: none;\n border-radius: 12px;\n font-size: 14px;\n font-weight: 600;\n cursor: pointer;\n transition: all 0.2s;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n }\n\n .control-btn svg {\n width: 18px;\n height: 18px;\n }\n\n .control-btn.primary {\n background: #1f2937;\n color: white;\n }\n\n .control-btn.primary:hover {\n background: #374151;\n }\n\n .control-btn.danger {\n background: #ef4444;\n color: white;\n }\n\n .control-btn.danger:hover {\n background: #dc2626;\n }\n\n .voice-mode-container {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n height: 100%;\n padding-bottom: 0;\n }\n\n .central-orb-container {\n position: relative;\n width: 120px;\n height: 120px;\n margin-bottom: 32px;\n cursor: pointer;\n }\n\n .central-orb {\n width: 100%;\n height: 100%;\n border-radius: 50%;\n background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);\n display: flex;\n align-items: center;\n justify-content: center;\n color: white;\n position: relative;\n z-index: 10;\n box-shadow: 0 10px 30px rgba(var(--primary-rgb), 0.3);\n transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);\n }\n\n .central-orb.active {\n animation: pulse 2s infinite;\n }\n \n .central-orb.idle {\n animation: floatOrb 4s ease-in-out infinite;\n cursor: pointer;\n }\n\n .central-orb.idle:hover {\n transform: scale(1.05);\n }\n\n .central-orb-glow {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 140%;\n height: 140%;\n background: radial-gradient(circle, rgba(var(--primary-rgb), 0.2) 0%, transparent 70%);\n animation: pulseGlowIdle 4s ease-in-out infinite;\n z-index: -1;\n pointer-events: none;\n }\n\n .central-orb svg {\n width: 24px;\n height: 24px;\n }\n\n .voice-status-text {\n font-size: 20px;\n font-weight: 600;\n color: var(--text);\n margin-bottom: 8px;\n text-align: center;\n }\n\n .voice-status-subtext {\n font-size: 14px;\n color: var(--text-muted);\n text-align: center;\n }\n\n /* Chat Mode Styles */\n .chat-messages {\n flex: 1;\n min-height: 0; /* Crucial for scrolling in flex column */\n overflow-y: auto;\n padding: 16px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n background: #f9fafb; \n \n /* Scrollbar Styling */\n scrollbar-width: thin;\n scrollbar-color: rgba(156, 163, 175, 0.5) transparent;\n }\n\n .chat-messages::-webkit-scrollbar {\n width: 6px;\n }\n\n .chat-messages::-webkit-scrollbar-track {\n background: transparent;\n }\n\n .chat-messages::-webkit-scrollbar-thumb {\n background-color: rgba(156, 163, 175, 0.5);\n border-radius: 3px;\n }\n\n .chat-messages::-webkit-scrollbar-thumb:hover {\n background-color: rgba(107, 114, 128, 0.8);\n }\n\n .chat-message {\n max-width: 85%;\n padding: 12px 16px;\n border-radius: 16px;\n font-size: 14px;\n line-height: 1.5;\n word-wrap: break-word;\n white-space: pre-wrap;\n }\n\n .chat-message.user {\n align-self: flex-end;\n background: #000000;\n color: white;\n border-bottom-right-radius: 4px;\n }\n\n .chat-message.assistant {\n align-self: flex-start;\n background: #ffffff;\n border: 1px solid #e5e7eb;\n color: var(--text);\n border-bottom-left-radius: 4px;\n box-shadow: 0 1px 2px rgba(0,0,0,0.05);\n }\n\n .chat-input-area {\n padding: 20px;\n border-top: 1px solid rgba(0, 0, 0, 0.05);\n display: flex;\n gap: 10px;\n align-items: center;\n background: white;\n z-index: 30;\n position: relative;\n border-bottom-left-radius: 28px;\n border-bottom-right-radius: 28px;\n }\n\n .chat-input {\n flex: 1;\n padding: 14px 20px;\n border: 1px solid #e5e7eb;\n border-radius: 28px;\n font-size: 15px;\n outline: none;\n transition: all 0.3s;\n background: #f3f4f6;\n color: #1f2937;\n }\n\n .chat-input:focus {\n border-color: var(--primary);\n background: white;\n box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);\n }\n\n .chat-send-btn {\n width: 48px;\n height: 48px;\n border-radius: 50%;\n background: var(--primary);\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);\n box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);\n flex-shrink: 0;\n }\n\n .chat-send-btn:hover {\n transform: scale(1.05) rotate(-10deg);\n background: var(--primary-hover);\n box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);\n }\n\n .chat-send-btn:active {\n transform: scale(0.95);\n }\n\n .chat-send-btn svg {\n width: 22px;\n height: 22px;\n color: white;\n margin-left: 2px;\n }\n\n /* Avatar Container */\n .avatar-container {\n background: transparent;\n flex: 1;\n display: flex;\n align-items: center;\n justify-content: center;\n position: relative;\n overflow: hidden;\n }\n \n /* Avatar Video */\n .avatar-video {\n width: 100%;\n height: 100%;\n object-fit: cover;\n }\n\n /* Voice Button (Simple) in Chat */\n .voice-btn-simple {\n position: relative;\n width: 44px; /* Matching send-btn size for symmetry */\n height: 44px;\n border-radius: 50%;\n border: 1.5px solid #e5e7eb;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.3s;\n overflow: visible;\n background: white;\n box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);\n }\n\n .voice-btn-simple:hover {\n transform: scale(1.05);\n background: #f9fafb;\n border-color: #9ca3af;\n box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);\n }\n\n .voice-btn-simple:active {\n animation: clickBounce 0.4s ease-out;\n }\n\n .voice-btn-icon {\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n color: #4b5563;\n }\n\n .voice-btn-icon svg {\n width: 20px;\n height: 20px;\n stroke-width: 2px;\n }\n\n /* Utility Classes */\n .absolute { position: absolute; }\n .relative { position: relative; }\n .rounded-full { border-radius: 9999px; }\n .flex { display: flex; }\n .items-center { align-items: center; }\n .justify-center { justify-content: center; }\n .w-full { width: 100%; }\n .h-full { height: 100%; }\n .z-50 { z-index: 50; }\n\n .branding-footer {\n display: flex;\n justify-content: center;\n padding: 4px 0 8px 0;\n background-color: #f9fafb;\n font-size: 10px;\n color: #9ca3af;\n font-weight: 500;\n letter-spacing: 0.025em;\n }\n\n .branding-footer b {\n color: #3b82f6;\n font-weight: 700;\n margin-left: 4px;\n }\n\n @media (max-width: 640px) {\n .widget-panel {\n width: 100vw !important;\n height: 100vh !important;\n max-width: 100vw !important;\n max-height: 100vh !important;\n top: 0 !important;\n left: 0 !important;\n right: 0 !important;\n bottom: 0 !important;\n border-radius: 0 !important;\n margin: 0 !important;\n }\n\n .widget-fab {\n width: 56px;\n height: 56px;\n bottom: 16px !important;\n right: 16px !important;\n }\n\n :host(.vanira-panel-open) .widget-fab {\n display: none !important;\n }\n\n .close-btn.maximize-btn {\n display: none !important;\n }\n\n .widget-header {\n padding: 12px 16px;\n }\n\n .widget-title {\n font-size: 16px;\n }\n\n .chat-input-area {\n padding: 12px;\n padding-bottom: env(safe-area-inset-bottom, 12px);\n }\n }\n";
1
+ export declare const widgetStyles = "\n :host(.vanira-portal) {\n position: fixed !important;\n bottom: 0 !important;\n right: 0 !important;\n top: auto !important;\n left: auto !important;\n width: 0 !important;\n height: 0 !important;\n pointer-events: none !important;\n z-index: 2147483647;\n overflow: visible !important;\n contain: none !important;\n }\n\n :host {\n display: block;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n box-sizing: border-box;\n\n /* Default Theme Variables */\n --primary: #6366f1;\n --primary-hover: #4f46e5;\n --primary-rgb: 99, 102, 241;\n --secondary: #4f46e5;\n --secondary-rgb: 79, 70, 229;\n --bg: #ffffff;\n --text: #1f2937;\n --text-muted: #6b7280;\n --border: #e5e7eb;\n --shadow: 0 10px 40px rgba(0, 0, 0, 0.1);\n --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.15);\n }\n\n :host * {\n box-sizing: border-box;\n }\n\n \n @keyframes fadeInScale {\n from { opacity: 0; transform: scale(0.8); }\n to { opacity: 1; transform: scale(1); }\n }\n\n @keyframes pulse {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.5; }\n }\n\n @keyframes wave {\n 0%, 100% { transform: translateY(0); }\n 50% { transform: translateY(-4px); }\n }\n\n @keyframes wave-rotate-1 {\n 0% { transform: rotate(0deg) scale(1); border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }\n 25% { transform: rotate(90deg) scale(1.02); border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%; }\n 50% { transform: rotate(180deg) scale(1); border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }\n 75% { transform: rotate(270deg) scale(0.98); border-radius: 40% 60% 70% 30% / 40% 40% 60% 50%; }\n 100% { transform: rotate(360deg) scale(1); border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }\n }\n\n @keyframes wave-rotate-2 {\n 0% { transform: rotate(60deg) scale(1.02); border-radius: 40% 60% 60% 40% / 60% 40% 60% 40%; }\n 33% { transform: rotate(180deg) scale(0.98); border-radius: 60% 40% 40% 60% / 40% 60% 40% 60%; }\n 66% { transform: rotate(300deg) scale(1.02); border-radius: 50% 50% 40% 60% / 60% 40% 50% 50%; }\n 100% { transform: rotate(420deg) scale(1.02); border-radius: 40% 60% 60% 40% / 60% 40% 60% 40%; }\n }\n\n @keyframes wave-rotate-3 {\n 0% { transform: rotate(120deg) scale(1); border-radius: 50% 50% 50% 50%; }\n 50% { transform: rotate(300deg) scale(1.05); border-radius: 40% 60% 50% 50% / 50% 50% 60% 40%; }\n 100% { transform: rotate(480deg) scale(1); border-radius: 50% 50% 50% 50%; }\n }\n\n @keyframes clickBounce {\n 0% { transform: scale(1); }\n 25% { transform: scale(0.9) rotate(-5deg); }\n 50% { transform: scale(1.15) rotate(5deg); }\n 75% { transform: scale(0.95) rotate(-2deg); }\n 100% { transform: scale(1) rotate(0deg); }\n }\n\n @keyframes pulseGlow {\n 0%, 100% { box-shadow: 0 4px 16px rgba(239, 68, 68, 0.4); }\n 50% { box-shadow: 0 4px 24px rgba(239, 68, 68, 0.6), 0 0 32px rgba(239, 68, 68, 0.3); }\n }\n\n @keyframes typingBounce {\n 0%, 80%, 100% { transform: translateY(0); }\n 40% { transform: translateY(-6px); }\n }\n\n @keyframes floatOrb {\n 0%, 100% { transform: translateY(0); }\n 50% { transform: translateY(-10px); }\n }\n\n @keyframes pulseGlowIdle {\n 0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.4; }\n 50% { transform: translate(-50%, -50%) scale(1.1); opacity: 0.2; }\n }\n\n @keyframes spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n }\n\n @keyframes voice-bars-orb {\n 0%, 100% { transform: scaleY(1); opacity: 0.7; }\n 50% { transform: scaleY(1.8); opacity: 1; }\n }\n\n\n .widget-fab {\n position: fixed;\n z-index: 2147483647;\n pointer-events: auto !important;\n width: 64px;\n height: 64px;\n border-radius: 50%;\n background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n box-shadow: var(--shadow);\n transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);\n animation: fadeInScale 0.4s ease-out;\n }\n\n .widget-fab:hover {\n transform: scale(1.1);\n box-shadow: var(--shadow-lg);\n }\n\n .widget-fab:active {\n transform: scale(0.95);\n }\n\n .widget-fab svg {\n width: 28px;\n height: 28px;\n color: white;\n }\n\n .widget-panel {\n position: fixed;\n z-index: 2147483647;\n pointer-events: auto;\n background: rgba(255, 255, 255, 0.98);\n backdrop-filter: blur(20px);\n -webkit-backdrop-filter: blur(20px);\n border: 1px solid #d1d5db;\n border-radius: 28px;\n box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.08);\n overflow: hidden;\n display: flex;\n flex-direction: column;\n transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n \n /* Default Dimensions */\n width: 400px;\n height: 600px;\n max-height: 90vh;\n max-width: 95vw;\n }\n\n .widget-panel.maximized {\n width: 90vw !important;\n height: 90vh !important;\n top: 5vh !important;\n left: 5vw !important;\n right: 5vw !important;\n bottom: 5vh !important;\n margin: auto;\n }\n\n .widget-body {\n padding: 0;\n flex: 1;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n min-height: 0;\n }\n\n .widget-panel.hidden {\n opacity: 0;\n pointer-events: none !important;\n transform: translateY(20px) scale(0.95);\n }\n\n .widget-header {\n background: #1f2937;\n color: white;\n padding: 14px 20px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n }\n\n .widget-title {\n font-size: 18px;\n font-weight: 600;\n margin: 0;\n letter-spacing: 0.3px;\n }\n\n .close-btn {\n background: rgba(255, 255, 255, 0.15);\n border: none;\n width: 36px;\n height: 36px;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n transition: all 0.2s;\n backdrop-filter: blur(10px);\n }\n\n .close-btn:hover {\n background: rgba(255, 255, 255, 0.25);\n transform: scale(1.1);\n }\n\n .close-btn.maximize-btn {\n display: flex;\n }\n\n .close-btn svg {\n width: 18px;\n height: 18px;\n color: white;\n flex-shrink: 0;\n }\n\n .status-indicator {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 16px;\n background: #f9fafb;\n border-radius: 12px;\n margin-bottom: 20px;\n }\n\n .status-dot {\n width: 10px;\n height: 10px;\n border-radius: 50%;\n background: #10b981;\n animation: pulse 2s infinite;\n }\n\n .status-text {\n font-size: 14px;\n color: var(--text-muted);\n margin: 0;\n }\n\n .controls {\n display: flex;\n gap: 12px;\n justify-content: center;\n }\n\n .control-btn {\n flex: 1;\n padding: 14px 20px;\n border: none;\n border-radius: 12px;\n font-size: 14px;\n font-weight: 600;\n cursor: pointer;\n transition: all 0.2s;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n }\n\n .control-btn svg {\n width: 18px;\n height: 18px;\n }\n\n .control-btn.primary {\n background: #1f2937;\n color: white;\n }\n\n .control-btn.primary:hover {\n background: #374151;\n }\n\n .control-btn.danger {\n background: #ef4444;\n color: white;\n }\n\n .control-btn.danger:hover {\n background: #dc2626;\n }\n\n .voice-mode-container {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n height: 100%;\n padding-bottom: 0;\n }\n\n .central-orb-container {\n position: relative;\n width: 120px;\n height: 120px;\n margin-bottom: 32px;\n cursor: pointer;\n }\n\n .central-orb {\n width: 100%;\n height: 100%;\n border-radius: 50%;\n background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);\n display: flex;\n align-items: center;\n justify-content: center;\n color: white;\n position: relative;\n z-index: 10;\n box-shadow: 0 10px 30px rgba(var(--primary-rgb), 0.3);\n transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);\n }\n\n .central-orb.active {\n animation: pulse 2s infinite;\n }\n \n .central-orb.idle {\n animation: floatOrb 4s ease-in-out infinite;\n cursor: pointer;\n }\n\n .central-orb.idle:hover {\n transform: scale(1.05);\n }\n\n .central-orb-glow {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 140%;\n height: 140%;\n background: radial-gradient(circle, rgba(var(--primary-rgb), 0.2) 0%, transparent 70%);\n animation: pulseGlowIdle 4s ease-in-out infinite;\n z-index: -1;\n pointer-events: none;\n }\n\n .central-orb svg {\n width: 24px;\n height: 24px;\n }\n\n .voice-status-text {\n font-size: 20px;\n font-weight: 600;\n color: var(--text);\n margin-bottom: 8px;\n text-align: center;\n }\n\n .voice-status-subtext {\n font-size: 14px;\n color: var(--text-muted);\n text-align: center;\n }\n\n /* Chat Mode Styles */\n .chat-messages {\n flex: 1;\n min-height: 0;\n overflow-y: auto;\n padding: 16px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n background: #f9fafb; \n \n scrollbar-width: thin;\n scrollbar-color: rgba(156, 163, 175, 0.5) transparent;\n }\n\n .chat-messages::-webkit-scrollbar {\n width: 6px;\n }\n\n .chat-messages::-webkit-scrollbar-track {\n background: transparent;\n }\n\n .chat-messages::-webkit-scrollbar-thumb {\n background-color: rgba(156, 163, 175, 0.5);\n border-radius: 3px;\n }\n\n .chat-message {\n max-width: 85%;\n padding: 12px 16px;\n border-radius: 16px;\n font-size: 14px;\n line-height: 1.5;\n word-wrap: break-word;\n white-space: pre-wrap;\n }\n\n .chat-message.user {\n align-self: flex-end;\n background: #000000;\n color: white;\n border-bottom-right-radius: 4px;\n }\n\n .chat-message.assistant {\n align-self: flex-start;\n background: #ffffff;\n border: 1px solid #e5e7eb;\n color: var(--text);\n border-bottom-left-radius: 4px;\n box-shadow: 0 1px 2px rgba(0,0,0,0.05);\n }\n\n .chat-input-area {\n padding: 20px;\n border-top: 1px solid rgba(0, 0, 0, 0.05);\n display: flex;\n gap: 10px;\n align-items: center;\n background: white;\n z-index: 30;\n position: relative;\n border-bottom-left-radius: 28px;\n border-bottom-right-radius: 28px;\n }\n\n .chat-input {\n flex: 1;\n padding: 14px 20px;\n border: 1px solid #e5e7eb;\n border-radius: 28px;\n font-size: 15px;\n outline: none;\n transition: all 0.3s;\n background: #f3f4f6;\n color: #1f2937;\n }\n\n .chat-input:focus {\n border-color: var(--primary);\n background: white;\n box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);\n }\n\n .chat-send-btn {\n width: 48px;\n height: 48px;\n border-radius: 50%;\n background: var(--primary);\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);\n box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);\n flex-shrink: 0;\n }\n\n .chat-send-btn:hover {\n transform: scale(1.05) rotate(-10deg);\n background: var(--primary-hover);\n box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);\n }\n\n .chat-send-btn:active {\n transform: scale(0.95);\n }\n\n .chat-send-btn svg {\n width: 22px;\n height: 22px;\n color: white;\n margin-left: 2px;\n }\n\n .avatar-container {\n background: transparent;\n flex: 1;\n display: flex;\n align-items: center;\n justify-content: center;\n position: relative;\n overflow: hidden;\n }\n \n .avatar-video {\n width: 100%;\n height: 100%;\n object-fit: cover;\n }\n\n .voice-btn-simple {\n position: relative;\n width: 44px;\n height: 44px;\n border-radius: 50%;\n border: 1.5px solid #e5e7eb;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.3s;\n overflow: visible;\n background: white;\n box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);\n }\n\n .voice-btn-simple:hover {\n transform: scale(1.05);\n background: #f9fafb;\n border-color: #9ca3af;\n box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);\n }\n\n .voice-btn-icon {\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n color: #4b5563;\n }\n\n .voice-btn-icon svg {\n width: 20px;\n height: 20px;\n stroke-width: 2px;\n }\n\n .absolute { position: absolute; }\n .relative { position: relative; }\n .rounded-full { border-radius: 9999px; }\n .flex { display: flex; }\n .items-center { align-items: center; }\n .justify-center { justify-content: center; }\n .w-full { width: 100%; }\n .h-full { height: 100%; }\n .z-50 { z-index: 50; }\n\n .branding-footer {\n display: flex;\n justify-content: center;\n padding: 4px 0 8px 0;\n background-color: #f9fafb;\n font-size: 10px;\n color: #9ca3af;\n font-weight: 500;\n letter-spacing: 0.025em;\n }\n\n .branding-footer b {\n color: #3b82f6;\n font-weight: 700;\n margin-left: 4px;\n }\n\n @media (max-width: 640px) {\n .widget-panel {\n width: 100vw !important;\n height: 100vh !important;\n max-width: 100vw !important;\n max-height: 100vh !important;\n top: 0 !important;\n left: 0 !important;\n right: 0 !important;\n bottom: 0 !important;\n border-radius: 0 !important;\n margin: 0 !important;\n }\n\n .widget-fab {\n width: 56px;\n height: 56px;\n bottom: 16px !important;\n right: 16px !important;\n }\n\n :host(.vanira-panel-open) .widget-fab {\n display: none !important;\n }\n\n .close-btn.maximize-btn {\n display: none !important;\n }\n\n .widget-header {\n padding: 12px 16px;\n }\n\n .widget-title {\n font-size: 16px;\n }\n\n .chat-input-area {\n padding: 12px;\n padding-bottom: env(safe-area-inset-bottom, 12px);\n }\n }\n";
@@ -47,13 +47,25 @@
47
47
  --secondary: ${t||h};
48
48
  --secondary-rgb: ${i};
49
49
  `},te=`
50
+ :host(.vanira-portal) {
51
+ position: fixed !important;
52
+ bottom: 0 !important;
53
+ right: 0 !important;
54
+ top: auto !important;
55
+ left: auto !important;
56
+ width: 0 !important;
57
+ height: 0 !important;
58
+ pointer-events: none !important;
59
+ z-index: 2147483647;
60
+ overflow: visible !important;
61
+ contain: none !important;
62
+ }
63
+
50
64
  :host {
51
65
  display: block;
52
66
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
53
67
  box-sizing: border-box;
54
- overflow: visible !important;
55
- contain: none !important;
56
-
68
+
57
69
  /* Default Theme Variables */
58
70
  --primary: #6366f1;
59
71
  --primary-hover: #4f46e5;
@@ -150,7 +162,8 @@
150
162
 
151
163
  .widget-fab {
152
164
  position: fixed;
153
- z-index: 9999;
165
+ z-index: 2147483647;
166
+ pointer-events: auto !important;
154
167
  width: 64px;
155
168
  height: 64px;
156
169
  border-radius: 50%;
@@ -182,11 +195,12 @@
182
195
 
183
196
  .widget-panel {
184
197
  position: fixed;
185
- z-index: 10000; /* Higher than FAB */
198
+ z-index: 2147483647;
199
+ pointer-events: auto;
186
200
  background: rgba(255, 255, 255, 0.98);
187
201
  backdrop-filter: blur(20px);
188
202
  -webkit-backdrop-filter: blur(20px);
189
- border: 1px solid #d1d5db; /* Solid light gray border for better differentiation */
203
+ border: 1px solid #d1d5db;
190
204
  border-radius: 28px;
191
205
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.08);
192
206
  overflow: hidden;
@@ -212,12 +226,6 @@
212
226
  margin: auto;
213
227
  }
214
228
 
215
- .widget-panel.maximized {
216
- width: 800px;
217
- max-width: calc(100vw - 40px);
218
- height: 80vh;
219
- }
220
-
221
229
  .widget-body {
222
230
  padding: 0;
223
231
  flex: 1;
@@ -229,10 +237,10 @@
229
237
 
230
238
  .widget-panel.hidden {
231
239
  opacity: 0;
232
- pointer-events: none;
240
+ pointer-events: none !important;
233
241
  transform: translateY(20px) scale(0.95);
234
242
  }
235
- /* ... rest of the content is redundant if I use replace or overwrite, but I will overwrite to include everything properly */
243
+
236
244
  .widget-header {
237
245
  background: #1f2937;
238
246
  color: white;
@@ -280,13 +288,6 @@
280
288
  flex-shrink: 0;
281
289
  }
282
290
 
283
- .widget-body {
284
- padding: 0;
285
- flex: 1;
286
- display: flex;
287
- flex-direction: column;
288
- }
289
-
290
291
  .status-indicator {
291
292
  display: flex;
292
293
  align-items: center;
@@ -435,7 +436,7 @@
435
436
  /* Chat Mode Styles */
436
437
  .chat-messages {
437
438
  flex: 1;
438
- min-height: 0; /* Crucial for scrolling in flex column */
439
+ min-height: 0;
439
440
  overflow-y: auto;
440
441
  padding: 16px;
441
442
  display: flex;
@@ -443,7 +444,6 @@
443
444
  gap: 12px;
444
445
  background: #f9fafb;
445
446
 
446
- /* Scrollbar Styling */
447
447
  scrollbar-width: thin;
448
448
  scrollbar-color: rgba(156, 163, 175, 0.5) transparent;
449
449
  }
@@ -461,10 +461,6 @@
461
461
  border-radius: 3px;
462
462
  }
463
463
 
464
- .chat-messages::-webkit-scrollbar-thumb:hover {
465
- background-color: rgba(107, 114, 128, 0.8);
466
- }
467
-
468
464
  .chat-message {
469
465
  max-width: 85%;
470
466
  padding: 12px 16px;
@@ -554,7 +550,6 @@
554
550
  margin-left: 2px;
555
551
  }
556
552
 
557
- /* Avatar Container */
558
553
  .avatar-container {
559
554
  background: transparent;
560
555
  flex: 1;
@@ -565,17 +560,15 @@
565
560
  overflow: hidden;
566
561
  }
567
562
 
568
- /* Avatar Video */
569
563
  .avatar-video {
570
564
  width: 100%;
571
565
  height: 100%;
572
566
  object-fit: cover;
573
567
  }
574
568
 
575
- /* Voice Button (Simple) in Chat */
576
569
  .voice-btn-simple {
577
570
  position: relative;
578
- width: 44px; /* Matching send-btn size for symmetry */
571
+ width: 44px;
579
572
  height: 44px;
580
573
  border-radius: 50%;
581
574
  border: 1.5px solid #e5e7eb;
@@ -596,10 +589,6 @@
596
589
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
597
590
  }
598
591
 
599
- .voice-btn-simple:active {
600
- animation: clickBounce 0.4s ease-out;
601
- }
602
-
603
592
  .voice-btn-icon {
604
593
  width: 100%;
605
594
  height: 100%;
@@ -615,7 +604,6 @@
615
604
  stroke-width: 2px;
616
605
  }
617
606
 
618
- /* Utility Classes */
619
607
  .absolute { position: absolute; }
620
608
  .relative { position: relative; }
621
609
  .rounded-full { border-radius: 9999px; }
@@ -1170,7 +1158,7 @@ overflow: hidden;
1170
1158
  <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);">
1171
1159
  ${p.audioLines.replace('width="24"','width="12"').replace('height="24"','height="12"')}
1172
1160
  </div>
1173
- `;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,c){return y.sendChatMessage(e,i,t,s,A=>{a&&a(A)},n,A=>{r&&A&&r(A)},c)}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,"primaryColor","#6366f1");o(this,"secondaryColor","#4f46e5");o(this,"gradient",null);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 c,A,l;const e=(c=this.sessionManager)==null?void 0:c.getSession();if(!e)return;const i=(l=(A=this.currentView)==null?void 0:A.getChatWindow)==null?void 0:l.call(A);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,c,A,l,d;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=(A=(c=this.currentView)==null?void 0:c.getChatWindow)==null?void 0:A.call(c),n=e.text||e.response||"";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 g=(l=this.sessionManager)==null?void 0:l.getSession();(g==null?void 0:g.messages.some(f=>f.content===n&&f.role===i))||(n&&(s.addMessage(i,n),(d=this.sessionManager)==null||d.pushMessage(i,n)),this.welcomeChipsData.length>0&&s.addButtons(this.welcomeChipsData))}}async initializeChatSession(e=!1){var i,s,n,a,r,c;if(this.sessionActive)try{y.setChatUrl(this.chatServerUrl);const A=(i=this.sessionManager)==null?void 0:i.getSession();if(!e&&(A!=null&&A.prospectId)){this.prospectId=A.prospectId,this.chatId=A.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=y.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,f;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(f=this.sessionManager)==null||f.pushMessage("assistant",d),this.playMessageSound("receive")}));return}this.prospectGroupId?this.prospectId=await y.createChatProspect(this.prospectGroupId):this.prospectId=`anon_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;const l=await y.fetchWelcomeMessage(this.agentId,this.prospectId,this.widgetId||void 0);l!=null&&l.chatId&&!this.chatId&&(this.chatId=l.chatId,this.eventSource||(this.eventSource=y.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,f;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(f=this.sessionManager)==null||f.pushMessage("assistant",d),this.playMessageSound("receive")}))),(n=this.sessionManager)==null||n.saveIds(this.prospectId,this.chatId)}catch(A){console.error("[VaniraAI] Chat init failed",A);const l="Hello! How can I help you today?";(r=(a=this.currentView)==null?void 0:a.getChatWindow)==null||r.call(a).addMessage("assistant",l),(c=this.sessionManager)==null||c.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.widgetId=e.widgetId||e.widget_id||"",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.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 y.createCall(this.agentId,null,this.prospectId||null,this.widgetMode),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,c;(c=(r=this.currentView)==null?void 0:r.setTranscription)==null||c.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,c;const a=new CustomEvent("vaniraai:tool_call",{detail:n,bubbles:!0,composed:!0});(c=(r=this.root)==null?void 0:r.host)==null||c.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="";const i=document.createElement("style");i.textContent=`@keyframes vanira-slide-up {
1161
+ `;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,c){return y.sendChatMessage(e,i,t,s,A=>{a&&a(A)},n,A=>{r&&A&&r(A)},c)}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,"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 c,A,l;const e=(c=this.sessionManager)==null?void 0:c.getSession();if(!e)return;const i=(l=(A=this.currentView)==null?void 0:A.getChatWindow)==null?void 0:l.call(A);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,c,A,l,d;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=(A=(c=this.currentView)==null?void 0:c.getChatWindow)==null?void 0:A.call(c),n=e.text||e.response||"";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 g=(l=this.sessionManager)==null?void 0:l.getSession();(g==null?void 0:g.messages.some(f=>f.content===n&&f.role===i))||(n&&(s.addMessage(i,n),(d=this.sessionManager)==null||d.pushMessage(i,n)),this.welcomeChipsData.length>0&&s.addButtons(this.welcomeChipsData))}}async initializeChatSession(e=!1){var i,s,n,a,r,c;if(this.sessionActive)try{y.setChatUrl(this.chatServerUrl);const A=(i=this.sessionManager)==null?void 0:i.getSession();if(!e&&(A!=null&&A.prospectId)){this.prospectId=A.prospectId,this.chatId=A.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=y.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,f;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(f=this.sessionManager)==null||f.pushMessage("assistant",d),this.playMessageSound("receive")}));return}this.prospectGroupId?this.prospectId=await y.createChatProspect(this.prospectGroupId):this.prospectId=`anon_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;const l=await y.fetchWelcomeMessage(this.agentId,this.prospectId,this.widgetId||void 0);l!=null&&l.chatId&&!this.chatId&&(this.chatId=l.chatId,this.eventSource||(this.eventSource=y.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,f;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(f=this.sessionManager)==null||f.pushMessage("assistant",d),this.playMessageSound("receive")}))),(n=this.sessionManager)==null||n.saveIds(this.prospectId,this.chatId)}catch(A){console.error("[VaniraAI] Chat init failed",A);const l="Hello! How can I help you today?";(r=(a=this.currentView)==null?void 0:a.getChatWindow)==null||r.call(a).addMessage("assistant",l),(c=this.sessionManager)==null||c.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.widgetId=e.widgetId||e.widget_id||"",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 y.createCall(this.agentId,null,this.prospectId||null,this.widgetMode),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,c;(c=(r=this.currentView)==null?void 0:r.setTranscription)==null||c.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,c;const a=new CustomEvent("vaniraai:tool_call",{detail:n,bubbles:!0,composed:!0});(c=(r=this.root)==null?void 0:r.host)==null||c.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 {
1174
1162
  from { opacity:0; transform:translateY(16px); }
1175
1163
  to { opacity:1; transform:translateY(0); }
1176
1164
  }`,this.root.appendChild(i);const s=document.createElement("style");s.textContent=`
@@ -1180,4 +1168,4 @@ overflow: hidden;
1180
1168
  ${U.styles}
1181
1169
  ${N.styles}
1182
1170
  ${this.gradient?`.widget-fab { background: ${this.gradient} !important; }`:""}
1183
- `,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 j(()=>this.togglePanel(),(A,l)=>{var d,g;(d=this.floatingWelcomeChips)==null||d.updateCoordinates(A,l,l>window.innerHeight/2),this.isPanelOpen&&((g=this.panel)==null||g.updatePosition({left:`${Math.max(20,Math.min(A-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"}))},(A,l)=>{localStorage.setItem(n,JSON.stringify({x:A,y:l}))}),this.floatingButton.setIcon(this.getFabIcon()),r?this.floatingButton.updateCoordinates(r.x,r.y):this.floatingButton.setPosition(this.getPosStyle()),this.floatingWelcomeChips=new U(A=>this.handleFloatingChipClick(A)),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&&D[this.widgetIcon]?D[this.widgetIcon]:this.widgetMode.includes("chat")?p.chat:p.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 c,A;const n=(A=(c=this.currentView)==null?void 0:c.getChatWindow)==null?void 0:A.call(c);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,c;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=y.listenForAdminReplies(this.chatId,this.prospectId,A=>{var l,d,g;(d=(l=this.currentView)==null?void 0:l.getChatWindow)==null||d.call(l).addMessage("assistant",A),(g=this.sessionManager)==null||g.pushMessage("assistant",A),this.playMessageSound("receive")})),i.addMessage("user",e),(r=this.sessionManager)==null||r.pushMessage("user",e),i.setTyping(!0),(c=this.sessionManager)==null||c.pushMessage("assistant","");try{let A=!1;await this.chatAdapter.sendMessage(e,this.agentId,this.prospectId,this.chatId,l=>{var d;A||(this.playMessageSound("receive"),A=!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;A||(this.playMessageSound("receive"),A=!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(A){i.setTyping(!1),console.error("[VaniraAI] Send message failed",A),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,"serverUrl","https://inboxapi.travelr.club");o(this,"position","bottom-right");o(this,"primaryColor","#000000");o(this,"secondaryColor","#000000");o(this,"gradient",null);this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["widget-id","agent-id","position","primary-color","secondary-color","server-url","gradient"]}connectedCallback(){console.log("[VaniraAI Widget] Initializing..."),this.readAttributes();const e={widgetId:this.widgetId,agentId:this.agentId,serverUrl:this.serverUrl,position:this.position,primaryColor:this.primaryColor,secondaryColor:this.secondaryColor,gradient:this.gradient};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.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")}async initializeExpandedConfig(){try{const e=await H.fetchWidgetConfig(this.widgetId);this.provider&&await this.provider.initialize(e)}catch(e){console.error("[VaniraAI Widget] Config failed:",e)}}}u.ChatService=y,u.ConfigService=H,u.SessionManager=k,u.VaniraAI=Y,u.VaniraWidget=de,u.WebRTCClient=C,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
1171
+ `,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 j(()=>this.togglePanel(),(A,l)=>{var d,g;(d=this.floatingWelcomeChips)==null||d.updateCoordinates(A,l,l>window.innerHeight/2),this.isPanelOpen&&((g=this.panel)==null||g.updatePosition({left:`${Math.max(20,Math.min(A-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"}))},(A,l)=>{localStorage.setItem(n,JSON.stringify({x:A,y:l}))}),this.floatingButton.setIcon(this.getFabIcon()),r?this.floatingButton.updateCoordinates(r.x,r.y):this.floatingButton.setPosition(this.getPosStyle()),this.floatingWelcomeChips=new U(A=>this.handleFloatingChipClick(A)),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&&D[this.widgetIcon]?D[this.widgetIcon]:this.widgetMode.includes("chat")?p.chat:p.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 c,A;const n=(A=(c=this.currentView)==null?void 0:c.getChatWindow)==null?void 0:A.call(c);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,c;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=y.listenForAdminReplies(this.chatId,this.prospectId,A=>{var l,d,g;(d=(l=this.currentView)==null?void 0:l.getChatWindow)==null||d.call(l).addMessage("assistant",A),(g=this.sessionManager)==null||g.pushMessage("assistant",A),this.playMessageSound("receive")})),i.addMessage("user",e),(r=this.sessionManager)==null||r.pushMessage("user",e),i.setTyping(!0),(c=this.sessionManager)==null||c.pushMessage("assistant","");try{let A=!1;await this.chatAdapter.sendMessage(e,this.agentId,this.prospectId,this.chatId,l=>{var d;A||(this.playMessageSound("receive"),A=!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;A||(this.playMessageSound("receive"),A=!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(A){i.setTyping(!1),console.error("[VaniraAI] Send message failed",A),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,"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"]}connectedCallback(){console.log("[VaniraAI Widget] Initializing..."),this.readAttributes();const e={widgetId:this.widgetId,agentId:this.agentId,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.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 H.fetchWidgetConfig(this.widgetId);this.provider&&await this.provider.initialize(e)}catch(e){console.error("[VaniraAI Widget] Config failed:",e)}}}u.ChatService=y,u.ConfigService=H,u.SessionManager=k,u.VaniraAI=Y,u.VaniraWidget=de,u.WebRTCClient=C,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
@@ -47,13 +47,25 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
47
47
  --secondary: ${t||h};
48
48
  --secondary-rgb: ${i};
49
49
  `},ie=`
50
+ :host(.vanira-portal) {
51
+ position: fixed !important;
52
+ bottom: 0 !important;
53
+ right: 0 !important;
54
+ top: auto !important;
55
+ left: auto !important;
56
+ width: 0 !important;
57
+ height: 0 !important;
58
+ pointer-events: none !important;
59
+ z-index: 2147483647;
60
+ overflow: visible !important;
61
+ contain: none !important;
62
+ }
63
+
50
64
  :host {
51
65
  display: block;
52
66
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
53
67
  box-sizing: border-box;
54
- overflow: visible !important;
55
- contain: none !important;
56
-
68
+
57
69
  /* Default Theme Variables */
58
70
  --primary: #6366f1;
59
71
  --primary-hover: #4f46e5;
@@ -150,7 +162,8 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
150
162
 
151
163
  .widget-fab {
152
164
  position: fixed;
153
- z-index: 9999;
165
+ z-index: 2147483647;
166
+ pointer-events: auto !important;
154
167
  width: 64px;
155
168
  height: 64px;
156
169
  border-radius: 50%;
@@ -182,11 +195,12 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
182
195
 
183
196
  .widget-panel {
184
197
  position: fixed;
185
- z-index: 10000; /* Higher than FAB */
198
+ z-index: 2147483647;
199
+ pointer-events: auto;
186
200
  background: rgba(255, 255, 255, 0.98);
187
201
  backdrop-filter: blur(20px);
188
202
  -webkit-backdrop-filter: blur(20px);
189
- border: 1px solid #d1d5db; /* Solid light gray border for better differentiation */
203
+ border: 1px solid #d1d5db;
190
204
  border-radius: 28px;
191
205
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.08);
192
206
  overflow: hidden;
@@ -212,12 +226,6 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
212
226
  margin: auto;
213
227
  }
214
228
 
215
- .widget-panel.maximized {
216
- width: 800px;
217
- max-width: calc(100vw - 40px);
218
- height: 80vh;
219
- }
220
-
221
229
  .widget-body {
222
230
  padding: 0;
223
231
  flex: 1;
@@ -229,10 +237,10 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
229
237
 
230
238
  .widget-panel.hidden {
231
239
  opacity: 0;
232
- pointer-events: none;
240
+ pointer-events: none !important;
233
241
  transform: translateY(20px) scale(0.95);
234
242
  }
235
- /* ... rest of the content is redundant if I use replace or overwrite, but I will overwrite to include everything properly */
243
+
236
244
  .widget-header {
237
245
  background: #1f2937;
238
246
  color: white;
@@ -280,13 +288,6 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
280
288
  flex-shrink: 0;
281
289
  }
282
290
 
283
- .widget-body {
284
- padding: 0;
285
- flex: 1;
286
- display: flex;
287
- flex-direction: column;
288
- }
289
-
290
291
  .status-indicator {
291
292
  display: flex;
292
293
  align-items: center;
@@ -435,7 +436,7 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
435
436
  /* Chat Mode Styles */
436
437
  .chat-messages {
437
438
  flex: 1;
438
- min-height: 0; /* Crucial for scrolling in flex column */
439
+ min-height: 0;
439
440
  overflow-y: auto;
440
441
  padding: 16px;
441
442
  display: flex;
@@ -443,7 +444,6 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
443
444
  gap: 12px;
444
445
  background: #f9fafb;
445
446
 
446
- /* Scrollbar Styling */
447
447
  scrollbar-width: thin;
448
448
  scrollbar-color: rgba(156, 163, 175, 0.5) transparent;
449
449
  }
@@ -461,10 +461,6 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
461
461
  border-radius: 3px;
462
462
  }
463
463
 
464
- .chat-messages::-webkit-scrollbar-thumb:hover {
465
- background-color: rgba(107, 114, 128, 0.8);
466
- }
467
-
468
464
  .chat-message {
469
465
  max-width: 85%;
470
466
  padding: 12px 16px;
@@ -554,7 +550,6 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
554
550
  margin-left: 2px;
555
551
  }
556
552
 
557
- /* Avatar Container */
558
553
  .avatar-container {
559
554
  background: transparent;
560
555
  flex: 1;
@@ -565,17 +560,15 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
565
560
  overflow: hidden;
566
561
  }
567
562
 
568
- /* Avatar Video */
569
563
  .avatar-video {
570
564
  width: 100%;
571
565
  height: 100%;
572
566
  object-fit: cover;
573
567
  }
574
568
 
575
- /* Voice Button (Simple) in Chat */
576
569
  .voice-btn-simple {
577
570
  position: relative;
578
- width: 44px; /* Matching send-btn size for symmetry */
571
+ width: 44px;
579
572
  height: 44px;
580
573
  border-radius: 50%;
581
574
  border: 1.5px solid #e5e7eb;
@@ -596,10 +589,6 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
596
589
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
597
590
  }
598
591
 
599
- .voice-btn-simple:active {
600
- animation: clickBounce 0.4s ease-out;
601
- }
602
-
603
592
  .voice-btn-icon {
604
593
  width: 100%;
605
594
  height: 100%;
@@ -615,7 +604,6 @@ var we=Object.defineProperty;var ue=(C,f,x)=>f in C?we(C,f,{enumerable:!0,config
615
604
  stroke-width: 2px;
616
605
  }
617
606
 
618
- /* Utility Classes */
619
607
  .absolute { position: absolute; }
620
608
  .relative { position: relative; }
621
609
  .rounded-full { border-radius: 9999px; }
@@ -1170,7 +1158,7 @@ overflow: hidden;
1170
1158
  <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);">
1171
1159
  ${p.audioLines.replace('width="24"','width="12"').replace('height="24"','height="12"')}
1172
1160
  </div>
1173
- `;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,c){return v.sendChatMessage(e,i,t,s,l=>{a&&a(l)},n,l=>{r&&l&&r(l)},c)}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,"primaryColor","#6366f1");o(this,"secondaryColor","#4f46e5");o(this,"gradient",null);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 P(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 c,l,A;const e=(c=this.sessionManager)==null?void 0:c.getSession();if(!e)return;const i=(A=(l=this.currentView)==null?void 0:l.getChatWindow)==null?void 0:A.call(l);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,c,l,A,d;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=(l=(c=this.currentView)==null?void 0:c.getChatWindow)==null?void 0:l.call(c),n=e.text||e.response||"";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 g=(A=this.sessionManager)==null?void 0:A.getSession();(g==null?void 0:g.messages.some(m=>m.content===n&&m.role===i))||(n&&(s.addMessage(i,n),(d=this.sessionManager)==null||d.pushMessage(i,n)),this.welcomeChipsData.length>0&&s.addButtons(this.welcomeChipsData))}}async initializeChatSession(e=!1){var i,s,n,a,r,c;if(this.sessionActive)try{v.setChatUrl(this.chatServerUrl);const l=(i=this.sessionManager)==null?void 0:i.getSession();if(!e&&(l!=null&&l.prospectId)){this.prospectId=l.prospectId,this.chatId=l.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,m;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(m=this.sessionManager)==null||m.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!=null&&A.chatId&&!this.chatId&&(this.chatId=A.chatId,this.eventSource||(this.eventSource=v.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,m;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(m=this.sessionManager)==null||m.pushMessage("assistant",d),this.playMessageSound("receive")}))),(n=this.sessionManager)==null||n.saveIds(this.prospectId,this.chatId)}catch(l){console.error("[VaniraAI] Chat init failed",l);const A="Hello! How can I help you today?";(r=(a=this.currentView)==null?void 0:a.getChatWindow)==null||r.call(a).addMessage("assistant",A),(c=this.sessionManager)==null||c.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.widgetId=e.widgetId||e.widget_id||"",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.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),s=new H({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,c;(c=(r=this.currentView)==null?void 0:r.setTranscription)==null||c.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,c;const a=new CustomEvent("vaniraai:tool_call",{detail:n,bubbles:!0,composed:!0});(c=(r=this.root)==null?void 0:r.host)==null||c.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="";const i=document.createElement("style");i.textContent=`@keyframes vanira-slide-up {
1161
+ `;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,c){return v.sendChatMessage(e,i,t,s,l=>{a&&a(l)},n,l=>{r&&l&&r(l)},c)}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,"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 P(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 c,l,A;const e=(c=this.sessionManager)==null?void 0:c.getSession();if(!e)return;const i=(A=(l=this.currentView)==null?void 0:l.getChatWindow)==null?void 0:A.call(l);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,c,l,A,d;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=(l=(c=this.currentView)==null?void 0:c.getChatWindow)==null?void 0:l.call(c),n=e.text||e.response||"";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 g=(A=this.sessionManager)==null?void 0:A.getSession();(g==null?void 0:g.messages.some(m=>m.content===n&&m.role===i))||(n&&(s.addMessage(i,n),(d=this.sessionManager)==null||d.pushMessage(i,n)),this.welcomeChipsData.length>0&&s.addButtons(this.welcomeChipsData))}}async initializeChatSession(e=!1){var i,s,n,a,r,c;if(this.sessionActive)try{v.setChatUrl(this.chatServerUrl);const l=(i=this.sessionManager)==null?void 0:i.getSession();if(!e&&(l!=null&&l.prospectId)){this.prospectId=l.prospectId,this.chatId=l.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,m;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(m=this.sessionManager)==null||m.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!=null&&A.chatId&&!this.chatId&&(this.chatId=A.chatId,this.eventSource||(this.eventSource=v.listenForAdminReplies(this.chatId,this.prospectId,d=>{var g,w,m;(w=(g=this.currentView)==null?void 0:g.getChatWindow)==null||w.call(g).addMessage("assistant",d),(m=this.sessionManager)==null||m.pushMessage("assistant",d),this.playMessageSound("receive")}))),(n=this.sessionManager)==null||n.saveIds(this.prospectId,this.chatId)}catch(l){console.error("[VaniraAI] Chat init failed",l);const A="Hello! How can I help you today?";(r=(a=this.currentView)==null?void 0:a.getChatWindow)==null||r.call(a).addMessage("assistant",A),(c=this.sessionManager)==null||c.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.widgetId=e.widgetId||e.widget_id||"",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),s=new H({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,c;(c=(r=this.currentView)==null?void 0:r.setTranscription)==null||c.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,c;const a=new CustomEvent("vaniraai:tool_call",{detail:n,bubbles:!0,composed:!0});(c=(r=this.root)==null?void 0:r.host)==null||c.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 {
1174
1162
  from { opacity:0; transform:translateY(16px); }
1175
1163
  to { opacity:1; transform:translateY(0); }
1176
1164
  }`,this.root.appendChild(i);const s=document.createElement("style");s.textContent=`
@@ -1180,5 +1168,5 @@ overflow: hidden;
1180
1168
  ${U.styles}
1181
1169
  ${N.styles}
1182
1170
  ${this.gradient?`.widget-fab { background: ${this.gradient} !important; }`:""}
1183
- `,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 j(()=>this.togglePanel(),(l,A)=>{var d,g;(d=this.floatingWelcomeChips)==null||d.updateCoordinates(l,A,A>window.innerHeight/2),this.isPanelOpen&&((g=this.panel)==null||g.updatePosition({left:`${Math.max(20,Math.min(l-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"}))},(l,A)=>{localStorage.setItem(n,JSON.stringify({x:l,y:A}))}),this.floatingButton.setIcon(this.getFabIcon()),r?this.floatingButton.updateCoordinates(r.x,r.y):this.floatingButton.setPosition(this.getPosStyle()),this.floatingWelcomeChips=new U(l=>this.handleFloatingChipClick(l)),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&&D[this.widgetIcon]?D[this.widgetIcon]:this.widgetMode.includes("chat")?p.chat:p.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 c,l;const n=(l=(c=this.currentView)==null?void 0:c.getChatWindow)==null?void 0:l.call(c);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,c;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,l=>{var A,d,g;(d=(A=this.currentView)==null?void 0:A.getChatWindow)==null||d.call(A).addMessage("assistant",l),(g=this.sessionManager)==null||g.pushMessage("assistant",l),this.playMessageSound("receive")})),i.addMessage("user",e),(r=this.sessionManager)==null||r.pushMessage("user",e),i.setTyping(!0),(c=this.sessionManager)==null||c.pushMessage("assistant","");try{let l=!1;await this.chatAdapter.sendMessage(e,this.agentId,this.prospectId,this.chatId,A=>{var d;l||(this.playMessageSound("receive"),l=!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;l||(this.playMessageSound("receive"),l=!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(l){i.setTyping(!1),console.error("[VaniraAI] Send message failed",l),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 Y=B;class de{static getProvider(t){return new Y(t)}}class F extends HTMLElement{constructor(){super();o(this,"shadow");o(this,"provider",null);o(this,"widgetId","");o(this,"agentId","");o(this,"serverUrl","https://inboxapi.travelr.club");o(this,"position","bottom-right");o(this,"primaryColor","#000000");o(this,"secondaryColor","#000000");o(this,"gradient",null);this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["widget-id","agent-id","position","primary-color","secondary-color","server-url","gradient"]}connectedCallback(){console.log("[VaniraAI Widget] Initializing..."),this.readAttributes();const e={widgetId:this.widgetId,agentId:this.agentId,serverUrl:this.serverUrl,position:this.position,primaryColor:this.primaryColor,secondaryColor:this.secondaryColor,gradient:this.gradient};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.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")}async initializeExpandedConfig(){try{const e=await x.fetchWidgetConfig(this.widgetId);this.provider&&await this.provider.initialize(e)}catch(e){console.error("[VaniraAI Widget] Config failed:",e)}}}customElements.get("vanira-convai")||customElements.define("vanira-convai",F),typeof window<"u"&&(window.VaniraConvAI=F,window.VaniraAI=H);const u=document.currentScript;if(u){const h=u.getAttribute("data-widget-id")||u.getAttribute("widget-id"),t=u.getAttribute("data-agent-id")||u.getAttribute("agent-id");if(h||t){const e=u.getAttribute("data-position")||"bottom-right",i=u.getAttribute("data-primary-color")||u.getAttribute("primary-color")||"#6366f1",s=u.getAttribute("data-secondary-color")||u.getAttribute("secondary-color"),n=u.getAttribute("data-gradient")||u.getAttribute("gradient"),a=u.getAttribute("data-server-url")||u.getAttribute("server-url"),r=document.createElement("vanira-convai");h&&r.setAttribute("widget-id",h),t&&r.setAttribute("agent-id",t),r.setAttribute("position",e),r.setAttribute("primary-color",i),s&&r.setAttribute("secondary-color",s),n&&r.setAttribute("gradient",n),a&&r.setAttribute("server-url",a),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>document.body.appendChild(r)):document.body.appendChild(r),r.addEventListener("vaniraai:tool_call",c=>{const l=c.detail;console.log("[VaniraAI Widget] Tool call received by host page:",l.name,l.arguments),typeof window.__vaniraai_tool_handler=="function"&&window.__vaniraai_tool_handler(l,{sendResult:A=>{console.log("[VaniraAI] sendResult called:",A)}})})}}})();
1171
+ `,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 j(()=>this.togglePanel(),(l,A)=>{var d,g;(d=this.floatingWelcomeChips)==null||d.updateCoordinates(l,A,A>window.innerHeight/2),this.isPanelOpen&&((g=this.panel)==null||g.updatePosition({left:`${Math.max(20,Math.min(l-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"}))},(l,A)=>{localStorage.setItem(n,JSON.stringify({x:l,y:A}))}),this.floatingButton.setIcon(this.getFabIcon()),r?this.floatingButton.updateCoordinates(r.x,r.y):this.floatingButton.setPosition(this.getPosStyle()),this.floatingWelcomeChips=new U(l=>this.handleFloatingChipClick(l)),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&&D[this.widgetIcon]?D[this.widgetIcon]:this.widgetMode.includes("chat")?p.chat:p.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 c,l;const n=(l=(c=this.currentView)==null?void 0:c.getChatWindow)==null?void 0:l.call(c);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,c;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,l=>{var A,d,g;(d=(A=this.currentView)==null?void 0:A.getChatWindow)==null||d.call(A).addMessage("assistant",l),(g=this.sessionManager)==null||g.pushMessage("assistant",l),this.playMessageSound("receive")})),i.addMessage("user",e),(r=this.sessionManager)==null||r.pushMessage("user",e),i.setTyping(!0),(c=this.sessionManager)==null||c.pushMessage("assistant","");try{let l=!1;await this.chatAdapter.sendMessage(e,this.agentId,this.prospectId,this.chatId,A=>{var d;l||(this.playMessageSound("receive"),l=!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;l||(this.playMessageSound("receive"),l=!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(l){i.setTyping(!1),console.error("[VaniraAI] Send message failed",l),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 Y=B;class de{static getProvider(t){return new Y(t)}}class F extends HTMLElement{constructor(){super();o(this,"shadow");o(this,"provider",null);o(this,"widgetId","");o(this,"agentId","");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"]}connectedCallback(){console.log("[VaniraAI Widget] Initializing..."),this.readAttributes();const e={widgetId:this.widgetId,agentId:this.agentId,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.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 x.fetchWidgetConfig(this.widgetId);this.provider&&await this.provider.initialize(e)}catch(e){console.error("[VaniraAI Widget] Config failed:",e)}}}customElements.get("vanira-convai")||customElements.define("vanira-convai",F),typeof window<"u"&&(window.VaniraConvAI=F,window.VaniraAI=H);const u=document.currentScript;if(u){const h=u.getAttribute("data-widget-id")||u.getAttribute("widget-id"),t=u.getAttribute("data-agent-id")||u.getAttribute("agent-id");if(h||t){const e=u.getAttribute("data-position")||"bottom-right",i=u.getAttribute("data-primary-color")||u.getAttribute("primary-color")||"#6366f1",s=u.getAttribute("data-secondary-color")||u.getAttribute("secondary-color"),n=u.getAttribute("data-gradient")||u.getAttribute("gradient"),a=u.getAttribute("data-server-url")||u.getAttribute("server-url"),r=document.createElement("vanira-convai");h&&r.setAttribute("widget-id",h),t&&r.setAttribute("agent-id",t),r.setAttribute("position",e),r.setAttribute("primary-color",i),s&&r.setAttribute("secondary-color",s),n&&r.setAttribute("gradient",n),a&&r.setAttribute("server-url",a),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>document.body.appendChild(r)):document.body.appendChild(r),r.addEventListener("vaniraai:tool_call",c=>{const l=c.detail;console.log("[VaniraAI Widget] Tool call received by host page:",l.name,l.arguments),typeof window.__vaniraai_tool_handler=="function"&&window.__vaniraai_tool_handler(l,{sendResult:A=>{console.log("[VaniraAI] sendResult called:",A)}})})}}})();
1184
1172
  //# sourceMappingURL=vanira-sdk.js.map