@memori.ai/memori-react 8.40.1 → 8.40.3
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/CHANGELOG.md +24 -0
- package/dist/components/MemoriWidget/MemoriWidget.js +34 -181
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/helpers/nats/useNatsSession.js +9 -1
- package/dist/helpers/nats/useNatsSession.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/esm/components/MemoriWidget/MemoriWidget.js +31 -180
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/helpers/nats/useNatsSession.js +9 -1
- package/esm/helpers/nats/useNatsSession.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/package.json +1 -1
- package/src/components/MemoriWidget/MemoriWidget.tsx +37 -246
- package/src/helpers/nats/useNatsSession.ts +21 -1
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [8.40.3](https://github.com/memori-ai/memori-react/compare/v8.40.2...v8.40.3) (2026-06-17)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Changes
|
|
7
|
+
|
|
8
|
+
* remove unused NATS timeout logic from MemoriWidget ([895f1b1](https://github.com/memori-ai/memori-react/commit/895f1b133ff2efa59444d7306d6714167a03d0e3))
|
|
9
|
+
|
|
10
|
+
## [8.40.2](https://github.com/memori-ai/memori-react/compare/v8.40.1...v8.40.2) (2026-06-17)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add unwrapDialogState function to handle nested currentState in NATS responses ([a6fcafc](https://github.com/memori-ai/memori-react/commit/a6fcafc7f000946baac6bb12e5f37972a956e828))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* reset clickedStart state in multiple scenarios within MemoriWidget ([a34ed85](https://github.com/memori-ai/memori-react/commit/a34ed853504a107b1096c8e82be64b97cdb30ede))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Changes
|
|
24
|
+
|
|
25
|
+
* improve error logging and clean up debug statements in MemoriWidget ([372b09a](https://github.com/memori-ai/memori-react/commit/372b09ac584aab552f5f1a7cde6258fef2a5493c))
|
|
26
|
+
|
|
3
27
|
## [8.40.1](https://github.com/memori-ai/memori-react/compare/v8.40.0...v8.40.1) (2026-06-17)
|
|
4
28
|
|
|
5
29
|
|
|
@@ -69,7 +69,9 @@ const NULL_PLACE_SPEC = {
|
|
|
69
69
|
longitude: null,
|
|
70
70
|
uncertaintyKm: null,
|
|
71
71
|
};
|
|
72
|
-
const
|
|
72
|
+
const logWidgetError = (context, detail) => {
|
|
73
|
+
console.error(`[MemoriWidget] ${context}`, detail !== null && detail !== void 0 ? detail : '');
|
|
74
|
+
};
|
|
73
75
|
function readCorrelationID(response) {
|
|
74
76
|
const value = response.correlationID;
|
|
75
77
|
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
@@ -451,12 +453,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
451
453
|
let gotError = false;
|
|
452
454
|
try {
|
|
453
455
|
const placeSpec = getPlaceSpecForEnterText(position);
|
|
454
|
-
console.debug('[EnterText] sendMessage: posting', {
|
|
455
|
-
sessionId: sessionID,
|
|
456
|
-
textLength: msg.length,
|
|
457
|
-
hasBatchQueued,
|
|
458
|
-
typingText,
|
|
459
|
-
});
|
|
460
456
|
const response = await postEnterTextAsync({
|
|
461
457
|
sessionId: sessionID,
|
|
462
458
|
text: msg,
|
|
@@ -465,11 +461,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
465
461
|
}),
|
|
466
462
|
...(placeSpec !== undefined && { place: placeSpec }),
|
|
467
463
|
});
|
|
468
|
-
console.debug('[EnterText] sendMessage: HTTP response', {
|
|
469
|
-
resultCode: response.resultCode,
|
|
470
|
-
correlationID: readCorrelationID(response),
|
|
471
|
-
resultMessage: response.resultMessage,
|
|
472
|
-
});
|
|
473
464
|
const correlationID = readCorrelationID(response);
|
|
474
465
|
if (response.resultCode === 0 && correlationID) {
|
|
475
466
|
registerPendingEnterText(correlationID, {
|
|
@@ -478,15 +469,11 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
478
469
|
useLoaderTextAsMsg,
|
|
479
470
|
hasBatchQueued,
|
|
480
471
|
});
|
|
481
|
-
console.info('[EnterText] sendMessage: accepted, showing typing indicator', {
|
|
482
|
-
correlationID: correlationID,
|
|
483
|
-
typingText,
|
|
484
|
-
});
|
|
485
472
|
setMemoriTyping(true);
|
|
486
473
|
setTypingText(typingText);
|
|
487
474
|
}
|
|
488
475
|
else if (response.resultCode === 0) {
|
|
489
|
-
|
|
476
|
+
logWidgetError('enter-text missing correlationID', response);
|
|
490
477
|
}
|
|
491
478
|
else if (response.resultCode === 404) {
|
|
492
479
|
setHistory(h => [...h.slice(0, h.length - 1)]);
|
|
@@ -496,7 +483,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
496
483
|
ROUTE: ((_d = (_c = window.location.pathname) === null || _c === void 0 ? void 0 : _c.split('/')) === null || _d === void 0 ? void 0 : _d.pop()) || '',
|
|
497
484
|
...(initialContextVars || {}),
|
|
498
485
|
}, initialQuestion, undefined, undefined, undefined, undefined, true).then(state => {
|
|
499
|
-
console.info('session timeout');
|
|
500
486
|
if (state === null || state === void 0 ? void 0 : state.sessionID) {
|
|
501
487
|
setTimeout(() => {
|
|
502
488
|
sendMessage(text, media, state === null || state === void 0 ? void 0 : state.sessionID);
|
|
@@ -518,13 +504,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
518
504
|
]);
|
|
519
505
|
}
|
|
520
506
|
else {
|
|
521
|
-
console.warn('[SEND_MESSAGE]', response);
|
|
522
507
|
return Promise.reject(response);
|
|
523
508
|
}
|
|
524
509
|
}
|
|
525
510
|
catch (error) {
|
|
526
|
-
console.error('[EnterText] sendMessage: request failed', error);
|
|
527
511
|
gotError = true;
|
|
512
|
+
logWidgetError('sendMessage failed', error);
|
|
528
513
|
setTypingText(undefined);
|
|
529
514
|
setMemoriTyping(false);
|
|
530
515
|
}
|
|
@@ -606,7 +591,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
606
591
|
}
|
|
607
592
|
}
|
|
608
593
|
catch (error) {
|
|
609
|
-
console.error('[TRANSLATE] Error during translation:', error);
|
|
610
594
|
translatedState = { ...state, emission };
|
|
611
595
|
translatedMsg = {
|
|
612
596
|
text: emission,
|
|
@@ -714,7 +698,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
714
698
|
try {
|
|
715
699
|
setTimeout(() => {
|
|
716
700
|
var _a;
|
|
717
|
-
console.log('snippet', s);
|
|
718
701
|
new Function((_a = s.content) !== null && _a !== void 0 ? _a : '')();
|
|
719
702
|
setTimeout(() => {
|
|
720
703
|
var _a, _b, _c;
|
|
@@ -723,8 +706,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
723
706
|
}, 400);
|
|
724
707
|
}, 1000);
|
|
725
708
|
}
|
|
726
|
-
catch (
|
|
727
|
-
console.warn(e);
|
|
709
|
+
catch (_a) {
|
|
728
710
|
}
|
|
729
711
|
});
|
|
730
712
|
};
|
|
@@ -760,8 +742,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
760
742
|
return window.location.href;
|
|
761
743
|
})();
|
|
762
744
|
}
|
|
763
|
-
catch (
|
|
764
|
-
console.debug(err);
|
|
745
|
+
catch (_m) {
|
|
765
746
|
}
|
|
766
747
|
const session = await initSession({
|
|
767
748
|
...params,
|
|
@@ -793,7 +774,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
793
774
|
};
|
|
794
775
|
}
|
|
795
776
|
else if (session === null || session === void 0 ? void 0 : session.resultMessage.startsWith('This Memori is aged restricted')) {
|
|
796
|
-
console.warn(session);
|
|
797
777
|
react_hot_toast_1.default.error(t('underageTwinSession', { age: minAge }));
|
|
798
778
|
}
|
|
799
779
|
else if ((session === null || session === void 0 ? void 0 : session.resultCode) === 403 && memori.privacyType !== 'PUBLIC') {
|
|
@@ -802,7 +782,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
802
782
|
return session;
|
|
803
783
|
}
|
|
804
784
|
else {
|
|
805
|
-
console.warn(session);
|
|
806
785
|
react_hot_toast_1.default.error(tst => ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("p", { children: t((0, error_1.getErrori18nKey)(session === null || session === void 0 ? void 0 : session.resultCode)) }), (0, jsx_runtime_1.jsx)(Button_1.default, { outlined: true, padded: false, onClick: () => react_hot_toast_1.default.dismiss(tst.id), icon: (0, jsx_runtime_1.jsx)(Close_1.default, {}), children: t('close') })] })), {
|
|
807
786
|
duration: Infinity,
|
|
808
787
|
});
|
|
@@ -810,7 +789,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
810
789
|
}
|
|
811
790
|
}
|
|
812
791
|
catch (err) {
|
|
813
|
-
|
|
792
|
+
logWidgetError('fetchSession failed', err);
|
|
814
793
|
}
|
|
815
794
|
};
|
|
816
795
|
const reopenSession = async (updateDialogState = false, password, recoveryTokens, tag, pin, initialContextVars, initialQuestion, birthDate, additionalInfoProp, continueFromChatLogID, continueFromSessionID, isSessionExpired) => {
|
|
@@ -842,8 +821,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
842
821
|
return window.location.href;
|
|
843
822
|
})();
|
|
844
823
|
}
|
|
845
|
-
catch (
|
|
846
|
-
console.debug('[REOPEN_SESSION] Error getting referral:', err);
|
|
824
|
+
catch (_o) {
|
|
847
825
|
}
|
|
848
826
|
const { sessionID, currentState, ...response } = await initSession({
|
|
849
827
|
memoriID: (_a = memori.engineMemoriID) !== null && _a !== void 0 ? _a : '',
|
|
@@ -870,12 +848,10 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
870
848
|
},
|
|
871
849
|
});
|
|
872
850
|
if (sessionID && currentState && response.resultCode === 0) {
|
|
873
|
-
console.log('[REOPEN_SESSION] Session initialized successfully:', sessionID);
|
|
874
851
|
setSessionId(sessionID);
|
|
875
852
|
if (updateDialogState) {
|
|
876
853
|
setCurrentDialogState(currentState);
|
|
877
854
|
if (currentState.emission) {
|
|
878
|
-
console.log('[REOPEN_SESSION] Processing emission:', currentState.emission);
|
|
879
855
|
const initialStatus = isSessionExpired && history.length > 1
|
|
880
856
|
? 'Session Expired, reopening session'
|
|
881
857
|
: history.length <= 1
|
|
@@ -927,22 +903,19 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
927
903
|
};
|
|
928
904
|
}
|
|
929
905
|
else if (response === null || response === void 0 ? void 0 : response.resultMessage.startsWith('This Memori is aged restricted')) {
|
|
930
|
-
console.error('[REOPEN_SESSION] Age restriction error:', response);
|
|
931
906
|
react_hot_toast_1.default.error(t('underageTwinSession', { age: minAge }));
|
|
932
907
|
}
|
|
933
908
|
else if ((response === null || response === void 0 ? void 0 : response.resultCode) === 403 &&
|
|
934
909
|
memori.privacyType !== 'PUBLIC') {
|
|
935
|
-
console.error('[REOPEN_SESSION] Authentication error');
|
|
936
910
|
setMemoriPwd(undefined);
|
|
937
911
|
setAuthModalState('password');
|
|
938
912
|
}
|
|
939
913
|
else {
|
|
940
|
-
console.error('[REOPEN_SESSION] Other error:', response);
|
|
941
914
|
react_hot_toast_1.default.error(t((0, error_1.getErrori18nKey)(response.resultCode)));
|
|
942
915
|
}
|
|
943
916
|
}
|
|
944
917
|
catch (err) {
|
|
945
|
-
|
|
918
|
+
logWidgetError('reopenSession failed', err);
|
|
946
919
|
}
|
|
947
920
|
setLoading(false);
|
|
948
921
|
return null;
|
|
@@ -950,7 +923,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
950
923
|
const changeTag = async (memoriId, sessionId, tag, pin) => {
|
|
951
924
|
var _a, _b, _c, _d, _f, _g, _h, _j, _k;
|
|
952
925
|
if (!memoriId || !sessionId) {
|
|
953
|
-
console.error('CHANGETAG/Session not found');
|
|
954
926
|
return Promise.reject('Session not found');
|
|
955
927
|
}
|
|
956
928
|
try {
|
|
@@ -982,7 +954,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
982
954
|
}
|
|
983
955
|
}
|
|
984
956
|
else if ([400, 401, 403, 404, 500].includes(resultCode)) {
|
|
985
|
-
console.warn('[APPCONTEXT/CHANGETAG]', resultCode);
|
|
986
957
|
let storageBirthDate = (0, configuration_1.getLocalConfig)('birthDate', undefined);
|
|
987
958
|
let referral;
|
|
988
959
|
try {
|
|
@@ -990,8 +961,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
990
961
|
return window.location.href;
|
|
991
962
|
})();
|
|
992
963
|
}
|
|
993
|
-
catch (
|
|
994
|
-
console.debug(err);
|
|
964
|
+
catch (_l) {
|
|
995
965
|
}
|
|
996
966
|
fetchSession({
|
|
997
967
|
memoriID: (_b = memori.engineMemoriID) !== null && _b !== void 0 ? _b : '',
|
|
@@ -1026,7 +996,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1026
996
|
}
|
|
1027
997
|
catch (_e) {
|
|
1028
998
|
let err = _e;
|
|
1029
|
-
console.warn('[APPCONTEXT/CHANGETAG]', err);
|
|
1030
999
|
return Promise.reject(err);
|
|
1031
1000
|
}
|
|
1032
1001
|
return null;
|
|
@@ -1077,7 +1046,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1077
1046
|
}, autoStart, defaultEnableAudio, (_u = defaultSpeakerActive !== null && defaultSpeakerActive !== void 0 ? defaultSpeakerActive : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.defaultSpeakerActive) !== null && _u !== void 0 ? _u : true);
|
|
1078
1047
|
const shouldPlayAudio = (text) => {
|
|
1079
1048
|
const currentSpeakerMuted = (0, configuration_1.getLocalConfig)('muteSpeaker', !defaultEnableAudio);
|
|
1080
|
-
console.log('[MemoriWidget] shouldPlayAudio', currentSpeakerMuted);
|
|
1081
1049
|
return (text &&
|
|
1082
1050
|
text.trim() &&
|
|
1083
1051
|
!preview &&
|
|
@@ -1090,15 +1058,12 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1090
1058
|
}
|
|
1091
1059
|
try {
|
|
1092
1060
|
const message = (0, utils_1.stripDuplicates)(text);
|
|
1093
|
-
console.debug('Processing speech message:', message);
|
|
1094
1061
|
if (message.length > 0) {
|
|
1095
1062
|
setUserMessage('');
|
|
1096
|
-
console.debug('Sending message:', message);
|
|
1097
1063
|
sendMessage(message);
|
|
1098
1064
|
}
|
|
1099
1065
|
}
|
|
1100
|
-
catch (
|
|
1101
|
-
console.error('Error in processSpeechAndSendMessage:', error);
|
|
1066
|
+
catch (_a) {
|
|
1102
1067
|
}
|
|
1103
1068
|
};
|
|
1104
1069
|
const { isListening, startRecording, stopRecording, } = (0, useSTT_1.useSTT)(sttConfig, processSpeechAndSendMessage, {
|
|
@@ -1132,8 +1097,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1132
1097
|
}
|
|
1133
1098
|
return translatedState;
|
|
1134
1099
|
}
|
|
1135
|
-
catch (
|
|
1136
|
-
console.error('Error in translateAndSpeak:', error);
|
|
1100
|
+
catch (_a) {
|
|
1137
1101
|
if (!hasUserActivatedSpeak) {
|
|
1138
1102
|
setHasUserActivatedSpeak(true);
|
|
1139
1103
|
}
|
|
@@ -1148,20 +1112,10 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1148
1112
|
]);
|
|
1149
1113
|
const processEnterTextDialogResponse = (0, react_1.useCallback)((event, pending) => {
|
|
1150
1114
|
var _a, _b;
|
|
1151
|
-
console.debug('[EnterText] processDialogResponse', {
|
|
1152
|
-
correlationID: event.correlationID,
|
|
1153
|
-
resultCode: event.resultCode,
|
|
1154
|
-
hasCurrentState: !!event.currentState,
|
|
1155
|
-
hasBatchQueued: pending.hasBatchQueued,
|
|
1156
|
-
});
|
|
1157
1115
|
const { msg, typingText: pendingTypingText, useLoaderTextAsMsg, } = pending;
|
|
1158
1116
|
const currentState = event.currentState;
|
|
1159
1117
|
if (event.resultCode !== 0 || !currentState) {
|
|
1160
1118
|
if (event.resultCode === 500 && event.resultMessage) {
|
|
1161
|
-
console.warn('[EnterText] processDialogResponse: server error', {
|
|
1162
|
-
correlationID: event.correlationID,
|
|
1163
|
-
resultMessage: event.resultMessage,
|
|
1164
|
-
});
|
|
1165
1119
|
setHistory(h => [
|
|
1166
1120
|
...h,
|
|
1167
1121
|
{
|
|
@@ -1174,24 +1128,15 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1174
1128
|
},
|
|
1175
1129
|
]);
|
|
1176
1130
|
}
|
|
1177
|
-
else if (event.resultCode !== 0) {
|
|
1178
|
-
console.warn('[SEND_MESSAGE/NATS]', event);
|
|
1179
|
-
}
|
|
1180
1131
|
return;
|
|
1181
1132
|
}
|
|
1182
1133
|
if (!msg) {
|
|
1183
|
-
console.debug('[EnterText] processDialogResponse: no msg in pending, skipping');
|
|
1184
1134
|
return;
|
|
1185
1135
|
}
|
|
1186
1136
|
setChatLogID(undefined);
|
|
1187
1137
|
const emission = useLoaderTextAsMsg && pendingTypingText
|
|
1188
1138
|
? pendingTypingText
|
|
1189
1139
|
: (_a = currentState.emission) !== null && _a !== void 0 ? _a : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
|
|
1190
|
-
console.debug('[EnterText] processDialogResponse: rendering emission', {
|
|
1191
|
-
correlationID: event.correlationID,
|
|
1192
|
-
emissionPreview: emission === null || emission === void 0 ? void 0 : emission.slice(0, 80),
|
|
1193
|
-
state: currentState.state,
|
|
1194
|
-
});
|
|
1195
1140
|
if (userLang.toLowerCase() !== language.toLowerCase() &&
|
|
1196
1141
|
emission &&
|
|
1197
1142
|
isMultilanguageEnabled) {
|
|
@@ -1242,9 +1187,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1242
1187
|
]);
|
|
1243
1188
|
const clearEnterTextPending = (0, react_1.useCallback)((correlationID, pending) => {
|
|
1244
1189
|
var _a;
|
|
1245
|
-
if (pending.natsTimeoutId) {
|
|
1246
|
-
clearTimeout(pending.natsTimeoutId);
|
|
1247
|
-
}
|
|
1248
1190
|
if ((_a = pending.waitForResponse) === null || _a === void 0 ? void 0 : _a.timeoutId) {
|
|
1249
1191
|
clearTimeout(pending.waitForResponse.timeoutId);
|
|
1250
1192
|
}
|
|
@@ -1258,11 +1200,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1258
1200
|
: event.errorCode
|
|
1259
1201
|
? `Error: ${event.errorCode}`
|
|
1260
1202
|
: 'Error: An unexpected error occurred';
|
|
1261
|
-
console.error('[EnterText] NATS error event', {
|
|
1262
|
-
correlationID,
|
|
1263
|
-
errorCode: event.errorCode,
|
|
1264
|
-
errorMessage: event.errorMessage,
|
|
1265
|
-
});
|
|
1266
1203
|
pushMessage({
|
|
1267
1204
|
text: errorText,
|
|
1268
1205
|
emitter: 'system',
|
|
@@ -1284,24 +1221,11 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1284
1221
|
const deliverEnterTextNatsResponse = (0, react_1.useCallback)((correlationID, event) => {
|
|
1285
1222
|
const pending = pendingEnterTextRef.current.get(correlationID);
|
|
1286
1223
|
if (!pending) {
|
|
1287
|
-
const pendingCorrelationIDs = [...pendingEnterTextRef.current.keys()];
|
|
1288
|
-
console.warn('[EnterText] NATS response buffered (no matching pending)', {
|
|
1289
|
-
receivedCorrelationID: correlationID,
|
|
1290
|
-
resultCode: event.resultCode,
|
|
1291
|
-
pendingCorrelationIDs,
|
|
1292
|
-
hint: pendingCorrelationIDs.length > 0
|
|
1293
|
-
? 'Use one of pendingCorrelationIDs in your nats pub correlation_id'
|
|
1294
|
-
: 'Send a message in the widget first, then copy correlationID from HTTP response logs',
|
|
1295
|
-
});
|
|
1296
1224
|
bufferedNatsResponsesRef.current.set(correlationID, event);
|
|
1297
1225
|
return;
|
|
1298
1226
|
}
|
|
1299
1227
|
clearEnterTextPending(correlationID, pending);
|
|
1300
1228
|
if (pending.waitForResponse) {
|
|
1301
|
-
console.info('[EnterText] NATS response delivered to waiter', {
|
|
1302
|
-
correlationID,
|
|
1303
|
-
resultCode: event.resultCode,
|
|
1304
|
-
});
|
|
1305
1229
|
pending.waitForResponse.resolve(event);
|
|
1306
1230
|
setMemoriTyping(false);
|
|
1307
1231
|
setTypingText(undefined);
|
|
@@ -1309,67 +1233,27 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1309
1233
|
}
|
|
1310
1234
|
processEnterTextDialogResponse(event, pending);
|
|
1311
1235
|
if (!pending.hasBatchQueued) {
|
|
1312
|
-
console.info('[EnterText] typing indicator cleared', { correlationID });
|
|
1313
1236
|
setMemoriTyping(false);
|
|
1314
1237
|
setTypingText(undefined);
|
|
1315
1238
|
}
|
|
1316
|
-
else {
|
|
1317
|
-
console.debug('[EnterText] typing kept (batch queued)', {
|
|
1318
|
-
correlationID,
|
|
1319
|
-
});
|
|
1320
|
-
}
|
|
1321
1239
|
}, [processEnterTextDialogResponse, clearEnterTextPending]);
|
|
1322
1240
|
const registerPendingEnterText = (0, react_1.useCallback)((correlationID, pending) => {
|
|
1323
1241
|
const buffered = bufferedNatsResponsesRef.current.get(correlationID);
|
|
1324
1242
|
if (buffered) {
|
|
1325
|
-
console.info('[EnterText] replaying buffered NATS response', {
|
|
1326
|
-
correlationID,
|
|
1327
|
-
waitForResponse: !!pending.waitForResponse,
|
|
1328
|
-
});
|
|
1329
1243
|
bufferedNatsResponsesRef.current.delete(correlationID);
|
|
1330
1244
|
pendingEnterTextRef.current.set(correlationID, pending);
|
|
1331
1245
|
deliverEnterTextNatsResponse(correlationID, buffered);
|
|
1332
1246
|
return;
|
|
1333
1247
|
}
|
|
1334
|
-
if (!pending.waitForResponse && !pending.natsTimeoutId) {
|
|
1335
|
-
pending.natsTimeoutId = setTimeout(() => {
|
|
1336
|
-
var _a;
|
|
1337
|
-
const current = pendingEnterTextRef.current.get(correlationID);
|
|
1338
|
-
if (!current)
|
|
1339
|
-
return;
|
|
1340
|
-
clearEnterTextPending(correlationID, current);
|
|
1341
|
-
console.error('[EnterText] NATS response timeout', {
|
|
1342
|
-
correlationID,
|
|
1343
|
-
timeoutMs: ENTER_TEXT_NATS_TIMEOUT_MS,
|
|
1344
|
-
});
|
|
1345
|
-
if (!current.hasBatchQueued) {
|
|
1346
|
-
setMemoriTyping(false);
|
|
1347
|
-
setTypingText(undefined);
|
|
1348
|
-
}
|
|
1349
|
-
(_a = current.waitForResponse) === null || _a === void 0 ? void 0 : _a.reject(new Error('NATS enter-text response timeout'));
|
|
1350
|
-
}, ENTER_TEXT_NATS_TIMEOUT_MS);
|
|
1351
|
-
}
|
|
1352
|
-
console.debug('[EnterText] pending registered', {
|
|
1353
|
-
correlationID,
|
|
1354
|
-
waitForResponse: !!pending.waitForResponse,
|
|
1355
|
-
hasBatchQueued: pending.hasBatchQueued,
|
|
1356
|
-
});
|
|
1357
1248
|
pendingEnterTextRef.current.set(correlationID, pending);
|
|
1358
|
-
}, [deliverEnterTextNatsResponse
|
|
1249
|
+
}, [deliverEnterTextNatsResponse]);
|
|
1359
1250
|
const waitForEnterTextNatsResponse = (0, react_1.useCallback)((correlationID, timeoutMs = 120000) => new Promise((resolve, reject) => {
|
|
1360
|
-
console.debug('[EnterText] waiting for NATS response', {
|
|
1361
|
-
correlationID,
|
|
1362
|
-
timeoutMs,
|
|
1363
|
-
});
|
|
1364
1251
|
const timeoutId = setTimeout(() => {
|
|
1365
1252
|
const current = pendingEnterTextRef.current.get(correlationID);
|
|
1366
1253
|
if (current) {
|
|
1367
1254
|
clearEnterTextPending(correlationID, current);
|
|
1368
1255
|
}
|
|
1369
|
-
|
|
1370
|
-
correlationID,
|
|
1371
|
-
timeoutMs,
|
|
1372
|
-
});
|
|
1256
|
+
logWidgetError('NATS timeout', { correlationID, timeoutMs });
|
|
1373
1257
|
reject(new Error('NATS enter-text response timeout'));
|
|
1374
1258
|
}, timeoutMs);
|
|
1375
1259
|
registerPendingEnterText(correlationID, {
|
|
@@ -1390,25 +1274,14 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1390
1274
|
baseUrl,
|
|
1391
1275
|
sessionId,
|
|
1392
1276
|
onProgress: (0, react_1.useCallback)((event) => {
|
|
1393
|
-
console.debug('[EnterText] NATS progress', {
|
|
1394
|
-
correlationID: event.correlationID,
|
|
1395
|
-
step: event.currentStep,
|
|
1396
|
-
finalStep: event.finalStep,
|
|
1397
|
-
message: event.message,
|
|
1398
|
-
});
|
|
1399
1277
|
if (event.message) {
|
|
1400
1278
|
setTypingText(event.message);
|
|
1401
1279
|
}
|
|
1402
1280
|
}, []),
|
|
1403
1281
|
onDialogResponse: (0, react_1.useCallback)((event) => {
|
|
1404
1282
|
const correlationID = event.correlationID;
|
|
1405
|
-
console.debug('[EnterText] NATS dialog.text_entered_response received', {
|
|
1406
|
-
correlationID,
|
|
1407
|
-
resultCode: event.resultCode,
|
|
1408
|
-
requestID: event.requestID,
|
|
1409
|
-
});
|
|
1410
1283
|
if (!correlationID) {
|
|
1411
|
-
|
|
1284
|
+
logWidgetError('NATS dialog response missing correlationID', event);
|
|
1412
1285
|
setMemoriTyping(false);
|
|
1413
1286
|
setTypingText(undefined);
|
|
1414
1287
|
return;
|
|
@@ -1438,7 +1311,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1438
1311
|
timeoutRef.current = undefined;
|
|
1439
1312
|
ttsStop();
|
|
1440
1313
|
}
|
|
1441
|
-
catch (
|
|
1314
|
+
catch (_a) {
|
|
1442
1315
|
}
|
|
1443
1316
|
};
|
|
1444
1317
|
(0, react_1.useEffect)(() => {
|
|
@@ -1715,8 +1588,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1715
1588
|
};
|
|
1716
1589
|
}));
|
|
1717
1590
|
}
|
|
1718
|
-
catch (
|
|
1719
|
-
console.error('[onClickStart] Error translating messages:', e);
|
|
1591
|
+
catch (_w) {
|
|
1720
1592
|
}
|
|
1721
1593
|
}
|
|
1722
1594
|
setHistory(translatedMessages);
|
|
@@ -1746,7 +1618,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1746
1618
|
if (response.resultCode !== 0 || !currentState) {
|
|
1747
1619
|
const { chatLogs } = await getSessionChatLogs(sessionID, sessionID);
|
|
1748
1620
|
setSessionId(undefined);
|
|
1749
|
-
setClickedStart(false);
|
|
1750
1621
|
await onClickStart(undefined, true, chatLogs === null || chatLogs === void 0 ? void 0 : chatLogs[0]);
|
|
1751
1622
|
return;
|
|
1752
1623
|
}
|
|
@@ -1758,13 +1629,13 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1758
1629
|
const session = await changeTag(memori.engineMemoriID, sessionID, personification.tag, personification.pin);
|
|
1759
1630
|
if (session && session.resultCode === 0) {
|
|
1760
1631
|
await translateAndSpeak(session.currentState, userLang);
|
|
1632
|
+
setClickedStart(false);
|
|
1761
1633
|
}
|
|
1762
1634
|
else {
|
|
1763
1635
|
throw new Error('No session');
|
|
1764
1636
|
}
|
|
1765
1637
|
}
|
|
1766
|
-
catch (
|
|
1767
|
-
console.error('[onClickStart] Error changing tag:', e);
|
|
1638
|
+
catch (_x) {
|
|
1768
1639
|
reopenSession(true, memori === null || memori === void 0 ? void 0 : memori.secretToken, undefined, personification.tag, personification.pin, {
|
|
1769
1640
|
LANG: userLang,
|
|
1770
1641
|
PATHNAME: (_l = window.location.pathname) === null || _l === void 0 ? void 0 : _l.toUpperCase(),
|
|
@@ -1786,6 +1657,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1786
1657
|
const session = await changeTag(memori.engineMemoriID, sessionID, constants_1.anonTag);
|
|
1787
1658
|
if (session && session.resultCode === 0) {
|
|
1788
1659
|
await translateAndSpeak(session.currentState, userLang);
|
|
1660
|
+
setClickedStart(false);
|
|
1789
1661
|
}
|
|
1790
1662
|
else {
|
|
1791
1663
|
throw new Error('No session');
|
|
@@ -1800,6 +1672,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1800
1672
|
...(initialContextVars || {}),
|
|
1801
1673
|
}, initialQuestion, birth).then(() => {
|
|
1802
1674
|
setHasUserActivatedSpeak(true);
|
|
1675
|
+
setClickedStart(false);
|
|
1803
1676
|
});
|
|
1804
1677
|
}
|
|
1805
1678
|
}
|
|
@@ -1831,28 +1704,23 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1831
1704
|
text: (await (0, translations_1.getTranslation)(m.text, userLang, language, baseUrl)).text,
|
|
1832
1705
|
})));
|
|
1833
1706
|
}
|
|
1834
|
-
catch (
|
|
1835
|
-
console.error('[onClickStart] Error translating messages:', e);
|
|
1707
|
+
catch (_y) {
|
|
1836
1708
|
}
|
|
1837
1709
|
}
|
|
1838
1710
|
setHistory(translatedMessages);
|
|
1839
1711
|
}
|
|
1840
|
-
catch (
|
|
1841
|
-
console.error('[onClickStart] Error retrieving chat logs:', e);
|
|
1712
|
+
catch (_z) {
|
|
1842
1713
|
}
|
|
1843
1714
|
if ((!!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length) && translatedMessages.length > 1) ||
|
|
1844
1715
|
!initialQuestion) {
|
|
1845
1716
|
setHasUserActivatedSpeak(true);
|
|
1717
|
+
setClickedStart(false);
|
|
1846
1718
|
await translateAndSpeak(currentState, userLang, undefined, !!(translatedMessages === null || translatedMessages === void 0 ? void 0 : translatedMessages.length));
|
|
1847
1719
|
}
|
|
1848
1720
|
else {
|
|
1849
|
-
console.log('[onClickStart] Starting with initial question');
|
|
1850
1721
|
translatedMessages = [];
|
|
1851
1722
|
setHistory([]);
|
|
1852
1723
|
const placeSpec = getPlaceSpecForEnterText(position);
|
|
1853
|
-
console.debug('[EnterText] onClickStart: posting initial question', {
|
|
1854
|
-
sessionId: sessionID,
|
|
1855
|
-
});
|
|
1856
1724
|
const response = await postEnterTextAsync({
|
|
1857
1725
|
sessionId: sessionID,
|
|
1858
1726
|
text: initialQuestion,
|
|
@@ -1861,10 +1729,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1861
1729
|
}),
|
|
1862
1730
|
...(placeSpec !== undefined && { place: placeSpec }),
|
|
1863
1731
|
});
|
|
1864
|
-
console.debug('[EnterText] onClickStart: HTTP response', {
|
|
1865
|
-
resultCode: response.resultCode,
|
|
1866
|
-
correlationID: readCorrelationID(response),
|
|
1867
|
-
});
|
|
1868
1732
|
if (response.resultCode === 500 && response.resultMessage) {
|
|
1869
1733
|
setHistory(h => [
|
|
1870
1734
|
...h,
|
|
@@ -1881,28 +1745,22 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1881
1745
|
}
|
|
1882
1746
|
const onClickStartCorrelationID = readCorrelationID(response);
|
|
1883
1747
|
if (response.resultCode === 0 && onClickStartCorrelationID) {
|
|
1884
|
-
console.info('[EnterText] onClickStart: accepted, showing typing indicator', {
|
|
1885
|
-
correlationID: onClickStartCorrelationID,
|
|
1886
|
-
});
|
|
1887
1748
|
setMemoriTyping(true);
|
|
1888
1749
|
try {
|
|
1889
1750
|
const natsEvent = await waitForEnterTextNatsResponse(onClickStartCorrelationID);
|
|
1890
|
-
console.info('[EnterText] onClickStart: NATS response received', {
|
|
1891
|
-
correlationID: onClickStartCorrelationID,
|
|
1892
|
-
resultCode: natsEvent.resultCode,
|
|
1893
|
-
});
|
|
1894
1751
|
if (natsEvent.resultCode === 0 && natsEvent.currentState) {
|
|
1895
1752
|
await translateAndSpeak(natsEvent.currentState, userLang, undefined, false);
|
|
1753
|
+
setClickedStart(false);
|
|
1896
1754
|
}
|
|
1897
1755
|
}
|
|
1898
|
-
catch (
|
|
1899
|
-
|
|
1756
|
+
catch (err) {
|
|
1757
|
+
logWidgetError('onClickStart NATS wait failed', err);
|
|
1900
1758
|
setMemoriTyping(false);
|
|
1901
1759
|
setTypingText(undefined);
|
|
1902
1760
|
}
|
|
1903
1761
|
}
|
|
1904
1762
|
else if (response.resultCode === 0) {
|
|
1905
|
-
|
|
1763
|
+
logWidgetError('onClickStart enter-text missing correlationID', response);
|
|
1906
1764
|
}
|
|
1907
1765
|
}
|
|
1908
1766
|
}
|
|
@@ -1910,11 +1768,13 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1910
1768
|
else {
|
|
1911
1769
|
setHistory([]);
|
|
1912
1770
|
await translateAndSpeak(dialogState, userLang);
|
|
1771
|
+
setClickedStart(false);
|
|
1913
1772
|
}
|
|
1914
1773
|
}, [memoriPwd, memori, memoriTokens, birthDate, sessionId, userLang, position]);
|
|
1915
1774
|
(0, react_1.useEffect)(() => {
|
|
1916
1775
|
if (!clickedStart &&
|
|
1917
1776
|
!sessionStartingRef.current &&
|
|
1777
|
+
!sessionId &&
|
|
1918
1778
|
autoStart &&
|
|
1919
1779
|
selectedLayout !== 'HIDDEN_CHAT') {
|
|
1920
1780
|
onClickStart();
|
|
@@ -1960,12 +1820,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1960
1820
|
if (resp.resultCode === 0) {
|
|
1961
1821
|
setExperts(experts);
|
|
1962
1822
|
}
|
|
1963
|
-
else {
|
|
1964
|
-
console.warn('Error fetching experts', resp);
|
|
1965
|
-
}
|
|
1966
1823
|
}
|
|
1967
|
-
catch (
|
|
1968
|
-
console.warn(err);
|
|
1824
|
+
catch (_a) {
|
|
1969
1825
|
}
|
|
1970
1826
|
}, [sessionId, memori === null || memori === void 0 ? void 0 : memori.enableBoardOfExperts]);
|
|
1971
1827
|
(0, react_1.useEffect)(() => {
|
|
@@ -1986,7 +1842,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1986
1842
|
if (!(tenant === null || tenant === void 0 ? void 0 : tenant.billingDelegation))
|
|
1987
1843
|
return true;
|
|
1988
1844
|
if (!ownerUserID && !ownerUserName) {
|
|
1989
|
-
console.warn('Cannot verify credits: missing owner identifier');
|
|
1990
1845
|
if (options === null || options === void 0 ? void 0 : options.notify) {
|
|
1991
1846
|
handleNotEnoughCredits();
|
|
1992
1847
|
}
|
|
@@ -2010,7 +1865,6 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
2010
1865
|
return true;
|
|
2011
1866
|
}
|
|
2012
1867
|
else {
|
|
2013
|
-
console.warn('Not enough credits. Required:', resp.required);
|
|
2014
1868
|
if (options === null || options === void 0 ? void 0 : options.notify) {
|
|
2015
1869
|
handleNotEnoughCredits();
|
|
2016
1870
|
}
|
|
@@ -2020,9 +1874,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
2020
1874
|
return false;
|
|
2021
1875
|
}
|
|
2022
1876
|
}
|
|
2023
|
-
catch (
|
|
2024
|
-
|
|
2025
|
-
console.debug(err);
|
|
1877
|
+
catch (err) {
|
|
1878
|
+
logWidgetError('checkCredits failed', err);
|
|
2026
1879
|
return true;
|
|
2027
1880
|
}
|
|
2028
1881
|
}, [
|