@memori.ai/memori-react 8.40.1 → 8.40.2
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 +17 -0
- package/dist/components/MemoriWidget/MemoriWidget.js +34 -159
- 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 -158
- 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 +38 -222
- package/src/helpers/nats/useNatsSession.ts +21 -1
- package/src/version.ts +1 -1
|
@@ -131,6 +131,10 @@ const NULL_PLACE_SPEC = {
|
|
|
131
131
|
|
|
132
132
|
const ENTER_TEXT_NATS_TIMEOUT_MS = 120_000;
|
|
133
133
|
|
|
134
|
+
const logWidgetError = (context: string, detail?: unknown) => {
|
|
135
|
+
console.error(`[MemoriWidget] ${context}`, detail ?? '');
|
|
136
|
+
};
|
|
137
|
+
|
|
134
138
|
/** Reads correlation id from HTTP async response (supports camelCase / snake_case). */
|
|
135
139
|
function readCorrelationID(response: {
|
|
136
140
|
correlationID?: string;
|
|
@@ -985,12 +989,6 @@ const MemoriWidget = ({
|
|
|
985
989
|
|
|
986
990
|
try {
|
|
987
991
|
const placeSpec = getPlaceSpecForEnterText(position);
|
|
988
|
-
console.debug('[EnterText] sendMessage: posting', {
|
|
989
|
-
sessionId: sessionID,
|
|
990
|
-
textLength: msg.length,
|
|
991
|
-
hasBatchQueued,
|
|
992
|
-
typingText,
|
|
993
|
-
});
|
|
994
992
|
const response = await postEnterTextAsync({
|
|
995
993
|
sessionId: sessionID,
|
|
996
994
|
text: msg,
|
|
@@ -999,11 +997,6 @@ const MemoriWidget = ({
|
|
|
999
997
|
}),
|
|
1000
998
|
...(placeSpec !== undefined && { place: placeSpec }),
|
|
1001
999
|
});
|
|
1002
|
-
console.debug('[EnterText] sendMessage: HTTP response', {
|
|
1003
|
-
resultCode: response.resultCode,
|
|
1004
|
-
correlationID: readCorrelationID(response),
|
|
1005
|
-
resultMessage: response.resultMessage,
|
|
1006
|
-
});
|
|
1007
1000
|
const correlationID = readCorrelationID(response);
|
|
1008
1001
|
if (response.resultCode === 0 && correlationID) {
|
|
1009
1002
|
registerPendingEnterText(correlationID, {
|
|
@@ -1012,20 +1005,10 @@ const MemoriWidget = ({
|
|
|
1012
1005
|
useLoaderTextAsMsg,
|
|
1013
1006
|
hasBatchQueued,
|
|
1014
1007
|
});
|
|
1015
|
-
console.info(
|
|
1016
|
-
'[EnterText] sendMessage: accepted, showing typing indicator',
|
|
1017
|
-
{
|
|
1018
|
-
correlationID: correlationID,
|
|
1019
|
-
typingText,
|
|
1020
|
-
}
|
|
1021
|
-
);
|
|
1022
1008
|
setMemoriTyping(true);
|
|
1023
1009
|
setTypingText(typingText);
|
|
1024
1010
|
} else if (response.resultCode === 0) {
|
|
1025
|
-
|
|
1026
|
-
'[EnterText] sendMessage: HTTP 200 but missing correlationID — cannot match NATS response',
|
|
1027
|
-
response
|
|
1028
|
-
);
|
|
1011
|
+
logWidgetError('enter-text missing correlationID', response);
|
|
1029
1012
|
} else if (response.resultCode === 404) {
|
|
1030
1013
|
// Handle expired session
|
|
1031
1014
|
// remove last sent message, will set it as initial
|
|
@@ -1050,7 +1033,6 @@ const MemoriWidget = ({
|
|
|
1050
1033
|
undefined,
|
|
1051
1034
|
true // isSessionExpired
|
|
1052
1035
|
).then(state => {
|
|
1053
|
-
console.info('session timeout');
|
|
1054
1036
|
if (state?.sessionID) {
|
|
1055
1037
|
setTimeout(() => {
|
|
1056
1038
|
sendMessage(text, media, state?.sessionID);
|
|
@@ -1070,12 +1052,11 @@ const MemoriWidget = ({
|
|
|
1070
1052
|
},
|
|
1071
1053
|
]);
|
|
1072
1054
|
} else {
|
|
1073
|
-
console.warn('[SEND_MESSAGE]', response);
|
|
1074
1055
|
return Promise.reject(response);
|
|
1075
1056
|
}
|
|
1076
1057
|
} catch (error) {
|
|
1077
|
-
console.error('[EnterText] sendMessage: request failed', error);
|
|
1078
1058
|
gotError = true;
|
|
1059
|
+
logWidgetError('sendMessage failed', error);
|
|
1079
1060
|
|
|
1080
1061
|
setTypingText(undefined);
|
|
1081
1062
|
setMemoriTyping(false);
|
|
@@ -1092,12 +1073,6 @@ const MemoriWidget = ({
|
|
|
1092
1073
|
msg?: string,
|
|
1093
1074
|
avoidPushingMessage: boolean = false
|
|
1094
1075
|
) => {
|
|
1095
|
-
// console.log('[TRANSLATE] Starting translation with params:', {
|
|
1096
|
-
// state,
|
|
1097
|
-
// userLang,
|
|
1098
|
-
// msg
|
|
1099
|
-
// });
|
|
1100
|
-
|
|
1101
1076
|
const emission = state?.emission ?? currentDialogState?.emission;
|
|
1102
1077
|
|
|
1103
1078
|
let translatedState = { ...state };
|
|
@@ -1110,7 +1085,6 @@ const MemoriWidget = ({
|
|
|
1110
1085
|
!isMultilanguageEnabled ||
|
|
1111
1086
|
avoidPushingMessage
|
|
1112
1087
|
) {
|
|
1113
|
-
// console.log('[TRANSLATE] Skipping translation - using original emission');
|
|
1114
1088
|
translatedState = { ...state, emission };
|
|
1115
1089
|
if (emission) {
|
|
1116
1090
|
translatedMsg = {
|
|
@@ -1132,12 +1106,10 @@ const MemoriWidget = ({
|
|
|
1132
1106
|
}
|
|
1133
1107
|
} else {
|
|
1134
1108
|
try {
|
|
1135
|
-
// console.log('[TRANSLATE] Translating emission');
|
|
1136
1109
|
const t = await getTranslation(emission, userLang, language, baseUrl);
|
|
1137
1110
|
|
|
1138
1111
|
// Handle hints translation if present
|
|
1139
1112
|
if (state.hints && state.hints.length > 0) {
|
|
1140
|
-
// console.log('[TRANSLATE] Translating hints');
|
|
1141
1113
|
const translatedHints = await Promise.all(
|
|
1142
1114
|
(state.hints ?? []).map(async hint => {
|
|
1143
1115
|
const tHint = await getTranslation(
|
|
@@ -1169,7 +1141,6 @@ const MemoriWidget = ({
|
|
|
1169
1141
|
}
|
|
1170
1142
|
|
|
1171
1143
|
if (t.text.length > 0) {
|
|
1172
|
-
// console.log('[TRANSLATE] Creating translated message');
|
|
1173
1144
|
translatedMsg = {
|
|
1174
1145
|
text: emission,
|
|
1175
1146
|
translatedText: t.text,
|
|
@@ -1190,7 +1161,6 @@ const MemoriWidget = ({
|
|
|
1190
1161
|
};
|
|
1191
1162
|
}
|
|
1192
1163
|
} catch (error) {
|
|
1193
|
-
console.error('[TRANSLATE] Error during translation:', error);
|
|
1194
1164
|
translatedState = { ...state, emission };
|
|
1195
1165
|
translatedMsg = {
|
|
1196
1166
|
text: emission,
|
|
@@ -1211,10 +1181,8 @@ const MemoriWidget = ({
|
|
|
1211
1181
|
}
|
|
1212
1182
|
}
|
|
1213
1183
|
|
|
1214
|
-
// console.log('[TRANSLATE] Setting translated state and message');
|
|
1215
1184
|
setCurrentDialogState(translatedState);
|
|
1216
1185
|
if (!avoidPushingMessage && translatedMsg) {
|
|
1217
|
-
// console.log('[TRANSLATE] Pushing translated message', translatedMsg);
|
|
1218
1186
|
pushMessage(translatedMsg);
|
|
1219
1187
|
}
|
|
1220
1188
|
|
|
@@ -1320,7 +1288,6 @@ const MemoriWidget = ({
|
|
|
1320
1288
|
executableSnippets?.forEach(s => {
|
|
1321
1289
|
try {
|
|
1322
1290
|
setTimeout(() => {
|
|
1323
|
-
console.log('snippet', s);
|
|
1324
1291
|
// eslint-disable-next-line no-new-func
|
|
1325
1292
|
new Function(s.content ?? '')();
|
|
1326
1293
|
|
|
@@ -1334,8 +1301,8 @@ const MemoriWidget = ({
|
|
|
1334
1301
|
);
|
|
1335
1302
|
}, 400);
|
|
1336
1303
|
}, 1000);
|
|
1337
|
-
} catch
|
|
1338
|
-
|
|
1304
|
+
} catch {
|
|
1305
|
+
// ignore snippet execution errors
|
|
1339
1306
|
}
|
|
1340
1307
|
});
|
|
1341
1308
|
};
|
|
@@ -1411,8 +1378,8 @@ const MemoriWidget = ({
|
|
|
1411
1378
|
referral = (() => {
|
|
1412
1379
|
return window.location.href;
|
|
1413
1380
|
})();
|
|
1414
|
-
} catch
|
|
1415
|
-
|
|
1381
|
+
} catch {
|
|
1382
|
+
// ignore referral URL errors
|
|
1416
1383
|
}
|
|
1417
1384
|
|
|
1418
1385
|
// Initialize session with parameters
|
|
@@ -1464,7 +1431,6 @@ const MemoriWidget = ({
|
|
|
1464
1431
|
else if (
|
|
1465
1432
|
session?.resultMessage.startsWith('This Memori is aged restricted')
|
|
1466
1433
|
) {
|
|
1467
|
-
console.warn(session);
|
|
1468
1434
|
toast.error(t('underageTwinSession', { age: minAge }));
|
|
1469
1435
|
}
|
|
1470
1436
|
// Handle authentication error
|
|
@@ -1475,7 +1441,6 @@ const MemoriWidget = ({
|
|
|
1475
1441
|
}
|
|
1476
1442
|
// Handle other errors
|
|
1477
1443
|
else {
|
|
1478
|
-
console.warn(session);
|
|
1479
1444
|
toast.error(
|
|
1480
1445
|
tst => (
|
|
1481
1446
|
<div>
|
|
@@ -1497,7 +1462,7 @@ const MemoriWidget = ({
|
|
|
1497
1462
|
return session;
|
|
1498
1463
|
}
|
|
1499
1464
|
} catch (err) {
|
|
1500
|
-
|
|
1465
|
+
logWidgetError('fetchSession failed', err);
|
|
1501
1466
|
}
|
|
1502
1467
|
};
|
|
1503
1468
|
|
|
@@ -1536,12 +1501,10 @@ const MemoriWidget = ({
|
|
|
1536
1501
|
undefined
|
|
1537
1502
|
);
|
|
1538
1503
|
let userBirthDate = birthDate ?? storageBirthDate;
|
|
1539
|
-
// console.log('[REOPEN_SESSION] Using birth date:', userBirthDate);
|
|
1540
1504
|
|
|
1541
1505
|
try {
|
|
1542
1506
|
// Show age verification if required and birth date not provided
|
|
1543
1507
|
if (!userBirthDate && !!minAge) {
|
|
1544
|
-
// console.log('[REOPEN_SESSION] Age verification required, showing modal');
|
|
1545
1508
|
setShowAgeVerification(true);
|
|
1546
1509
|
return;
|
|
1547
1510
|
}
|
|
@@ -1555,7 +1518,6 @@ const MemoriWidget = ({
|
|
|
1555
1518
|
!recoveryTokens &&
|
|
1556
1519
|
!memoriTokens
|
|
1557
1520
|
) {
|
|
1558
|
-
// console.log('[REOPEN_SESSION] Authentication required, showing modal');
|
|
1559
1521
|
setAuthModalState('password');
|
|
1560
1522
|
return;
|
|
1561
1523
|
}
|
|
@@ -1571,13 +1533,11 @@ const MemoriWidget = ({
|
|
|
1571
1533
|
referral = (() => {
|
|
1572
1534
|
return window.location.href;
|
|
1573
1535
|
})();
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
console.debug('[REOPEN_SESSION] Error getting referral:', err);
|
|
1536
|
+
} catch {
|
|
1537
|
+
// ignore referral URL errors
|
|
1577
1538
|
}
|
|
1578
1539
|
|
|
1579
1540
|
// Initialize session with provided parameters
|
|
1580
|
-
// console.log('[REOPEN_SESSION] Initializing session...');
|
|
1581
1541
|
const { sessionID, currentState, ...response } = await initSession({
|
|
1582
1542
|
memoriID: memori.engineMemoriID ?? '',
|
|
1583
1543
|
password: password || memoriPwd || memori.secretToken,
|
|
@@ -1614,22 +1574,13 @@ const MemoriWidget = ({
|
|
|
1614
1574
|
|
|
1615
1575
|
// Handle successful session initialization
|
|
1616
1576
|
if (sessionID && currentState && response.resultCode === 0) {
|
|
1617
|
-
console.log(
|
|
1618
|
-
'[REOPEN_SESSION] Session initialized successfully:',
|
|
1619
|
-
sessionID
|
|
1620
|
-
);
|
|
1621
1577
|
setSessionId(sessionID);
|
|
1622
1578
|
|
|
1623
1579
|
// Update dialog state and history if requested
|
|
1624
1580
|
if (updateDialogState) {
|
|
1625
|
-
// console.log('[REOPEN_SESSION] Updating dialog state');
|
|
1626
1581
|
setCurrentDialogState(currentState);
|
|
1627
1582
|
|
|
1628
1583
|
if (currentState.emission) {
|
|
1629
|
-
console.log(
|
|
1630
|
-
'[REOPEN_SESSION] Processing emission:',
|
|
1631
|
-
currentState.emission
|
|
1632
|
-
);
|
|
1633
1584
|
// Determine initial status message based on context
|
|
1634
1585
|
// Show status message only if session expired and there's existing history
|
|
1635
1586
|
const initialStatus =
|
|
@@ -1690,7 +1641,6 @@ const MemoriWidget = ({
|
|
|
1690
1641
|
else if (
|
|
1691
1642
|
response?.resultMessage.startsWith('This Memori is aged restricted')
|
|
1692
1643
|
) {
|
|
1693
|
-
console.error('[REOPEN_SESSION] Age restriction error:', response);
|
|
1694
1644
|
toast.error(t('underageTwinSession', { age: minAge }));
|
|
1695
1645
|
}
|
|
1696
1646
|
// Handle authentication error
|
|
@@ -1698,17 +1648,15 @@ const MemoriWidget = ({
|
|
|
1698
1648
|
response?.resultCode === 403 &&
|
|
1699
1649
|
memori.privacyType !== 'PUBLIC'
|
|
1700
1650
|
) {
|
|
1701
|
-
console.error('[REOPEN_SESSION] Authentication error');
|
|
1702
1651
|
setMemoriPwd(undefined);
|
|
1703
1652
|
setAuthModalState('password');
|
|
1704
1653
|
}
|
|
1705
1654
|
// Handle other errors
|
|
1706
1655
|
else {
|
|
1707
|
-
console.error('[REOPEN_SESSION] Other error:', response);
|
|
1708
1656
|
toast.error(t(getErrori18nKey(response.resultCode)));
|
|
1709
1657
|
}
|
|
1710
1658
|
} catch (err) {
|
|
1711
|
-
|
|
1659
|
+
logWidgetError('reopenSession failed', err);
|
|
1712
1660
|
}
|
|
1713
1661
|
// Reset loading state
|
|
1714
1662
|
setLoading(false);
|
|
@@ -1723,7 +1671,6 @@ const MemoriWidget = ({
|
|
|
1723
1671
|
pin?: string
|
|
1724
1672
|
) => {
|
|
1725
1673
|
if (!memoriId || !sessionId) {
|
|
1726
|
-
console.error('CHANGETAG/Session not found');
|
|
1727
1674
|
return Promise.reject('Session not found');
|
|
1728
1675
|
}
|
|
1729
1676
|
|
|
@@ -1763,7 +1710,6 @@ const MemoriWidget = ({
|
|
|
1763
1710
|
};
|
|
1764
1711
|
}
|
|
1765
1712
|
} else if ([400, 401, 403, 404, 500].includes(resultCode)) {
|
|
1766
|
-
console.warn('[APPCONTEXT/CHANGETAG]', resultCode);
|
|
1767
1713
|
let storageBirthDate = getLocalConfig<string | undefined>(
|
|
1768
1714
|
'birthDate',
|
|
1769
1715
|
undefined
|
|
@@ -1774,8 +1720,8 @@ const MemoriWidget = ({
|
|
|
1774
1720
|
referral = (() => {
|
|
1775
1721
|
return window.location.href;
|
|
1776
1722
|
})();
|
|
1777
|
-
} catch
|
|
1778
|
-
|
|
1723
|
+
} catch {
|
|
1724
|
+
// ignore referral URL errors
|
|
1779
1725
|
}
|
|
1780
1726
|
|
|
1781
1727
|
fetchSession({
|
|
@@ -1817,7 +1763,6 @@ const MemoriWidget = ({
|
|
|
1817
1763
|
}
|
|
1818
1764
|
} catch (_e) {
|
|
1819
1765
|
let err = _e as Error;
|
|
1820
|
-
console.warn('[APPCONTEXT/CHANGETAG]', err);
|
|
1821
1766
|
return Promise.reject(err);
|
|
1822
1767
|
}
|
|
1823
1768
|
|
|
@@ -1857,8 +1802,6 @@ const MemoriWidget = ({
|
|
|
1857
1802
|
const [requestedListening, setRequestedListening] = useState(false);
|
|
1858
1803
|
const startListeningRef = useRef<(() => Promise<void>) | null>(null);
|
|
1859
1804
|
|
|
1860
|
-
// console.log('tenantID', tenantID);
|
|
1861
|
-
|
|
1862
1805
|
// Define TTS configuration
|
|
1863
1806
|
const ttsConfig = useMemo(
|
|
1864
1807
|
() => ({
|
|
@@ -1913,7 +1856,6 @@ const MemoriWidget = ({
|
|
|
1913
1856
|
'muteSpeaker',
|
|
1914
1857
|
!defaultEnableAudio
|
|
1915
1858
|
);
|
|
1916
|
-
console.log('[MemoriWidget] shouldPlayAudio', currentSpeakerMuted);
|
|
1917
1859
|
return (
|
|
1918
1860
|
text &&
|
|
1919
1861
|
text.trim() &&
|
|
@@ -1925,7 +1867,6 @@ const MemoriWidget = ({
|
|
|
1925
1867
|
|
|
1926
1868
|
// Create a single, centralized function to process and send messages
|
|
1927
1869
|
const processSpeechAndSendMessage = (text: string) => {
|
|
1928
|
-
// console.log('processSpeechAndSendMessage', text);
|
|
1929
1870
|
// Skip if already processing or no text
|
|
1930
1871
|
if (!text || text.trim().length === 0) {
|
|
1931
1872
|
return;
|
|
@@ -1934,17 +1875,15 @@ const MemoriWidget = ({
|
|
|
1934
1875
|
try {
|
|
1935
1876
|
// Process the text
|
|
1936
1877
|
const message = stripDuplicates(text);
|
|
1937
|
-
console.debug('Processing speech message:', message);
|
|
1938
1878
|
|
|
1939
1879
|
if (message.length > 0) {
|
|
1940
1880
|
setUserMessage('');
|
|
1941
1881
|
|
|
1942
1882
|
// Send the message
|
|
1943
|
-
console.debug('Sending message:', message);
|
|
1944
1883
|
sendMessage(message);
|
|
1945
1884
|
}
|
|
1946
|
-
} catch
|
|
1947
|
-
|
|
1885
|
+
} catch {
|
|
1886
|
+
// ignore speech processing errors
|
|
1948
1887
|
}
|
|
1949
1888
|
};
|
|
1950
1889
|
|
|
@@ -2027,8 +1966,7 @@ const MemoriWidget = ({
|
|
|
2027
1966
|
}
|
|
2028
1967
|
|
|
2029
1968
|
return translatedState;
|
|
2030
|
-
} catch
|
|
2031
|
-
console.error('Error in translateAndSpeak:', error);
|
|
1969
|
+
} catch {
|
|
2032
1970
|
// Still update activation state even if there's an error
|
|
2033
1971
|
if (!hasUserActivatedSpeak) {
|
|
2034
1972
|
setHasUserActivatedSpeak(true);
|
|
@@ -2047,12 +1985,6 @@ const MemoriWidget = ({
|
|
|
2047
1985
|
|
|
2048
1986
|
const processEnterTextDialogResponse = useCallback(
|
|
2049
1987
|
(event: NatsDialogResponseEvent, pending: PendingEnterText) => {
|
|
2050
|
-
console.debug('[EnterText] processDialogResponse', {
|
|
2051
|
-
correlationID: event.correlationID,
|
|
2052
|
-
resultCode: event.resultCode,
|
|
2053
|
-
hasCurrentState: !!event.currentState,
|
|
2054
|
-
hasBatchQueued: pending.hasBatchQueued,
|
|
2055
|
-
});
|
|
2056
1988
|
const {
|
|
2057
1989
|
msg,
|
|
2058
1990
|
typingText: pendingTypingText,
|
|
@@ -2062,10 +1994,6 @@ const MemoriWidget = ({
|
|
|
2062
1994
|
|
|
2063
1995
|
if (event.resultCode !== 0 || !currentState) {
|
|
2064
1996
|
if (event.resultCode === 500 && event.resultMessage) {
|
|
2065
|
-
console.warn('[EnterText] processDialogResponse: server error', {
|
|
2066
|
-
correlationID: event.correlationID,
|
|
2067
|
-
resultMessage: event.resultMessage,
|
|
2068
|
-
});
|
|
2069
1997
|
setHistory(h => [
|
|
2070
1998
|
...h,
|
|
2071
1999
|
{
|
|
@@ -2077,16 +2005,11 @@ const MemoriWidget = ({
|
|
|
2077
2005
|
date: new Date().toISOString(),
|
|
2078
2006
|
},
|
|
2079
2007
|
]);
|
|
2080
|
-
} else if (event.resultCode !== 0) {
|
|
2081
|
-
console.warn('[SEND_MESSAGE/NATS]', event);
|
|
2082
2008
|
}
|
|
2083
2009
|
return;
|
|
2084
2010
|
}
|
|
2085
2011
|
|
|
2086
2012
|
if (!msg) {
|
|
2087
|
-
console.debug(
|
|
2088
|
-
'[EnterText] processDialogResponse: no msg in pending, skipping'
|
|
2089
|
-
);
|
|
2090
2013
|
return;
|
|
2091
2014
|
}
|
|
2092
2015
|
|
|
@@ -2096,12 +2019,6 @@ const MemoriWidget = ({
|
|
|
2096
2019
|
? pendingTypingText
|
|
2097
2020
|
: currentState.emission ?? currentDialogState?.emission;
|
|
2098
2021
|
|
|
2099
|
-
console.debug('[EnterText] processDialogResponse: rendering emission', {
|
|
2100
|
-
correlationID: event.correlationID,
|
|
2101
|
-
emissionPreview: emission?.slice(0, 80),
|
|
2102
|
-
state: currentState.state,
|
|
2103
|
-
});
|
|
2104
|
-
|
|
2105
2022
|
if (
|
|
2106
2023
|
userLang.toLowerCase() !== language.toLowerCase() &&
|
|
2107
2024
|
emission &&
|
|
@@ -2178,12 +2095,6 @@ const MemoriWidget = ({
|
|
|
2178
2095
|
? `Error: ${event.errorCode}`
|
|
2179
2096
|
: 'Error: An unexpected error occurred';
|
|
2180
2097
|
|
|
2181
|
-
console.error('[EnterText] NATS error event', {
|
|
2182
|
-
correlationID,
|
|
2183
|
-
errorCode: event.errorCode,
|
|
2184
|
-
errorMessage: event.errorMessage,
|
|
2185
|
-
});
|
|
2186
|
-
|
|
2187
2098
|
pushMessage({
|
|
2188
2099
|
text: errorText,
|
|
2189
2100
|
emitter: 'system',
|
|
@@ -2213,19 +2124,6 @@ const MemoriWidget = ({
|
|
|
2213
2124
|
(correlationID: string, event: NatsDialogResponseEvent) => {
|
|
2214
2125
|
const pending = pendingEnterTextRef.current.get(correlationID);
|
|
2215
2126
|
if (!pending) {
|
|
2216
|
-
const pendingCorrelationIDs = [...pendingEnterTextRef.current.keys()];
|
|
2217
|
-
console.warn(
|
|
2218
|
-
'[EnterText] NATS response buffered (no matching pending)',
|
|
2219
|
-
{
|
|
2220
|
-
receivedCorrelationID: correlationID,
|
|
2221
|
-
resultCode: event.resultCode,
|
|
2222
|
-
pendingCorrelationIDs,
|
|
2223
|
-
hint:
|
|
2224
|
-
pendingCorrelationIDs.length > 0
|
|
2225
|
-
? 'Use one of pendingCorrelationIDs in your nats pub correlation_id'
|
|
2226
|
-
: 'Send a message in the widget first, then copy correlationID from HTTP response logs',
|
|
2227
|
-
}
|
|
2228
|
-
);
|
|
2229
2127
|
bufferedNatsResponsesRef.current.set(correlationID, event);
|
|
2230
2128
|
return;
|
|
2231
2129
|
}
|
|
@@ -2233,10 +2131,6 @@ const MemoriWidget = ({
|
|
|
2233
2131
|
clearEnterTextPending(correlationID, pending);
|
|
2234
2132
|
|
|
2235
2133
|
if (pending.waitForResponse) {
|
|
2236
|
-
console.info('[EnterText] NATS response delivered to waiter', {
|
|
2237
|
-
correlationID,
|
|
2238
|
-
resultCode: event.resultCode,
|
|
2239
|
-
});
|
|
2240
2134
|
pending.waitForResponse.resolve(event);
|
|
2241
2135
|
setMemoriTyping(false);
|
|
2242
2136
|
setTypingText(undefined);
|
|
@@ -2246,13 +2140,8 @@ const MemoriWidget = ({
|
|
|
2246
2140
|
processEnterTextDialogResponse(event, pending);
|
|
2247
2141
|
|
|
2248
2142
|
if (!pending.hasBatchQueued) {
|
|
2249
|
-
console.info('[EnterText] typing indicator cleared', { correlationID });
|
|
2250
2143
|
setMemoriTyping(false);
|
|
2251
2144
|
setTypingText(undefined);
|
|
2252
|
-
} else {
|
|
2253
|
-
console.debug('[EnterText] typing kept (batch queued)', {
|
|
2254
|
-
correlationID,
|
|
2255
|
-
});
|
|
2256
2145
|
}
|
|
2257
2146
|
},
|
|
2258
2147
|
[processEnterTextDialogResponse, clearEnterTextPending]
|
|
@@ -2262,10 +2151,6 @@ const MemoriWidget = ({
|
|
|
2262
2151
|
(correlationID: string, pending: PendingEnterText) => {
|
|
2263
2152
|
const buffered = bufferedNatsResponsesRef.current.get(correlationID);
|
|
2264
2153
|
if (buffered) {
|
|
2265
|
-
console.info('[EnterText] replaying buffered NATS response', {
|
|
2266
|
-
correlationID,
|
|
2267
|
-
waitForResponse: !!pending.waitForResponse,
|
|
2268
|
-
});
|
|
2269
2154
|
bufferedNatsResponsesRef.current.delete(correlationID);
|
|
2270
2155
|
pendingEnterTextRef.current.set(correlationID, pending);
|
|
2271
2156
|
deliverEnterTextNatsResponse(correlationID, buffered);
|
|
@@ -2277,7 +2162,7 @@ const MemoriWidget = ({
|
|
|
2277
2162
|
const current = pendingEnterTextRef.current.get(correlationID);
|
|
2278
2163
|
if (!current) return;
|
|
2279
2164
|
clearEnterTextPending(correlationID, current);
|
|
2280
|
-
|
|
2165
|
+
logWidgetError('NATS timeout', {
|
|
2281
2166
|
correlationID,
|
|
2282
2167
|
timeoutMs: ENTER_TEXT_NATS_TIMEOUT_MS,
|
|
2283
2168
|
});
|
|
@@ -2291,11 +2176,6 @@ const MemoriWidget = ({
|
|
|
2291
2176
|
}, ENTER_TEXT_NATS_TIMEOUT_MS);
|
|
2292
2177
|
}
|
|
2293
2178
|
|
|
2294
|
-
console.debug('[EnterText] pending registered', {
|
|
2295
|
-
correlationID,
|
|
2296
|
-
waitForResponse: !!pending.waitForResponse,
|
|
2297
|
-
hasBatchQueued: pending.hasBatchQueued,
|
|
2298
|
-
});
|
|
2299
2179
|
pendingEnterTextRef.current.set(correlationID, pending);
|
|
2300
2180
|
},
|
|
2301
2181
|
[deliverEnterTextNatsResponse, clearEnterTextPending]
|
|
@@ -2304,19 +2184,12 @@ const MemoriWidget = ({
|
|
|
2304
2184
|
const waitForEnterTextNatsResponse = useCallback(
|
|
2305
2185
|
(correlationID: string, timeoutMs = 120000) =>
|
|
2306
2186
|
new Promise<NatsDialogResponseEvent>((resolve, reject) => {
|
|
2307
|
-
console.debug('[EnterText] waiting for NATS response', {
|
|
2308
|
-
correlationID,
|
|
2309
|
-
timeoutMs,
|
|
2310
|
-
});
|
|
2311
2187
|
const timeoutId = setTimeout(() => {
|
|
2312
2188
|
const current = pendingEnterTextRef.current.get(correlationID);
|
|
2313
2189
|
if (current) {
|
|
2314
2190
|
clearEnterTextPending(correlationID, current);
|
|
2315
2191
|
}
|
|
2316
|
-
|
|
2317
|
-
correlationID,
|
|
2318
|
-
timeoutMs,
|
|
2319
|
-
});
|
|
2192
|
+
logWidgetError('NATS timeout', { correlationID, timeoutMs });
|
|
2320
2193
|
reject(new Error('NATS enter-text response timeout'));
|
|
2321
2194
|
}, timeoutMs);
|
|
2322
2195
|
|
|
@@ -2342,12 +2215,6 @@ const MemoriWidget = ({
|
|
|
2342
2215
|
baseUrl,
|
|
2343
2216
|
sessionId,
|
|
2344
2217
|
onProgress: useCallback((event: NatsProgressEvent) => {
|
|
2345
|
-
console.debug('[EnterText] NATS progress', {
|
|
2346
|
-
correlationID: event.correlationID,
|
|
2347
|
-
step: event.currentStep,
|
|
2348
|
-
finalStep: event.finalStep,
|
|
2349
|
-
message: event.message,
|
|
2350
|
-
});
|
|
2351
2218
|
if (event.message) {
|
|
2352
2219
|
setTypingText(event.message);
|
|
2353
2220
|
}
|
|
@@ -2355,19 +2222,8 @@ const MemoriWidget = ({
|
|
|
2355
2222
|
onDialogResponse: useCallback(
|
|
2356
2223
|
(event: NatsDialogResponseEvent) => {
|
|
2357
2224
|
const correlationID = event.correlationID;
|
|
2358
|
-
console.debug(
|
|
2359
|
-
'[EnterText] NATS dialog.text_entered_response received',
|
|
2360
|
-
{
|
|
2361
|
-
correlationID,
|
|
2362
|
-
resultCode: event.resultCode,
|
|
2363
|
-
requestID: event.requestID,
|
|
2364
|
-
}
|
|
2365
|
-
);
|
|
2366
2225
|
if (!correlationID) {
|
|
2367
|
-
|
|
2368
|
-
'[EnterText] dialog_text_entered_response without correlationID',
|
|
2369
|
-
event
|
|
2370
|
-
);
|
|
2226
|
+
logWidgetError('NATS dialog response missing correlationID', event);
|
|
2371
2227
|
setMemoriTyping(false);
|
|
2372
2228
|
setTypingText(undefined);
|
|
2373
2229
|
return;
|
|
@@ -2408,8 +2264,8 @@ const MemoriWidget = ({
|
|
|
2408
2264
|
setClickedStart(false);
|
|
2409
2265
|
timeoutRef.current = undefined;
|
|
2410
2266
|
ttsStop();
|
|
2411
|
-
} catch
|
|
2412
|
-
//
|
|
2267
|
+
} catch {
|
|
2268
|
+
// ignore reset errors
|
|
2413
2269
|
}
|
|
2414
2270
|
};
|
|
2415
2271
|
useEffect(() => {
|
|
@@ -2673,12 +2529,6 @@ const MemoriWidget = ({
|
|
|
2673
2529
|
chatLog?: ChatLog,
|
|
2674
2530
|
targetSessionID?: string
|
|
2675
2531
|
) => {
|
|
2676
|
-
// console.log('[onClickStart] Starting with params:', {
|
|
2677
|
-
// session,
|
|
2678
|
-
// initialSessionExpired,
|
|
2679
|
-
// chatLog
|
|
2680
|
-
// });
|
|
2681
|
-
|
|
2682
2532
|
const sessionID = chatLog ? undefined : session?.sessionID || sessionId;
|
|
2683
2533
|
const dialogState = chatLog
|
|
2684
2534
|
? undefined
|
|
@@ -2829,8 +2679,8 @@ const MemoriWidget = ({
|
|
|
2829
2679
|
};
|
|
2830
2680
|
})
|
|
2831
2681
|
);
|
|
2832
|
-
} catch
|
|
2833
|
-
|
|
2682
|
+
} catch {
|
|
2683
|
+
// ignore translation errors
|
|
2834
2684
|
}
|
|
2835
2685
|
}
|
|
2836
2686
|
|
|
@@ -2897,8 +2747,7 @@ const MemoriWidget = ({
|
|
|
2897
2747
|
} else {
|
|
2898
2748
|
throw new Error('No session');
|
|
2899
2749
|
}
|
|
2900
|
-
} catch
|
|
2901
|
-
console.error('[onClickStart] Error changing tag:', e);
|
|
2750
|
+
} catch {
|
|
2902
2751
|
reopenSession(
|
|
2903
2752
|
true,
|
|
2904
2753
|
memori?.secretToken,
|
|
@@ -3010,14 +2859,14 @@ const MemoriWidget = ({
|
|
|
3010
2859
|
).text,
|
|
3011
2860
|
}))
|
|
3012
2861
|
);
|
|
3013
|
-
} catch
|
|
3014
|
-
|
|
2862
|
+
} catch {
|
|
2863
|
+
// ignore translation errors
|
|
3015
2864
|
}
|
|
3016
2865
|
}
|
|
3017
2866
|
|
|
3018
2867
|
setHistory(translatedMessages);
|
|
3019
|
-
} catch
|
|
3020
|
-
|
|
2868
|
+
} catch {
|
|
2869
|
+
// ignore chat log retrieval errors
|
|
3021
2870
|
}
|
|
3022
2871
|
|
|
3023
2872
|
if (
|
|
@@ -3036,19 +2885,12 @@ const MemoriWidget = ({
|
|
|
3036
2885
|
!!translatedMessages?.length
|
|
3037
2886
|
);
|
|
3038
2887
|
} else {
|
|
3039
|
-
console.log('[onClickStart] Starting with initial question');
|
|
3040
2888
|
// remove default initial message
|
|
3041
2889
|
translatedMessages = [];
|
|
3042
2890
|
setHistory([]);
|
|
3043
2891
|
|
|
3044
2892
|
// we have no chat history, we start by initial question
|
|
3045
2893
|
const placeSpec = getPlaceSpecForEnterText(position);
|
|
3046
|
-
console.debug(
|
|
3047
|
-
'[EnterText] onClickStart: posting initial question',
|
|
3048
|
-
{
|
|
3049
|
-
sessionId: sessionID,
|
|
3050
|
-
}
|
|
3051
|
-
);
|
|
3052
2894
|
const response = await postEnterTextAsync({
|
|
3053
2895
|
sessionId: sessionID!,
|
|
3054
2896
|
text: initialQuestion,
|
|
@@ -3057,11 +2899,6 @@ const MemoriWidget = ({
|
|
|
3057
2899
|
}),
|
|
3058
2900
|
...(placeSpec !== undefined && { place: placeSpec }),
|
|
3059
2901
|
});
|
|
3060
|
-
console.debug('[EnterText] onClickStart: HTTP response', {
|
|
3061
|
-
resultCode: response.resultCode,
|
|
3062
|
-
correlationID: readCorrelationID(response),
|
|
3063
|
-
});
|
|
3064
|
-
|
|
3065
2902
|
// Handle 500 error from EnterTextAsync
|
|
3066
2903
|
if (response.resultCode === 500 && response.resultMessage) {
|
|
3067
2904
|
setHistory(h => [
|
|
@@ -3080,24 +2917,11 @@ const MemoriWidget = ({
|
|
|
3080
2917
|
|
|
3081
2918
|
const onClickStartCorrelationID = readCorrelationID(response);
|
|
3082
2919
|
if (response.resultCode === 0 && onClickStartCorrelationID) {
|
|
3083
|
-
console.info(
|
|
3084
|
-
'[EnterText] onClickStart: accepted, showing typing indicator',
|
|
3085
|
-
{
|
|
3086
|
-
correlationID: onClickStartCorrelationID,
|
|
3087
|
-
}
|
|
3088
|
-
);
|
|
3089
2920
|
setMemoriTyping(true);
|
|
3090
2921
|
try {
|
|
3091
2922
|
const natsEvent = await waitForEnterTextNatsResponse(
|
|
3092
2923
|
onClickStartCorrelationID
|
|
3093
2924
|
);
|
|
3094
|
-
console.info(
|
|
3095
|
-
'[EnterText] onClickStart: NATS response received',
|
|
3096
|
-
{
|
|
3097
|
-
correlationID: onClickStartCorrelationID,
|
|
3098
|
-
resultCode: natsEvent.resultCode,
|
|
3099
|
-
}
|
|
3100
|
-
);
|
|
3101
2925
|
if (natsEvent.resultCode === 0 && natsEvent.currentState) {
|
|
3102
2926
|
await translateAndSpeak(
|
|
3103
2927
|
natsEvent.currentState,
|
|
@@ -3107,16 +2931,13 @@ const MemoriWidget = ({
|
|
|
3107
2931
|
);
|
|
3108
2932
|
setClickedStart(false);
|
|
3109
2933
|
}
|
|
3110
|
-
} catch (
|
|
3111
|
-
|
|
2934
|
+
} catch (err) {
|
|
2935
|
+
logWidgetError('onClickStart NATS wait failed', err);
|
|
3112
2936
|
setMemoriTyping(false);
|
|
3113
2937
|
setTypingText(undefined);
|
|
3114
2938
|
}
|
|
3115
2939
|
} else if (response.resultCode === 0) {
|
|
3116
|
-
|
|
3117
|
-
'[EnterText] onClickStart: HTTP 200 but missing correlationID',
|
|
3118
|
-
response
|
|
3119
|
-
);
|
|
2940
|
+
logWidgetError('onClickStart enter-text missing correlationID', response);
|
|
3120
2941
|
}
|
|
3121
2942
|
}
|
|
3122
2943
|
}
|
|
@@ -3201,11 +3022,9 @@ const MemoriWidget = ({
|
|
|
3201
3022
|
|
|
3202
3023
|
if (resp.resultCode === 0) {
|
|
3203
3024
|
setExperts(experts);
|
|
3204
|
-
} else {
|
|
3205
|
-
console.warn('Error fetching experts', resp);
|
|
3206
3025
|
}
|
|
3207
|
-
} catch
|
|
3208
|
-
|
|
3026
|
+
} catch {
|
|
3027
|
+
// ignore expert fetch errors
|
|
3209
3028
|
}
|
|
3210
3029
|
}, [sessionId, memori?.enableBoardOfExperts]);
|
|
3211
3030
|
useEffect(() => {
|
|
@@ -3234,7 +3053,6 @@ const MemoriWidget = ({
|
|
|
3234
3053
|
// Without either owner identifier we cannot call the API, so we fail closed
|
|
3235
3054
|
// instead of silently letting the session start unverified.
|
|
3236
3055
|
if (!ownerUserID && !ownerUserName) {
|
|
3237
|
-
console.warn('Cannot verify credits: missing owner identifier');
|
|
3238
3056
|
if (options?.notify) {
|
|
3239
3057
|
handleNotEnoughCredits();
|
|
3240
3058
|
} else {
|
|
@@ -3258,7 +3076,6 @@ const MemoriWidget = ({
|
|
|
3258
3076
|
setHasEnoughCredits(true);
|
|
3259
3077
|
return true;
|
|
3260
3078
|
} else {
|
|
3261
|
-
console.warn('Not enough credits. Required:', resp.required);
|
|
3262
3079
|
if (options?.notify) {
|
|
3263
3080
|
handleNotEnoughCredits();
|
|
3264
3081
|
} else {
|
|
@@ -3266,9 +3083,8 @@ const MemoriWidget = ({
|
|
|
3266
3083
|
}
|
|
3267
3084
|
return false;
|
|
3268
3085
|
}
|
|
3269
|
-
} catch (
|
|
3270
|
-
|
|
3271
|
-
console.debug(err);
|
|
3086
|
+
} catch (err) {
|
|
3087
|
+
logWidgetError('checkCredits failed', err);
|
|
3272
3088
|
return true;
|
|
3273
3089
|
}
|
|
3274
3090
|
},
|