@crestapps/ai-chat-ui 1.0.0-preview.90 → 1.0.0-preview.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-chat-widget.js +153 -5
- package/dist/ai-chat-widget.js.map +1 -1
- package/dist/ai-chat-widget.min.js +1 -1
- package/dist/ai-chat-widget.min.js.map +1 -1
- package/dist/ai-chat.css +13 -0
- package/dist/ai-chat.css.map +1 -1
- package/dist/ai-chat.js +432 -157
- package/dist/ai-chat.js.map +1 -1
- package/dist/ai-chat.min.css +1 -1
- package/dist/ai-chat.min.js +1 -1
- package/dist/ai-chat.min.js.map +1 -1
- package/dist/chat-interaction-settings.js +63 -0
- package/dist/chat-interaction-settings.js.map +1 -1
- package/dist/chat-interaction-settings.min.js +1 -1
- package/dist/chat-interaction-settings.min.js.map +1 -1
- package/dist/chat-interaction.js +424 -163
- package/dist/chat-interaction.js.map +1 -1
- package/dist/chat-interaction.min.js +1 -1
- package/dist/chat-interaction.min.js.map +1 -1
- package/dist/chat-widget.css +13 -0
- package/dist/chat-widget.css.map +1 -1
- package/dist/chat-widget.min.css +1 -1
- package/dist/document-drop-zone.js +92 -14
- package/dist/document-drop-zone.js.map +1 -1
- package/dist/document-drop-zone.min.js +1 -1
- package/dist/document-drop-zone.min.js.map +1 -1
- package/package.json +1 -1
package/dist/ai-chat-widget.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
function clampWidgetValue(value, min, max) {
|
|
7
7
|
return Math.min(Math.max(value, min), max);
|
|
8
8
|
}
|
|
9
|
-
window.
|
|
9
|
+
window.coreAIChatWidgetBehavior = window.coreAIChatWidgetBehavior || function () {
|
|
10
10
|
function parsePixelValue(value) {
|
|
11
11
|
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
12
12
|
return value;
|
|
@@ -582,7 +582,101 @@ window.openAIChatWidgetBehavior = window.openAIChatWidgetBehavior || function ()
|
|
|
582
582
|
onBeforeUnmount: dispose
|
|
583
583
|
};
|
|
584
584
|
}();
|
|
585
|
-
window.
|
|
585
|
+
window.coreAIChatWidgetManager = window.coreAIChatWidgetManager || function () {
|
|
586
|
+
function getAttributeValue(element, attributeName) {
|
|
587
|
+
var value = element.getAttribute(attributeName);
|
|
588
|
+
return value === null || value === '' ? null : value;
|
|
589
|
+
}
|
|
590
|
+
function parseBooleanAttributeValue(value) {
|
|
591
|
+
if (value === null || value === undefined) {
|
|
592
|
+
return null;
|
|
593
|
+
}
|
|
594
|
+
if (typeof value === 'boolean') {
|
|
595
|
+
return value;
|
|
596
|
+
}
|
|
597
|
+
var normalized = String(value).trim().toLowerCase();
|
|
598
|
+
if (normalized === 'true') {
|
|
599
|
+
return true;
|
|
600
|
+
}
|
|
601
|
+
if (normalized === 'false') {
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
function parseJsonAttribute(element, attributeName, description) {
|
|
607
|
+
var rawValue = getAttributeValue(element, attributeName);
|
|
608
|
+
if (!rawValue) {
|
|
609
|
+
return null;
|
|
610
|
+
}
|
|
611
|
+
try {
|
|
612
|
+
return JSON.parse(rawValue);
|
|
613
|
+
} catch (error) {
|
|
614
|
+
console.error('Failed to parse ' + description + ' JSON.', error);
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
function buildOptionsFromDataAttributes(element) {
|
|
619
|
+
var widgetContainerSelector = getAttributeValue(element, 'data-coreai-chat-widget-container-selector');
|
|
620
|
+
if (!widgetContainerSelector) {
|
|
621
|
+
return null;
|
|
622
|
+
}
|
|
623
|
+
var chatConfig = null;
|
|
624
|
+
if (window.coreAIChatManager && typeof window.coreAIChatManager.buildConfigFromElement === 'function') {
|
|
625
|
+
chatConfig = window.coreAIChatManager.buildConfigFromElement(element, {
|
|
626
|
+
allowWidgetHost: true
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
var profileId = getAttributeValue(element, 'data-coreai-chat-widget-profile-id');
|
|
630
|
+
var profileName = getAttributeValue(element, 'data-coreai-chat-widget-profile-name');
|
|
631
|
+
var profileDisplayText = getAttributeValue(element, 'data-coreai-chat-widget-profile-display-text');
|
|
632
|
+
var profileWelcomeMessage = getAttributeValue(element, 'data-coreai-chat-widget-profile-welcome-message');
|
|
633
|
+
var profileChatMode = getAttributeValue(element, 'data-coreai-chat-widget-profile-chat-mode');
|
|
634
|
+
var profileTtsVoiceName = getAttributeValue(element, 'data-coreai-chat-widget-profile-tts-voice-name');
|
|
635
|
+
var profileMetricsEnabled = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-profile-enable-session-metrics'));
|
|
636
|
+
var profileSessionDocuments = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-profile-allow-session-documents'));
|
|
637
|
+
var profile = null;
|
|
638
|
+
if (profileId || profileName || profileDisplayText || profileWelcomeMessage || profileChatMode || profileTtsVoiceName || profileMetricsEnabled !== null || profileSessionDocuments !== null) {
|
|
639
|
+
profile = {
|
|
640
|
+
id: profileId,
|
|
641
|
+
name: profileName,
|
|
642
|
+
displayText: profileDisplayText,
|
|
643
|
+
welcomeMessage: profileWelcomeMessage,
|
|
644
|
+
chatMode: profileChatMode,
|
|
645
|
+
ttsVoiceName: profileTtsVoiceName,
|
|
646
|
+
enableSessionMetrics: profileMetricsEnabled === true,
|
|
647
|
+
allowSessionDocuments: profileSessionDocuments === true
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
var enableDragging = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-enable-dragging'));
|
|
651
|
+
var enableResizing = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-enable-resizing'));
|
|
652
|
+
var persistLayout = parseBooleanAttributeValue(getAttributeValue(element, 'data-coreai-chat-widget-persist-layout'));
|
|
653
|
+
return {
|
|
654
|
+
shellSelector: getAttributeValue(element, 'data-coreai-chat-widget-shell-selector'),
|
|
655
|
+
widgetContainerSelector: widgetContainerSelector,
|
|
656
|
+
toggleButtonSelector: getAttributeValue(element, 'data-coreai-chat-widget-toggle-button-selector'),
|
|
657
|
+
closeButtonSelector: getAttributeValue(element, 'data-coreai-chat-widget-close-button-selector'),
|
|
658
|
+
inputSelector: getAttributeValue(element, 'data-coreai-chat-widget-input-selector'),
|
|
659
|
+
profile: profile,
|
|
660
|
+
widgetStateName: getAttributeValue(element, 'data-coreai-chat-widget-state-name'),
|
|
661
|
+
openStateValue: getAttributeValue(element, 'data-coreai-chat-widget-open-state-value'),
|
|
662
|
+
closedStateValue: getAttributeValue(element, 'data-coreai-chat-widget-closed-state-value'),
|
|
663
|
+
openIconHtml: getAttributeValue(element, 'data-coreai-chat-widget-open-icon-html'),
|
|
664
|
+
closedIconHtml: getAttributeValue(element, 'data-coreai-chat-widget-closed-icon-html'),
|
|
665
|
+
chatConfig: chatConfig ? Object.assign({}, chatConfig, {
|
|
666
|
+
widget: Object.assign({}, chatConfig.widget || {}, {
|
|
667
|
+
chatWidgetContainer: widgetContainerSelector,
|
|
668
|
+
chatWidgetStateName: getAttributeValue(element, 'data-coreai-chat-widget-state-name'),
|
|
669
|
+
newChatButton: getAttributeValue(element, 'data-coreai-chat-widget-new-chat-button-selector'),
|
|
670
|
+
toggleButtonSelector: getAttributeValue(element, 'data-coreai-chat-widget-toggle-button-selector'),
|
|
671
|
+
resetSizeButtonSelector: getAttributeValue(element, 'data-coreai-chat-widget-reset-size-button-selector'),
|
|
672
|
+
dragHandleSelector: getAttributeValue(element, 'data-coreai-chat-widget-drag-handle-selector'),
|
|
673
|
+
enableDragging: enableDragging === null ? undefined : enableDragging,
|
|
674
|
+
enableResizing: enableResizing === null ? undefined : enableResizing,
|
|
675
|
+
persistLayout: persistLayout === null ? undefined : persistLayout
|
|
676
|
+
})
|
|
677
|
+
}) : null
|
|
678
|
+
};
|
|
679
|
+
}
|
|
586
680
|
function initialize(options) {
|
|
587
681
|
if (!options) {
|
|
588
682
|
return null;
|
|
@@ -590,7 +684,7 @@ window.openAIChatWidgetManager = window.openAIChatWidgetManager || function () {
|
|
|
590
684
|
var chatConfig = options.chatConfig;
|
|
591
685
|
if (!chatConfig && options.configElementSelector) {
|
|
592
686
|
var configElement = document.querySelector(options.configElementSelector);
|
|
593
|
-
chatConfig = configElement ?
|
|
687
|
+
chatConfig = configElement ? parseJsonAttribute(configElement, 'data-config', 'AI chat widget config') : null;
|
|
594
688
|
}
|
|
595
689
|
if (!chatConfig) {
|
|
596
690
|
return null;
|
|
@@ -676,7 +770,7 @@ window.openAIChatWidgetManager = window.openAIChatWidgetManager || function () {
|
|
|
676
770
|
shell.style.visibility = '';
|
|
677
771
|
}
|
|
678
772
|
}
|
|
679
|
-
var widgetApp = window.
|
|
773
|
+
var widgetApp = window.coreAIChatManager.initialize(chatConfig);
|
|
680
774
|
if (options.applySessionProfilePatch !== false && window.crestAppsAIChat && window.crestAppsAIChat.patchSessionProfileSync) {
|
|
681
775
|
window.crestAppsAIChat.patchSessionProfileSync(widgetApp);
|
|
682
776
|
}
|
|
@@ -807,8 +901,62 @@ window.openAIChatWidgetManager = window.openAIChatWidgetManager || function () {
|
|
|
807
901
|
}
|
|
808
902
|
return widgetApp;
|
|
809
903
|
}
|
|
904
|
+
function initializeFromElement(element) {
|
|
905
|
+
if (!element || element.dataset.coreAiChatWidgetInitialized === 'true') {
|
|
906
|
+
return element ? element.__coreAIChatWidgetApp || null : null;
|
|
907
|
+
}
|
|
908
|
+
var jsonOptions = parseJsonAttribute(element, 'data-coreai-chat-widget-config', 'CoreAI chat widget config');
|
|
909
|
+
var attributeOptions = buildOptionsFromDataAttributes(element);
|
|
910
|
+
if (!jsonOptions && !attributeOptions) {
|
|
911
|
+
return null;
|
|
912
|
+
}
|
|
913
|
+
var options = Object.assign({}, jsonOptions || {}, attributeOptions || {});
|
|
914
|
+
var widgetApp = initialize(options);
|
|
915
|
+
if (!widgetApp) {
|
|
916
|
+
return null;
|
|
917
|
+
}
|
|
918
|
+
element.dataset.coreAiChatWidgetInitialized = 'true';
|
|
919
|
+
element.__coreAIChatWidgetApp = widgetApp;
|
|
920
|
+
return widgetApp;
|
|
921
|
+
}
|
|
922
|
+
function scanForAutoInitialization(root) {
|
|
923
|
+
if (!root || typeof root.querySelectorAll !== 'function') {
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
if (typeof root.matches === 'function' && root.matches('[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]')) {
|
|
927
|
+
initializeFromElement(root);
|
|
928
|
+
}
|
|
929
|
+
root.querySelectorAll('[data-coreai-chat-widget-config],[data-coreai-chat-widget-container-selector]').forEach(initializeFromElement);
|
|
930
|
+
}
|
|
931
|
+
function startAutoInitialization() {
|
|
932
|
+
scanForAutoInitialization(document);
|
|
933
|
+
if (typeof MutationObserver === 'undefined') {
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
var observer = new MutationObserver(function (mutations) {
|
|
937
|
+
mutations.forEach(function (mutation) {
|
|
938
|
+
mutation.addedNodes.forEach(function (node) {
|
|
939
|
+
if (node && node.nodeType === 1) {
|
|
940
|
+
scanForAutoInitialization(node);
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
});
|
|
944
|
+
});
|
|
945
|
+
observer.observe(document.body, {
|
|
946
|
+
childList: true,
|
|
947
|
+
subtree: true
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
if (document.readyState === 'loading') {
|
|
951
|
+
document.addEventListener('DOMContentLoaded', startAutoInitialization, {
|
|
952
|
+
once: true
|
|
953
|
+
});
|
|
954
|
+
} else {
|
|
955
|
+
startAutoInitialization();
|
|
956
|
+
}
|
|
810
957
|
return {
|
|
811
|
-
initialize: initialize
|
|
958
|
+
initialize: initialize,
|
|
959
|
+
initializeFromElement: initializeFromElement
|
|
812
960
|
};
|
|
813
961
|
}();
|
|
814
962
|
//# sourceMappingURL=ai-chat-widget.js.map
|