@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
|
@@ -129,7 +129,9 @@ const NULL_PLACE_SPEC = {
|
|
|
129
129
|
uncertaintyKm: null,
|
|
130
130
|
} as const;
|
|
131
131
|
|
|
132
|
-
const
|
|
132
|
+
const logWidgetError = (context: string, detail?: unknown) => {
|
|
133
|
+
console.error(`[MemoriWidget] ${context}`, detail ?? '');
|
|
134
|
+
};
|
|
133
135
|
|
|
134
136
|
/** Reads correlation id from HTTP async response (supports camelCase / snake_case). */
|
|
135
137
|
function readCorrelationID(response: {
|
|
@@ -649,7 +651,6 @@ const MemoriWidget = ({
|
|
|
649
651
|
typingText?: string;
|
|
650
652
|
useLoaderTextAsMsg?: boolean;
|
|
651
653
|
hasBatchQueued?: boolean;
|
|
652
|
-
natsTimeoutId?: ReturnType<typeof setTimeout>;
|
|
653
654
|
waitForResponse?: {
|
|
654
655
|
resolve: (event: NatsDialogResponseEvent) => void;
|
|
655
656
|
reject: (error: Error) => void;
|
|
@@ -985,12 +986,6 @@ const MemoriWidget = ({
|
|
|
985
986
|
|
|
986
987
|
try {
|
|
987
988
|
const placeSpec = getPlaceSpecForEnterText(position);
|
|
988
|
-
console.debug('[EnterText] sendMessage: posting', {
|
|
989
|
-
sessionId: sessionID,
|
|
990
|
-
textLength: msg.length,
|
|
991
|
-
hasBatchQueued,
|
|
992
|
-
typingText,
|
|
993
|
-
});
|
|
994
989
|
const response = await postEnterTextAsync({
|
|
995
990
|
sessionId: sessionID,
|
|
996
991
|
text: msg,
|
|
@@ -999,11 +994,6 @@ const MemoriWidget = ({
|
|
|
999
994
|
}),
|
|
1000
995
|
...(placeSpec !== undefined && { place: placeSpec }),
|
|
1001
996
|
});
|
|
1002
|
-
console.debug('[EnterText] sendMessage: HTTP response', {
|
|
1003
|
-
resultCode: response.resultCode,
|
|
1004
|
-
correlationID: readCorrelationID(response),
|
|
1005
|
-
resultMessage: response.resultMessage,
|
|
1006
|
-
});
|
|
1007
997
|
const correlationID = readCorrelationID(response);
|
|
1008
998
|
if (response.resultCode === 0 && correlationID) {
|
|
1009
999
|
registerPendingEnterText(correlationID, {
|
|
@@ -1012,20 +1002,10 @@ const MemoriWidget = ({
|
|
|
1012
1002
|
useLoaderTextAsMsg,
|
|
1013
1003
|
hasBatchQueued,
|
|
1014
1004
|
});
|
|
1015
|
-
console.info(
|
|
1016
|
-
'[EnterText] sendMessage: accepted, showing typing indicator',
|
|
1017
|
-
{
|
|
1018
|
-
correlationID: correlationID,
|
|
1019
|
-
typingText,
|
|
1020
|
-
}
|
|
1021
|
-
);
|
|
1022
1005
|
setMemoriTyping(true);
|
|
1023
1006
|
setTypingText(typingText);
|
|
1024
1007
|
} else if (response.resultCode === 0) {
|
|
1025
|
-
|
|
1026
|
-
'[EnterText] sendMessage: HTTP 200 but missing correlationID — cannot match NATS response',
|
|
1027
|
-
response
|
|
1028
|
-
);
|
|
1008
|
+
logWidgetError('enter-text missing correlationID', response);
|
|
1029
1009
|
} else if (response.resultCode === 404) {
|
|
1030
1010
|
// Handle expired session
|
|
1031
1011
|
// remove last sent message, will set it as initial
|
|
@@ -1050,7 +1030,6 @@ const MemoriWidget = ({
|
|
|
1050
1030
|
undefined,
|
|
1051
1031
|
true // isSessionExpired
|
|
1052
1032
|
).then(state => {
|
|
1053
|
-
console.info('session timeout');
|
|
1054
1033
|
if (state?.sessionID) {
|
|
1055
1034
|
setTimeout(() => {
|
|
1056
1035
|
sendMessage(text, media, state?.sessionID);
|
|
@@ -1070,12 +1049,11 @@ const MemoriWidget = ({
|
|
|
1070
1049
|
},
|
|
1071
1050
|
]);
|
|
1072
1051
|
} else {
|
|
1073
|
-
console.warn('[SEND_MESSAGE]', response);
|
|
1074
1052
|
return Promise.reject(response);
|
|
1075
1053
|
}
|
|
1076
1054
|
} catch (error) {
|
|
1077
|
-
console.error('[EnterText] sendMessage: request failed', error);
|
|
1078
1055
|
gotError = true;
|
|
1056
|
+
logWidgetError('sendMessage failed', error);
|
|
1079
1057
|
|
|
1080
1058
|
setTypingText(undefined);
|
|
1081
1059
|
setMemoriTyping(false);
|
|
@@ -1092,12 +1070,6 @@ const MemoriWidget = ({
|
|
|
1092
1070
|
msg?: string,
|
|
1093
1071
|
avoidPushingMessage: boolean = false
|
|
1094
1072
|
) => {
|
|
1095
|
-
// console.log('[TRANSLATE] Starting translation with params:', {
|
|
1096
|
-
// state,
|
|
1097
|
-
// userLang,
|
|
1098
|
-
// msg
|
|
1099
|
-
// });
|
|
1100
|
-
|
|
1101
1073
|
const emission = state?.emission ?? currentDialogState?.emission;
|
|
1102
1074
|
|
|
1103
1075
|
let translatedState = { ...state };
|
|
@@ -1110,7 +1082,6 @@ const MemoriWidget = ({
|
|
|
1110
1082
|
!isMultilanguageEnabled ||
|
|
1111
1083
|
avoidPushingMessage
|
|
1112
1084
|
) {
|
|
1113
|
-
// console.log('[TRANSLATE] Skipping translation - using original emission');
|
|
1114
1085
|
translatedState = { ...state, emission };
|
|
1115
1086
|
if (emission) {
|
|
1116
1087
|
translatedMsg = {
|
|
@@ -1132,12 +1103,10 @@ const MemoriWidget = ({
|
|
|
1132
1103
|
}
|
|
1133
1104
|
} else {
|
|
1134
1105
|
try {
|
|
1135
|
-
// console.log('[TRANSLATE] Translating emission');
|
|
1136
1106
|
const t = await getTranslation(emission, userLang, language, baseUrl);
|
|
1137
1107
|
|
|
1138
1108
|
// Handle hints translation if present
|
|
1139
1109
|
if (state.hints && state.hints.length > 0) {
|
|
1140
|
-
// console.log('[TRANSLATE] Translating hints');
|
|
1141
1110
|
const translatedHints = await Promise.all(
|
|
1142
1111
|
(state.hints ?? []).map(async hint => {
|
|
1143
1112
|
const tHint = await getTranslation(
|
|
@@ -1169,7 +1138,6 @@ const MemoriWidget = ({
|
|
|
1169
1138
|
}
|
|
1170
1139
|
|
|
1171
1140
|
if (t.text.length > 0) {
|
|
1172
|
-
// console.log('[TRANSLATE] Creating translated message');
|
|
1173
1141
|
translatedMsg = {
|
|
1174
1142
|
text: emission,
|
|
1175
1143
|
translatedText: t.text,
|
|
@@ -1190,7 +1158,6 @@ const MemoriWidget = ({
|
|
|
1190
1158
|
};
|
|
1191
1159
|
}
|
|
1192
1160
|
} catch (error) {
|
|
1193
|
-
console.error('[TRANSLATE] Error during translation:', error);
|
|
1194
1161
|
translatedState = { ...state, emission };
|
|
1195
1162
|
translatedMsg = {
|
|
1196
1163
|
text: emission,
|
|
@@ -1211,10 +1178,8 @@ const MemoriWidget = ({
|
|
|
1211
1178
|
}
|
|
1212
1179
|
}
|
|
1213
1180
|
|
|
1214
|
-
// console.log('[TRANSLATE] Setting translated state and message');
|
|
1215
1181
|
setCurrentDialogState(translatedState);
|
|
1216
1182
|
if (!avoidPushingMessage && translatedMsg) {
|
|
1217
|
-
// console.log('[TRANSLATE] Pushing translated message', translatedMsg);
|
|
1218
1183
|
pushMessage(translatedMsg);
|
|
1219
1184
|
}
|
|
1220
1185
|
|
|
@@ -1320,7 +1285,6 @@ const MemoriWidget = ({
|
|
|
1320
1285
|
executableSnippets?.forEach(s => {
|
|
1321
1286
|
try {
|
|
1322
1287
|
setTimeout(() => {
|
|
1323
|
-
console.log('snippet', s);
|
|
1324
1288
|
// eslint-disable-next-line no-new-func
|
|
1325
1289
|
new Function(s.content ?? '')();
|
|
1326
1290
|
|
|
@@ -1334,8 +1298,8 @@ const MemoriWidget = ({
|
|
|
1334
1298
|
);
|
|
1335
1299
|
}, 400);
|
|
1336
1300
|
}, 1000);
|
|
1337
|
-
} catch
|
|
1338
|
-
|
|
1301
|
+
} catch {
|
|
1302
|
+
// ignore snippet execution errors
|
|
1339
1303
|
}
|
|
1340
1304
|
});
|
|
1341
1305
|
};
|
|
@@ -1411,8 +1375,8 @@ const MemoriWidget = ({
|
|
|
1411
1375
|
referral = (() => {
|
|
1412
1376
|
return window.location.href;
|
|
1413
1377
|
})();
|
|
1414
|
-
} catch
|
|
1415
|
-
|
|
1378
|
+
} catch {
|
|
1379
|
+
// ignore referral URL errors
|
|
1416
1380
|
}
|
|
1417
1381
|
|
|
1418
1382
|
// Initialize session with parameters
|
|
@@ -1464,7 +1428,6 @@ const MemoriWidget = ({
|
|
|
1464
1428
|
else if (
|
|
1465
1429
|
session?.resultMessage.startsWith('This Memori is aged restricted')
|
|
1466
1430
|
) {
|
|
1467
|
-
console.warn(session);
|
|
1468
1431
|
toast.error(t('underageTwinSession', { age: minAge }));
|
|
1469
1432
|
}
|
|
1470
1433
|
// Handle authentication error
|
|
@@ -1475,7 +1438,6 @@ const MemoriWidget = ({
|
|
|
1475
1438
|
}
|
|
1476
1439
|
// Handle other errors
|
|
1477
1440
|
else {
|
|
1478
|
-
console.warn(session);
|
|
1479
1441
|
toast.error(
|
|
1480
1442
|
tst => (
|
|
1481
1443
|
<div>
|
|
@@ -1497,7 +1459,7 @@ const MemoriWidget = ({
|
|
|
1497
1459
|
return session;
|
|
1498
1460
|
}
|
|
1499
1461
|
} catch (err) {
|
|
1500
|
-
|
|
1462
|
+
logWidgetError('fetchSession failed', err);
|
|
1501
1463
|
}
|
|
1502
1464
|
};
|
|
1503
1465
|
|
|
@@ -1536,12 +1498,10 @@ const MemoriWidget = ({
|
|
|
1536
1498
|
undefined
|
|
1537
1499
|
);
|
|
1538
1500
|
let userBirthDate = birthDate ?? storageBirthDate;
|
|
1539
|
-
// console.log('[REOPEN_SESSION] Using birth date:', userBirthDate);
|
|
1540
1501
|
|
|
1541
1502
|
try {
|
|
1542
1503
|
// Show age verification if required and birth date not provided
|
|
1543
1504
|
if (!userBirthDate && !!minAge) {
|
|
1544
|
-
// console.log('[REOPEN_SESSION] Age verification required, showing modal');
|
|
1545
1505
|
setShowAgeVerification(true);
|
|
1546
1506
|
return;
|
|
1547
1507
|
}
|
|
@@ -1555,7 +1515,6 @@ const MemoriWidget = ({
|
|
|
1555
1515
|
!recoveryTokens &&
|
|
1556
1516
|
!memoriTokens
|
|
1557
1517
|
) {
|
|
1558
|
-
// console.log('[REOPEN_SESSION] Authentication required, showing modal');
|
|
1559
1518
|
setAuthModalState('password');
|
|
1560
1519
|
return;
|
|
1561
1520
|
}
|
|
@@ -1571,13 +1530,11 @@ const MemoriWidget = ({
|
|
|
1571
1530
|
referral = (() => {
|
|
1572
1531
|
return window.location.href;
|
|
1573
1532
|
})();
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
console.debug('[REOPEN_SESSION] Error getting referral:', err);
|
|
1533
|
+
} catch {
|
|
1534
|
+
// ignore referral URL errors
|
|
1577
1535
|
}
|
|
1578
1536
|
|
|
1579
1537
|
// Initialize session with provided parameters
|
|
1580
|
-
// console.log('[REOPEN_SESSION] Initializing session...');
|
|
1581
1538
|
const { sessionID, currentState, ...response } = await initSession({
|
|
1582
1539
|
memoriID: memori.engineMemoriID ?? '',
|
|
1583
1540
|
password: password || memoriPwd || memori.secretToken,
|
|
@@ -1614,22 +1571,13 @@ const MemoriWidget = ({
|
|
|
1614
1571
|
|
|
1615
1572
|
// Handle successful session initialization
|
|
1616
1573
|
if (sessionID && currentState && response.resultCode === 0) {
|
|
1617
|
-
console.log(
|
|
1618
|
-
'[REOPEN_SESSION] Session initialized successfully:',
|
|
1619
|
-
sessionID
|
|
1620
|
-
);
|
|
1621
1574
|
setSessionId(sessionID);
|
|
1622
1575
|
|
|
1623
1576
|
// Update dialog state and history if requested
|
|
1624
1577
|
if (updateDialogState) {
|
|
1625
|
-
// console.log('[REOPEN_SESSION] Updating dialog state');
|
|
1626
1578
|
setCurrentDialogState(currentState);
|
|
1627
1579
|
|
|
1628
1580
|
if (currentState.emission) {
|
|
1629
|
-
console.log(
|
|
1630
|
-
'[REOPEN_SESSION] Processing emission:',
|
|
1631
|
-
currentState.emission
|
|
1632
|
-
);
|
|
1633
1581
|
// Determine initial status message based on context
|
|
1634
1582
|
// Show status message only if session expired and there's existing history
|
|
1635
1583
|
const initialStatus =
|
|
@@ -1690,7 +1638,6 @@ const MemoriWidget = ({
|
|
|
1690
1638
|
else if (
|
|
1691
1639
|
response?.resultMessage.startsWith('This Memori is aged restricted')
|
|
1692
1640
|
) {
|
|
1693
|
-
console.error('[REOPEN_SESSION] Age restriction error:', response);
|
|
1694
1641
|
toast.error(t('underageTwinSession', { age: minAge }));
|
|
1695
1642
|
}
|
|
1696
1643
|
// Handle authentication error
|
|
@@ -1698,17 +1645,15 @@ const MemoriWidget = ({
|
|
|
1698
1645
|
response?.resultCode === 403 &&
|
|
1699
1646
|
memori.privacyType !== 'PUBLIC'
|
|
1700
1647
|
) {
|
|
1701
|
-
console.error('[REOPEN_SESSION] Authentication error');
|
|
1702
1648
|
setMemoriPwd(undefined);
|
|
1703
1649
|
setAuthModalState('password');
|
|
1704
1650
|
}
|
|
1705
1651
|
// Handle other errors
|
|
1706
1652
|
else {
|
|
1707
|
-
console.error('[REOPEN_SESSION] Other error:', response);
|
|
1708
1653
|
toast.error(t(getErrori18nKey(response.resultCode)));
|
|
1709
1654
|
}
|
|
1710
1655
|
} catch (err) {
|
|
1711
|
-
|
|
1656
|
+
logWidgetError('reopenSession failed', err);
|
|
1712
1657
|
}
|
|
1713
1658
|
// Reset loading state
|
|
1714
1659
|
setLoading(false);
|
|
@@ -1723,7 +1668,6 @@ const MemoriWidget = ({
|
|
|
1723
1668
|
pin?: string
|
|
1724
1669
|
) => {
|
|
1725
1670
|
if (!memoriId || !sessionId) {
|
|
1726
|
-
console.error('CHANGETAG/Session not found');
|
|
1727
1671
|
return Promise.reject('Session not found');
|
|
1728
1672
|
}
|
|
1729
1673
|
|
|
@@ -1763,7 +1707,6 @@ const MemoriWidget = ({
|
|
|
1763
1707
|
};
|
|
1764
1708
|
}
|
|
1765
1709
|
} else if ([400, 401, 403, 404, 500].includes(resultCode)) {
|
|
1766
|
-
console.warn('[APPCONTEXT/CHANGETAG]', resultCode);
|
|
1767
1710
|
let storageBirthDate = getLocalConfig<string | undefined>(
|
|
1768
1711
|
'birthDate',
|
|
1769
1712
|
undefined
|
|
@@ -1774,8 +1717,8 @@ const MemoriWidget = ({
|
|
|
1774
1717
|
referral = (() => {
|
|
1775
1718
|
return window.location.href;
|
|
1776
1719
|
})();
|
|
1777
|
-
} catch
|
|
1778
|
-
|
|
1720
|
+
} catch {
|
|
1721
|
+
// ignore referral URL errors
|
|
1779
1722
|
}
|
|
1780
1723
|
|
|
1781
1724
|
fetchSession({
|
|
@@ -1817,7 +1760,6 @@ const MemoriWidget = ({
|
|
|
1817
1760
|
}
|
|
1818
1761
|
} catch (_e) {
|
|
1819
1762
|
let err = _e as Error;
|
|
1820
|
-
console.warn('[APPCONTEXT/CHANGETAG]', err);
|
|
1821
1763
|
return Promise.reject(err);
|
|
1822
1764
|
}
|
|
1823
1765
|
|
|
@@ -1857,8 +1799,6 @@ const MemoriWidget = ({
|
|
|
1857
1799
|
const [requestedListening, setRequestedListening] = useState(false);
|
|
1858
1800
|
const startListeningRef = useRef<(() => Promise<void>) | null>(null);
|
|
1859
1801
|
|
|
1860
|
-
// console.log('tenantID', tenantID);
|
|
1861
|
-
|
|
1862
1802
|
// Define TTS configuration
|
|
1863
1803
|
const ttsConfig = useMemo(
|
|
1864
1804
|
() => ({
|
|
@@ -1913,7 +1853,6 @@ const MemoriWidget = ({
|
|
|
1913
1853
|
'muteSpeaker',
|
|
1914
1854
|
!defaultEnableAudio
|
|
1915
1855
|
);
|
|
1916
|
-
console.log('[MemoriWidget] shouldPlayAudio', currentSpeakerMuted);
|
|
1917
1856
|
return (
|
|
1918
1857
|
text &&
|
|
1919
1858
|
text.trim() &&
|
|
@@ -1925,7 +1864,6 @@ const MemoriWidget = ({
|
|
|
1925
1864
|
|
|
1926
1865
|
// Create a single, centralized function to process and send messages
|
|
1927
1866
|
const processSpeechAndSendMessage = (text: string) => {
|
|
1928
|
-
// console.log('processSpeechAndSendMessage', text);
|
|
1929
1867
|
// Skip if already processing or no text
|
|
1930
1868
|
if (!text || text.trim().length === 0) {
|
|
1931
1869
|
return;
|
|
@@ -1934,17 +1872,15 @@ const MemoriWidget = ({
|
|
|
1934
1872
|
try {
|
|
1935
1873
|
// Process the text
|
|
1936
1874
|
const message = stripDuplicates(text);
|
|
1937
|
-
console.debug('Processing speech message:', message);
|
|
1938
1875
|
|
|
1939
1876
|
if (message.length > 0) {
|
|
1940
1877
|
setUserMessage('');
|
|
1941
1878
|
|
|
1942
1879
|
// Send the message
|
|
1943
|
-
console.debug('Sending message:', message);
|
|
1944
1880
|
sendMessage(message);
|
|
1945
1881
|
}
|
|
1946
|
-
} catch
|
|
1947
|
-
|
|
1882
|
+
} catch {
|
|
1883
|
+
// ignore speech processing errors
|
|
1948
1884
|
}
|
|
1949
1885
|
};
|
|
1950
1886
|
|
|
@@ -2027,8 +1963,7 @@ const MemoriWidget = ({
|
|
|
2027
1963
|
}
|
|
2028
1964
|
|
|
2029
1965
|
return translatedState;
|
|
2030
|
-
} catch
|
|
2031
|
-
console.error('Error in translateAndSpeak:', error);
|
|
1966
|
+
} catch {
|
|
2032
1967
|
// Still update activation state even if there's an error
|
|
2033
1968
|
if (!hasUserActivatedSpeak) {
|
|
2034
1969
|
setHasUserActivatedSpeak(true);
|
|
@@ -2047,12 +1982,6 @@ const MemoriWidget = ({
|
|
|
2047
1982
|
|
|
2048
1983
|
const processEnterTextDialogResponse = useCallback(
|
|
2049
1984
|
(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
1985
|
const {
|
|
2057
1986
|
msg,
|
|
2058
1987
|
typingText: pendingTypingText,
|
|
@@ -2062,10 +1991,6 @@ const MemoriWidget = ({
|
|
|
2062
1991
|
|
|
2063
1992
|
if (event.resultCode !== 0 || !currentState) {
|
|
2064
1993
|
if (event.resultCode === 500 && event.resultMessage) {
|
|
2065
|
-
console.warn('[EnterText] processDialogResponse: server error', {
|
|
2066
|
-
correlationID: event.correlationID,
|
|
2067
|
-
resultMessage: event.resultMessage,
|
|
2068
|
-
});
|
|
2069
1994
|
setHistory(h => [
|
|
2070
1995
|
...h,
|
|
2071
1996
|
{
|
|
@@ -2077,16 +2002,11 @@ const MemoriWidget = ({
|
|
|
2077
2002
|
date: new Date().toISOString(),
|
|
2078
2003
|
},
|
|
2079
2004
|
]);
|
|
2080
|
-
} else if (event.resultCode !== 0) {
|
|
2081
|
-
console.warn('[SEND_MESSAGE/NATS]', event);
|
|
2082
2005
|
}
|
|
2083
2006
|
return;
|
|
2084
2007
|
}
|
|
2085
2008
|
|
|
2086
2009
|
if (!msg) {
|
|
2087
|
-
console.debug(
|
|
2088
|
-
'[EnterText] processDialogResponse: no msg in pending, skipping'
|
|
2089
|
-
);
|
|
2090
2010
|
return;
|
|
2091
2011
|
}
|
|
2092
2012
|
|
|
@@ -2096,12 +2016,6 @@ const MemoriWidget = ({
|
|
|
2096
2016
|
? pendingTypingText
|
|
2097
2017
|
: currentState.emission ?? currentDialogState?.emission;
|
|
2098
2018
|
|
|
2099
|
-
console.debug('[EnterText] processDialogResponse: rendering emission', {
|
|
2100
|
-
correlationID: event.correlationID,
|
|
2101
|
-
emissionPreview: emission?.slice(0, 80),
|
|
2102
|
-
state: currentState.state,
|
|
2103
|
-
});
|
|
2104
|
-
|
|
2105
2019
|
if (
|
|
2106
2020
|
userLang.toLowerCase() !== language.toLowerCase() &&
|
|
2107
2021
|
emission &&
|
|
@@ -2158,9 +2072,6 @@ const MemoriWidget = ({
|
|
|
2158
2072
|
|
|
2159
2073
|
const clearEnterTextPending = useCallback(
|
|
2160
2074
|
(correlationID: string, pending: PendingEnterText) => {
|
|
2161
|
-
if (pending.natsTimeoutId) {
|
|
2162
|
-
clearTimeout(pending.natsTimeoutId);
|
|
2163
|
-
}
|
|
2164
2075
|
if (pending.waitForResponse?.timeoutId) {
|
|
2165
2076
|
clearTimeout(pending.waitForResponse.timeoutId);
|
|
2166
2077
|
}
|
|
@@ -2178,12 +2089,6 @@ const MemoriWidget = ({
|
|
|
2178
2089
|
? `Error: ${event.errorCode}`
|
|
2179
2090
|
: 'Error: An unexpected error occurred';
|
|
2180
2091
|
|
|
2181
|
-
console.error('[EnterText] NATS error event', {
|
|
2182
|
-
correlationID,
|
|
2183
|
-
errorCode: event.errorCode,
|
|
2184
|
-
errorMessage: event.errorMessage,
|
|
2185
|
-
});
|
|
2186
|
-
|
|
2187
2092
|
pushMessage({
|
|
2188
2093
|
text: errorText,
|
|
2189
2094
|
emitter: 'system',
|
|
@@ -2213,19 +2118,6 @@ const MemoriWidget = ({
|
|
|
2213
2118
|
(correlationID: string, event: NatsDialogResponseEvent) => {
|
|
2214
2119
|
const pending = pendingEnterTextRef.current.get(correlationID);
|
|
2215
2120
|
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
2121
|
bufferedNatsResponsesRef.current.set(correlationID, event);
|
|
2230
2122
|
return;
|
|
2231
2123
|
}
|
|
@@ -2233,10 +2125,6 @@ const MemoriWidget = ({
|
|
|
2233
2125
|
clearEnterTextPending(correlationID, pending);
|
|
2234
2126
|
|
|
2235
2127
|
if (pending.waitForResponse) {
|
|
2236
|
-
console.info('[EnterText] NATS response delivered to waiter', {
|
|
2237
|
-
correlationID,
|
|
2238
|
-
resultCode: event.resultCode,
|
|
2239
|
-
});
|
|
2240
2128
|
pending.waitForResponse.resolve(event);
|
|
2241
2129
|
setMemoriTyping(false);
|
|
2242
2130
|
setTypingText(undefined);
|
|
@@ -2246,13 +2134,8 @@ const MemoriWidget = ({
|
|
|
2246
2134
|
processEnterTextDialogResponse(event, pending);
|
|
2247
2135
|
|
|
2248
2136
|
if (!pending.hasBatchQueued) {
|
|
2249
|
-
console.info('[EnterText] typing indicator cleared', { correlationID });
|
|
2250
2137
|
setMemoriTyping(false);
|
|
2251
2138
|
setTypingText(undefined);
|
|
2252
|
-
} else {
|
|
2253
|
-
console.debug('[EnterText] typing kept (batch queued)', {
|
|
2254
|
-
correlationID,
|
|
2255
|
-
});
|
|
2256
2139
|
}
|
|
2257
2140
|
},
|
|
2258
2141
|
[processEnterTextDialogResponse, clearEnterTextPending]
|
|
@@ -2262,61 +2145,26 @@ const MemoriWidget = ({
|
|
|
2262
2145
|
(correlationID: string, pending: PendingEnterText) => {
|
|
2263
2146
|
const buffered = bufferedNatsResponsesRef.current.get(correlationID);
|
|
2264
2147
|
if (buffered) {
|
|
2265
|
-
console.info('[EnterText] replaying buffered NATS response', {
|
|
2266
|
-
correlationID,
|
|
2267
|
-
waitForResponse: !!pending.waitForResponse,
|
|
2268
|
-
});
|
|
2269
2148
|
bufferedNatsResponsesRef.current.delete(correlationID);
|
|
2270
2149
|
pendingEnterTextRef.current.set(correlationID, pending);
|
|
2271
2150
|
deliverEnterTextNatsResponse(correlationID, buffered);
|
|
2272
2151
|
return;
|
|
2273
2152
|
}
|
|
2274
2153
|
|
|
2275
|
-
if (!pending.waitForResponse && !pending.natsTimeoutId) {
|
|
2276
|
-
pending.natsTimeoutId = setTimeout(() => {
|
|
2277
|
-
const current = pendingEnterTextRef.current.get(correlationID);
|
|
2278
|
-
if (!current) return;
|
|
2279
|
-
clearEnterTextPending(correlationID, current);
|
|
2280
|
-
console.error('[EnterText] NATS response timeout', {
|
|
2281
|
-
correlationID,
|
|
2282
|
-
timeoutMs: ENTER_TEXT_NATS_TIMEOUT_MS,
|
|
2283
|
-
});
|
|
2284
|
-
if (!current.hasBatchQueued) {
|
|
2285
|
-
setMemoriTyping(false);
|
|
2286
|
-
setTypingText(undefined);
|
|
2287
|
-
}
|
|
2288
|
-
current.waitForResponse?.reject(
|
|
2289
|
-
new Error('NATS enter-text response timeout')
|
|
2290
|
-
);
|
|
2291
|
-
}, ENTER_TEXT_NATS_TIMEOUT_MS);
|
|
2292
|
-
}
|
|
2293
|
-
|
|
2294
|
-
console.debug('[EnterText] pending registered', {
|
|
2295
|
-
correlationID,
|
|
2296
|
-
waitForResponse: !!pending.waitForResponse,
|
|
2297
|
-
hasBatchQueued: pending.hasBatchQueued,
|
|
2298
|
-
});
|
|
2299
2154
|
pendingEnterTextRef.current.set(correlationID, pending);
|
|
2300
2155
|
},
|
|
2301
|
-
[deliverEnterTextNatsResponse
|
|
2156
|
+
[deliverEnterTextNatsResponse]
|
|
2302
2157
|
);
|
|
2303
2158
|
|
|
2304
2159
|
const waitForEnterTextNatsResponse = useCallback(
|
|
2305
2160
|
(correlationID: string, timeoutMs = 120000) =>
|
|
2306
2161
|
new Promise<NatsDialogResponseEvent>((resolve, reject) => {
|
|
2307
|
-
console.debug('[EnterText] waiting for NATS response', {
|
|
2308
|
-
correlationID,
|
|
2309
|
-
timeoutMs,
|
|
2310
|
-
});
|
|
2311
2162
|
const timeoutId = setTimeout(() => {
|
|
2312
2163
|
const current = pendingEnterTextRef.current.get(correlationID);
|
|
2313
2164
|
if (current) {
|
|
2314
2165
|
clearEnterTextPending(correlationID, current);
|
|
2315
2166
|
}
|
|
2316
|
-
|
|
2317
|
-
correlationID,
|
|
2318
|
-
timeoutMs,
|
|
2319
|
-
});
|
|
2167
|
+
logWidgetError('NATS timeout', { correlationID, timeoutMs });
|
|
2320
2168
|
reject(new Error('NATS enter-text response timeout'));
|
|
2321
2169
|
}, timeoutMs);
|
|
2322
2170
|
|
|
@@ -2342,12 +2190,6 @@ const MemoriWidget = ({
|
|
|
2342
2190
|
baseUrl,
|
|
2343
2191
|
sessionId,
|
|
2344
2192
|
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
2193
|
if (event.message) {
|
|
2352
2194
|
setTypingText(event.message);
|
|
2353
2195
|
}
|
|
@@ -2355,19 +2197,8 @@ const MemoriWidget = ({
|
|
|
2355
2197
|
onDialogResponse: useCallback(
|
|
2356
2198
|
(event: NatsDialogResponseEvent) => {
|
|
2357
2199
|
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
2200
|
if (!correlationID) {
|
|
2367
|
-
|
|
2368
|
-
'[EnterText] dialog_text_entered_response without correlationID',
|
|
2369
|
-
event
|
|
2370
|
-
);
|
|
2201
|
+
logWidgetError('NATS dialog response missing correlationID', event);
|
|
2371
2202
|
setMemoriTyping(false);
|
|
2372
2203
|
setTypingText(undefined);
|
|
2373
2204
|
return;
|
|
@@ -2408,8 +2239,8 @@ const MemoriWidget = ({
|
|
|
2408
2239
|
setClickedStart(false);
|
|
2409
2240
|
timeoutRef.current = undefined;
|
|
2410
2241
|
ttsStop();
|
|
2411
|
-
} catch
|
|
2412
|
-
//
|
|
2242
|
+
} catch {
|
|
2243
|
+
// ignore reset errors
|
|
2413
2244
|
}
|
|
2414
2245
|
};
|
|
2415
2246
|
useEffect(() => {
|
|
@@ -2673,12 +2504,6 @@ const MemoriWidget = ({
|
|
|
2673
2504
|
chatLog?: ChatLog,
|
|
2674
2505
|
targetSessionID?: string
|
|
2675
2506
|
) => {
|
|
2676
|
-
// console.log('[onClickStart] Starting with params:', {
|
|
2677
|
-
// session,
|
|
2678
|
-
// initialSessionExpired,
|
|
2679
|
-
// chatLog
|
|
2680
|
-
// });
|
|
2681
|
-
|
|
2682
2507
|
const sessionID = chatLog ? undefined : session?.sessionID || sessionId;
|
|
2683
2508
|
const dialogState = chatLog
|
|
2684
2509
|
? undefined
|
|
@@ -2829,8 +2654,8 @@ const MemoriWidget = ({
|
|
|
2829
2654
|
};
|
|
2830
2655
|
})
|
|
2831
2656
|
);
|
|
2832
|
-
} catch
|
|
2833
|
-
|
|
2657
|
+
} catch {
|
|
2658
|
+
// ignore translation errors
|
|
2834
2659
|
}
|
|
2835
2660
|
}
|
|
2836
2661
|
|
|
@@ -2897,8 +2722,7 @@ const MemoriWidget = ({
|
|
|
2897
2722
|
} else {
|
|
2898
2723
|
throw new Error('No session');
|
|
2899
2724
|
}
|
|
2900
|
-
} catch
|
|
2901
|
-
console.error('[onClickStart] Error changing tag:', e);
|
|
2725
|
+
} catch {
|
|
2902
2726
|
reopenSession(
|
|
2903
2727
|
true,
|
|
2904
2728
|
memori?.secretToken,
|
|
@@ -3010,14 +2834,14 @@ const MemoriWidget = ({
|
|
|
3010
2834
|
).text,
|
|
3011
2835
|
}))
|
|
3012
2836
|
);
|
|
3013
|
-
} catch
|
|
3014
|
-
|
|
2837
|
+
} catch {
|
|
2838
|
+
// ignore translation errors
|
|
3015
2839
|
}
|
|
3016
2840
|
}
|
|
3017
2841
|
|
|
3018
2842
|
setHistory(translatedMessages);
|
|
3019
|
-
} catch
|
|
3020
|
-
|
|
2843
|
+
} catch {
|
|
2844
|
+
// ignore chat log retrieval errors
|
|
3021
2845
|
}
|
|
3022
2846
|
|
|
3023
2847
|
if (
|
|
@@ -3036,19 +2860,12 @@ const MemoriWidget = ({
|
|
|
3036
2860
|
!!translatedMessages?.length
|
|
3037
2861
|
);
|
|
3038
2862
|
} else {
|
|
3039
|
-
console.log('[onClickStart] Starting with initial question');
|
|
3040
2863
|
// remove default initial message
|
|
3041
2864
|
translatedMessages = [];
|
|
3042
2865
|
setHistory([]);
|
|
3043
2866
|
|
|
3044
2867
|
// we have no chat history, we start by initial question
|
|
3045
2868
|
const placeSpec = getPlaceSpecForEnterText(position);
|
|
3046
|
-
console.debug(
|
|
3047
|
-
'[EnterText] onClickStart: posting initial question',
|
|
3048
|
-
{
|
|
3049
|
-
sessionId: sessionID,
|
|
3050
|
-
}
|
|
3051
|
-
);
|
|
3052
2869
|
const response = await postEnterTextAsync({
|
|
3053
2870
|
sessionId: sessionID!,
|
|
3054
2871
|
text: initialQuestion,
|
|
@@ -3057,11 +2874,6 @@ const MemoriWidget = ({
|
|
|
3057
2874
|
}),
|
|
3058
2875
|
...(placeSpec !== undefined && { place: placeSpec }),
|
|
3059
2876
|
});
|
|
3060
|
-
console.debug('[EnterText] onClickStart: HTTP response', {
|
|
3061
|
-
resultCode: response.resultCode,
|
|
3062
|
-
correlationID: readCorrelationID(response),
|
|
3063
|
-
});
|
|
3064
|
-
|
|
3065
2877
|
// Handle 500 error from EnterTextAsync
|
|
3066
2878
|
if (response.resultCode === 500 && response.resultMessage) {
|
|
3067
2879
|
setHistory(h => [
|
|
@@ -3080,24 +2892,11 @@ const MemoriWidget = ({
|
|
|
3080
2892
|
|
|
3081
2893
|
const onClickStartCorrelationID = readCorrelationID(response);
|
|
3082
2894
|
if (response.resultCode === 0 && onClickStartCorrelationID) {
|
|
3083
|
-
console.info(
|
|
3084
|
-
'[EnterText] onClickStart: accepted, showing typing indicator',
|
|
3085
|
-
{
|
|
3086
|
-
correlationID: onClickStartCorrelationID,
|
|
3087
|
-
}
|
|
3088
|
-
);
|
|
3089
2895
|
setMemoriTyping(true);
|
|
3090
2896
|
try {
|
|
3091
2897
|
const natsEvent = await waitForEnterTextNatsResponse(
|
|
3092
2898
|
onClickStartCorrelationID
|
|
3093
2899
|
);
|
|
3094
|
-
console.info(
|
|
3095
|
-
'[EnterText] onClickStart: NATS response received',
|
|
3096
|
-
{
|
|
3097
|
-
correlationID: onClickStartCorrelationID,
|
|
3098
|
-
resultCode: natsEvent.resultCode,
|
|
3099
|
-
}
|
|
3100
|
-
);
|
|
3101
2900
|
if (natsEvent.resultCode === 0 && natsEvent.currentState) {
|
|
3102
2901
|
await translateAndSpeak(
|
|
3103
2902
|
natsEvent.currentState,
|
|
@@ -3107,16 +2906,13 @@ const MemoriWidget = ({
|
|
|
3107
2906
|
);
|
|
3108
2907
|
setClickedStart(false);
|
|
3109
2908
|
}
|
|
3110
|
-
} catch (
|
|
3111
|
-
|
|
2909
|
+
} catch (err) {
|
|
2910
|
+
logWidgetError('onClickStart NATS wait failed', err);
|
|
3112
2911
|
setMemoriTyping(false);
|
|
3113
2912
|
setTypingText(undefined);
|
|
3114
2913
|
}
|
|
3115
2914
|
} else if (response.resultCode === 0) {
|
|
3116
|
-
|
|
3117
|
-
'[EnterText] onClickStart: HTTP 200 but missing correlationID',
|
|
3118
|
-
response
|
|
3119
|
-
);
|
|
2915
|
+
logWidgetError('onClickStart enter-text missing correlationID', response);
|
|
3120
2916
|
}
|
|
3121
2917
|
}
|
|
3122
2918
|
}
|
|
@@ -3201,11 +2997,9 @@ const MemoriWidget = ({
|
|
|
3201
2997
|
|
|
3202
2998
|
if (resp.resultCode === 0) {
|
|
3203
2999
|
setExperts(experts);
|
|
3204
|
-
} else {
|
|
3205
|
-
console.warn('Error fetching experts', resp);
|
|
3206
3000
|
}
|
|
3207
|
-
} catch
|
|
3208
|
-
|
|
3001
|
+
} catch {
|
|
3002
|
+
// ignore expert fetch errors
|
|
3209
3003
|
}
|
|
3210
3004
|
}, [sessionId, memori?.enableBoardOfExperts]);
|
|
3211
3005
|
useEffect(() => {
|
|
@@ -3234,7 +3028,6 @@ const MemoriWidget = ({
|
|
|
3234
3028
|
// Without either owner identifier we cannot call the API, so we fail closed
|
|
3235
3029
|
// instead of silently letting the session start unverified.
|
|
3236
3030
|
if (!ownerUserID && !ownerUserName) {
|
|
3237
|
-
console.warn('Cannot verify credits: missing owner identifier');
|
|
3238
3031
|
if (options?.notify) {
|
|
3239
3032
|
handleNotEnoughCredits();
|
|
3240
3033
|
} else {
|
|
@@ -3258,7 +3051,6 @@ const MemoriWidget = ({
|
|
|
3258
3051
|
setHasEnoughCredits(true);
|
|
3259
3052
|
return true;
|
|
3260
3053
|
} else {
|
|
3261
|
-
console.warn('Not enough credits. Required:', resp.required);
|
|
3262
3054
|
if (options?.notify) {
|
|
3263
3055
|
handleNotEnoughCredits();
|
|
3264
3056
|
} else {
|
|
@@ -3266,9 +3058,8 @@ const MemoriWidget = ({
|
|
|
3266
3058
|
}
|
|
3267
3059
|
return false;
|
|
3268
3060
|
}
|
|
3269
|
-
} catch (
|
|
3270
|
-
|
|
3271
|
-
console.debug(err);
|
|
3061
|
+
} catch (err) {
|
|
3062
|
+
logWidgetError('checkCredits failed', err);
|
|
3272
3063
|
return true;
|
|
3273
3064
|
}
|
|
3274
3065
|
},
|