@alan-ai/alan-sdk-web 1.8.75 → 1.8.76
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/AlanButton.d.ts +4 -0
- package/dist/alan_lib.js +105 -62
- package/dist/alan_lib.min.js +1 -1
- package/package.json +1 -1
package/dist/AlanButton.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ export interface AlanButton {
|
|
|
8
8
|
isActive: () => boolean;
|
|
9
9
|
remove: () => void;
|
|
10
10
|
sendText: (text: string) => void;
|
|
11
|
+
theme: {
|
|
12
|
+
setTheme: (theme: 'light' | 'dark') => void;
|
|
13
|
+
getTheme: () => string,
|
|
14
|
+
};
|
|
11
15
|
textChat: {
|
|
12
16
|
setAudioOutputEnabled: (value: boolean) => void,
|
|
13
17
|
isAudioOutputEnabled: () => boolean,
|
package/dist/alan_lib.js
CHANGED
|
@@ -89452,6 +89452,7 @@
|
|
|
89452
89452
|
|
|
89453
89453
|
// alan_btn/src/state.ts
|
|
89454
89454
|
var uiState = {
|
|
89455
|
+
currentTheme: null,
|
|
89455
89456
|
lib: {
|
|
89456
89457
|
version: ""
|
|
89457
89458
|
},
|
|
@@ -93706,10 +93707,28 @@ code.hljs {
|
|
|
93706
93707
|
}
|
|
93707
93708
|
}
|
|
93708
93709
|
}
|
|
93710
|
+
function broadcastThemeToIframes() {
|
|
93711
|
+
const theme = uiState.currentTheme;
|
|
93712
|
+
const iframes = window.frames;
|
|
93713
|
+
const message = {
|
|
93714
|
+
type: "alanThemeEvent",
|
|
93715
|
+
theme
|
|
93716
|
+
};
|
|
93717
|
+
for (let i = 0; i < iframes.length; i++) {
|
|
93718
|
+
try {
|
|
93719
|
+
iframes[i].postMessage(message, "*");
|
|
93720
|
+
} catch (error) {
|
|
93721
|
+
console.error(`Failed to send message to iframe ${i}`, error);
|
|
93722
|
+
}
|
|
93723
|
+
}
|
|
93724
|
+
}
|
|
93709
93725
|
function onIFrameSizeListener(event) {
|
|
93710
93726
|
if (event.data && event.data.source !== "alan-chat-iframe") {
|
|
93711
93727
|
return;
|
|
93712
93728
|
}
|
|
93729
|
+
if (broadcastThemeToIframes) {
|
|
93730
|
+
broadcastThemeToIframes();
|
|
93731
|
+
}
|
|
93713
93732
|
if (event.data?.height) {
|
|
93714
93733
|
adjustIFrameSize(event.data);
|
|
93715
93734
|
}
|
|
@@ -93986,7 +94005,7 @@ code.hljs {
|
|
|
93986
94005
|
|
|
93987
94006
|
// alan_btn/alan_btn.ts
|
|
93988
94007
|
(function(ns) {
|
|
93989
|
-
uiState.lib.version = "alan-version.1.8.
|
|
94008
|
+
uiState.lib.version = "alan-version.1.8.76".replace("alan-version.", "");
|
|
93990
94009
|
if (window.alanBtn) {
|
|
93991
94010
|
console.warn("Alan: the Alan Button source code has already added (v." + uiState.lib.version + ")");
|
|
93992
94011
|
}
|
|
@@ -94093,6 +94112,14 @@ code.hljs {
|
|
|
94093
94112
|
sendText: (text) => {
|
|
94094
94113
|
_sendText(text);
|
|
94095
94114
|
},
|
|
94115
|
+
theme: {
|
|
94116
|
+
setTheme: (theme) => {
|
|
94117
|
+
changeTheme(theme);
|
|
94118
|
+
},
|
|
94119
|
+
getTheme: () => {
|
|
94120
|
+
return uiState.currentTheme;
|
|
94121
|
+
}
|
|
94122
|
+
},
|
|
94096
94123
|
textChat: {
|
|
94097
94124
|
setAudioOutputEnabled: (value) => {
|
|
94098
94125
|
if (value === true) {
|
|
@@ -94440,6 +94467,7 @@ code.hljs {
|
|
|
94440
94467
|
}
|
|
94441
94468
|
return value;
|
|
94442
94469
|
}
|
|
94470
|
+
uiState.currentTheme = options?.theme || null;
|
|
94443
94471
|
uiState.btn.zIndex = options.zIndex || findHighestZIndex() + 1;
|
|
94444
94472
|
btnIconsZIndex = uiState.btn.zIndex - 2;
|
|
94445
94473
|
btnTextPanelsZIndex = uiState.btn.zIndex - 1;
|
|
@@ -94921,7 +94949,7 @@ code.hljs {
|
|
|
94921
94949
|
createAlanStyleSheet(options);
|
|
94922
94950
|
function connectProject() {
|
|
94923
94951
|
uiState.project.id = options.key;
|
|
94924
|
-
|
|
94952
|
+
applyOptionsFromLocalStorage();
|
|
94925
94953
|
switchState(getDefaultBtnState(DISCONNECTED));
|
|
94926
94954
|
window.tutorProject = window.alan.project(options.key, getAuthData(options.authData), options.host, null, {
|
|
94927
94955
|
platform: mode === "demo" ? "alanplayground" : null,
|
|
@@ -95478,12 +95506,10 @@ code.hljs {
|
|
|
95478
95506
|
if (isTutorMode()) {
|
|
95479
95507
|
manageSyncPageStateListeners(true);
|
|
95480
95508
|
}
|
|
95481
|
-
function
|
|
95482
|
-
|
|
95483
|
-
|
|
95484
|
-
|
|
95485
|
-
if (data && data.web) {
|
|
95486
|
-
keepButtonPositionAfterDnD = data.web.alanButtonDragAndDrop?.keepButtonPositionAfterDnD || data.web.keepButtonPositionAfterDnD;
|
|
95509
|
+
function changeOptions(options2) {
|
|
95510
|
+
manageSyncPageStateListeners(options2?.pageState?.autoSync !== false);
|
|
95511
|
+
if (options2) {
|
|
95512
|
+
keepButtonPositionAfterDnD = options2.alanButtonDragAndDrop?.keepButtonPositionAfterDnD || options2.keepButtonPositionAfterDnD;
|
|
95487
95513
|
if (!keepButtonPositionAfterDnD) {
|
|
95488
95514
|
clearSavedBtnPosition();
|
|
95489
95515
|
}
|
|
@@ -95491,39 +95517,37 @@ code.hljs {
|
|
|
95491
95517
|
} else {
|
|
95492
95518
|
setButtonPosition();
|
|
95493
95519
|
}
|
|
95494
|
-
|
|
95495
|
-
|
|
95496
|
-
}
|
|
95497
|
-
if (data && data.web && data.web.hideS2TPanel === true) {
|
|
95520
|
+
dragAndDropEnabled = options2?.alanButtonDragAndDrop?.dragAndDropEnabled;
|
|
95521
|
+
if (options2?.hideS2TPanel === true) {
|
|
95498
95522
|
hideSpeach2TextPanel();
|
|
95499
95523
|
} else {
|
|
95500
95524
|
showSpeach2TextPanel();
|
|
95501
95525
|
}
|
|
95502
|
-
if (
|
|
95526
|
+
if (options2?.alanButtonPopup?.popupEnabled === true || options2?.popupEnabled === true) {
|
|
95503
95527
|
popupEnabled = true;
|
|
95504
95528
|
} else {
|
|
95505
95529
|
popupEnabled = false;
|
|
95506
95530
|
hidePopup();
|
|
95507
95531
|
}
|
|
95508
95532
|
if (!isTutorMode()) {
|
|
95509
|
-
if (
|
|
95533
|
+
if (options2?.chatOptions?.textChat?.enabled === true) {
|
|
95510
95534
|
uiState.textChat.available = true;
|
|
95511
|
-
voiceEnabledInTextChat =
|
|
95512
|
-
const
|
|
95513
|
-
const
|
|
95514
|
-
if (
|
|
95515
|
-
initHighlightJs(
|
|
95516
|
-
}
|
|
95517
|
-
uiState.textChat.options =
|
|
95518
|
-
if (getVoiceEnabledFlag() !==
|
|
95519
|
-
if (
|
|
95535
|
+
voiceEnabledInTextChat = options2.chatOptions?.textChat?.voice?.enabled;
|
|
95536
|
+
const codeThemeFromOptions = options2.chatOptions?.textChat?.bubbles?.response?.codeTheme || "light";
|
|
95537
|
+
const currentCodeTheme = uiState.textChat.options?.bubbles?.response?.codeTheme;
|
|
95538
|
+
if (currentCodeTheme !== codeThemeFromOptions) {
|
|
95539
|
+
initHighlightJs(codeThemeFromOptions);
|
|
95540
|
+
}
|
|
95541
|
+
uiState.textChat.options = options2?.chatOptions?.textChat;
|
|
95542
|
+
if (getVoiceEnabledFlag() !== options2?.chatOptions?.textChat?.audio?.enabled) {
|
|
95543
|
+
if (options2?.chatOptions?.textChat?.audio?.enabled) {
|
|
95520
95544
|
enableAudio(false);
|
|
95521
95545
|
} else {
|
|
95522
95546
|
disableAudio(false);
|
|
95523
95547
|
}
|
|
95524
95548
|
}
|
|
95525
95549
|
initTextChat();
|
|
95526
|
-
if (isInlinedMode() ||
|
|
95550
|
+
if (isInlinedMode() || options2?.chatOptions?.textChat?.popup?.openByDefualt === true || isTextChatSavedStateOpened()) {
|
|
95527
95551
|
if (!textChatWasClosedManually) {
|
|
95528
95552
|
showTextChat(true);
|
|
95529
95553
|
}
|
|
@@ -95533,26 +95557,21 @@ code.hljs {
|
|
|
95533
95557
|
hideTextChat();
|
|
95534
95558
|
}
|
|
95535
95559
|
}
|
|
95536
|
-
if (
|
|
95537
|
-
turnOffTimeout =
|
|
95560
|
+
if (options2?.timeout !== void 0) {
|
|
95561
|
+
turnOffTimeout = options2.timeout;
|
|
95538
95562
|
setTurnOffVoiceTimeout();
|
|
95539
95563
|
}
|
|
95540
|
-
if (
|
|
95541
|
-
|
|
95542
|
-
|
|
95543
|
-
|
|
95544
|
-
|
|
95545
|
-
if (data && data.web) {
|
|
95546
|
-
applyBtnSizeOptions(data.web.buttonSize || btnModes[mode].btnSize);
|
|
95564
|
+
if (!isTutorMode()) {
|
|
95565
|
+
if (options2) {
|
|
95566
|
+
applyLogoOptions(options2);
|
|
95567
|
+
applyBtnOptions(options2);
|
|
95568
|
+
applyBtnSizeOptions(options2.buttonSize || btnModes[mode].btnSize);
|
|
95547
95569
|
}
|
|
95548
95570
|
}
|
|
95549
|
-
if (
|
|
95550
|
-
|
|
95571
|
+
if (options2?.playReadyToListenSound !== void 0) {
|
|
95572
|
+
applyPlayReadyToListenSoundOptions(options2.playReadyToListenSound);
|
|
95551
95573
|
}
|
|
95552
|
-
if (
|
|
95553
|
-
applyPlayReadyToListenSoundOptions(data.web.playReadyToListenSound);
|
|
95554
|
-
}
|
|
95555
|
-
if (data && data.web && data.web.hidden === true) {
|
|
95574
|
+
if (options2?.hidden === true) {
|
|
95556
95575
|
hideBtn();
|
|
95557
95576
|
} else {
|
|
95558
95577
|
if (btnDisabled) {
|
|
@@ -95564,6 +95583,32 @@ code.hljs {
|
|
|
95564
95583
|
}
|
|
95565
95584
|
}
|
|
95566
95585
|
}
|
|
95586
|
+
function saveOptions(fullOptions) {
|
|
95587
|
+
if (isLocalStorageAvailable && fullOptions) {
|
|
95588
|
+
alanBtnSavedOptions = fullOptions;
|
|
95589
|
+
localStorage.setItem(getBtnOptionsStorageKey(), JSON.stringify(fullOptions));
|
|
95590
|
+
}
|
|
95591
|
+
}
|
|
95592
|
+
function onOptionsReceived(data) {
|
|
95593
|
+
console.log("Alan: options received");
|
|
95594
|
+
console.timeEnd("Alan: receiving options time");
|
|
95595
|
+
saveOptions(data);
|
|
95596
|
+
changeOptions(getOptionsByTheme(data?.web, uiState.currentTheme || options.theme));
|
|
95597
|
+
}
|
|
95598
|
+
function changeTheme(theme) {
|
|
95599
|
+
const options2 = getOptionsByTheme(alanBtnSavedOptions?.web, theme);
|
|
95600
|
+
if (options2) {
|
|
95601
|
+
changeOptions(options2);
|
|
95602
|
+
}
|
|
95603
|
+
uiState.currentTheme = theme;
|
|
95604
|
+
broadcastThemeToIframes();
|
|
95605
|
+
}
|
|
95606
|
+
function getOptionsByTheme(options2, theme) {
|
|
95607
|
+
if (theme) {
|
|
95608
|
+
return options2?.themes?.[theme]?.options || options2;
|
|
95609
|
+
}
|
|
95610
|
+
return options2;
|
|
95611
|
+
}
|
|
95567
95612
|
function onConnectStatusChange(res) {
|
|
95568
95613
|
if (res === "disconnected") {
|
|
95569
95614
|
if (previousState !== OFFLINE) {
|
|
@@ -97694,7 +97739,7 @@ ${LEARN_MORE_LABEL}
|
|
|
97694
97739
|
}
|
|
97695
97740
|
}
|
|
97696
97741
|
}
|
|
97697
|
-
function
|
|
97742
|
+
function getBtnOptionsStorageKey() {
|
|
97698
97743
|
var key = "";
|
|
97699
97744
|
if (options && options.key) {
|
|
97700
97745
|
key = options.key;
|
|
@@ -97734,39 +97779,39 @@ ${LEARN_MORE_LABEL}
|
|
|
97734
97779
|
createAlanStyleSheet(options);
|
|
97735
97780
|
}
|
|
97736
97781
|
}
|
|
97737
|
-
function applyLogoOptions(
|
|
97738
|
-
if (
|
|
97739
|
-
if (
|
|
97740
|
-
listenStateBtnIconImg.src =
|
|
97741
|
-
processStateBtnIconImg.src =
|
|
97742
|
-
replyStateBtnIconImg.src =
|
|
97782
|
+
function applyLogoOptions(options2) {
|
|
97783
|
+
if (options2) {
|
|
97784
|
+
if (options2.logoUrl && !options2.logoIdle && !options2.logoListen && !options2.logoProcess && !options2.logoReply && !options2.logoTextChat) {
|
|
97785
|
+
listenStateBtnIconImg.src = options2.logoUrl;
|
|
97786
|
+
processStateBtnIconImg.src = options2.logoUrl;
|
|
97787
|
+
replyStateBtnIconImg.src = options2.logoUrl;
|
|
97743
97788
|
} else {
|
|
97744
97789
|
if (uiState.textChat.available) {
|
|
97745
|
-
if (
|
|
97746
|
-
defaultStateBtnIconImg.src =
|
|
97790
|
+
if (options2.logoTextChat) {
|
|
97791
|
+
defaultStateBtnIconImg.src = options2.logoTextChat;
|
|
97747
97792
|
} else {
|
|
97748
97793
|
defaultStateBtnIconImg.src = btnIcons.alanLogoIconSrc;
|
|
97749
97794
|
}
|
|
97750
97795
|
} else {
|
|
97751
|
-
if (
|
|
97752
|
-
defaultStateBtnIconImg.src =
|
|
97796
|
+
if (options2.logoIdle) {
|
|
97797
|
+
defaultStateBtnIconImg.src = options2.logoIdle;
|
|
97753
97798
|
} else {
|
|
97754
97799
|
defaultStateBtnIconImg.src = btnIcons.micIconSrc;
|
|
97755
97800
|
}
|
|
97756
|
-
if (
|
|
97757
|
-
listenStateBtnIconImg.src =
|
|
97801
|
+
if (options2.logoListen) {
|
|
97802
|
+
listenStateBtnIconImg.src = options2.logoListen;
|
|
97758
97803
|
} else {
|
|
97759
97804
|
listenStateBtnIconImg.removeAttribute("src");
|
|
97760
97805
|
listenStateBtnIconImg.style.opacity = "0";
|
|
97761
97806
|
}
|
|
97762
|
-
if (
|
|
97763
|
-
processStateBtnIconImg.src =
|
|
97807
|
+
if (options2.logoProcess) {
|
|
97808
|
+
processStateBtnIconImg.src = options2.logoProcess;
|
|
97764
97809
|
} else {
|
|
97765
97810
|
processStateBtnIconImg.removeAttribute("src");
|
|
97766
97811
|
processStateBtnIconImg.style.opacity = "0";
|
|
97767
97812
|
}
|
|
97768
|
-
if (
|
|
97769
|
-
replyStateBtnIconImg.src =
|
|
97813
|
+
if (options2.logoReply) {
|
|
97814
|
+
replyStateBtnIconImg.src = options2.logoReply;
|
|
97770
97815
|
} else {
|
|
97771
97816
|
replyStateBtnIconImg.removeAttribute("src");
|
|
97772
97817
|
replyStateBtnIconImg.style.opacity = "0";
|
|
@@ -97786,19 +97831,17 @@ ${LEARN_MORE_LABEL}
|
|
|
97786
97831
|
} else {
|
|
97787
97832
|
if (isLocalStorageAvailable) {
|
|
97788
97833
|
try {
|
|
97789
|
-
|
|
97834
|
+
applyOptionsFromLocalStorage();
|
|
97790
97835
|
} catch (e) {
|
|
97791
97836
|
}
|
|
97792
97837
|
}
|
|
97793
97838
|
}
|
|
97794
|
-
function
|
|
97839
|
+
function applyOptionsFromLocalStorage() {
|
|
97795
97840
|
if (isLocalStorageAvailable) {
|
|
97796
97841
|
try {
|
|
97797
|
-
alanBtnSavedOptions = JSON.parse(localStorage.getItem(
|
|
97842
|
+
alanBtnSavedOptions = JSON.parse(localStorage.getItem(getBtnOptionsStorageKey()));
|
|
97798
97843
|
if (alanBtnSavedOptions && alanBtnSavedOptions.web) {
|
|
97799
|
-
|
|
97800
|
-
applyBtnOptions(alanBtnSavedOptions.web);
|
|
97801
|
-
}
|
|
97844
|
+
applyBtnOptions(getOptionsByTheme(alanBtnSavedOptions.web, options.theme));
|
|
97802
97845
|
}
|
|
97803
97846
|
} catch (e) {
|
|
97804
97847
|
}
|