@crestapps/ai-chat-ui 1.0.0-rc.8 → 1.1.0

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.
@@ -1,2 +1,2 @@
1
- function clampWidgetValue(e,t,i){return Math.min(Math.max(e,t),i)}window.coreAIChatWidgetBehavior=window.coreAIChatWidgetBehavior||function(){function e(e){if("number"==typeof e&&Number.isFinite(e))return e;if("string"!=typeof e)return null;var t=parseFloat(e);return Number.isFinite(t)?t:null}function t(t,i){if(t&&!t.widgetIsInitialized)if(i.widget.chatWidgetContainer)if(i.widget.chatWidgetStateName){var n=document.querySelector(i.widget.chatWidgetContainer);if(n){i.widget.chatHistorySection&&(t.chatHistorySection=document.querySelector(i.widget.chatHistorySection)),t.chatWidgetStateName=i.widget.chatWidgetStateName,t.chatWidgetStateSession=i.widget.chatWidgetStateName+"Session",t.chatWidgetStateDocuments=i.widget.chatWidgetStateName+"Documents",t.chatWidgetLayoutKey=i.widget.chatWidgetStateName+"Layout",t.widgetContainerElement=n,t.widgetToggleButtonElement=i.widget.toggleButtonSelector?document.querySelector(i.widget.toggleButtonSelector):null,t.widgetResetSizeButtonElement=i.widget.resetSizeButtonSelector?document.querySelector(i.widget.resetSizeButtonSelector):null,t.widgetDefaultWidth=e(i.widget.defaultWidth)||e(window.getComputedStyle(n).width)||380,t.widgetDefaultHeight=e(i.widget.defaultHeight)||e(window.getComputedStyle(n).height)||520,t.widgetIsInitialized=!0,t.clearStoredWidgetDocuments(),t.documents=[],i.widget.enableResizing&&(n.classList.add("ai-chat-widget-resizable"),n.style.minWidth=(e(i.widget.minWidth)||320)+"px",n.style.minHeight=(e(i.widget.minHeight)||420)+"px","undefined"!=typeof ResizeObserver&&(t.widgetResizeObserver=new ResizeObserver(function(){t.persistWidgetPanelSize(),t.constrainWidgetElementsToViewport(),t.updateWidgetResetSizeButtonVisibility()}),t.widgetResizeObserver.observe(n)));var o=i.widget.dragHandleSelector||".ai-chat-widget-header",a=n.querySelector(o);if(i.widget.enableDragging&&a&&(a.classList.add("ai-chat-widget-drag-handle"),n.classList.add("ai-chat-widget-draggable"),t.attachDraggableWidgetElement(n,a,"panel",!1)),i.widget.enableDragging&&t.widgetToggleButtonElement&&(t.widgetToggleButtonElement.classList.add("ai-chat-widget-draggable"),t.attachDraggableWidgetElement(t.widgetToggleButtonElement,t.widgetToggleButtonElement,"toggle",!0)),t.widgetResetSizeButtonElement&&t.widgetResetSizeButtonElement.addEventListener("click",function(e){e.preventDefault(),t.resetWidgetSize()}),t.restoreWidgetLayout(),t.widgetViewportResizeHandler||(t.widgetViewportResizeHandler=function(){i.widget.persistLayout?t.restoreWidgetLayout():t.constrainWidgetElementsToViewport(),t.updateWidgetResetSizeButtonVisibility()},window.addEventListener("resize",t.widgetViewportResizeHandler)),t.reloadCurrentSession(),i.autoCreateSession&&!t.getSessionId()&&t.startNewSession(),i.widget.showHistoryButton&&t.chatHistorySection){var s=document.querySelector(i.widget.showHistoryButton);if(s&&s.addEventListener("click",function(){t.chatHistorySection.classList.toggle("show")}),i.widget.closeHistoryButton){var l=document.querySelector(i.widget.closeHistoryButton);l&&l.addEventListener("click",function(){t.showChatScreen()})}}if(i.widget.newChatButton){var r=document.querySelector(i.widget.newChatButton);r&&r.addEventListener("click",function(){t.resetSession(),t.showChatScreen()})}}}else console.error("The widget chatWidgetStateName is required.");else console.error("The widget chatWidgetContainer is required.")}function i(e){e&&(e.widgetResizeObserver&&(e.widgetResizeObserver.disconnect(),e.widgetResizeObserver=null),e.widgetViewportResizeHandler&&(window.removeEventListener("resize",e.widgetViewportResizeHandler),e.widgetViewportResizeHandler=null))}return{attach:function(t,i){t&&!t.__aiChatWidgetAttached&&(t.__aiChatWidgetAttached=!0,t.chatWidgetStateName=null,t.chatWidgetStateSession=null,t.chatWidgetStateDocuments=null,t.chatWidgetLayoutKey=null,t.chatHistorySection=null,t.widgetContainerElement=null,t.widgetToggleButtonElement=null,t.widgetResetSizeButtonElement=null,t.widgetResizeObserver=null,t.widgetViewportResizeHandler=null,t.widgetDefaultWidth=null,t.widgetDefaultHeight=null,t.widgetIsInitialized=!1,t.getStoredWidgetLayout=function(){if(!this.chatWidgetLayoutKey||!i.widget.persistLayout)return{};try{var e=localStorage.getItem(this.chatWidgetLayoutKey);return e&&JSON.parse(e)||{}}catch(e){return console.warn("Failed to read widget layout state.",e),{}}},t.saveStoredWidgetLayout=function(e){if(this.chatWidgetLayoutKey&&i.widget.persistLayout){var t=this.getStoredWidgetLayout(),n=Object.assign({},t);void 0!==e.panel&&(n.panel=Object.assign({},t.panel||{},e.panel||{})),void 0!==e.position&&(n.position=Object.assign({},t.position||{},e.position||{})),localStorage.setItem(this.chatWidgetLayoutKey,JSON.stringify(n))}},t.getElementSize=function(t,i,n){if(!t)return{width:i||0,height:n||0};var o=t.getBoundingClientRect(),a=window.getComputedStyle(t);return{width:Math.round(o.width||e(a.width)||i||0),height:Math.round(o.height||e(a.height)||n||0)}},t.getElementPosition=function(t){if(!t)return{left:0,top:0};var i=t.getBoundingClientRect(),n=window.getComputedStyle(t),o=e(t.style.left),a=e(t.style.top),s=e(n.left),l=e(n.top),r="none"===n.display;return{left:Math.round(r&&Number.isFinite(o)?o:i.left||o||s||0),top:Math.round(r&&Number.isFinite(a)?a:i.top||a||l||0)}},t.getAvailableWidgetPositionRange=function(e,t){return{padding:8,maxLeft:Math.max(8,window.innerWidth-e-8),maxTop:Math.max(8,window.innerHeight-t-8)}},t.createStoredPosition=function(e,t,i,n){var o=this.getAvailableWidgetPositionRange(i,n),a=Math.max(0,o.maxLeft-o.padding),s=Math.max(0,o.maxTop-o.padding);return{left:Math.round(e),top:Math.round(t),leftRatio:0===a?0:(e-o.padding)/a,topRatio:0===s?0:(t-o.padding)/s}},t.resolveStoredPosition=function(e,t,i){if(!e)return null;var n=this.getAvailableWidgetPositionRange(t,i),o=Number(e.left),a=Number(e.top),s=Number(e.leftRatio),l=Number(e.topRatio);return Number.isFinite(s)&&(o=n.padding+Math.max(0,n.maxLeft-n.padding)*s),Number.isFinite(l)&&(a=n.padding+Math.max(0,n.maxTop-n.padding)*l),Number.isFinite(o)&&Number.isFinite(a)?this.clampWidgetPosition(o,a,t,i):null},t.clampWidgetPosition=function(e,t,i,n){var o=this.getAvailableWidgetPositionRange(i,n);return{left:Math.round(clampWidgetValue(e,o.padding,o.maxLeft)),top:Math.round(clampWidgetValue(t,o.padding,o.maxTop))}},t.getStoredWidgetDocuments=function(){return this.clearStoredWidgetDocuments(),[]},t.saveStoredWidgetDocuments=function(){this.clearStoredWidgetDocuments()},t.clearStoredWidgetDocuments=function(){this.chatWidgetStateDocuments&&localStorage.removeItem(this.chatWidgetStateDocuments)},t.applyAbsolutePosition=function(e,t,i){e&&(e.style.left=t+"px",e.style.top=i+"px",e.style.right="auto",e.style.bottom="auto")},t.getWidgetDefaultSize=function(){return{width:this.widgetDefaultWidth||e(i.widget.defaultWidth)||380,height:this.widgetDefaultHeight||e(i.widget.defaultHeight)||520}},t.getWidgetToggleGap=function(){return 8},t.isWidgetPanelVisible=function(){if(!this.widgetContainerElement)return!1;var e=window.getComputedStyle(this.widgetContainerElement);return this.widgetContainerElement.classList.contains("open")&&"none"!==e.display},t.persistWidgetPanelPosition=function(){if(this.widgetContainerElement&&i.widget.persistLayout){var e=this.getWidgetDefaultSize(),t=this.getElementPosition(this.widgetContainerElement),n=this.getElementSize(this.widgetContainerElement,e.width,e.height),o=this.getElementSize(this.widgetToggleButtonElement,52,52),a=this.clampWidgetPosition(t.left+n.width-o.width,t.top+n.height+this.getWidgetToggleGap(),o.width,o.height);this.saveStoredWidgetLayout({position:this.createStoredPosition(a.left,a.top,o.width,o.height)})}},t.persistWidgetTogglePosition=function(){if(this.widgetToggleButtonElement&&i.widget.persistLayout){var e=this.getElementPosition(this.widgetToggleButtonElement),t=this.getElementSize(this.widgetToggleButtonElement,52,52);this.saveStoredWidgetLayout({position:this.createStoredPosition(e.left,e.top,t.width,t.height)})}},t.persistWidgetPanelSize=function(){if(this.widgetContainerElement&&i.widget.enableResizing&&i.widget.persistLayout){var e=this.getWidgetDefaultSize(),t=this.getElementSize(this.widgetContainerElement,e.width,e.height);this.saveStoredWidgetLayout({panel:{width:Math.abs(t.width-e.width)<=1?null:t.width,height:Math.abs(t.height-e.height)<=1?null:t.height}})}},t.syncTogglePositionToPanel=function(e){if(void 0===e&&(e=!0),this.widgetContainerElement&&this.widgetToggleButtonElement){var t=this.getWidgetDefaultSize(),n=this.getElementSize(this.widgetContainerElement,t.width,t.height),o=this.getElementSize(this.widgetToggleButtonElement,52,52),a=this.getElementPosition(this.widgetContainerElement),s=this.clampWidgetPosition(a.left+n.width-o.width,a.top+n.height+this.getWidgetToggleGap(),o.width,o.height);this.applyAbsolutePosition(this.widgetToggleButtonElement,s.left,s.top),e&&i.widget.persistLayout&&this.persistWidgetTogglePosition()}},t.syncPanelPositionToToggle=function(e){if(void 0===e&&(e=!0),this.widgetContainerElement&&this.widgetToggleButtonElement){var t=this.getWidgetDefaultSize(),n=this.getElementSize(this.widgetContainerElement,t.width,t.height),o=this.getElementSize(this.widgetToggleButtonElement,52,52),a=this.getElementPosition(this.widgetToggleButtonElement),s=this.clampWidgetPosition(a.left+o.width-n.width,a.top-n.height-this.getWidgetToggleGap(),n.width,n.height);this.applyAbsolutePosition(this.widgetContainerElement,s.left,s.top),e&&i.widget.persistLayout&&this.persistWidgetPanelPosition()}},t.updateWidgetResetSizeButtonVisibility=function(){if(this.widgetResetSizeButtonElement)if(i.widget.enableResizing&&this.widgetContainerElement){var e=this.getWidgetDefaultSize(),t=this.getElementSize(this.widgetContainerElement,e.width,e.height),n=Math.abs(t.width-e.width)>1||Math.abs(t.height-e.height)>1||!!this.widgetContainerElement.style.width||!!this.widgetContainerElement.style.height;this.widgetResetSizeButtonElement.classList.toggle("d-none",!n)}else this.widgetResetSizeButtonElement.classList.add("d-none")},t.resetWidgetSize=function(){this.widgetContainerElement&&i.widget.enableResizing&&(this.widgetContainerElement.style.removeProperty("width"),this.widgetContainerElement.style.removeProperty("height"),this.persistWidgetPanelSize(),this.constrainWidgetElementsToViewport(),this.updateWidgetResetSizeButtonVisibility())},t.restoreWidgetLayout=function(){var e=this.getStoredWidgetLayout();this.widgetContainerElement&&i.widget.enableResizing&&(Number.isFinite(e.panel&&e.panel.width)?this.widgetContainerElement.style.width=e.panel.width+"px":this.widgetContainerElement.style.removeProperty("width"),Number.isFinite(e.panel&&e.panel.height)?this.widgetContainerElement.style.height=e.panel.height+"px":this.widgetContainerElement.style.removeProperty("height"));var t=this.getElementSize(this.widgetToggleButtonElement,52,52),n=this.resolveStoredPosition(e.position,t.width,t.height);this.widgetToggleButtonElement&&i.widget.enableDragging&&n?(this.applyAbsolutePosition(this.widgetToggleButtonElement,n.left,n.top),this.syncPanelPositionToToggle(!1)):this.widgetToggleButtonElement&&i.widget.enableDragging&&Number.isFinite(e.toggle&&e.toggle.left)&&Number.isFinite(e.toggle&&e.toggle.top)?(this.applyAbsolutePosition(this.widgetToggleButtonElement,e.toggle.left,e.toggle.top),this.syncPanelPositionToToggle(!1)):this.widgetContainerElement&&i.widget.enableDragging&&Number.isFinite(e.panel&&e.panel.left)&&Number.isFinite(e.panel&&e.panel.top)&&(this.applyAbsolutePosition(this.widgetContainerElement,e.panel.left,e.panel.top),this.syncTogglePositionToPanel(!1)),this.constrainWidgetElementsToViewport(),this.updateWidgetResetSizeButtonVisibility()},t.attachDraggableWidgetElement=function(e,t,n,o){if(e&&t&&i.widget.enableDragging){var a=null,s=0,l=0,r=0,d=0,g=!1,c=this;t.addEventListener("pointerdown",function(i){if(0===i.button&&("panel"!==n||!i.target.closest("button, a, input, textarea, select, option, label"))){var o=e.getBoundingClientRect();s=i.clientX,l=i.clientY,r=o.left,d=o.top,g=!1,a=i.pointerId,e.classList.add("ai-chat-widget-dragging"),t.setPointerCapture&&t.setPointerCapture(i.pointerId),document.addEventListener("pointermove",h),document.addEventListener("pointerup",u),document.addEventListener("pointercancel",u),i.preventDefault()}})}function u(t){null!==a&&(t&&void 0!==t.pointerId&&t.pointerId!==a||(document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",u),document.removeEventListener("pointercancel",u),e.classList.remove("ai-chat-widget-dragging"),a=null,g&&("panel"===n?(c.syncTogglePositionToPanel(!1),c.persistWidgetPanelPosition()):"toggle"===n&&(c.syncPanelPositionToToggle(!1),c.persistWidgetTogglePosition()),i.widget.persistLayout&&(c.persistWidgetPanelPosition(),c.persistWidgetTogglePosition()),o&&(e.dataset.dragSuppressClick="true",window.setTimeout(function(){"true"===e.dataset.dragSuppressClick&&(e.dataset.dragSuppressClick="false")},0)))))}function h(t){if(null!==a&&t.pointerId===a){var i=t.clientX-s,o=t.clientY-l;if(g||!(Math.hypot(i,o)<4)){g=!0;var u=c.getWidgetDefaultSize(),h=c.getElementSize(e,"panel"===n?u.width:52,"panel"===n?u.height:52),w=c.clampWidgetPosition(r+i,d+o,h.width,h.height);c.applyAbsolutePosition(e,w.left,w.top),"panel"===n?c.syncTogglePositionToPanel(!1):"toggle"===n&&c.syncPanelPositionToToggle(!1)}}}},t.constrainWidgetElementsToViewport=function(){if(this.widgetContainerElement&&this.widgetContainerElement.style.left&&this.isWidgetPanelVisible()){var e=this.getWidgetDefaultSize(),t=this.getElementSize(this.widgetContainerElement,e.width,e.height),n=this.getElementPosition(this.widgetContainerElement),o=this.clampWidgetPosition(n.left,n.top,t.width,t.height);this.applyAbsolutePosition(this.widgetContainerElement,o.left,o.top),this.syncTogglePositionToPanel(!1),i.widget.persistLayout&&(this.persistWidgetPanelPosition(),this.persistWidgetTogglePosition())}else if(this.widgetToggleButtonElement&&this.widgetToggleButtonElement.style.left){var a=this.getElementSize(this.widgetToggleButtonElement,52,52),s=this.getElementPosition(this.widgetToggleButtonElement),l=this.clampWidgetPosition(s.left,s.top,a.width,a.height);this.applyAbsolutePosition(this.widgetToggleButtonElement,l.left,l.top),this.syncPanelPositionToToggle(!1),i.widget.persistLayout&&(this.persistWidgetTogglePosition(),this.persistWidgetPanelPosition())}},t.showChatScreen=function(){this.chatHistorySection&&this.chatHistorySection.classList.remove("show")})},initialize:t,onMounted:t,resolveSessionId:function(e){return e&&e.widgetIsInitialized?localStorage.getItem(e.chatWidgetStateSession):null},onSessionInitialized:function(e,t){e&&e.widgetIsInitialized&&localStorage.setItem(e.chatWidgetStateSession,t)},onSessionReset:function(e){e&&e.widgetIsInitialized&&(localStorage.removeItem(e.chatWidgetStateSession),e.clearStoredWidgetDocuments())},onDocumentsChanged:function(e,t){e&&e.widgetIsInitialized&&e.saveStoredWidgetDocuments(t)},handleReceiveError:function(e){e&&e.widgetIsInitialized&&!e.isSessionStarted&&!e._attemptedSessionRecovery&&(e._attemptedSessionRecovery=!0,localStorage.removeItem(e.chatWidgetStateSession),e.clearStoredWidgetDocuments(),e.startNewSession())},dispose:i,onBeforeUnmount:i}}(),window.coreAIChatWidgetManager=window.coreAIChatWidgetManager||function(){function e(e,t){var i=e.getAttribute(t);return null===i||""===i?null:i}function t(e){if(null==e)return null;if("boolean"==typeof e)return e;var t=String(e).trim().toLowerCase();return"true"===t||"false"!==t&&null}function i(t,i,n){var o=e(t,i);if(!o)return null;try{return JSON.parse(o)}catch(e){return console.error("Failed to parse "+n+" JSON.",e),null}}function n(e){if(!e)return null;var t=e.chatConfig;if(!t&&e.configElementSelector){var n=document.querySelector(e.configElementSelector);t=n?i(n,"data-config","AI chat widget config"):null}if(!t)return null;if(e.messageTemplateSelector){var o=document.querySelector(e.messageTemplateSelector);o&&(t.messageTemplate=o.innerHTML)}if(e.indicatorTemplateSelector){var a=document.querySelector(e.indicatorTemplateSelector);a&&(t.indicatorTemplate=a.innerHTML)}var s=document.querySelector(e.shellSelector),l=document.querySelector(e.widgetContainerSelector),r=document.querySelector(e.toggleButtonSelector),d=document.querySelector(e.closeButtonSelector),g=e.inputSelector?document.querySelector(e.inputSelector):null,c=e.widgetStateName||t.widget.chatWidgetStateName,u=e.widgetOpenStateKey||c+"Open",h=c+"Layout",w=e.openStateValue||"open",m=e.closedStateValue||"closed";g&&e.profile&&e.profile.id&&g.setAttribute("data-profile-id",e.profile.id);try{var p=localStorage.getItem(h),f=p&&JSON.parse(p)||{},S=f.position||{},y=f.panel||{},v=Number(S.left),b=Number(S.top),W=localStorage.getItem(u)===w;if(s&&(s.dataset.deferReveal=W?"true":"false",s.dataset.initialOpen=W?"true":"false"),l&&r){var E=Number.isFinite(Number(y.width))?Number(y.width):Math.round(parseFloat(window.getComputedStyle(l).width)||380),P=Number.isFinite(Number(y.height))?Number(y.height):Math.round(parseFloat(window.getComputedStyle(l).height)||520),T=Math.max(8,window.innerWidth-52-8),C=Math.max(8,window.innerHeight-52-8);if(Number.isFinite(Number(S.leftRatio))&&(v=8+Math.max(0,T-8)*Number(S.leftRatio)),Number.isFinite(Number(S.topRatio))&&(b=8+Math.max(0,C-8)*Number(S.topRatio)),Number.isFinite(v)&&Number.isFinite(b)&&(v=Math.round(clampWidgetValue(v,8,T)),b=Math.round(clampWidgetValue(b,8,C))),Number.isFinite(v)&&Number.isFinite(b)){r.style.left=v+"px",r.style.top=b+"px",r.style.right="auto",r.style.bottom="auto";l.style.left=v+52-E+"px",l.style.top=b-P-8+"px",l.style.right="auto",l.style.bottom="auto"}}l&&(l.classList.remove("open"),l.style.display="none",l.setAttribute("aria-hidden","true")),r&&(r.innerHTML=W?e.openIconHtml:e.closedIconHtml)}catch(e){console.warn("Failed to restore widget layout before initialization.",e)}finally{s&&"true"!==s.dataset.deferReveal&&(s.style.visibility="")}var z=window.coreAIChatManager.initialize(t);function L(){s&&(s.style.visibility="",s.dataset.deferReveal="false")}function B(){z&&"function"==typeof z.syncPanelPositionToToggle&&z.syncPanelPositionToToggle(!1)}function R(){l&&l.querySelectorAll("[data-tts-message-index]").forEach(function(e){var t=Number(e.getAttribute("data-tts-message-index"))===z.ttsPlayingMessageIndex;e.classList.toggle("tts-playing",t),e.setAttribute("title",t?"Pause audio":"Read aloud")})}function I(){requestAnimationFrame(R)}function N(t){if(z){var i=l.classList.contains("open");t&&!i&&"function"==typeof z.syncPanelPositionToToggle?z.syncPanelPositionToToggle():!t&&i&&"function"==typeof z.syncTogglePositionToPanel&&z.syncTogglePositionToPanel()}l.classList.toggle("open",t),l.style.display=t?"flex":"none",l.setAttribute("aria-hidden",t?"false":"true"),r.innerHTML=t?e.openIconHtml:e.closedIconHtml,localStorage.setItem(u,t?w:m),t&&"function"==typeof window.renderPendingCharts&&setTimeout(function(){window.renderPendingCharts()},100)}!1!==e.applySessionProfilePatch&&window.crestAppsAIChat&&window.crestAppsAIChat.patchSessionProfileSync&&window.crestAppsAIChat.patchSessionProfileSync(z);var M=s&&"true"===s.dataset.initialOpen;return N(M),function(e){if(s&&"true"===s.dataset.deferReveal&&e){var t=!1,i=null;if("undefined"!=typeof ResizeObserver){var n=0,o=0,a=0;(i=new ResizeObserver(function(e){var t=e&&e[0];if(t){var i=Math.round(t.contentRect.width),s=Math.round(t.contentRect.height);i&&s&&(B(),i===n&&s===o?a++:(n=i,o=s,a=0),a>=1&&r())}})).observe(l),window.setTimeout(r,150)}else window.setTimeout(r,0)}else L();function r(){t||(t=!0,i&&i.disconnect(),requestAnimationFrame(function(){B(),requestAnimationFrame(function(){L()})}))}}(M),z&&"function"==typeof z.$watch&&z.$watch("ttsPlayingMessageIndex",function(){I()}),I(),r&&r.addEventListener("click",function(){"true"!==r.dataset.dragSuppressClick?N(!l.classList.contains("open")):r.dataset.dragSuppressClick="false"}),d&&d.addEventListener("click",function(){N(!1)}),z}function o(o){if(!o||"true"===o.dataset.coreAiChatWidgetInitialized)return o&&o.__coreAIChatWidgetApp||null;var a=i(o,"data-coreai-chat-widget-config","CoreAI chat widget config"),s=function(i){var n=e(i,"data-coreai-chat-widget-container-selector");if(!n)return null;var o=null;window.coreAIChatManager&&"function"==typeof window.coreAIChatManager.buildConfigFromElement&&(o=window.coreAIChatManager.buildConfigFromElement(i,{allowWidgetHost:!0}));var a=e(i,"data-coreai-chat-widget-profile-id"),s=e(i,"data-coreai-chat-widget-profile-name"),l=e(i,"data-coreai-chat-widget-profile-display-text"),r=e(i,"data-coreai-chat-widget-profile-welcome-message"),d=e(i,"data-coreai-chat-widget-profile-chat-mode"),g=e(i,"data-coreai-chat-widget-profile-tts-voice-name"),c=t(e(i,"data-coreai-chat-widget-profile-enable-session-metrics")),u=t(e(i,"data-coreai-chat-widget-profile-allow-session-documents")),h=null;(a||s||l||r||d||g||null!==c||null!==u)&&(h={id:a,name:s,displayText:l,welcomeMessage:r,chatMode:d,ttsVoiceName:g,enableSessionMetrics:!0===c,allowSessionDocuments:!0===u});var w=t(e(i,"data-coreai-chat-widget-enable-dragging")),m=t(e(i,"data-coreai-chat-widget-enable-resizing")),p=t(e(i,"data-coreai-chat-widget-persist-layout"));return{shellSelector:e(i,"data-coreai-chat-widget-shell-selector"),widgetContainerSelector:n,toggleButtonSelector:e(i,"data-coreai-chat-widget-toggle-button-selector"),closeButtonSelector:e(i,"data-coreai-chat-widget-close-button-selector"),inputSelector:e(i,"data-coreai-chat-widget-input-selector"),messageTemplateSelector:e(i,"data-coreai-chat-widget-message-template-selector"),indicatorTemplateSelector:e(i,"data-coreai-chat-widget-indicator-template-selector"),profile:h,widgetStateName:e(i,"data-coreai-chat-widget-state-name"),openStateValue:e(i,"data-coreai-chat-widget-open-state-value"),closedStateValue:e(i,"data-coreai-chat-widget-closed-state-value"),openIconHtml:e(i,"data-coreai-chat-widget-open-icon-html"),closedIconHtml:e(i,"data-coreai-chat-widget-closed-icon-html"),chatConfig:o?Object.assign({},o,{widget:Object.assign({},o.widget||{},{chatWidgetContainer:n,chatWidgetStateName:e(i,"data-coreai-chat-widget-state-name"),newChatButton:e(i,"data-coreai-chat-widget-new-chat-button-selector"),toggleButtonSelector:e(i,"data-coreai-chat-widget-toggle-button-selector"),resetSizeButtonSelector:e(i,"data-coreai-chat-widget-reset-size-button-selector"),dragHandleSelector:e(i,"data-coreai-chat-widget-drag-handle-selector"),enableDragging:null===w?void 0:w,enableResizing:null===m?void 0:m,persistLayout:null===p?void 0:p})}):null}}(o);if(!a&&!s)return null;var l=n(Object.assign({},a||{},s||{}));return l?(o.dataset.coreAiChatWidgetInitialized="true",o.__coreAIChatWidgetApp=l,l):null}function a(e){e&&"function"==typeof e.querySelectorAll&&("function"==typeof e.matches&&e.matches("[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]")&&o(e),e.querySelectorAll("[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]").forEach(o))}function s(){(a(document),"undefined"!=typeof MutationObserver)&&new MutationObserver(function(e){e.forEach(function(e){e.addedNodes.forEach(function(e){e&&1===e.nodeType&&a(e)})})}).observe(document.body,{childList:!0,subtree:!0})}return"loading"===document.readyState?document.addEventListener("DOMContentLoaded",s,{once:!0}):s(),{initialize:n,initializeFromElement:o}}();
1
+ function clampWidgetValue(e,t,i){return Math.min(Math.max(e,t),i)}window.coreAIChatWidgetBehavior=window.coreAIChatWidgetBehavior||function(){function e(e){if("number"==typeof e&&Number.isFinite(e))return e;if("string"!=typeof e)return null;var t=parseFloat(e);return Number.isFinite(t)?t:null}function t(t,i){if(t&&!t.widgetIsInitialized)if(i.widget.chatWidgetContainer)if(i.widget.chatWidgetStateName){var n=document.querySelector(i.widget.chatWidgetContainer);if(n){i.widget.chatHistorySection&&(t.chatHistorySection=document.querySelector(i.widget.chatHistorySection)),t.chatWidgetStateName=i.widget.chatWidgetStateName,t.chatWidgetStateSession=i.widget.chatWidgetStateName+"Session",t.chatWidgetStateDocuments=i.widget.chatWidgetStateName+"Documents",t.chatWidgetLayoutKey=i.widget.chatWidgetStateName+"Layout",t.widgetContainerElement=n,t.widgetToggleButtonElement=i.widget.toggleButtonSelector?document.querySelector(i.widget.toggleButtonSelector):null,t.widgetResetSizeButtonElement=i.widget.resetSizeButtonSelector?document.querySelector(i.widget.resetSizeButtonSelector):null,t.widgetDefaultWidth=e(i.widget.defaultWidth)||e(window.getComputedStyle(n).width)||380,t.widgetDefaultHeight=e(i.widget.defaultHeight)||e(window.getComputedStyle(n).height)||520,t.widgetIsInitialized=!0,t.clearStoredWidgetDocuments(),t.documents=[],i.widget.enableResizing&&(n.classList.add("ai-chat-widget-resizable"),n.style.minWidth=(e(i.widget.minWidth)||320)+"px",n.style.minHeight=(e(i.widget.minHeight)||420)+"px","undefined"!=typeof ResizeObserver&&(t.widgetResizeObserver=new ResizeObserver(function(){t.persistWidgetPanelSize(),t.constrainWidgetElementsToViewport(),t.updateWidgetResetSizeButtonVisibility()}),t.widgetResizeObserver.observe(n)));var o=i.widget.dragHandleSelector||".ai-chat-widget-header",a=n.querySelector(o);if(i.widget.enableDragging&&a&&(a.classList.add("ai-chat-widget-drag-handle"),n.classList.add("ai-chat-widget-draggable"),t.attachDraggableWidgetElement(n,a,"panel",!1)),i.widget.enableDragging&&t.widgetToggleButtonElement&&(t.widgetToggleButtonElement.classList.add("ai-chat-widget-draggable"),t.attachDraggableWidgetElement(t.widgetToggleButtonElement,t.widgetToggleButtonElement,"toggle",!0)),t.widgetResetSizeButtonElement&&t.widgetResetSizeButtonElement.addEventListener("click",function(e){e.preventDefault(),t.resetWidgetSize()}),t.restoreWidgetLayout(),t.widgetViewportResizeHandler||(t.widgetViewportResizeHandler=function(){i.widget.persistLayout?t.restoreWidgetLayout():t.constrainWidgetElementsToViewport(),t.updateWidgetResetSizeButtonVisibility()},window.addEventListener("resize",t.widgetViewportResizeHandler)),t.reloadCurrentSession(),i.widget.showHistoryButton&&t.chatHistorySection){var l=document.querySelector(i.widget.showHistoryButton);if(l&&l.addEventListener("click",function(){t.chatHistorySection.classList.toggle("show")}),i.widget.closeHistoryButton){var s=document.querySelector(i.widget.closeHistoryButton);s&&s.addEventListener("click",function(){t.showChatScreen()})}}if(i.widget.newChatButton){var r=document.querySelector(i.widget.newChatButton);r&&r.addEventListener("click",function(){t.resetSession(),t.showChatScreen()})}}}else console.error("The widget chatWidgetStateName is required.");else console.error("The widget chatWidgetContainer is required.")}function i(e){e&&(e.widgetResizeObserver&&(e.widgetResizeObserver.disconnect(),e.widgetResizeObserver=null),e.widgetViewportResizeHandler&&(window.removeEventListener("resize",e.widgetViewportResizeHandler),e.widgetViewportResizeHandler=null))}return{attach:function(t,i){t&&!t.__aiChatWidgetAttached&&(t.__aiChatWidgetAttached=!0,t.chatWidgetStateName=null,t.chatWidgetStateSession=null,t.chatWidgetStateDocuments=null,t.chatWidgetLayoutKey=null,t.chatHistorySection=null,t.widgetContainerElement=null,t.widgetToggleButtonElement=null,t.widgetResetSizeButtonElement=null,t.widgetResizeObserver=null,t.widgetViewportResizeHandler=null,t.widgetDefaultWidth=null,t.widgetDefaultHeight=null,t.widgetIsInitialized=!1,t.getStoredWidgetLayout=function(){if(!this.chatWidgetLayoutKey||!i.widget.persistLayout)return{};try{var e=localStorage.getItem(this.chatWidgetLayoutKey);return e&&JSON.parse(e)||{}}catch(e){return console.warn("Failed to read widget layout state.",e),{}}},t.saveStoredWidgetLayout=function(e){if(this.chatWidgetLayoutKey&&i.widget.persistLayout){var t=this.getStoredWidgetLayout(),n=Object.assign({},t);void 0!==e.panel&&(n.panel=Object.assign({},t.panel||{},e.panel||{})),void 0!==e.position&&(n.position=Object.assign({},t.position||{},e.position||{})),localStorage.setItem(this.chatWidgetLayoutKey,JSON.stringify(n))}},t.getElementSize=function(t,i,n){if(!t)return{width:i||0,height:n||0};var o=t.getBoundingClientRect(),a=window.getComputedStyle(t);return{width:Math.round(o.width||e(a.width)||i||0),height:Math.round(o.height||e(a.height)||n||0)}},t.getElementPosition=function(t){if(!t)return{left:0,top:0};var i=t.getBoundingClientRect(),n=window.getComputedStyle(t),o=e(t.style.left),a=e(t.style.top),l=e(n.left),s=e(n.top),r="none"===n.display;return{left:Math.round(r&&Number.isFinite(o)?o:i.left||o||l||0),top:Math.round(r&&Number.isFinite(a)?a:i.top||a||s||0)}},t.getAvailableWidgetPositionRange=function(e,t){return{padding:8,maxLeft:Math.max(8,window.innerWidth-e-8),maxTop:Math.max(8,window.innerHeight-t-8)}},t.createStoredPosition=function(e,t,i,n){var o=this.getAvailableWidgetPositionRange(i,n),a=Math.max(0,o.maxLeft-o.padding),l=Math.max(0,o.maxTop-o.padding);return{left:Math.round(e),top:Math.round(t),leftRatio:0===a?0:(e-o.padding)/a,topRatio:0===l?0:(t-o.padding)/l}},t.resolveStoredPosition=function(e,t,i){if(!e)return null;var n=this.getAvailableWidgetPositionRange(t,i),o=Number(e.left),a=Number(e.top),l=Number(e.leftRatio),s=Number(e.topRatio);return Number.isFinite(l)&&(o=n.padding+Math.max(0,n.maxLeft-n.padding)*l),Number.isFinite(s)&&(a=n.padding+Math.max(0,n.maxTop-n.padding)*s),Number.isFinite(o)&&Number.isFinite(a)?this.clampWidgetPosition(o,a,t,i):null},t.clampWidgetPosition=function(e,t,i,n){var o=this.getAvailableWidgetPositionRange(i,n);return{left:Math.round(clampWidgetValue(e,o.padding,o.maxLeft)),top:Math.round(clampWidgetValue(t,o.padding,o.maxTop))}},t.getStoredWidgetDocuments=function(){return this.clearStoredWidgetDocuments(),[]},t.saveStoredWidgetDocuments=function(){this.clearStoredWidgetDocuments()},t.clearStoredWidgetDocuments=function(){this.chatWidgetStateDocuments&&localStorage.removeItem(this.chatWidgetStateDocuments)},t.applyAbsolutePosition=function(e,t,i){e&&(e.style.left=t+"px",e.style.top=i+"px",e.style.right="auto",e.style.bottom="auto")},t.getWidgetDefaultSize=function(){return{width:this.widgetDefaultWidth||e(i.widget.defaultWidth)||380,height:this.widgetDefaultHeight||e(i.widget.defaultHeight)||520}},t.getWidgetToggleGap=function(){return 8},t.isWidgetPanelVisible=function(){if(!this.widgetContainerElement)return!1;var e=window.getComputedStyle(this.widgetContainerElement);return this.widgetContainerElement.classList.contains("open")&&"none"!==e.display},t.persistWidgetPanelPosition=function(){if(this.widgetContainerElement&&i.widget.persistLayout){var e=this.getWidgetDefaultSize(),t=this.getElementPosition(this.widgetContainerElement),n=this.getElementSize(this.widgetContainerElement,e.width,e.height),o=this.getElementSize(this.widgetToggleButtonElement,52,52),a=this.clampWidgetPosition(t.left+n.width-o.width,t.top+n.height+this.getWidgetToggleGap(),o.width,o.height);this.saveStoredWidgetLayout({position:this.createStoredPosition(a.left,a.top,o.width,o.height)})}},t.persistWidgetTogglePosition=function(){if(this.widgetToggleButtonElement&&i.widget.persistLayout){var e=this.getElementPosition(this.widgetToggleButtonElement),t=this.getElementSize(this.widgetToggleButtonElement,52,52);this.saveStoredWidgetLayout({position:this.createStoredPosition(e.left,e.top,t.width,t.height)})}},t.persistWidgetPanelSize=function(){if(this.widgetContainerElement&&i.widget.enableResizing&&i.widget.persistLayout){var e=this.getWidgetDefaultSize(),t=this.getElementSize(this.widgetContainerElement,e.width,e.height);this.saveStoredWidgetLayout({panel:{width:Math.abs(t.width-e.width)<=1?null:t.width,height:Math.abs(t.height-e.height)<=1?null:t.height}})}},t.syncTogglePositionToPanel=function(e){if(void 0===e&&(e=!0),this.widgetContainerElement&&this.widgetToggleButtonElement){var t=this.getWidgetDefaultSize(),n=this.getElementSize(this.widgetContainerElement,t.width,t.height),o=this.getElementSize(this.widgetToggleButtonElement,52,52),a=this.getElementPosition(this.widgetContainerElement),l=this.clampWidgetPosition(a.left+n.width-o.width,a.top+n.height+this.getWidgetToggleGap(),o.width,o.height);this.applyAbsolutePosition(this.widgetToggleButtonElement,l.left,l.top),e&&i.widget.persistLayout&&this.persistWidgetTogglePosition()}},t.syncPanelPositionToToggle=function(e){if(void 0===e&&(e=!0),this.widgetContainerElement&&this.widgetToggleButtonElement){var t=this.getWidgetDefaultSize(),n=this.getElementSize(this.widgetContainerElement,t.width,t.height),o=this.getElementSize(this.widgetToggleButtonElement,52,52),a=this.getElementPosition(this.widgetToggleButtonElement),l=this.clampWidgetPosition(a.left+o.width-n.width,a.top-n.height-this.getWidgetToggleGap(),n.width,n.height);this.applyAbsolutePosition(this.widgetContainerElement,l.left,l.top),e&&i.widget.persistLayout&&this.persistWidgetPanelPosition()}},t.updateWidgetResetSizeButtonVisibility=function(){if(this.widgetResetSizeButtonElement)if(i.widget.enableResizing&&this.widgetContainerElement){var e=this.getWidgetDefaultSize(),t=this.getElementSize(this.widgetContainerElement,e.width,e.height),n=Math.abs(t.width-e.width)>1||Math.abs(t.height-e.height)>1||!!this.widgetContainerElement.style.width||!!this.widgetContainerElement.style.height;this.widgetResetSizeButtonElement.classList.toggle("d-none",!n)}else this.widgetResetSizeButtonElement.classList.add("d-none")},t.resetWidgetSize=function(){this.widgetContainerElement&&i.widget.enableResizing&&(this.widgetContainerElement.style.removeProperty("width"),this.widgetContainerElement.style.removeProperty("height"),this.persistWidgetPanelSize(),this.constrainWidgetElementsToViewport(),this.updateWidgetResetSizeButtonVisibility())},t.restoreWidgetLayout=function(){var e=this.getStoredWidgetLayout();this.widgetContainerElement&&i.widget.enableResizing&&(Number.isFinite(e.panel&&e.panel.width)?this.widgetContainerElement.style.width=e.panel.width+"px":this.widgetContainerElement.style.removeProperty("width"),Number.isFinite(e.panel&&e.panel.height)?this.widgetContainerElement.style.height=e.panel.height+"px":this.widgetContainerElement.style.removeProperty("height"));var t=this.getElementSize(this.widgetToggleButtonElement,52,52),n=this.resolveStoredPosition(e.position,t.width,t.height);this.widgetToggleButtonElement&&i.widget.enableDragging&&n?(this.applyAbsolutePosition(this.widgetToggleButtonElement,n.left,n.top),this.syncPanelPositionToToggle(!1)):this.widgetToggleButtonElement&&i.widget.enableDragging&&Number.isFinite(e.toggle&&e.toggle.left)&&Number.isFinite(e.toggle&&e.toggle.top)?(this.applyAbsolutePosition(this.widgetToggleButtonElement,e.toggle.left,e.toggle.top),this.syncPanelPositionToToggle(!1)):this.widgetContainerElement&&i.widget.enableDragging&&Number.isFinite(e.panel&&e.panel.left)&&Number.isFinite(e.panel&&e.panel.top)&&(this.applyAbsolutePosition(this.widgetContainerElement,e.panel.left,e.panel.top),this.syncTogglePositionToPanel(!1)),this.constrainWidgetElementsToViewport(),this.updateWidgetResetSizeButtonVisibility()},t.attachDraggableWidgetElement=function(e,t,n,o){if(e&&t&&i.widget.enableDragging){var a=null,l=0,s=0,r=0,d=0,g=!1,c=this;t.addEventListener("pointerdown",function(i){if(0===i.button&&("panel"!==n||!i.target.closest("button, a, input, textarea, select, option, label"))){var o=e.getBoundingClientRect();l=i.clientX,s=i.clientY,r=o.left,d=o.top,g=!1,a=i.pointerId,e.classList.add("ai-chat-widget-dragging"),t.setPointerCapture&&t.setPointerCapture(i.pointerId),document.addEventListener("pointermove",h),document.addEventListener("pointerup",u),document.addEventListener("pointercancel",u),i.preventDefault()}})}function u(t){null!==a&&(t&&void 0!==t.pointerId&&t.pointerId!==a||(document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",u),document.removeEventListener("pointercancel",u),e.classList.remove("ai-chat-widget-dragging"),a=null,g&&("panel"===n?(c.syncTogglePositionToPanel(!1),c.persistWidgetPanelPosition()):"toggle"===n&&(c.syncPanelPositionToToggle(!1),c.persistWidgetTogglePosition()),i.widget.persistLayout&&(c.persistWidgetPanelPosition(),c.persistWidgetTogglePosition()),o&&(e.dataset.dragSuppressClick="true",window.setTimeout(function(){"true"===e.dataset.dragSuppressClick&&(e.dataset.dragSuppressClick="false")},0)))))}function h(t){if(null!==a&&t.pointerId===a){var i=t.clientX-l,o=t.clientY-s;if(g||!(Math.hypot(i,o)<4)){g=!0;var u=c.getWidgetDefaultSize(),h=c.getElementSize(e,"panel"===n?u.width:52,"panel"===n?u.height:52),w=c.clampWidgetPosition(r+i,d+o,h.width,h.height);c.applyAbsolutePosition(e,w.left,w.top),"panel"===n?c.syncTogglePositionToPanel(!1):"toggle"===n&&c.syncPanelPositionToToggle(!1)}}}},t.constrainWidgetElementsToViewport=function(){if(this.widgetContainerElement&&this.widgetContainerElement.style.left&&this.isWidgetPanelVisible()){var e=this.getWidgetDefaultSize(),t=this.getElementSize(this.widgetContainerElement,e.width,e.height),n=this.getElementPosition(this.widgetContainerElement),o=this.clampWidgetPosition(n.left,n.top,t.width,t.height);this.applyAbsolutePosition(this.widgetContainerElement,o.left,o.top),this.syncTogglePositionToPanel(!1),i.widget.persistLayout&&(this.persistWidgetPanelPosition(),this.persistWidgetTogglePosition())}else if(this.widgetToggleButtonElement&&this.widgetToggleButtonElement.style.left){var a=this.getElementSize(this.widgetToggleButtonElement,52,52),l=this.getElementPosition(this.widgetToggleButtonElement),s=this.clampWidgetPosition(l.left,l.top,a.width,a.height);this.applyAbsolutePosition(this.widgetToggleButtonElement,s.left,s.top),this.syncPanelPositionToToggle(!1),i.widget.persistLayout&&(this.persistWidgetTogglePosition(),this.persistWidgetPanelPosition())}},t.showChatScreen=function(){this.chatHistorySection&&this.chatHistorySection.classList.remove("show")})},initialize:t,onMounted:t,resolveSessionId:function(e){return e&&e.widgetIsInitialized?localStorage.getItem(e.chatWidgetStateSession):null},onSessionInitialized:function(e,t){e&&e.widgetIsInitialized&&localStorage.setItem(e.chatWidgetStateSession,t)},onSessionReset:function(e){e&&e.widgetIsInitialized&&(localStorage.removeItem(e.chatWidgetStateSession),e.clearStoredWidgetDocuments())},onDocumentsChanged:function(e,t){e&&e.widgetIsInitialized&&e.saveStoredWidgetDocuments(t)},handleReceiveError:function(e){e&&e.widgetIsInitialized&&!e.isSessionStarted&&!e._attemptedSessionRecovery&&(e._attemptedSessionRecovery=!0,localStorage.removeItem(e.chatWidgetStateSession),e.clearStoredWidgetDocuments(),e.startNewSession())},dispose:i,onBeforeUnmount:i}}(),window.coreAIChatWidgetManager=window.coreAIChatWidgetManager||function(){function e(e,t){var i=e.getAttribute(t);return null===i||""===i?null:i}function t(e){if(null==e)return null;if("boolean"==typeof e)return e;var t=String(e).trim().toLowerCase();return"true"===t||"false"!==t&&null}function i(t,i,n){var o=e(t,i);if(!o)return null;try{return JSON.parse(o)}catch(e){return console.error("Failed to parse "+n+" JSON.",e),null}}function n(e){if(!e)return null;var t=e.chatConfig;if(!t&&e.configElementSelector){var n=document.querySelector(e.configElementSelector);t=n?i(n,"data-config","AI chat widget config"):null}if(!t)return null;if(e.messageTemplateSelector){var o=document.querySelector(e.messageTemplateSelector);o&&(t.messageTemplate=o.innerHTML)}if(e.indicatorTemplateSelector){var a=document.querySelector(e.indicatorTemplateSelector);a&&(t.indicatorTemplate=a.innerHTML)}var l=document.querySelector(e.shellSelector),s=document.querySelector(e.widgetContainerSelector),r=document.querySelector(e.toggleButtonSelector),d=document.querySelector(e.closeButtonSelector),g=e.inputSelector?document.querySelector(e.inputSelector):null,c=e.widgetStateName||t.widget.chatWidgetStateName,u=e.widgetOpenStateKey||c+"Open",h=c+"Layout",w=e.openStateValue||"open",m=e.closedStateValue||"closed";g&&e.profile&&e.profile.id&&g.setAttribute("data-profile-id",e.profile.id);try{var p=localStorage.getItem(h),f=p&&JSON.parse(p)||{},S=f.position||{},y=f.panel||{},v=Number(S.left),b=Number(S.top),W=localStorage.getItem(u)===w;if(l&&(l.dataset.deferReveal=W?"true":"false",l.dataset.initialOpen=W?"true":"false"),s&&r){var E=Number.isFinite(Number(y.width))?Number(y.width):Math.round(parseFloat(window.getComputedStyle(s).width)||380),P=Number.isFinite(Number(y.height))?Number(y.height):Math.round(parseFloat(window.getComputedStyle(s).height)||520),T=Math.max(8,window.innerWidth-52-8),C=Math.max(8,window.innerHeight-52-8);if(Number.isFinite(Number(S.leftRatio))&&(v=8+Math.max(0,T-8)*Number(S.leftRatio)),Number.isFinite(Number(S.topRatio))&&(b=8+Math.max(0,C-8)*Number(S.topRatio)),Number.isFinite(v)&&Number.isFinite(b)&&(v=Math.round(clampWidgetValue(v,8,T)),b=Math.round(clampWidgetValue(b,8,C))),Number.isFinite(v)&&Number.isFinite(b)){r.style.left=v+"px",r.style.top=b+"px",r.style.right="auto",r.style.bottom="auto";s.style.left=v+52-E+"px",s.style.top=b-P-8+"px",s.style.right="auto",s.style.bottom="auto"}}s&&(s.classList.remove("open"),s.style.display="none",s.setAttribute("aria-hidden","true")),r&&(r.innerHTML=W?e.openIconHtml:e.closedIconHtml)}catch(e){console.warn("Failed to restore widget layout before initialization.",e)}finally{l&&"true"!==l.dataset.deferReveal&&(l.style.visibility="")}var z=window.coreAIChatManager.initialize(t);function L(){l&&(l.style.visibility="",l.dataset.deferReveal="false")}function B(){z&&"function"==typeof z.syncPanelPositionToToggle&&z.syncPanelPositionToToggle(!1)}function R(){s&&s.querySelectorAll("[data-tts-message-index]").forEach(function(e){var t=Number(e.getAttribute("data-tts-message-index"))===z.ttsPlayingMessageIndex;e.classList.toggle("tts-playing",t),e.setAttribute("title",t?"Pause audio":"Read aloud")})}function I(){requestAnimationFrame(R)}function N(t){if(z){var i=s.classList.contains("open");t&&!i&&"function"==typeof z.syncPanelPositionToToggle?z.syncPanelPositionToToggle():!t&&i&&"function"==typeof z.syncTogglePositionToPanel&&z.syncTogglePositionToPanel()}s.classList.toggle("open",t),s.style.display=t?"flex":"none",s.setAttribute("aria-hidden",t?"false":"true"),r.innerHTML=t?e.openIconHtml:e.closedIconHtml,localStorage.setItem(u,t?w:m),t&&"function"==typeof window.renderPendingCharts&&setTimeout(function(){window.renderPendingCharts()},100)}!1!==e.applySessionProfilePatch&&window.crestAppsAIChat&&window.crestAppsAIChat.patchSessionProfileSync&&window.crestAppsAIChat.patchSessionProfileSync(z);var M=l&&"true"===l.dataset.initialOpen;return N(M),function(e){if(l&&"true"===l.dataset.deferReveal&&e){var t=!1,i=null;if("undefined"!=typeof ResizeObserver){var n=0,o=0,a=0;(i=new ResizeObserver(function(e){var t=e&&e[0];if(t){var i=Math.round(t.contentRect.width),l=Math.round(t.contentRect.height);i&&l&&(B(),i===n&&l===o?a++:(n=i,o=l,a=0),a>=1&&r())}})).observe(s),window.setTimeout(r,150)}else window.setTimeout(r,0)}else L();function r(){t||(t=!0,i&&i.disconnect(),requestAnimationFrame(function(){B(),requestAnimationFrame(function(){L()})}))}}(M),z&&"function"==typeof z.$watch&&z.$watch("ttsPlayingMessageIndex",function(){I()}),I(),r&&r.addEventListener("click",function(){"true"!==r.dataset.dragSuppressClick?N(!s.classList.contains("open")):r.dataset.dragSuppressClick="false"}),d&&d.addEventListener("click",function(){N(!1)}),z}function o(o){if(!o||"true"===o.dataset.coreAiChatWidgetInitialized)return o&&o.__coreAIChatWidgetApp||null;var a=i(o,"data-coreai-chat-widget-config","CoreAI chat widget config"),l=function(i){var n=e(i,"data-coreai-chat-widget-container-selector");if(!n)return null;var o=null;window.coreAIChatManager&&"function"==typeof window.coreAIChatManager.buildConfigFromElement&&(o=window.coreAIChatManager.buildConfigFromElement(i,{allowWidgetHost:!0}));var a=e(i,"data-coreai-chat-widget-profile-id"),l=e(i,"data-coreai-chat-widget-profile-name"),s=e(i,"data-coreai-chat-widget-profile-display-text"),r=e(i,"data-coreai-chat-widget-profile-welcome-message"),d=e(i,"data-coreai-chat-widget-profile-initial-prompt"),g=e(i,"data-coreai-chat-widget-profile-chat-mode"),c=e(i,"data-coreai-chat-widget-profile-tts-voice-name"),u=t(e(i,"data-coreai-chat-widget-profile-enable-session-metrics")),h=t(e(i,"data-coreai-chat-widget-profile-allow-session-documents")),w=null;(a||l||s||r||g||c||null!==u||null!==h)&&(w={id:a,name:l,displayText:s,welcomeMessage:r,initialPrompt:d,chatMode:g,ttsVoiceName:c,enableSessionMetrics:!0===u,allowSessionDocuments:!0===h});var m=t(e(i,"data-coreai-chat-widget-enable-dragging")),p=t(e(i,"data-coreai-chat-widget-enable-resizing")),f=t(e(i,"data-coreai-chat-widget-persist-layout"));return{shellSelector:e(i,"data-coreai-chat-widget-shell-selector"),widgetContainerSelector:n,toggleButtonSelector:e(i,"data-coreai-chat-widget-toggle-button-selector"),closeButtonSelector:e(i,"data-coreai-chat-widget-close-button-selector"),inputSelector:e(i,"data-coreai-chat-widget-input-selector"),messageTemplateSelector:e(i,"data-coreai-chat-widget-message-template-selector"),indicatorTemplateSelector:e(i,"data-coreai-chat-widget-indicator-template-selector"),profile:w,widgetStateName:e(i,"data-coreai-chat-widget-state-name"),openStateValue:e(i,"data-coreai-chat-widget-open-state-value"),closedStateValue:e(i,"data-coreai-chat-widget-closed-state-value"),openIconHtml:e(i,"data-coreai-chat-widget-open-icon-html"),closedIconHtml:e(i,"data-coreai-chat-widget-closed-icon-html"),chatConfig:o?Object.assign({},o,{initialPrompt:d||o.initialPrompt,widget:Object.assign({},o.widget||{},{chatWidgetContainer:n,chatWidgetStateName:e(i,"data-coreai-chat-widget-state-name"),newChatButton:e(i,"data-coreai-chat-widget-new-chat-button-selector"),toggleButtonSelector:e(i,"data-coreai-chat-widget-toggle-button-selector"),resetSizeButtonSelector:e(i,"data-coreai-chat-widget-reset-size-button-selector"),dragHandleSelector:e(i,"data-coreai-chat-widget-drag-handle-selector"),enableDragging:null===m?void 0:m,enableResizing:null===p?void 0:p,persistLayout:null===f?void 0:f})}):null}}(o);if(!a&&!l)return null;var s=n(Object.assign({},a||{},l||{}));return s?(o.dataset.coreAiChatWidgetInitialized="true",o.__coreAIChatWidgetApp=s,s):null}function a(e){e&&"function"==typeof e.querySelectorAll&&("function"==typeof e.matches&&e.matches("[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]")&&o(e),e.querySelectorAll("[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]").forEach(o))}function l(){(a(document),"undefined"!=typeof MutationObserver)&&new MutationObserver(function(e){e.forEach(function(e){e.addedNodes.forEach(function(e){e&&1===e.nodeType&&a(e)})})}).observe(document.body,{childList:!0,subtree:!0})}return"loading"===document.readyState?document.addEventListener("DOMContentLoaded",l,{once:!0}):l(),{initialize:n,initializeFromElement:o}}();
2
2
  //# sourceMappingURL=ai-chat-widget.min.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["ai-chat-widget.js"],"names":["clampWidgetValue","value","min","max","Math","window","coreAIChatWidgetBehavior","parsePixelValue","Number","isFinite","parsed","parseFloat","initialize","app","config","widgetIsInitialized","widget","chatWidgetContainer","chatWidgetStateName","document","querySelector","chatHistorySection","chatWidgetStateSession","chatWidgetStateDocuments","chatWidgetLayoutKey","widgetContainerElement","widgetToggleButtonElement","toggleButtonSelector","widgetResetSizeButtonElement","resetSizeButtonSelector","widgetDefaultWidth","defaultWidth","getComputedStyle","width","widgetDefaultHeight","defaultHeight","height","clearStoredWidgetDocuments","documents","enableResizing","classList","add","style","minWidth","minHeight","ResizeObserver","widgetResizeObserver","persistWidgetPanelSize","constrainWidgetElementsToViewport","updateWidgetResetSizeButtonVisibility","observe","dragHandleSelector","dragHandle","enableDragging","attachDraggableWidgetElement","addEventListener","event","preventDefault","resetWidgetSize","restoreWidgetLayout","widgetViewportResizeHandler","persistLayout","reloadCurrentSession","autoCreateSession","getSessionId","startNewSession","showHistoryButton","toggle","closeHistoryButton","showChatScreen","newChatButton","resetSession","console","error","dispose","disconnect","removeEventListener","attach","__aiChatWidgetAttached","getStoredWidgetLayout","this","storedLayout","localStorage","getItem","JSON","parse","warn","saveStoredWidgetLayout","partialLayout","currentLayout","nextLayout","Object","assign","undefined","panel","position","setItem","stringify","getElementSize","element","fallbackWidth","fallbackHeight","rect","getBoundingClientRect","computed","round","getElementPosition","left","top","inlineLeft","inlineTop","computedLeft","computedTop","isHidden","display","getAvailableWidgetPositionRange","padding","maxLeft","innerWidth","maxTop","innerHeight","createStoredPosition","range","leftSpan","topSpan","leftRatio","topRatio","resolveStoredPosition","storedPosition","clampWidgetPosition","getStoredWidgetDocuments","saveStoredWidgetDocuments","removeItem","applyAbsolutePosition","right","bottom","getWidgetDefaultSize","getWidgetToggleGap","isWidgetPanelVisible","contains","persistWidgetPanelPosition","panelDefaultSize","panelPosition","panelSize","toggleSize","linkedPosition","persistWidgetTogglePosition","togglePosition","defaultSize","currentSize","abs","syncTogglePositionToPanel","syncPanelPositionToToggle","isResized","removeProperty","storedTogglePosition","handle","layoutKey","suppressClickOnDrag","activePointerId","startX","startY","startLeft","startTop","dragged","self","button","target","closest","clientX","clientY","pointerId","setPointerCapture","onPointerMove","stopDragging","remove","dataset","dragSuppressClick","setTimeout","deltaX","deltaY","hypot","nextPosition","clampedPanel","clampedToggle","onMounted","resolveSessionId","onSessionInitialized","sessionId","onSessionReset","onDocumentsChanged","handleReceiveError","isSessionStarted","_attemptedSessionRecovery","onBeforeUnmount","coreAIChatWidgetManager","getAttributeValue","attributeName","getAttribute","parseBooleanAttributeValue","normalized","String","trim","toLowerCase","parseJsonAttribute","description","rawValue","options","chatConfig","configElementSelector","configElement","messageTemplateSelector","messageTemplate","innerHTML","indicatorTemplateSelector","indicatorTemplate","shell","shellSelector","widgetContainer","widgetContainerSelector","toggleButton","closeButton","closeButtonSelector","profileInput","inputSelector","widgetStateName","widgetOpenStateKey","widgetLayoutKey","openStateValue","closedStateValue","profile","id","setAttribute","layout","panelLayout","toggleLeft","toggleTop","isOpen","deferReveal","initialOpen","panelWidth","panelHeight","openIconHtml","closedIconHtml","visibility","widgetApp","coreAIChatManager","revealShell","syncOpenPanelPosition","updateTtsPlaybackButtons","querySelectorAll","forEach","isPlaying","ttsPlayingMessageIndex","queueTtsPlaybackButtonUpdate","requestAnimationFrame","setWidgetOpen","isCurrentlyOpen","renderPendingCharts","applySessionProfilePatch","crestAppsAIChat","patchSessionProfileSync","hasRevealed","resizeObserver","lastWidth","lastHeight","stablePasses","entries","entry","contentRect","finalizeReveal","revealShellWhenStable","$watch","initializeFromElement","coreAiChatWidgetInitialized","__coreAIChatWidgetApp","jsonOptions","attributeOptions","buildConfigFromElement","allowWidgetHost","profileId","profileName","profileDisplayText","profileWelcomeMessage","profileChatMode","profileTtsVoiceName","profileMetricsEnabled","profileSessionDocuments","name","displayText","welcomeMessage","chatMode","ttsVoiceName","enableSessionMetrics","allowSessionDocuments","buildOptionsFromDataAttributes","scanForAutoInitialization","root","matches","startAutoInitialization","MutationObserver","mutations","mutation","addedNodes","node","nodeType","body","childList","subtree","readyState","once"],"mappings":"AAAA,SAASA,iBAAiBC,EAAOC,EAAKC,GAClC,OAAOC,KAAKF,IAAIE,KAAKD,IAAIF,EAAOC,GAAMC,EAC1C,CAEAE,OAAOC,yBAA2BD,OAAOC,0BAA4B,WACjE,SAASC,EAAgBN,GACrB,GAAqB,iBAAVA,GAAsBO,OAAOC,SAASR,GAC7C,OAAOA,EAGX,GAAqB,iBAAVA,EACP,OAAO,KAG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/K,EAAQgL,sBAAwB9B,EAEzBA,GANI,IAOf,CAEA,SAASmD,EAA0BC,GAC1BA,GAAyC,mBAA1BA,EAAK/C,mBAIG,mBAAjB+C,EAAKC,SAA0BD,EAAKC,QAAQ,kFACnDzB,EAAsBwB,GAG1BA,EAAK/C,iBAAiB,iFAAiFC,QAAQsB,GACnH,CAEA,SAAS0B,KACLH,EAA0BrR,UAEM,oBAArByR,mBAII,IAAIA,iBAAiB,SAAUC,GAC1CA,EAAUlD,QAAQ,SAAUmD,GACxBA,EAASC,WAAWpD,QAAQ,SAAUqD,GAC9BA,GAA0B,IAAlBA,EAAKC,UACbT,EAA0BQ,EAElC,EACJ,EACJ,GAES9P,QAAQ/B,SAAS+R,KAAM,CAC5BC,WAAW,EACXC,SAAS,GAEjB,CAQA,MAN4B,YAAxBjS,SAASkS,WACTlS,SAASoC,iBAAiB,mBAAoBoP,EAAyB,CAAEW,MAAM,IAE/EX,IAGG,CACH/R,WAAYA,EACZqQ,sBAAuBA,EAE/B,CAvcmE","file":"ai-chat-widget.min.js","sourcesContent":["function clampWidgetValue(value, min, max) {\n return Math.min(Math.max(value, min), max);\n}\n\nwindow.coreAIChatWidgetBehavior = window.coreAIChatWidgetBehavior || function () {\n function parsePixelValue(value) {\n if (typeof value === 'number' && Number.isFinite(value)) {\n return value;\n }\n\n if (typeof value !== 'string') {\n return null;\n }\n\n var parsed = parseFloat(value);\n return Number.isFinite(parsed) ? parsed : null;\n }\n\n function attach(app, config) {\n if (!app || app.__aiChatWidgetAttached) {\n return;\n }\n\n app.__aiChatWidgetAttached = true;\n app.chatWidgetStateName = null;\n app.chatWidgetStateSession = null;\n app.chatWidgetStateDocuments = null;\n app.chatWidgetLayoutKey = null;\n app.chatHistorySection = null;\n app.widgetContainerElement = null;\n app.widgetToggleButtonElement = null;\n app.widgetResetSizeButtonElement = null;\n app.widgetResizeObserver = null;\n app.widgetViewportResizeHandler = null;\n app.widgetDefaultWidth = null;\n app.widgetDefaultHeight = null;\n app.widgetIsInitialized = false;\n\n app.getStoredWidgetLayout = function () {\n if (!this.chatWidgetLayoutKey || !config.widget.persistLayout) {\n return {};\n }\n\n try {\n var storedLayout = localStorage.getItem(this.chatWidgetLayoutKey);\n return storedLayout ? JSON.parse(storedLayout) || {} : {};\n }\n catch (error) {\n console.warn('Failed to read widget layout state.', error);\n return {};\n }\n };\n\n app.saveStoredWidgetLayout = function (partialLayout) {\n if (!this.chatWidgetLayoutKey || !config.widget.persistLayout) {\n return;\n }\n\n var currentLayout = this.getStoredWidgetLayout();\n var nextLayout = Object.assign({}, currentLayout);\n\n if (partialLayout.panel !== undefined) {\n nextLayout.panel = Object.assign({}, currentLayout.panel || {}, partialLayout.panel || {});\n }\n\n if (partialLayout.position !== undefined) {\n nextLayout.position = Object.assign({}, currentLayout.position || {}, partialLayout.position || {});\n }\n\n localStorage.setItem(this.chatWidgetLayoutKey, JSON.stringify(nextLayout));\n };\n\n app.getElementSize = function (element, fallbackWidth, fallbackHeight) {\n if (!element) {\n return {\n width: fallbackWidth || 0,\n height: fallbackHeight || 0\n };\n }\n\n var rect = element.getBoundingClientRect();\n var computed = window.getComputedStyle(element);\n\n return {\n width: Math.round(rect.width || parsePixelValue(computed.width) || fallbackWidth || 0),\n height: Math.round(rect.height || parsePixelValue(computed.height) || fallbackHeight || 0)\n };\n };\n\n app.getElementPosition = function (element) {\n if (!element) {\n return {\n left: 0,\n top: 0\n };\n }\n\n var rect = element.getBoundingClientRect();\n var computed = window.getComputedStyle(element);\n var inlineLeft = parsePixelValue(element.style.left);\n var inlineTop = parsePixelValue(element.style.top);\n var computedLeft = parsePixelValue(computed.left);\n var computedTop = parsePixelValue(computed.top);\n var isHidden = computed.display === 'none';\n\n return {\n left: Math.round(isHidden && Number.isFinite(inlineLeft) ? inlineLeft : rect.left || inlineLeft || computedLeft || 0),\n top: Math.round(isHidden && Number.isFinite(inlineTop) ? inlineTop : rect.top || inlineTop || computedTop || 0)\n };\n };\n\n app.getAvailableWidgetPositionRange = function (width, height) {\n var viewportPadding = 8;\n return {\n padding: viewportPadding,\n maxLeft: Math.max(viewportPadding, window.innerWidth - width - viewportPadding),\n maxTop: Math.max(viewportPadding, window.innerHeight - height - viewportPadding)\n };\n };\n\n app.createStoredPosition = function (left, top, width, height) {\n var range = this.getAvailableWidgetPositionRange(width, height);\n var leftSpan = Math.max(0, range.maxLeft - range.padding);\n var topSpan = Math.max(0, range.maxTop - range.padding);\n\n return {\n left: Math.round(left),\n top: Math.round(top),\n leftRatio: leftSpan === 0 ? 0 : (left - range.padding) / leftSpan,\n topRatio: topSpan === 0 ? 0 : (top - range.padding) / topSpan\n };\n };\n\n app.resolveStoredPosition = function (storedPosition, width, height) {\n if (!storedPosition) {\n return null;\n }\n\n var range = this.getAvailableWidgetPositionRange(width, height);\n var left = Number(storedPosition.left);\n var top = Number(storedPosition.top);\n var leftRatio = Number(storedPosition.leftRatio);\n var topRatio = Number(storedPosition.topRatio);\n\n if (Number.isFinite(leftRatio)) {\n left = range.padding + Math.max(0, range.maxLeft - range.padding) * leftRatio;\n }\n\n if (Number.isFinite(topRatio)) {\n top = range.padding + Math.max(0, range.maxTop - range.padding) * topRatio;\n }\n\n if (!Number.isFinite(left) || !Number.isFinite(top)) {\n return null;\n }\n\n return this.clampWidgetPosition(left, top, width, height);\n };\n\n app.clampWidgetPosition = function (left, top, width, height) {\n var range = this.getAvailableWidgetPositionRange(width, height);\n\n return {\n left: Math.round(clampWidgetValue(left, range.padding, range.maxLeft)),\n top: Math.round(clampWidgetValue(top, range.padding, range.maxTop))\n };\n };\n\n app.getStoredWidgetDocuments = function () {\n this.clearStoredWidgetDocuments();\n return [];\n };\n\n app.saveStoredWidgetDocuments = function () {\n this.clearStoredWidgetDocuments();\n };\n\n app.clearStoredWidgetDocuments = function () {\n if (!this.chatWidgetStateDocuments) {\n return;\n }\n\n localStorage.removeItem(this.chatWidgetStateDocuments);\n };\n\n app.applyAbsolutePosition = function (element, left, top) {\n if (!element) {\n return;\n }\n\n element.style.left = left + 'px';\n element.style.top = top + 'px';\n element.style.right = 'auto';\n element.style.bottom = 'auto';\n };\n\n app.getWidgetDefaultSize = function () {\n return {\n width: this.widgetDefaultWidth || parsePixelValue(config.widget.defaultWidth) || 380,\n height: this.widgetDefaultHeight || parsePixelValue(config.widget.defaultHeight) || 520\n };\n };\n\n app.getWidgetToggleGap = function () {\n return 8;\n };\n\n app.isWidgetPanelVisible = function () {\n if (!this.widgetContainerElement) {\n return false;\n }\n\n var computed = window.getComputedStyle(this.widgetContainerElement);\n return this.widgetContainerElement.classList.contains('open') && computed.display !== 'none';\n };\n\n app.persistWidgetPanelPosition = function () {\n if (!this.widgetContainerElement || !config.widget.persistLayout) {\n return;\n }\n\n var panelDefaultSize = this.getWidgetDefaultSize();\n var panelPosition = this.getElementPosition(this.widgetContainerElement);\n var panelSize = this.getElementSize(this.widgetContainerElement, panelDefaultSize.width, panelDefaultSize.height);\n var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);\n var linkedPosition = this.clampWidgetPosition(\n panelPosition.left + panelSize.width - toggleSize.width,\n panelPosition.top + panelSize.height + this.getWidgetToggleGap(),\n toggleSize.width,\n toggleSize.height);\n\n this.saveStoredWidgetLayout({ position: this.createStoredPosition(linkedPosition.left, linkedPosition.top, toggleSize.width, toggleSize.height) });\n };\n\n app.persistWidgetTogglePosition = function () {\n if (!this.widgetToggleButtonElement || !config.widget.persistLayout) {\n return;\n }\n\n var togglePosition = this.getElementPosition(this.widgetToggleButtonElement);\n var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);\n this.saveStoredWidgetLayout({ position: this.createStoredPosition(togglePosition.left, togglePosition.top, toggleSize.width, toggleSize.height) });\n };\n\n app.persistWidgetPanelSize = function () {\n if (!this.widgetContainerElement || !config.widget.enableResizing || !config.widget.persistLayout) {\n return;\n }\n\n var defaultSize = this.getWidgetDefaultSize();\n var currentSize = this.getElementSize(this.widgetContainerElement, defaultSize.width, defaultSize.height);\n\n this.saveStoredWidgetLayout({\n panel: {\n width: Math.abs(currentSize.width - defaultSize.width) <= 1 ? null : currentSize.width,\n height: Math.abs(currentSize.height - defaultSize.height) <= 1 ? null : currentSize.height\n }\n });\n };\n\n app.syncTogglePositionToPanel = function (persistLayout) {\n if (persistLayout === undefined) {\n persistLayout = true;\n }\n\n if (!this.widgetContainerElement || !this.widgetToggleButtonElement) {\n return;\n }\n\n var panelDefaultSize = this.getWidgetDefaultSize();\n var panelSize = this.getElementSize(this.widgetContainerElement, panelDefaultSize.width, panelDefaultSize.height);\n var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);\n var panelPosition = this.getElementPosition(this.widgetContainerElement);\n var linkedPosition = this.clampWidgetPosition(\n panelPosition.left + panelSize.width - toggleSize.width,\n panelPosition.top + panelSize.height + this.getWidgetToggleGap(),\n toggleSize.width,\n toggleSize.height);\n\n this.applyAbsolutePosition(this.widgetToggleButtonElement, linkedPosition.left, linkedPosition.top);\n\n if (persistLayout && config.widget.persistLayout) {\n this.persistWidgetTogglePosition();\n }\n };\n\n app.syncPanelPositionToToggle = function (persistLayout) {\n if (persistLayout === undefined) {\n persistLayout = true;\n }\n\n if (!this.widgetContainerElement || !this.widgetToggleButtonElement) {\n return;\n }\n\n var panelDefaultSize = this.getWidgetDefaultSize();\n var panelSize = this.getElementSize(this.widgetContainerElement, panelDefaultSize.width, panelDefaultSize.height);\n var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);\n var togglePosition = this.getElementPosition(this.widgetToggleButtonElement);\n var linkedPosition = this.clampWidgetPosition(\n togglePosition.left + toggleSize.width - panelSize.width,\n togglePosition.top - panelSize.height - this.getWidgetToggleGap(),\n panelSize.width,\n panelSize.height);\n\n this.applyAbsolutePosition(this.widgetContainerElement, linkedPosition.left, linkedPosition.top);\n\n if (persistLayout && config.widget.persistLayout) {\n this.persistWidgetPanelPosition();\n }\n };\n\n app.updateWidgetResetSizeButtonVisibility = function () {\n if (!this.widgetResetSizeButtonElement) {\n return;\n }\n\n if (!config.widget.enableResizing || !this.widgetContainerElement) {\n this.widgetResetSizeButtonElement.classList.add('d-none');\n return;\n }\n\n var defaultSize = this.getWidgetDefaultSize();\n var currentSize = this.getElementSize(this.widgetContainerElement, defaultSize.width, defaultSize.height);\n var isResized =\n Math.abs(currentSize.width - defaultSize.width) > 1 ||\n Math.abs(currentSize.height - defaultSize.height) > 1 ||\n !!this.widgetContainerElement.style.width ||\n !!this.widgetContainerElement.style.height;\n\n this.widgetResetSizeButtonElement.classList.toggle('d-none', !isResized);\n };\n\n app.resetWidgetSize = function () {\n if (!this.widgetContainerElement || !config.widget.enableResizing) {\n return;\n }\n\n this.widgetContainerElement.style.removeProperty('width');\n this.widgetContainerElement.style.removeProperty('height');\n this.persistWidgetPanelSize();\n this.constrainWidgetElementsToViewport();\n this.updateWidgetResetSizeButtonVisibility();\n };\n\n app.restoreWidgetLayout = function () {\n var storedLayout = this.getStoredWidgetLayout();\n\n if (this.widgetContainerElement && config.widget.enableResizing) {\n if (Number.isFinite(storedLayout.panel && storedLayout.panel.width)) {\n this.widgetContainerElement.style.width = storedLayout.panel.width + 'px';\n }\n else {\n this.widgetContainerElement.style.removeProperty('width');\n }\n\n if (Number.isFinite(storedLayout.panel && storedLayout.panel.height)) {\n this.widgetContainerElement.style.height = storedLayout.panel.height + 'px';\n }\n else {\n this.widgetContainerElement.style.removeProperty('height');\n }\n }\n\n var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);\n var storedTogglePosition = this.resolveStoredPosition(storedLayout.position, toggleSize.width, toggleSize.height);\n if (this.widgetToggleButtonElement && config.widget.enableDragging && storedTogglePosition) {\n this.applyAbsolutePosition(this.widgetToggleButtonElement, storedTogglePosition.left, storedTogglePosition.top);\n this.syncPanelPositionToToggle(false);\n }\n else if (this.widgetToggleButtonElement && config.widget.enableDragging &&\n Number.isFinite(storedLayout.toggle && storedLayout.toggle.left) &&\n Number.isFinite(storedLayout.toggle && storedLayout.toggle.top)) {\n this.applyAbsolutePosition(this.widgetToggleButtonElement, storedLayout.toggle.left, storedLayout.toggle.top);\n this.syncPanelPositionToToggle(false);\n }\n else if (this.widgetContainerElement && config.widget.enableDragging &&\n Number.isFinite(storedLayout.panel && storedLayout.panel.left) &&\n Number.isFinite(storedLayout.panel && storedLayout.panel.top)) {\n this.applyAbsolutePosition(this.widgetContainerElement, storedLayout.panel.left, storedLayout.panel.top);\n this.syncTogglePositionToPanel(false);\n }\n\n this.constrainWidgetElementsToViewport();\n this.updateWidgetResetSizeButtonVisibility();\n };\n\n app.attachDraggableWidgetElement = function (element, handle, layoutKey, suppressClickOnDrag) {\n if (!element || !handle || !config.widget.enableDragging) {\n return;\n }\n\n var activePointerId = null;\n var startX = 0;\n var startY = 0;\n var startLeft = 0;\n var startTop = 0;\n var dragged = false;\n var dragThreshold = 4;\n var interactiveSelector = 'button, a, input, textarea, select, option, label';\n var self = this;\n\n function stopDragging(event) {\n if (activePointerId === null) {\n return;\n }\n\n if (event && event.pointerId !== undefined && event.pointerId !== activePointerId) {\n return;\n }\n\n document.removeEventListener('pointermove', onPointerMove);\n document.removeEventListener('pointerup', stopDragging);\n document.removeEventListener('pointercancel', stopDragging);\n element.classList.remove('ai-chat-widget-dragging');\n activePointerId = null;\n\n if (!dragged) {\n return;\n }\n\n if (layoutKey === 'panel') {\n self.syncTogglePositionToPanel(false);\n self.persistWidgetPanelPosition();\n }\n else if (layoutKey === 'toggle') {\n self.syncPanelPositionToToggle(false);\n self.persistWidgetTogglePosition();\n }\n\n if (config.widget.persistLayout) {\n self.persistWidgetPanelPosition();\n self.persistWidgetTogglePosition();\n }\n\n if (suppressClickOnDrag) {\n element.dataset.dragSuppressClick = 'true';\n window.setTimeout(function () {\n if (element.dataset.dragSuppressClick === 'true') {\n element.dataset.dragSuppressClick = 'false';\n }\n }, 0);\n }\n }\n\n function onPointerMove(event) {\n if (activePointerId === null || event.pointerId !== activePointerId) {\n return;\n }\n\n var deltaX = event.clientX - startX;\n var deltaY = event.clientY - startY;\n\n if (!dragged && Math.hypot(deltaX, deltaY) < dragThreshold) {\n return;\n }\n\n dragged = true;\n\n var defaultSize = self.getWidgetDefaultSize();\n var currentSize = self.getElementSize(\n element,\n layoutKey === 'panel' ? defaultSize.width : 52,\n layoutKey === 'panel' ? defaultSize.height : 52);\n var nextPosition = self.clampWidgetPosition(startLeft + deltaX, startTop + deltaY, currentSize.width, currentSize.height);\n\n self.applyAbsolutePosition(element, nextPosition.left, nextPosition.top);\n\n if (layoutKey === 'panel') {\n self.syncTogglePositionToPanel(false);\n }\n else if (layoutKey === 'toggle') {\n self.syncPanelPositionToToggle(false);\n }\n }\n\n handle.addEventListener('pointerdown', function (event) {\n if (event.button !== 0) {\n return;\n }\n\n if (layoutKey === 'panel' && event.target.closest(interactiveSelector)) {\n return;\n }\n\n var rect = element.getBoundingClientRect();\n startX = event.clientX;\n startY = event.clientY;\n startLeft = rect.left;\n startTop = rect.top;\n dragged = false;\n activePointerId = event.pointerId;\n element.classList.add('ai-chat-widget-dragging');\n\n if (handle.setPointerCapture) {\n handle.setPointerCapture(event.pointerId);\n }\n\n document.addEventListener('pointermove', onPointerMove);\n document.addEventListener('pointerup', stopDragging);\n document.addEventListener('pointercancel', stopDragging);\n event.preventDefault();\n });\n };\n\n app.constrainWidgetElementsToViewport = function () {\n if (this.widgetContainerElement && this.widgetContainerElement.style.left && this.isWidgetPanelVisible()) {\n var panelDefaultSize = this.getWidgetDefaultSize();\n var panelSize = this.getElementSize(this.widgetContainerElement, panelDefaultSize.width, panelDefaultSize.height);\n var panelPosition = this.getElementPosition(this.widgetContainerElement);\n var clampedPanel = this.clampWidgetPosition(panelPosition.left, panelPosition.top, panelSize.width, panelSize.height);\n\n this.applyAbsolutePosition(this.widgetContainerElement, clampedPanel.left, clampedPanel.top);\n this.syncTogglePositionToPanel(false);\n\n if (config.widget.persistLayout) {\n this.persistWidgetPanelPosition();\n this.persistWidgetTogglePosition();\n }\n }\n else if (this.widgetToggleButtonElement && this.widgetToggleButtonElement.style.left) {\n var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);\n var togglePosition = this.getElementPosition(this.widgetToggleButtonElement);\n var clampedToggle = this.clampWidgetPosition(togglePosition.left, togglePosition.top, toggleSize.width, toggleSize.height);\n\n this.applyAbsolutePosition(this.widgetToggleButtonElement, clampedToggle.left, clampedToggle.top);\n this.syncPanelPositionToToggle(false);\n\n if (config.widget.persistLayout) {\n this.persistWidgetTogglePosition();\n this.persistWidgetPanelPosition();\n }\n }\n };\n\n app.showChatScreen = function () {\n if (!this.chatHistorySection) {\n return;\n }\n\n this.chatHistorySection.classList.remove('show');\n };\n }\n\n function initialize(app, config) {\n if (!app || app.widgetIsInitialized) {\n return;\n }\n\n if (!config.widget.chatWidgetContainer) {\n console.error('The widget chatWidgetContainer is required.');\n return;\n }\n\n if (!config.widget.chatWidgetStateName) {\n console.error('The widget chatWidgetStateName is required.');\n return;\n }\n\n var chatWidgetContainer = document.querySelector(config.widget.chatWidgetContainer);\n if (!chatWidgetContainer) {\n return;\n }\n\n if (config.widget.chatHistorySection) {\n app.chatHistorySection = document.querySelector(config.widget.chatHistorySection);\n }\n\n app.chatWidgetStateName = config.widget.chatWidgetStateName;\n app.chatWidgetStateSession = config.widget.chatWidgetStateName + 'Session';\n app.chatWidgetStateDocuments = config.widget.chatWidgetStateName + 'Documents';\n app.chatWidgetLayoutKey = config.widget.chatWidgetStateName + 'Layout';\n app.widgetContainerElement = chatWidgetContainer;\n app.widgetToggleButtonElement = config.widget.toggleButtonSelector ? document.querySelector(config.widget.toggleButtonSelector) : null;\n app.widgetResetSizeButtonElement = config.widget.resetSizeButtonSelector ? document.querySelector(config.widget.resetSizeButtonSelector) : null;\n app.widgetDefaultWidth = parsePixelValue(config.widget.defaultWidth) || parsePixelValue(window.getComputedStyle(chatWidgetContainer).width) || 380;\n app.widgetDefaultHeight = parsePixelValue(config.widget.defaultHeight) || parsePixelValue(window.getComputedStyle(chatWidgetContainer).height) || 520;\n app.widgetIsInitialized = true;\n app.clearStoredWidgetDocuments();\n app.documents = [];\n\n if (config.widget.enableResizing) {\n chatWidgetContainer.classList.add('ai-chat-widget-resizable');\n chatWidgetContainer.style.minWidth = (parsePixelValue(config.widget.minWidth) || 320) + 'px';\n chatWidgetContainer.style.minHeight = (parsePixelValue(config.widget.minHeight) || 420) + 'px';\n\n if (typeof ResizeObserver !== 'undefined') {\n app.widgetResizeObserver = new ResizeObserver(function () {\n app.persistWidgetPanelSize();\n app.constrainWidgetElementsToViewport();\n app.updateWidgetResetSizeButtonVisibility();\n });\n\n app.widgetResizeObserver.observe(chatWidgetContainer);\n }\n }\n\n var dragHandleSelector = config.widget.dragHandleSelector || '.ai-chat-widget-header';\n var dragHandle = chatWidgetContainer.querySelector(dragHandleSelector);\n\n if (config.widget.enableDragging && dragHandle) {\n dragHandle.classList.add('ai-chat-widget-drag-handle');\n chatWidgetContainer.classList.add('ai-chat-widget-draggable');\n app.attachDraggableWidgetElement(chatWidgetContainer, dragHandle, 'panel', false);\n }\n\n if (config.widget.enableDragging && app.widgetToggleButtonElement) {\n app.widgetToggleButtonElement.classList.add('ai-chat-widget-draggable');\n app.attachDraggableWidgetElement(app.widgetToggleButtonElement, app.widgetToggleButtonElement, 'toggle', true);\n }\n\n if (app.widgetResetSizeButtonElement) {\n app.widgetResetSizeButtonElement.addEventListener('click', function (event) {\n event.preventDefault();\n app.resetWidgetSize();\n });\n }\n\n app.restoreWidgetLayout();\n\n if (!app.widgetViewportResizeHandler) {\n app.widgetViewportResizeHandler = function () {\n if (config.widget.persistLayout) {\n app.restoreWidgetLayout();\n } else {\n app.constrainWidgetElementsToViewport();\n }\n\n app.updateWidgetResetSizeButtonVisibility();\n };\n\n window.addEventListener('resize', app.widgetViewportResizeHandler);\n }\n\n app.reloadCurrentSession();\n\n if (config.autoCreateSession && !app.getSessionId()) {\n app.startNewSession();\n }\n\n if (config.widget.showHistoryButton && app.chatHistorySection) {\n var showHistoryButton = document.querySelector(config.widget.showHistoryButton);\n if (showHistoryButton) {\n showHistoryButton.addEventListener('click', function () {\n app.chatHistorySection.classList.toggle('show');\n });\n }\n\n if (config.widget.closeHistoryButton) {\n var closeHistoryButton = document.querySelector(config.widget.closeHistoryButton);\n if (closeHistoryButton) {\n closeHistoryButton.addEventListener('click', function () {\n app.showChatScreen();\n });\n }\n }\n }\n\n if (config.widget.newChatButton) {\n var newChatButton = document.querySelector(config.widget.newChatButton);\n if (newChatButton) {\n newChatButton.addEventListener('click', function () {\n app.resetSession();\n app.showChatScreen();\n });\n }\n }\n }\n\n function resolveSessionId(app) {\n if (!app || !app.widgetIsInitialized) {\n return null;\n }\n\n return localStorage.getItem(app.chatWidgetStateSession);\n }\n\n function onSessionInitialized(app, sessionId) {\n if (app && app.widgetIsInitialized) {\n localStorage.setItem(app.chatWidgetStateSession, sessionId);\n }\n }\n\n function onSessionReset(app) {\n if (app && app.widgetIsInitialized) {\n localStorage.removeItem(app.chatWidgetStateSession);\n app.clearStoredWidgetDocuments();\n }\n }\n\n function onDocumentsChanged(app, documents) {\n if (app && app.widgetIsInitialized) {\n app.saveStoredWidgetDocuments(documents);\n }\n }\n\n function handleReceiveError(app) {\n if (app && app.widgetIsInitialized && !app.isSessionStarted && !app._attemptedSessionRecovery) {\n app._attemptedSessionRecovery = true;\n localStorage.removeItem(app.chatWidgetStateSession);\n app.clearStoredWidgetDocuments();\n app.startNewSession();\n }\n }\n\n function dispose(app) {\n if (!app) {\n return;\n }\n\n if (app.widgetResizeObserver) {\n app.widgetResizeObserver.disconnect();\n app.widgetResizeObserver = null;\n }\n\n if (app.widgetViewportResizeHandler) {\n window.removeEventListener('resize', app.widgetViewportResizeHandler);\n app.widgetViewportResizeHandler = null;\n }\n }\n\n return {\n attach: attach,\n initialize: initialize,\n onMounted: initialize,\n resolveSessionId: resolveSessionId,\n onSessionInitialized: onSessionInitialized,\n onSessionReset: onSessionReset,\n onDocumentsChanged: onDocumentsChanged,\n handleReceiveError: handleReceiveError,\n dispose: dispose,\n onBeforeUnmount: dispose\n };\n}();\n\nwindow.coreAIChatWidgetManager = window.coreAIChatWidgetManager || function () {\n function getAttributeValue(element, attributeName) {\n var value = element.getAttribute(attributeName);\n return value === null || value === '' ? null : value;\n }\n\n function parseBooleanAttributeValue(value) {\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === 'boolean') {\n return value;\n }\n\n var normalized = String(value).trim().toLowerCase();\n if (normalized === 'true') {\n return true;\n }\n\n if (normalized === 'false') {\n return false;\n }\n\n return null;\n }\n\n function parseJsonAttribute(element, attributeName, description) {\n var rawValue = getAttributeValue(element, attributeName);\n if (!rawValue) {\n return null;\n }\n\n try {\n return JSON.parse(rawValue);\n }\n catch (error) {\n console.error('Failed to parse ' + description + ' JSON.', error);\n return null;\n }\n }\n\n function buildOptionsFromDataAttributes(element) {\n var widgetContainerSelector = getAttributeValue(element, 'data-coreai-chat-widget-container-selector');\n if (!widgetContainerSelector) {\n return null;\n }\n\n var chatConfig = null;\n if (window.coreAIChatManager && typeof window.coreAIChatManager.buildConfigFromElement === 'function') {\n chatConfig = window.coreAIChatManager.buildConfigFromElement(element, { allowWidgetHost: true });\n }\n\n var profileId = getAttributeValue(element, 'data-coreai-chat-widget-profile-id');\n var profileName = getAttributeValue(element, 'data-coreai-chat-widget-profile-name');\n var profileDisplayText = getAttributeValue(element, 'data-coreai-chat-widget-profile-display-text');\n var profileWelcomeMessage = getAttributeValue(element, 'data-coreai-chat-widget-profile-welcome-message');\n var profileChatMode = getAttributeValue(element, 'data-coreai-chat-widget-profile-chat-mode');\n var profileTtsVoiceName = getAttributeValue(element, 'data-coreai-chat-widget-profile-tts-voice-name');\n var profileMetricsEnabled = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-profile-enable-session-metrics'));\n var profileSessionDocuments = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-profile-allow-session-documents'));\n var profile = null;\n\n if (profileId || profileName || profileDisplayText || profileWelcomeMessage || profileChatMode || profileTtsVoiceName || profileMetricsEnabled !== null || profileSessionDocuments !== null) {\n profile = {\n id: profileId,\n name: profileName,\n displayText: profileDisplayText,\n welcomeMessage: profileWelcomeMessage,\n chatMode: profileChatMode,\n ttsVoiceName: profileTtsVoiceName,\n enableSessionMetrics: profileMetricsEnabled === true,\n allowSessionDocuments: profileSessionDocuments === true\n };\n }\n\n var enableDragging = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-enable-dragging'));\n var enableResizing = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-enable-resizing'));\n var persistLayout = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-persist-layout'));\n\n return {\n shellSelector: getAttributeValue(element, 'data-coreai-chat-widget-shell-selector'),\n widgetContainerSelector: widgetContainerSelector,\n toggleButtonSelector: getAttributeValue(element, 'data-coreai-chat-widget-toggle-button-selector'),\n closeButtonSelector: getAttributeValue(element, 'data-coreai-chat-widget-close-button-selector'),\n inputSelector: getAttributeValue(element, 'data-coreai-chat-widget-input-selector'),\n messageTemplateSelector: getAttributeValue(element, 'data-coreai-chat-widget-message-template-selector'),\n indicatorTemplateSelector: getAttributeValue(element, 'data-coreai-chat-widget-indicator-template-selector'),\n profile: profile,\n widgetStateName: getAttributeValue(element, 'data-coreai-chat-widget-state-name'),\n openStateValue: getAttributeValue(element, 'data-coreai-chat-widget-open-state-value'),\n closedStateValue: getAttributeValue(element, 'data-coreai-chat-widget-closed-state-value'),\n openIconHtml: getAttributeValue(element, 'data-coreai-chat-widget-open-icon-html'),\n closedIconHtml: getAttributeValue(element, 'data-coreai-chat-widget-closed-icon-html'),\n chatConfig: chatConfig ? Object.assign({}, chatConfig, {\n widget: Object.assign({}, chatConfig.widget || {}, {\n chatWidgetContainer: widgetContainerSelector,\n chatWidgetStateName: getAttributeValue(element, 'data-coreai-chat-widget-state-name'),\n newChatButton: getAttributeValue(element, 'data-coreai-chat-widget-new-chat-button-selector'),\n toggleButtonSelector: getAttributeValue(element, 'data-coreai-chat-widget-toggle-button-selector'),\n resetSizeButtonSelector: getAttributeValue(element, 'data-coreai-chat-widget-reset-size-button-selector'),\n dragHandleSelector: getAttributeValue(element, 'data-coreai-chat-widget-drag-handle-selector'),\n enableDragging: enableDragging === null ? undefined : enableDragging,\n enableResizing: enableResizing === null ? undefined : enableResizing,\n persistLayout: persistLayout === null ? undefined : persistLayout,\n })\n }) : null\n };\n }\n\n function initialize(options) {\n if (!options) {\n return null;\n }\n\n var chatConfig = options.chatConfig;\n if (!chatConfig && options.configElementSelector) {\n var configElement = document.querySelector(options.configElementSelector);\n chatConfig = configElement ? parseJsonAttribute(configElement, 'data-config', 'AI chat widget config') : null;\n }\n\n if (!chatConfig) {\n return null;\n }\n\n if (options.messageTemplateSelector) {\n var messageTemplate = document.querySelector(options.messageTemplateSelector);\n if (messageTemplate) {\n chatConfig.messageTemplate = messageTemplate.innerHTML;\n }\n }\n\n if (options.indicatorTemplateSelector) {\n var indicatorTemplate = document.querySelector(options.indicatorTemplateSelector);\n if (indicatorTemplate) {\n chatConfig.indicatorTemplate = indicatorTemplate.innerHTML;\n }\n }\n\n var shell = document.querySelector(options.shellSelector);\n var widgetContainer = document.querySelector(options.widgetContainerSelector);\n var toggleButton = document.querySelector(options.toggleButtonSelector);\n var closeButton = document.querySelector(options.closeButtonSelector);\n var profileInput = options.inputSelector ? document.querySelector(options.inputSelector) : null;\n var widgetStateName = options.widgetStateName || chatConfig.widget.chatWidgetStateName;\n var widgetOpenStateKey = options.widgetOpenStateKey || (widgetStateName + 'Open');\n var widgetLayoutKey = widgetStateName + 'Layout';\n var openStateValue = options.openStateValue || 'open';\n var closedStateValue = options.closedStateValue || 'closed';\n\n if (profileInput && options.profile && options.profile.id) {\n profileInput.setAttribute('data-profile-id', options.profile.id);\n }\n\n try {\n var storedLayout = localStorage.getItem(widgetLayoutKey);\n var layout = storedLayout ? JSON.parse(storedLayout) || {} : {};\n var position = layout.position || {};\n var panelLayout = layout.panel || {};\n var toggleLeft = Number(position.left);\n var toggleTop = Number(position.top);\n var isOpen = localStorage.getItem(widgetOpenStateKey) === openStateValue;\n var viewportPadding = 8;\n\n if (shell) {\n shell.dataset.deferReveal = isOpen ? 'true' : 'false';\n shell.dataset.initialOpen = isOpen ? 'true' : 'false';\n }\n\n if (widgetContainer && toggleButton) {\n var toggleSize = 52;\n var panelWidth = Number.isFinite(Number(panelLayout.width))\n ? Number(panelLayout.width)\n : Math.round(parseFloat(window.getComputedStyle(widgetContainer).width) || 380);\n var panelHeight = Number.isFinite(Number(panelLayout.height))\n ? Number(panelLayout.height)\n : Math.round(parseFloat(window.getComputedStyle(widgetContainer).height) || 520);\n var maxLeft = Math.max(viewportPadding, window.innerWidth - toggleSize - viewportPadding);\n var maxTop = Math.max(viewportPadding, window.innerHeight - toggleSize - viewportPadding);\n if (Number.isFinite(Number(position.leftRatio))) {\n toggleLeft = viewportPadding + Math.max(0, maxLeft - viewportPadding) * Number(position.leftRatio);\n }\n if (Number.isFinite(Number(position.topRatio))) {\n toggleTop = viewportPadding + Math.max(0, maxTop - viewportPadding) * Number(position.topRatio);\n }\n if (Number.isFinite(toggleLeft) && Number.isFinite(toggleTop)) {\n toggleLeft = Math.round(clampWidgetValue(toggleLeft, viewportPadding, maxLeft));\n toggleTop = Math.round(clampWidgetValue(toggleTop, viewportPadding, maxTop));\n }\n\n if (Number.isFinite(toggleLeft) && Number.isFinite(toggleTop)) {\n toggleButton.style.left = toggleLeft + 'px';\n toggleButton.style.top = toggleTop + 'px';\n toggleButton.style.right = 'auto';\n toggleButton.style.bottom = 'auto';\n\n var toggleGap = 8;\n widgetContainer.style.left = (toggleLeft + toggleSize - panelWidth) + 'px';\n widgetContainer.style.top = (toggleTop - panelHeight - toggleGap) + 'px';\n widgetContainer.style.right = 'auto';\n widgetContainer.style.bottom = 'auto';\n }\n }\n\n if (widgetContainer) {\n widgetContainer.classList.remove('open');\n widgetContainer.style.display = 'none';\n widgetContainer.setAttribute('aria-hidden', 'true');\n }\n\n if (toggleButton) {\n toggleButton.innerHTML = isOpen ? options.openIconHtml : options.closedIconHtml;\n }\n }\n catch (error) {\n console.warn('Failed to restore widget layout before initialization.', error);\n }\n finally {\n if (shell && shell.dataset.deferReveal !== 'true') {\n shell.style.visibility = '';\n }\n }\n\n var widgetApp = window.coreAIChatManager.initialize(chatConfig);\n if (options.applySessionProfilePatch !== false && window.crestAppsAIChat && window.crestAppsAIChat.patchSessionProfileSync) {\n window.crestAppsAIChat.patchSessionProfileSync(widgetApp);\n }\n\n function revealShell() {\n if (!shell) {\n return;\n }\n\n shell.style.visibility = '';\n shell.dataset.deferReveal = 'false';\n }\n\n function syncOpenPanelPosition() {\n if (!widgetApp || typeof widgetApp.syncPanelPositionToToggle !== 'function') {\n return;\n }\n\n widgetApp.syncPanelPositionToToggle(false);\n }\n\n function updateTtsPlaybackButtons() {\n if (!widgetContainer) {\n return;\n }\n\n var buttons = widgetContainer.querySelectorAll('[data-tts-message-index]');\n buttons.forEach(function (button) {\n var buttonIndex = Number(button.getAttribute('data-tts-message-index'));\n var isPlaying = buttonIndex === widgetApp.ttsPlayingMessageIndex;\n button.classList.toggle('tts-playing', isPlaying);\n button.setAttribute('title', isPlaying ? 'Pause audio' : 'Read aloud');\n });\n }\n\n function queueTtsPlaybackButtonUpdate() {\n requestAnimationFrame(updateTtsPlaybackButtons);\n }\n\n function revealShellWhenStable(initialOpen) {\n if (!shell || shell.dataset.deferReveal !== 'true' || !initialOpen) {\n revealShell();\n return;\n }\n\n var hasRevealed = false;\n var resizeObserver = null;\n\n function finalizeReveal() {\n if (hasRevealed) {\n return;\n }\n\n hasRevealed = true;\n\n if (resizeObserver) {\n resizeObserver.disconnect();\n }\n\n requestAnimationFrame(function () {\n syncOpenPanelPosition();\n requestAnimationFrame(function () {\n revealShell();\n });\n });\n }\n\n if (typeof ResizeObserver === 'undefined') {\n window.setTimeout(finalizeReveal, 0);\n return;\n }\n\n var lastWidth = 0;\n var lastHeight = 0;\n var stablePasses = 0;\n\n resizeObserver = new ResizeObserver(function (entries) {\n var entry = entries && entries[0];\n if (!entry) {\n return;\n }\n\n var width = Math.round(entry.contentRect.width);\n var height = Math.round(entry.contentRect.height);\n if (!width || !height) {\n return;\n }\n\n syncOpenPanelPosition();\n\n if (width === lastWidth && height === lastHeight) {\n stablePasses++;\n }\n else {\n lastWidth = width;\n lastHeight = height;\n stablePasses = 0;\n }\n\n if (stablePasses >= 1) {\n finalizeReveal();\n }\n });\n\n resizeObserver.observe(widgetContainer);\n window.setTimeout(finalizeReveal, 150);\n }\n\n function setWidgetOpen(isOpen) {\n if (widgetApp) {\n var isCurrentlyOpen = widgetContainer.classList.contains('open');\n if (isOpen && !isCurrentlyOpen && typeof widgetApp.syncPanelPositionToToggle === 'function') {\n widgetApp.syncPanelPositionToToggle();\n }\n else if (!isOpen && isCurrentlyOpen && typeof widgetApp.syncTogglePositionToPanel === 'function') {\n widgetApp.syncTogglePositionToPanel();\n }\n }\n\n widgetContainer.classList.toggle('open', isOpen);\n widgetContainer.style.display = isOpen ? 'flex' : 'none';\n widgetContainer.setAttribute('aria-hidden', isOpen ? 'false' : 'true');\n toggleButton.innerHTML = isOpen ? options.openIconHtml : options.closedIconHtml;\n localStorage.setItem(widgetOpenStateKey, isOpen ? openStateValue : closedStateValue);\n\n if (isOpen && typeof window.renderPendingCharts === 'function') {\n setTimeout(function () { window.renderPendingCharts(); }, 100);\n }\n }\n\n var initialOpen = shell && shell.dataset.initialOpen === 'true';\n setWidgetOpen(initialOpen);\n revealShellWhenStable(initialOpen);\n\n if (widgetApp && typeof widgetApp.$watch === 'function') {\n widgetApp.$watch('ttsPlayingMessageIndex', function () {\n queueTtsPlaybackButtonUpdate();\n });\n }\n\n queueTtsPlaybackButtonUpdate();\n\n if (toggleButton) {\n toggleButton.addEventListener('click', function () {\n if (toggleButton.dataset.dragSuppressClick === 'true') {\n toggleButton.dataset.dragSuppressClick = 'false';\n return;\n }\n\n setWidgetOpen(!widgetContainer.classList.contains('open'));\n });\n }\n\n if (closeButton) {\n closeButton.addEventListener('click', function () {\n setWidgetOpen(false);\n });\n }\n\n return widgetApp;\n }\n\n function initializeFromElement(element) {\n if (!element || element.dataset.coreAiChatWidgetInitialized === 'true') {\n return element ? element.__coreAIChatWidgetApp || null : null;\n }\n\n var jsonOptions = parseJsonAttribute(element, 'data-coreai-chat-widget-config', 'CoreAI chat widget config');\n var attributeOptions = buildOptionsFromDataAttributes(element);\n if (!jsonOptions && !attributeOptions) {\n return null;\n }\n\n var options = Object.assign({}, jsonOptions || {}, attributeOptions || {});\n\n var widgetApp = initialize(options);\n if (!widgetApp) {\n return null;\n }\n\n element.dataset.coreAiChatWidgetInitialized = 'true';\n element.__coreAIChatWidgetApp = widgetApp;\n\n return widgetApp;\n }\n\n function scanForAutoInitialization(root) {\n if (!root || typeof root.querySelectorAll !== 'function') {\n return;\n }\n\n if (typeof root.matches === 'function' && root.matches('[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]')) {\n initializeFromElement(root);\n }\n\n root.querySelectorAll('[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]').forEach(initializeFromElement);\n }\n\n function startAutoInitialization() {\n scanForAutoInitialization(document);\n\n if (typeof MutationObserver === 'undefined') {\n return;\n }\n\n var observer = new MutationObserver(function (mutations) {\n mutations.forEach(function (mutation) {\n mutation.addedNodes.forEach(function (node) {\n if (node && node.nodeType === 1) {\n scanForAutoInitialization(node);\n }\n });\n });\n });\n\n observer.observe(document.body, {\n childList: true,\n subtree: true,\n });\n }\n\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', startAutoInitialization, { once: true });\n } else {\n startAutoInitialization();\n }\n\n return {\n initialize: initialize,\n initializeFromElement: initializeFromElement,\n };\n}();\n"]}
1
+ {"version":3,"sources":["ai-chat-widget.js"],"names":["clampWidgetValue","value","min","max","Math","window","coreAIChatWidgetBehavior","parsePixelValue","Number","isFinite","parsed","parseFloat","initialize","app","config","widgetIsInitialized","widget","chatWidgetContainer","chatWidgetStateName","document","querySelector","chatHistorySection","chatWidgetStateSession","chatWidgetStateDocuments","chatWidgetLayoutKey","widgetContainerElement","widgetToggleButtonElement","toggleButtonSelector","widgetResetSizeButtonElement","resetSizeButtonSelector","widgetDefaultWidth","defaultWidth","getComputedStyle","width","widgetDefaultHeight","defaultHeight","height","clearStoredWidgetDocuments","documents","enableResizing","classList","add","style","minWidth","minHeight","ResizeObserver","widgetResizeObserver","persistWidgetPanelSize","constrainWidgetElementsToViewport","updateWidgetResetSizeButtonVisibility","observe","dragHandleSelector","dragHandle","enableDragging","attachDraggableWidgetElement","addEventListener","event","preventDefault","resetWidgetSize","restoreWidgetLayout","widgetViewportResizeHandler","persistLayout","reloadCurrentSession","showHistoryButton","toggle","closeHistoryButton","showChatScreen","newChatButton","resetSession","console","error","dispose","disconnect","removeEventListener","attach","__aiChatWidgetAttached","getStoredWidgetLayout","this","storedLayout","localStorage","getItem","JSON","parse","warn","saveStoredWidgetLayout","partialLayout","currentLayout","nextLayout","Object","assign","undefined","panel","position","setItem","stringify","getElementSize","element","fallbackWidth","fallbackHeight","rect","getBoundingClientRect","computed","round","getElementPosition","left","top","inlineLeft","inlineTop","computedLeft","computedTop","isHidden","display","getAvailableWidgetPositionRange","padding","maxLeft","innerWidth","maxTop","innerHeight","createStoredPosition","range","leftSpan","topSpan","leftRatio","topRatio","resolveStoredPosition","storedPosition","clampWidgetPosition","getStoredWidgetDocuments","saveStoredWidgetDocuments","removeItem","applyAbsolutePosition","right","bottom","getWidgetDefaultSize","getWidgetToggleGap","isWidgetPanelVisible","contains","persistWidgetPanelPosition","panelDefaultSize","panelPosition","panelSize","toggleSize","linkedPosition","persistWidgetTogglePosition","togglePosition","defaultSize","currentSize","abs","syncTogglePositionToPanel","syncPanelPositionToToggle","isResized","removeProperty","storedTogglePosition","handle","layoutKey","suppressClickOnDrag","activePointerId","startX","startY","startLeft","startTop","dragged","self","button","target","closest","clientX","clientY","pointerId","setPointerCapture","onPointerMove","stopDragging","remove","dataset","dragSuppressClick","setTimeout","deltaX","deltaY","hypot","nextPosition","clampedPanel","clampedToggle","onMounted","resolveSessionId","onSessionInitialized","sessionId","onSessionReset","onDocumentsChanged","handleReceiveError","isSessionStarted","_attemptedSessionRecovery","startNewSession","onBeforeUnmount","coreAIChatWidgetManager","getAttributeValue","attributeName","getAttribute","parseBooleanAttributeValue","normalized","String","trim","toLowerCase","parseJsonAttribute","description","rawValue","options","chatConfig","configElementSelector","configElement","messageTemplateSelector","messageTemplate","innerHTML","indicatorTemplateSelector","indicatorTemplate","shell","shellSelector","widgetContainer","widgetContainerSelector","toggleButton","closeButton","closeButtonSelector","profileInput","inputSelector","widgetStateName","widgetOpenStateKey","widgetLayoutKey","openStateValue","closedStateValue","profile","id","setAttribute","layout","panelLayout","toggleLeft","toggleTop","isOpen","deferReveal","initialOpen","panelWidth","panelHeight","openIconHtml","closedIconHtml","visibility","widgetApp","coreAIChatManager","revealShell","syncOpenPanelPosition","updateTtsPlaybackButtons","querySelectorAll","forEach","isPlaying","ttsPlayingMessageIndex","queueTtsPlaybackButtonUpdate","requestAnimationFrame","setWidgetOpen","isCurrentlyOpen","renderPendingCharts","applySessionProfilePatch","crestAppsAIChat","patchSessionProfileSync","hasRevealed","resizeObserver","lastWidth","lastHeight","stablePasses","entries","entry","contentRect","finalizeReveal","revealShellWhenStable","$watch","initializeFromElement","coreAiChatWidgetInitialized","__coreAIChatWidgetApp","jsonOptions","attributeOptions","buildConfigFromElement","allowWidgetHost","profileId","profileName","profileDisplayText","profileWelcomeMessage","profileInitialPrompt","profileChatMode","profileTtsVoiceName","profileMetricsEnabled","profileSessionDocuments","name","displayText","welcomeMessage","initialPrompt","chatMode","ttsVoiceName","enableSessionMetrics","allowSessionDocuments","buildOptionsFromDataAttributes","scanForAutoInitialization","root","matches","startAutoInitialization","MutationObserver","mutations","mutation","addedNodes","node","nodeType","body","childList","subtree","readyState","once"],"mappings":"AAAA,SAASA,iBAAiBC,EAAOC,EAAKC,GAClC,OAAOC,KAAKF,IAAIE,KAAKD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AA+BvM,GACtD,IAAKkL,IAAgBC,EACjB,OAAO,KAGX,IAEIhC,EAAYvO,EAFF4E,OAAOC,OAAO,CAAC,EAAGyL,GAAe,CAAC,EAAGC,GAAoB,CAAC,IAGxE,OAAKhC,GAILnJ,EAAQ6E,QAAQmG,4BAA8B,OAC9ChL,EAAQiL,sBAAwB9B,EAEzBA,GANI,IAOf,CAEA,SAASqD,EAA0BC,GAC1BA,GAAyC,mBAA1BA,EAAKjD,mBAIG,mBAAjBiD,EAAKC,SAA0BD,EAAKC,QAAQ,kFACnD3B,EAAsB0B,GAG1BA,EAAKjD,iBAAiB,iFAAiFC,QAAQsB,GACnH,CAEA,SAAS4B,KACLH,EAA0BrR,UAEM,oBAArByR,mBAII,IAAIA,iBAAiB,SAAUC,GAC1CA,EAAUpD,QAAQ,SAAUqD,GACxBA,EAASC,WAAWtD,QAAQ,SAAUuD,GAC9BA,GAA0B,IAAlBA,EAAKC,UACbT,EAA0BQ,EAElC,EACJ,EACJ,GAES9P,QAAQ/B,SAAS+R,KAAM,CAC5BC,WAAW,EACXC,SAAS,GAEjB,CAQA,MAN4B,YAAxBjS,SAASkS,WACTlS,SAASoC,iBAAiB,mBAAoBoP,EAAyB,CAAEW,MAAM,IAE/EX,IAGG,CACH/R,WAAYA,EACZmQ,sBAAuBA,EAE/B,CA1cmE","file":"ai-chat-widget.min.js","sourcesContent":["function clampWidgetValue(value, min, max) {\n return Math.min(Math.max(value, min), max);\n}\n\nwindow.coreAIChatWidgetBehavior = window.coreAIChatWidgetBehavior || function () {\n function parsePixelValue(value) {\n if (typeof value === 'number' && Number.isFinite(value)) {\n return value;\n }\n\n if (typeof value !== 'string') {\n return null;\n }\n\n var parsed = parseFloat(value);\n return Number.isFinite(parsed) ? parsed : null;\n }\n\n function attach(app, config) {\n if (!app || app.__aiChatWidgetAttached) {\n return;\n }\n\n app.__aiChatWidgetAttached = true;\n app.chatWidgetStateName = null;\n app.chatWidgetStateSession = null;\n app.chatWidgetStateDocuments = null;\n app.chatWidgetLayoutKey = null;\n app.chatHistorySection = null;\n app.widgetContainerElement = null;\n app.widgetToggleButtonElement = null;\n app.widgetResetSizeButtonElement = null;\n app.widgetResizeObserver = null;\n app.widgetViewportResizeHandler = null;\n app.widgetDefaultWidth = null;\n app.widgetDefaultHeight = null;\n app.widgetIsInitialized = false;\n\n app.getStoredWidgetLayout = function () {\n if (!this.chatWidgetLayoutKey || !config.widget.persistLayout) {\n return {};\n }\n\n try {\n var storedLayout = localStorage.getItem(this.chatWidgetLayoutKey);\n return storedLayout ? JSON.parse(storedLayout) || {} : {};\n }\n catch (error) {\n console.warn('Failed to read widget layout state.', error);\n return {};\n }\n };\n\n app.saveStoredWidgetLayout = function (partialLayout) {\n if (!this.chatWidgetLayoutKey || !config.widget.persistLayout) {\n return;\n }\n\n var currentLayout = this.getStoredWidgetLayout();\n var nextLayout = Object.assign({}, currentLayout);\n\n if (partialLayout.panel !== undefined) {\n nextLayout.panel = Object.assign({}, currentLayout.panel || {}, partialLayout.panel || {});\n }\n\n if (partialLayout.position !== undefined) {\n nextLayout.position = Object.assign({}, currentLayout.position || {}, partialLayout.position || {});\n }\n\n localStorage.setItem(this.chatWidgetLayoutKey, JSON.stringify(nextLayout));\n };\n\n app.getElementSize = function (element, fallbackWidth, fallbackHeight) {\n if (!element) {\n return {\n width: fallbackWidth || 0,\n height: fallbackHeight || 0\n };\n }\n\n var rect = element.getBoundingClientRect();\n var computed = window.getComputedStyle(element);\n\n return {\n width: Math.round(rect.width || parsePixelValue(computed.width) || fallbackWidth || 0),\n height: Math.round(rect.height || parsePixelValue(computed.height) || fallbackHeight || 0)\n };\n };\n\n app.getElementPosition = function (element) {\n if (!element) {\n return {\n left: 0,\n top: 0\n };\n }\n\n var rect = element.getBoundingClientRect();\n var computed = window.getComputedStyle(element);\n var inlineLeft = parsePixelValue(element.style.left);\n var inlineTop = parsePixelValue(element.style.top);\n var computedLeft = parsePixelValue(computed.left);\n var computedTop = parsePixelValue(computed.top);\n var isHidden = computed.display === 'none';\n\n return {\n left: Math.round(isHidden && Number.isFinite(inlineLeft) ? inlineLeft : rect.left || inlineLeft || computedLeft || 0),\n top: Math.round(isHidden && Number.isFinite(inlineTop) ? inlineTop : rect.top || inlineTop || computedTop || 0)\n };\n };\n\n app.getAvailableWidgetPositionRange = function (width, height) {\n var viewportPadding = 8;\n return {\n padding: viewportPadding,\n maxLeft: Math.max(viewportPadding, window.innerWidth - width - viewportPadding),\n maxTop: Math.max(viewportPadding, window.innerHeight - height - viewportPadding)\n };\n };\n\n app.createStoredPosition = function (left, top, width, height) {\n var range = this.getAvailableWidgetPositionRange(width, height);\n var leftSpan = Math.max(0, range.maxLeft - range.padding);\n var topSpan = Math.max(0, range.maxTop - range.padding);\n\n return {\n left: Math.round(left),\n top: Math.round(top),\n leftRatio: leftSpan === 0 ? 0 : (left - range.padding) / leftSpan,\n topRatio: topSpan === 0 ? 0 : (top - range.padding) / topSpan\n };\n };\n\n app.resolveStoredPosition = function (storedPosition, width, height) {\n if (!storedPosition) {\n return null;\n }\n\n var range = this.getAvailableWidgetPositionRange(width, height);\n var left = Number(storedPosition.left);\n var top = Number(storedPosition.top);\n var leftRatio = Number(storedPosition.leftRatio);\n var topRatio = Number(storedPosition.topRatio);\n\n if (Number.isFinite(leftRatio)) {\n left = range.padding + Math.max(0, range.maxLeft - range.padding) * leftRatio;\n }\n\n if (Number.isFinite(topRatio)) {\n top = range.padding + Math.max(0, range.maxTop - range.padding) * topRatio;\n }\n\n if (!Number.isFinite(left) || !Number.isFinite(top)) {\n return null;\n }\n\n return this.clampWidgetPosition(left, top, width, height);\n };\n\n app.clampWidgetPosition = function (left, top, width, height) {\n var range = this.getAvailableWidgetPositionRange(width, height);\n\n return {\n left: Math.round(clampWidgetValue(left, range.padding, range.maxLeft)),\n top: Math.round(clampWidgetValue(top, range.padding, range.maxTop))\n };\n };\n\n app.getStoredWidgetDocuments = function () {\n this.clearStoredWidgetDocuments();\n return [];\n };\n\n app.saveStoredWidgetDocuments = function () {\n this.clearStoredWidgetDocuments();\n };\n\n app.clearStoredWidgetDocuments = function () {\n if (!this.chatWidgetStateDocuments) {\n return;\n }\n\n localStorage.removeItem(this.chatWidgetStateDocuments);\n };\n\n app.applyAbsolutePosition = function (element, left, top) {\n if (!element) {\n return;\n }\n\n element.style.left = left + 'px';\n element.style.top = top + 'px';\n element.style.right = 'auto';\n element.style.bottom = 'auto';\n };\n\n app.getWidgetDefaultSize = function () {\n return {\n width: this.widgetDefaultWidth || parsePixelValue(config.widget.defaultWidth) || 380,\n height: this.widgetDefaultHeight || parsePixelValue(config.widget.defaultHeight) || 520\n };\n };\n\n app.getWidgetToggleGap = function () {\n return 8;\n };\n\n app.isWidgetPanelVisible = function () {\n if (!this.widgetContainerElement) {\n return false;\n }\n\n var computed = window.getComputedStyle(this.widgetContainerElement);\n return this.widgetContainerElement.classList.contains('open') && computed.display !== 'none';\n };\n\n app.persistWidgetPanelPosition = function () {\n if (!this.widgetContainerElement || !config.widget.persistLayout) {\n return;\n }\n\n var panelDefaultSize = this.getWidgetDefaultSize();\n var panelPosition = this.getElementPosition(this.widgetContainerElement);\n var panelSize = this.getElementSize(this.widgetContainerElement, panelDefaultSize.width, panelDefaultSize.height);\n var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);\n var linkedPosition = this.clampWidgetPosition(\n panelPosition.left + panelSize.width - toggleSize.width,\n panelPosition.top + panelSize.height + this.getWidgetToggleGap(),\n toggleSize.width,\n toggleSize.height);\n\n this.saveStoredWidgetLayout({ position: this.createStoredPosition(linkedPosition.left, linkedPosition.top, toggleSize.width, toggleSize.height) });\n };\n\n app.persistWidgetTogglePosition = function () {\n if (!this.widgetToggleButtonElement || !config.widget.persistLayout) {\n return;\n }\n\n var togglePosition = this.getElementPosition(this.widgetToggleButtonElement);\n var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);\n this.saveStoredWidgetLayout({ position: this.createStoredPosition(togglePosition.left, togglePosition.top, toggleSize.width, toggleSize.height) });\n };\n\n app.persistWidgetPanelSize = function () {\n if (!this.widgetContainerElement || !config.widget.enableResizing || !config.widget.persistLayout) {\n return;\n }\n\n var defaultSize = this.getWidgetDefaultSize();\n var currentSize = this.getElementSize(this.widgetContainerElement, defaultSize.width, defaultSize.height);\n\n this.saveStoredWidgetLayout({\n panel: {\n width: Math.abs(currentSize.width - defaultSize.width) <= 1 ? null : currentSize.width,\n height: Math.abs(currentSize.height - defaultSize.height) <= 1 ? null : currentSize.height\n }\n });\n };\n\n app.syncTogglePositionToPanel = function (persistLayout) {\n if (persistLayout === undefined) {\n persistLayout = true;\n }\n\n if (!this.widgetContainerElement || !this.widgetToggleButtonElement) {\n return;\n }\n\n var panelDefaultSize = this.getWidgetDefaultSize();\n var panelSize = this.getElementSize(this.widgetContainerElement, panelDefaultSize.width, panelDefaultSize.height);\n var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);\n var panelPosition = this.getElementPosition(this.widgetContainerElement);\n var linkedPosition = this.clampWidgetPosition(\n panelPosition.left + panelSize.width - toggleSize.width,\n panelPosition.top + panelSize.height + this.getWidgetToggleGap(),\n toggleSize.width,\n toggleSize.height);\n\n this.applyAbsolutePosition(this.widgetToggleButtonElement, linkedPosition.left, linkedPosition.top);\n\n if (persistLayout && config.widget.persistLayout) {\n this.persistWidgetTogglePosition();\n }\n };\n\n app.syncPanelPositionToToggle = function (persistLayout) {\n if (persistLayout === undefined) {\n persistLayout = true;\n }\n\n if (!this.widgetContainerElement || !this.widgetToggleButtonElement) {\n return;\n }\n\n var panelDefaultSize = this.getWidgetDefaultSize();\n var panelSize = this.getElementSize(this.widgetContainerElement, panelDefaultSize.width, panelDefaultSize.height);\n var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);\n var togglePosition = this.getElementPosition(this.widgetToggleButtonElement);\n var linkedPosition = this.clampWidgetPosition(\n togglePosition.left + toggleSize.width - panelSize.width,\n togglePosition.top - panelSize.height - this.getWidgetToggleGap(),\n panelSize.width,\n panelSize.height);\n\n this.applyAbsolutePosition(this.widgetContainerElement, linkedPosition.left, linkedPosition.top);\n\n if (persistLayout && config.widget.persistLayout) {\n this.persistWidgetPanelPosition();\n }\n };\n\n app.updateWidgetResetSizeButtonVisibility = function () {\n if (!this.widgetResetSizeButtonElement) {\n return;\n }\n\n if (!config.widget.enableResizing || !this.widgetContainerElement) {\n this.widgetResetSizeButtonElement.classList.add('d-none');\n return;\n }\n\n var defaultSize = this.getWidgetDefaultSize();\n var currentSize = this.getElementSize(this.widgetContainerElement, defaultSize.width, defaultSize.height);\n var isResized =\n Math.abs(currentSize.width - defaultSize.width) > 1 ||\n Math.abs(currentSize.height - defaultSize.height) > 1 ||\n !!this.widgetContainerElement.style.width ||\n !!this.widgetContainerElement.style.height;\n\n this.widgetResetSizeButtonElement.classList.toggle('d-none', !isResized);\n };\n\n app.resetWidgetSize = function () {\n if (!this.widgetContainerElement || !config.widget.enableResizing) {\n return;\n }\n\n this.widgetContainerElement.style.removeProperty('width');\n this.widgetContainerElement.style.removeProperty('height');\n this.persistWidgetPanelSize();\n this.constrainWidgetElementsToViewport();\n this.updateWidgetResetSizeButtonVisibility();\n };\n\n app.restoreWidgetLayout = function () {\n var storedLayout = this.getStoredWidgetLayout();\n\n if (this.widgetContainerElement && config.widget.enableResizing) {\n if (Number.isFinite(storedLayout.panel && storedLayout.panel.width)) {\n this.widgetContainerElement.style.width = storedLayout.panel.width + 'px';\n }\n else {\n this.widgetContainerElement.style.removeProperty('width');\n }\n\n if (Number.isFinite(storedLayout.panel && storedLayout.panel.height)) {\n this.widgetContainerElement.style.height = storedLayout.panel.height + 'px';\n }\n else {\n this.widgetContainerElement.style.removeProperty('height');\n }\n }\n\n var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);\n var storedTogglePosition = this.resolveStoredPosition(storedLayout.position, toggleSize.width, toggleSize.height);\n if (this.widgetToggleButtonElement && config.widget.enableDragging && storedTogglePosition) {\n this.applyAbsolutePosition(this.widgetToggleButtonElement, storedTogglePosition.left, storedTogglePosition.top);\n this.syncPanelPositionToToggle(false);\n }\n else if (this.widgetToggleButtonElement && config.widget.enableDragging &&\n Number.isFinite(storedLayout.toggle && storedLayout.toggle.left) &&\n Number.isFinite(storedLayout.toggle && storedLayout.toggle.top)) {\n this.applyAbsolutePosition(this.widgetToggleButtonElement, storedLayout.toggle.left, storedLayout.toggle.top);\n this.syncPanelPositionToToggle(false);\n }\n else if (this.widgetContainerElement && config.widget.enableDragging &&\n Number.isFinite(storedLayout.panel && storedLayout.panel.left) &&\n Number.isFinite(storedLayout.panel && storedLayout.panel.top)) {\n this.applyAbsolutePosition(this.widgetContainerElement, storedLayout.panel.left, storedLayout.panel.top);\n this.syncTogglePositionToPanel(false);\n }\n\n this.constrainWidgetElementsToViewport();\n this.updateWidgetResetSizeButtonVisibility();\n };\n\n app.attachDraggableWidgetElement = function (element, handle, layoutKey, suppressClickOnDrag) {\n if (!element || !handle || !config.widget.enableDragging) {\n return;\n }\n\n var activePointerId = null;\n var startX = 0;\n var startY = 0;\n var startLeft = 0;\n var startTop = 0;\n var dragged = false;\n var dragThreshold = 4;\n var interactiveSelector = 'button, a, input, textarea, select, option, label';\n var self = this;\n\n function stopDragging(event) {\n if (activePointerId === null) {\n return;\n }\n\n if (event && event.pointerId !== undefined && event.pointerId !== activePointerId) {\n return;\n }\n\n document.removeEventListener('pointermove', onPointerMove);\n document.removeEventListener('pointerup', stopDragging);\n document.removeEventListener('pointercancel', stopDragging);\n element.classList.remove('ai-chat-widget-dragging');\n activePointerId = null;\n\n if (!dragged) {\n return;\n }\n\n if (layoutKey === 'panel') {\n self.syncTogglePositionToPanel(false);\n self.persistWidgetPanelPosition();\n }\n else if (layoutKey === 'toggle') {\n self.syncPanelPositionToToggle(false);\n self.persistWidgetTogglePosition();\n }\n\n if (config.widget.persistLayout) {\n self.persistWidgetPanelPosition();\n self.persistWidgetTogglePosition();\n }\n\n if (suppressClickOnDrag) {\n element.dataset.dragSuppressClick = 'true';\n window.setTimeout(function () {\n if (element.dataset.dragSuppressClick === 'true') {\n element.dataset.dragSuppressClick = 'false';\n }\n }, 0);\n }\n }\n\n function onPointerMove(event) {\n if (activePointerId === null || event.pointerId !== activePointerId) {\n return;\n }\n\n var deltaX = event.clientX - startX;\n var deltaY = event.clientY - startY;\n\n if (!dragged && Math.hypot(deltaX, deltaY) < dragThreshold) {\n return;\n }\n\n dragged = true;\n\n var defaultSize = self.getWidgetDefaultSize();\n var currentSize = self.getElementSize(\n element,\n layoutKey === 'panel' ? defaultSize.width : 52,\n layoutKey === 'panel' ? defaultSize.height : 52);\n var nextPosition = self.clampWidgetPosition(startLeft + deltaX, startTop + deltaY, currentSize.width, currentSize.height);\n\n self.applyAbsolutePosition(element, nextPosition.left, nextPosition.top);\n\n if (layoutKey === 'panel') {\n self.syncTogglePositionToPanel(false);\n }\n else if (layoutKey === 'toggle') {\n self.syncPanelPositionToToggle(false);\n }\n }\n\n handle.addEventListener('pointerdown', function (event) {\n if (event.button !== 0) {\n return;\n }\n\n if (layoutKey === 'panel' && event.target.closest(interactiveSelector)) {\n return;\n }\n\n var rect = element.getBoundingClientRect();\n startX = event.clientX;\n startY = event.clientY;\n startLeft = rect.left;\n startTop = rect.top;\n dragged = false;\n activePointerId = event.pointerId;\n element.classList.add('ai-chat-widget-dragging');\n\n if (handle.setPointerCapture) {\n handle.setPointerCapture(event.pointerId);\n }\n\n document.addEventListener('pointermove', onPointerMove);\n document.addEventListener('pointerup', stopDragging);\n document.addEventListener('pointercancel', stopDragging);\n event.preventDefault();\n });\n };\n\n app.constrainWidgetElementsToViewport = function () {\n if (this.widgetContainerElement && this.widgetContainerElement.style.left && this.isWidgetPanelVisible()) {\n var panelDefaultSize = this.getWidgetDefaultSize();\n var panelSize = this.getElementSize(this.widgetContainerElement, panelDefaultSize.width, panelDefaultSize.height);\n var panelPosition = this.getElementPosition(this.widgetContainerElement);\n var clampedPanel = this.clampWidgetPosition(panelPosition.left, panelPosition.top, panelSize.width, panelSize.height);\n\n this.applyAbsolutePosition(this.widgetContainerElement, clampedPanel.left, clampedPanel.top);\n this.syncTogglePositionToPanel(false);\n\n if (config.widget.persistLayout) {\n this.persistWidgetPanelPosition();\n this.persistWidgetTogglePosition();\n }\n }\n else if (this.widgetToggleButtonElement && this.widgetToggleButtonElement.style.left) {\n var toggleSize = this.getElementSize(this.widgetToggleButtonElement, 52, 52);\n var togglePosition = this.getElementPosition(this.widgetToggleButtonElement);\n var clampedToggle = this.clampWidgetPosition(togglePosition.left, togglePosition.top, toggleSize.width, toggleSize.height);\n\n this.applyAbsolutePosition(this.widgetToggleButtonElement, clampedToggle.left, clampedToggle.top);\n this.syncPanelPositionToToggle(false);\n\n if (config.widget.persistLayout) {\n this.persistWidgetTogglePosition();\n this.persistWidgetPanelPosition();\n }\n }\n };\n\n app.showChatScreen = function () {\n if (!this.chatHistorySection) {\n return;\n }\n\n this.chatHistorySection.classList.remove('show');\n };\n }\n\n function initialize(app, config) {\n if (!app || app.widgetIsInitialized) {\n return;\n }\n\n if (!config.widget.chatWidgetContainer) {\n console.error('The widget chatWidgetContainer is required.');\n return;\n }\n\n if (!config.widget.chatWidgetStateName) {\n console.error('The widget chatWidgetStateName is required.');\n return;\n }\n\n var chatWidgetContainer = document.querySelector(config.widget.chatWidgetContainer);\n if (!chatWidgetContainer) {\n return;\n }\n\n if (config.widget.chatHistorySection) {\n app.chatHistorySection = document.querySelector(config.widget.chatHistorySection);\n }\n\n app.chatWidgetStateName = config.widget.chatWidgetStateName;\n app.chatWidgetStateSession = config.widget.chatWidgetStateName + 'Session';\n app.chatWidgetStateDocuments = config.widget.chatWidgetStateName + 'Documents';\n app.chatWidgetLayoutKey = config.widget.chatWidgetStateName + 'Layout';\n app.widgetContainerElement = chatWidgetContainer;\n app.widgetToggleButtonElement = config.widget.toggleButtonSelector ? document.querySelector(config.widget.toggleButtonSelector) : null;\n app.widgetResetSizeButtonElement = config.widget.resetSizeButtonSelector ? document.querySelector(config.widget.resetSizeButtonSelector) : null;\n app.widgetDefaultWidth = parsePixelValue(config.widget.defaultWidth) || parsePixelValue(window.getComputedStyle(chatWidgetContainer).width) || 380;\n app.widgetDefaultHeight = parsePixelValue(config.widget.defaultHeight) || parsePixelValue(window.getComputedStyle(chatWidgetContainer).height) || 520;\n app.widgetIsInitialized = true;\n app.clearStoredWidgetDocuments();\n app.documents = [];\n\n if (config.widget.enableResizing) {\n chatWidgetContainer.classList.add('ai-chat-widget-resizable');\n chatWidgetContainer.style.minWidth = (parsePixelValue(config.widget.minWidth) || 320) + 'px';\n chatWidgetContainer.style.minHeight = (parsePixelValue(config.widget.minHeight) || 420) + 'px';\n\n if (typeof ResizeObserver !== 'undefined') {\n app.widgetResizeObserver = new ResizeObserver(function () {\n app.persistWidgetPanelSize();\n app.constrainWidgetElementsToViewport();\n app.updateWidgetResetSizeButtonVisibility();\n });\n\n app.widgetResizeObserver.observe(chatWidgetContainer);\n }\n }\n\n var dragHandleSelector = config.widget.dragHandleSelector || '.ai-chat-widget-header';\n var dragHandle = chatWidgetContainer.querySelector(dragHandleSelector);\n\n if (config.widget.enableDragging && dragHandle) {\n dragHandle.classList.add('ai-chat-widget-drag-handle');\n chatWidgetContainer.classList.add('ai-chat-widget-draggable');\n app.attachDraggableWidgetElement(chatWidgetContainer, dragHandle, 'panel', false);\n }\n\n if (config.widget.enableDragging && app.widgetToggleButtonElement) {\n app.widgetToggleButtonElement.classList.add('ai-chat-widget-draggable');\n app.attachDraggableWidgetElement(app.widgetToggleButtonElement, app.widgetToggleButtonElement, 'toggle', true);\n }\n\n if (app.widgetResetSizeButtonElement) {\n app.widgetResetSizeButtonElement.addEventListener('click', function (event) {\n event.preventDefault();\n app.resetWidgetSize();\n });\n }\n\n app.restoreWidgetLayout();\n\n if (!app.widgetViewportResizeHandler) {\n app.widgetViewportResizeHandler = function () {\n if (config.widget.persistLayout) {\n app.restoreWidgetLayout();\n } else {\n app.constrainWidgetElementsToViewport();\n }\n\n app.updateWidgetResetSizeButtonVisibility();\n };\n\n window.addEventListener('resize', app.widgetViewportResizeHandler);\n }\n\n app.reloadCurrentSession();\n\n if (config.widget.showHistoryButton && app.chatHistorySection) {\n var showHistoryButton = document.querySelector(config.widget.showHistoryButton);\n if (showHistoryButton) {\n showHistoryButton.addEventListener('click', function () {\n app.chatHistorySection.classList.toggle('show');\n });\n }\n\n if (config.widget.closeHistoryButton) {\n var closeHistoryButton = document.querySelector(config.widget.closeHistoryButton);\n if (closeHistoryButton) {\n closeHistoryButton.addEventListener('click', function () {\n app.showChatScreen();\n });\n }\n }\n }\n\n if (config.widget.newChatButton) {\n var newChatButton = document.querySelector(config.widget.newChatButton);\n if (newChatButton) {\n newChatButton.addEventListener('click', function () {\n app.resetSession();\n app.showChatScreen();\n });\n }\n }\n }\n\n function resolveSessionId(app) {\n if (!app || !app.widgetIsInitialized) {\n return null;\n }\n\n return localStorage.getItem(app.chatWidgetStateSession);\n }\n\n function onSessionInitialized(app, sessionId) {\n if (app && app.widgetIsInitialized) {\n localStorage.setItem(app.chatWidgetStateSession, sessionId);\n }\n }\n\n function onSessionReset(app) {\n if (app && app.widgetIsInitialized) {\n localStorage.removeItem(app.chatWidgetStateSession);\n app.clearStoredWidgetDocuments();\n }\n }\n\n function onDocumentsChanged(app, documents) {\n if (app && app.widgetIsInitialized) {\n app.saveStoredWidgetDocuments(documents);\n }\n }\n\n function handleReceiveError(app) {\n if (app && app.widgetIsInitialized && !app.isSessionStarted && !app._attemptedSessionRecovery) {\n app._attemptedSessionRecovery = true;\n localStorage.removeItem(app.chatWidgetStateSession);\n app.clearStoredWidgetDocuments();\n app.startNewSession();\n }\n }\n\n function dispose(app) {\n if (!app) {\n return;\n }\n\n if (app.widgetResizeObserver) {\n app.widgetResizeObserver.disconnect();\n app.widgetResizeObserver = null;\n }\n\n if (app.widgetViewportResizeHandler) {\n window.removeEventListener('resize', app.widgetViewportResizeHandler);\n app.widgetViewportResizeHandler = null;\n }\n }\n\n return {\n attach: attach,\n initialize: initialize,\n onMounted: initialize,\n resolveSessionId: resolveSessionId,\n onSessionInitialized: onSessionInitialized,\n onSessionReset: onSessionReset,\n onDocumentsChanged: onDocumentsChanged,\n handleReceiveError: handleReceiveError,\n dispose: dispose,\n onBeforeUnmount: dispose\n };\n}();\n\nwindow.coreAIChatWidgetManager = window.coreAIChatWidgetManager || function () {\n function getAttributeValue(element, attributeName) {\n var value = element.getAttribute(attributeName);\n return value === null || value === '' ? null : value;\n }\n\n function parseBooleanAttributeValue(value) {\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === 'boolean') {\n return value;\n }\n\n var normalized = String(value).trim().toLowerCase();\n if (normalized === 'true') {\n return true;\n }\n\n if (normalized === 'false') {\n return false;\n }\n\n return null;\n }\n\n function parseJsonAttribute(element, attributeName, description) {\n var rawValue = getAttributeValue(element, attributeName);\n if (!rawValue) {\n return null;\n }\n\n try {\n return JSON.parse(rawValue);\n }\n catch (error) {\n console.error('Failed to parse ' + description + ' JSON.', error);\n return null;\n }\n }\n\n function buildOptionsFromDataAttributes(element) {\n var widgetContainerSelector = getAttributeValue(element, 'data-coreai-chat-widget-container-selector');\n if (!widgetContainerSelector) {\n return null;\n }\n\n var chatConfig = null;\n if (window.coreAIChatManager && typeof window.coreAIChatManager.buildConfigFromElement === 'function') {\n chatConfig = window.coreAIChatManager.buildConfigFromElement(element, { allowWidgetHost: true });\n }\n\n var profileId = getAttributeValue(element, 'data-coreai-chat-widget-profile-id');\n var profileName = getAttributeValue(element, 'data-coreai-chat-widget-profile-name');\n var profileDisplayText = getAttributeValue(element, 'data-coreai-chat-widget-profile-display-text');\n var profileWelcomeMessage = getAttributeValue(element, 'data-coreai-chat-widget-profile-welcome-message');\n var profileInitialPrompt = getAttributeValue(element, 'data-coreai-chat-widget-profile-initial-prompt');\n var profileChatMode = getAttributeValue(element, 'data-coreai-chat-widget-profile-chat-mode');\n var profileTtsVoiceName = getAttributeValue(element, 'data-coreai-chat-widget-profile-tts-voice-name');\n var profileMetricsEnabled = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-profile-enable-session-metrics'));\n var profileSessionDocuments = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-profile-allow-session-documents'));\n var profile = null;\n\n if (profileId || profileName || profileDisplayText || profileWelcomeMessage || profileChatMode || profileTtsVoiceName || profileMetricsEnabled !== null || profileSessionDocuments !== null) {\n profile = {\n id: profileId,\n name: profileName,\n displayText: profileDisplayText,\n welcomeMessage: profileWelcomeMessage,\n initialPrompt: profileInitialPrompt,\n chatMode: profileChatMode,\n ttsVoiceName: profileTtsVoiceName,\n enableSessionMetrics: profileMetricsEnabled === true,\n allowSessionDocuments: profileSessionDocuments === true\n };\n }\n\n var enableDragging = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-enable-dragging'));\n var enableResizing = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-enable-resizing'));\n var persistLayout = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-persist-layout'));\n\n return {\n shellSelector: getAttributeValue(element, 'data-coreai-chat-widget-shell-selector'),\n widgetContainerSelector: widgetContainerSelector,\n toggleButtonSelector: getAttributeValue(element, 'data-coreai-chat-widget-toggle-button-selector'),\n closeButtonSelector: getAttributeValue(element, 'data-coreai-chat-widget-close-button-selector'),\n inputSelector: getAttributeValue(element, 'data-coreai-chat-widget-input-selector'),\n messageTemplateSelector: getAttributeValue(element, 'data-coreai-chat-widget-message-template-selector'),\n indicatorTemplateSelector: getAttributeValue(element, 'data-coreai-chat-widget-indicator-template-selector'),\n profile: profile,\n widgetStateName: getAttributeValue(element, 'data-coreai-chat-widget-state-name'),\n openStateValue: getAttributeValue(element, 'data-coreai-chat-widget-open-state-value'),\n closedStateValue: getAttributeValue(element, 'data-coreai-chat-widget-closed-state-value'),\n openIconHtml: getAttributeValue(element, 'data-coreai-chat-widget-open-icon-html'),\n closedIconHtml: getAttributeValue(element, 'data-coreai-chat-widget-closed-icon-html'),\n chatConfig: chatConfig ? Object.assign({}, chatConfig, {\n initialPrompt: profileInitialPrompt || chatConfig.initialPrompt,\n widget: Object.assign({}, chatConfig.widget || {}, {\n chatWidgetContainer: widgetContainerSelector,\n chatWidgetStateName: getAttributeValue(element, 'data-coreai-chat-widget-state-name'),\n newChatButton: getAttributeValue(element, 'data-coreai-chat-widget-new-chat-button-selector'),\n toggleButtonSelector: getAttributeValue(element, 'data-coreai-chat-widget-toggle-button-selector'),\n resetSizeButtonSelector: getAttributeValue(element, 'data-coreai-chat-widget-reset-size-button-selector'),\n dragHandleSelector: getAttributeValue(element, 'data-coreai-chat-widget-drag-handle-selector'),\n enableDragging: enableDragging === null ? undefined : enableDragging,\n enableResizing: enableResizing === null ? undefined : enableResizing,\n persistLayout: persistLayout === null ? undefined : persistLayout,\n })\n }) : null\n };\n }\n\n function initialize(options) {\n if (!options) {\n return null;\n }\n\n var chatConfig = options.chatConfig;\n if (!chatConfig && options.configElementSelector) {\n var configElement = document.querySelector(options.configElementSelector);\n chatConfig = configElement ? parseJsonAttribute(configElement, 'data-config', 'AI chat widget config') : null;\n }\n\n if (!chatConfig) {\n return null;\n }\n\n if (options.messageTemplateSelector) {\n var messageTemplate = document.querySelector(options.messageTemplateSelector);\n if (messageTemplate) {\n chatConfig.messageTemplate = messageTemplate.innerHTML;\n }\n }\n\n if (options.indicatorTemplateSelector) {\n var indicatorTemplate = document.querySelector(options.indicatorTemplateSelector);\n if (indicatorTemplate) {\n chatConfig.indicatorTemplate = indicatorTemplate.innerHTML;\n }\n }\n\n var shell = document.querySelector(options.shellSelector);\n var widgetContainer = document.querySelector(options.widgetContainerSelector);\n var toggleButton = document.querySelector(options.toggleButtonSelector);\n var closeButton = document.querySelector(options.closeButtonSelector);\n var profileInput = options.inputSelector ? document.querySelector(options.inputSelector) : null;\n var widgetStateName = options.widgetStateName || chatConfig.widget.chatWidgetStateName;\n var widgetOpenStateKey = options.widgetOpenStateKey || (widgetStateName + 'Open');\n var widgetLayoutKey = widgetStateName + 'Layout';\n var openStateValue = options.openStateValue || 'open';\n var closedStateValue = options.closedStateValue || 'closed';\n\n if (profileInput && options.profile && options.profile.id) {\n profileInput.setAttribute('data-profile-id', options.profile.id);\n }\n\n try {\n var storedLayout = localStorage.getItem(widgetLayoutKey);\n var layout = storedLayout ? JSON.parse(storedLayout) || {} : {};\n var position = layout.position || {};\n var panelLayout = layout.panel || {};\n var toggleLeft = Number(position.left);\n var toggleTop = Number(position.top);\n var isOpen = localStorage.getItem(widgetOpenStateKey) === openStateValue;\n var viewportPadding = 8;\n\n if (shell) {\n shell.dataset.deferReveal = isOpen ? 'true' : 'false';\n shell.dataset.initialOpen = isOpen ? 'true' : 'false';\n }\n\n if (widgetContainer && toggleButton) {\n var toggleSize = 52;\n var panelWidth = Number.isFinite(Number(panelLayout.width))\n ? Number(panelLayout.width)\n : Math.round(parseFloat(window.getComputedStyle(widgetContainer).width) || 380);\n var panelHeight = Number.isFinite(Number(panelLayout.height))\n ? Number(panelLayout.height)\n : Math.round(parseFloat(window.getComputedStyle(widgetContainer).height) || 520);\n var maxLeft = Math.max(viewportPadding, window.innerWidth - toggleSize - viewportPadding);\n var maxTop = Math.max(viewportPadding, window.innerHeight - toggleSize - viewportPadding);\n if (Number.isFinite(Number(position.leftRatio))) {\n toggleLeft = viewportPadding + Math.max(0, maxLeft - viewportPadding) * Number(position.leftRatio);\n }\n if (Number.isFinite(Number(position.topRatio))) {\n toggleTop = viewportPadding + Math.max(0, maxTop - viewportPadding) * Number(position.topRatio);\n }\n if (Number.isFinite(toggleLeft) && Number.isFinite(toggleTop)) {\n toggleLeft = Math.round(clampWidgetValue(toggleLeft, viewportPadding, maxLeft));\n toggleTop = Math.round(clampWidgetValue(toggleTop, viewportPadding, maxTop));\n }\n\n if (Number.isFinite(toggleLeft) && Number.isFinite(toggleTop)) {\n toggleButton.style.left = toggleLeft + 'px';\n toggleButton.style.top = toggleTop + 'px';\n toggleButton.style.right = 'auto';\n toggleButton.style.bottom = 'auto';\n\n var toggleGap = 8;\n widgetContainer.style.left = (toggleLeft + toggleSize - panelWidth) + 'px';\n widgetContainer.style.top = (toggleTop - panelHeight - toggleGap) + 'px';\n widgetContainer.style.right = 'auto';\n widgetContainer.style.bottom = 'auto';\n }\n }\n\n if (widgetContainer) {\n widgetContainer.classList.remove('open');\n widgetContainer.style.display = 'none';\n widgetContainer.setAttribute('aria-hidden', 'true');\n }\n\n if (toggleButton) {\n toggleButton.innerHTML = isOpen ? options.openIconHtml : options.closedIconHtml;\n }\n }\n catch (error) {\n console.warn('Failed to restore widget layout before initialization.', error);\n }\n finally {\n if (shell && shell.dataset.deferReveal !== 'true') {\n shell.style.visibility = '';\n }\n }\n\n var widgetApp = window.coreAIChatManager.initialize(chatConfig);\n if (options.applySessionProfilePatch !== false && window.crestAppsAIChat && window.crestAppsAIChat.patchSessionProfileSync) {\n window.crestAppsAIChat.patchSessionProfileSync(widgetApp);\n }\n\n function revealShell() {\n if (!shell) {\n return;\n }\n\n shell.style.visibility = '';\n shell.dataset.deferReveal = 'false';\n }\n\n function syncOpenPanelPosition() {\n if (!widgetApp || typeof widgetApp.syncPanelPositionToToggle !== 'function') {\n return;\n }\n\n widgetApp.syncPanelPositionToToggle(false);\n }\n\n function updateTtsPlaybackButtons() {\n if (!widgetContainer) {\n return;\n }\n\n var buttons = widgetContainer.querySelectorAll('[data-tts-message-index]');\n buttons.forEach(function (button) {\n var buttonIndex = Number(button.getAttribute('data-tts-message-index'));\n var isPlaying = buttonIndex === widgetApp.ttsPlayingMessageIndex;\n button.classList.toggle('tts-playing', isPlaying);\n button.setAttribute('title', isPlaying ? 'Pause audio' : 'Read aloud');\n });\n }\n\n function queueTtsPlaybackButtonUpdate() {\n requestAnimationFrame(updateTtsPlaybackButtons);\n }\n\n function revealShellWhenStable(initialOpen) {\n if (!shell || shell.dataset.deferReveal !== 'true' || !initialOpen) {\n revealShell();\n return;\n }\n\n var hasRevealed = false;\n var resizeObserver = null;\n\n function finalizeReveal() {\n if (hasRevealed) {\n return;\n }\n\n hasRevealed = true;\n\n if (resizeObserver) {\n resizeObserver.disconnect();\n }\n\n requestAnimationFrame(function () {\n syncOpenPanelPosition();\n requestAnimationFrame(function () {\n revealShell();\n });\n });\n }\n\n if (typeof ResizeObserver === 'undefined') {\n window.setTimeout(finalizeReveal, 0);\n return;\n }\n\n var lastWidth = 0;\n var lastHeight = 0;\n var stablePasses = 0;\n\n resizeObserver = new ResizeObserver(function (entries) {\n var entry = entries && entries[0];\n if (!entry) {\n return;\n }\n\n var width = Math.round(entry.contentRect.width);\n var height = Math.round(entry.contentRect.height);\n if (!width || !height) {\n return;\n }\n\n syncOpenPanelPosition();\n\n if (width === lastWidth && height === lastHeight) {\n stablePasses++;\n }\n else {\n lastWidth = width;\n lastHeight = height;\n stablePasses = 0;\n }\n\n if (stablePasses >= 1) {\n finalizeReveal();\n }\n });\n\n resizeObserver.observe(widgetContainer);\n window.setTimeout(finalizeReveal, 150);\n }\n\n function setWidgetOpen(isOpen) {\n if (widgetApp) {\n var isCurrentlyOpen = widgetContainer.classList.contains('open');\n if (isOpen && !isCurrentlyOpen && typeof widgetApp.syncPanelPositionToToggle === 'function') {\n widgetApp.syncPanelPositionToToggle();\n }\n else if (!isOpen && isCurrentlyOpen && typeof widgetApp.syncTogglePositionToPanel === 'function') {\n widgetApp.syncTogglePositionToPanel();\n }\n }\n\n widgetContainer.classList.toggle('open', isOpen);\n widgetContainer.style.display = isOpen ? 'flex' : 'none';\n widgetContainer.setAttribute('aria-hidden', isOpen ? 'false' : 'true');\n toggleButton.innerHTML = isOpen ? options.openIconHtml : options.closedIconHtml;\n localStorage.setItem(widgetOpenStateKey, isOpen ? openStateValue : closedStateValue);\n\n if (isOpen && typeof window.renderPendingCharts === 'function') {\n setTimeout(function () { window.renderPendingCharts(); }, 100);\n }\n }\n\n var initialOpen = shell && shell.dataset.initialOpen === 'true';\n setWidgetOpen(initialOpen);\n revealShellWhenStable(initialOpen);\n\n if (widgetApp && typeof widgetApp.$watch === 'function') {\n widgetApp.$watch('ttsPlayingMessageIndex', function () {\n queueTtsPlaybackButtonUpdate();\n });\n }\n\n queueTtsPlaybackButtonUpdate();\n\n if (toggleButton) {\n toggleButton.addEventListener('click', function () {\n if (toggleButton.dataset.dragSuppressClick === 'true') {\n toggleButton.dataset.dragSuppressClick = 'false';\n return;\n }\n\n setWidgetOpen(!widgetContainer.classList.contains('open'));\n });\n }\n\n if (closeButton) {\n closeButton.addEventListener('click', function () {\n setWidgetOpen(false);\n });\n }\n\n return widgetApp;\n }\n\n function initializeFromElement(element) {\n if (!element || element.dataset.coreAiChatWidgetInitialized === 'true') {\n return element ? element.__coreAIChatWidgetApp || null : null;\n }\n\n var jsonOptions = parseJsonAttribute(element, 'data-coreai-chat-widget-config', 'CoreAI chat widget config');\n var attributeOptions = buildOptionsFromDataAttributes(element);\n if (!jsonOptions && !attributeOptions) {\n return null;\n }\n\n var options = Object.assign({}, jsonOptions || {}, attributeOptions || {});\n\n var widgetApp = initialize(options);\n if (!widgetApp) {\n return null;\n }\n\n element.dataset.coreAiChatWidgetInitialized = 'true';\n element.__coreAIChatWidgetApp = widgetApp;\n\n return widgetApp;\n }\n\n function scanForAutoInitialization(root) {\n if (!root || typeof root.querySelectorAll !== 'function') {\n return;\n }\n\n if (typeof root.matches === 'function' && root.matches('[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]')) {\n initializeFromElement(root);\n }\n\n root.querySelectorAll('[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]').forEach(initializeFromElement);\n }\n\n function startAutoInitialization() {\n scanForAutoInitialization(document);\n\n if (typeof MutationObserver === 'undefined') {\n return;\n }\n\n var observer = new MutationObserver(function (mutations) {\n mutations.forEach(function (mutation) {\n mutation.addedNodes.forEach(function (node) {\n if (node && node.nodeType === 1) {\n scanForAutoInitialization(node);\n }\n });\n });\n });\n\n observer.observe(document.body, {\n childList: true,\n subtree: true,\n });\n }\n\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', startAutoInitialization, { once: true });\n } else {\n startAutoInitialization();\n }\n\n return {\n initialize: initialize,\n initializeFromElement: initializeFromElement,\n };\n}();\n"]}
package/dist/ai-chat.js CHANGED
@@ -1186,10 +1186,12 @@ window.coreAIChatManager = function () {
1186
1186
  });
1187
1187
 
1188
1188
  // When the session is new (no messages) and an initial prompt is configured,
1189
- // automatically send it as the first user message to trigger an AI response.
1189
+ // display it as the first assistant message without invoking the AI.
1190
1190
  if (_this3.messages.length === 0 && config.initialPrompt) {
1191
- _this3.prompt = config.initialPrompt;
1192
- _this3.sendMessage();
1191
+ _this3.addMessage({
1192
+ role: 'assistant',
1193
+ content: config.initialPrompt
1194
+ });
1193
1195
  }
1194
1196
  });
1195
1197
  _this3.connection.on("ReceiveError", function (error) {
@@ -1355,8 +1357,6 @@ window.coreAIChatManager = function () {
1355
1357
  console.info("SignalR: reconnected.");
1356
1358
  if (_this3.isSessionStarted) {
1357
1359
  _this3.reloadCurrentSession();
1358
- } else if (config.autoCreateSession) {
1359
- _this3.startNewSession();
1360
1360
  }
1361
1361
  });
1362
1362
  _this3.connection.onclose(function (error) {
@@ -2311,12 +2311,17 @@ window.coreAIChatManager = function () {
2311
2311
  this.sessionRating = null;
2312
2312
  this.messages = [];
2313
2313
  this.documents = [];
2314
- if (!config.autoCreateSession) {
2314
+
2315
+ // When an initial prompt is configured, show it as the first
2316
+ // assistant message instead of the generic placeholder.
2317
+ if (config.initialPrompt) {
2318
+ this.addMessage({
2319
+ role: 'assistant',
2320
+ content: config.initialPrompt
2321
+ });
2322
+ } else {
2315
2323
  this.showPlaceholder();
2316
2324
  }
2317
- if (config.autoCreateSession) {
2318
- this.startNewSession();
2319
- }
2320
2325
  if (widgetBehavior && typeof widgetBehavior.onSessionReset === 'function') {
2321
2326
  widgetBehavior.onSessionReset(this, config);
2322
2327
  }
@@ -2421,8 +2426,6 @@ window.coreAIChatManager = function () {
2421
2426
  var sessionId = this.getSessionId();
2422
2427
  if (!hasWidgetConfig && sessionId) {
2423
2428
  this.loadSession(sessionId);
2424
- } else if (this.isOrchestratorAvailable() && config.autoCreateSession && !hasWidgetConfig && !sessionId) {
2425
- this.startNewSession();
2426
2429
  }
2427
2430
 
2428
2431
  // Initialize document bar if enabled.
@@ -2532,6 +2535,15 @@ window.coreAIChatManager = function () {
2532
2535
  this.addMessage(initialMessages[_i5]);
2533
2536
  }
2534
2537
 
2538
+ // When no messages were loaded and an initial prompt is configured,
2539
+ // display it as the first assistant message without invoking the AI.
2540
+ if (this.messages.length === 0 && config.initialPrompt) {
2541
+ this.addMessage({
2542
+ role: 'assistant',
2543
+ content: config.initialPrompt
2544
+ });
2545
+ }
2546
+
2535
2547
  // Update feedback icons in the DOM after initial messages have rendered.
2536
2548
  this.$nextTick(function () {
2537
2549
  _this22.refreshAllFeedbackIcons();
@@ -2611,6 +2623,13 @@ window.coreAIChatManager = function () {
2611
2623
  if (widgetBehavior && typeof widgetBehavior.onSessionInitialized === 'function') {
2612
2624
  widgetBehavior.onSessionInitialized(this, sessionId, config);
2613
2625
  }
2626
+
2627
+ // For non-widget pages, update the browser URL so that a page
2628
+ // refresh reloads the correct session instead of starting fresh.
2629
+ if (!hasWidgetConfig && sessionId && config.sessionUrlTemplate && typeof history !== 'undefined' && history.replaceState) {
2630
+ var sessionUrl = config.sessionUrlTemplate.replace('{sessionId}', encodeURIComponent(sessionId));
2631
+ history.replaceState(null, '', sessionUrl);
2632
+ }
2614
2633
  },
2615
2634
  getSessionId: function getSessionId() {
2616
2635
  var sessionId = this.inputElement ? this.inputElement.getAttribute('data-session-id') : null;
@@ -2895,6 +2914,7 @@ window.coreAIChatManager = function () {
2895
2914
  supportedExtensionsText: getAttributeValue(element, 'data-coreai-chat-supported-extensions-text'),
2896
2915
  existingDocuments: (_parseJsonAttribute2 = parseJsonAttribute(element, 'data-coreai-chat-existing-documents', 'CoreAI chat existing documents')) !== null && _parseJsonAttribute2 !== void 0 ? _parseJsonAttribute2 : undefined,
2897
2916
  initialPrompt: getAttributeValue(element, 'data-coreai-chat-initial-prompt'),
2917
+ sessionUrlTemplate: getAttributeValue(element, 'data-coreai-chat-session-url-template'),
2898
2918
  userLabel: getAttributeValue(element, 'data-coreai-chat-user-label'),
2899
2919
  assistantLabel: getAttributeValue(element, 'data-coreai-chat-assistant-label'),
2900
2920
  copyTitle: getAttributeValue(element, 'data-coreai-chat-copy-title'),
@@ -2904,7 +2924,6 @@ window.coreAIChatManager = function () {
2904
2924
  metricsEnabled: 'data-coreai-chat-metrics-enabled',
2905
2925
  textToSpeechEnabled: 'data-coreai-chat-text-to-speech-enabled',
2906
2926
  sessionDocumentsEnabled: 'data-coreai-chat-session-documents-enabled',
2907
- autoCreateSession: 'data-coreai-chat-auto-create-session',
2908
2927
  singleResponseMode: 'data-coreai-chat-single-response-mode'
2909
2928
  };
2910
2929
  Object.keys(booleanAttributes).forEach(function (key) {