@memori.ai/memori-react 7.0.5 → 7.0.6
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 +8 -0
- package/README.md +1 -0
- package/dist/components/MemoriWidget/MemoriWidget.d.ts +2 -1
- package/dist/components/MemoriWidget/MemoriWidget.js +124 -103
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/esm/components/MemoriWidget/MemoriWidget.d.ts +2 -1
- package/esm/components/MemoriWidget/MemoriWidget.js +124 -103
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +3 -2
- package/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/MemoriWidget/MemoriWidget.tsx +152 -127
- package/src/index.stories.tsx +14 -0
- package/src/index.tsx +4 -0
|
@@ -150,7 +150,7 @@ let memoriPassword;
|
|
|
150
150
|
let speakerMuted = false;
|
|
151
151
|
let memoriSpeaking = false;
|
|
152
152
|
let userToken;
|
|
153
|
-
const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenantID, memoriLang, multilingual, integration, layout = 'DEFAULT', customLayout, showInstruct = false, showShare, preview = false, embed = false, showInputs = true, showDates = false, showContextPerLine = false, showSettings = true, showTypingText = false, showClear = false, showLogin = false, showOnlyLastMessages, height = '100vh', secret, baseUrl = 'https://aisuru.com', apiUrl = 'https://backend.memori.ai', initialContextVars, initialQuestion, ogImage, sessionID: initialSessionID, tenant, personification, authToken, AZURE_COGNITIVE_SERVICES_TTS_KEY, defaultSpeakerActive = true, onStateChange, additionalInfo, additionalSettings, customMediaRenderer, userAvatar, }) => {
|
|
153
|
+
const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenantID, memoriLang, multilingual, integration, layout = 'DEFAULT', customLayout, showInstruct = false, showShare, preview = false, embed = false, showInputs = true, showDates = false, showContextPerLine = false, showSettings = true, showTypingText = false, showClear = false, showLogin = false, showOnlyLastMessages, height = '100vh', secret, baseUrl = 'https://aisuru.com', apiUrl = 'https://backend.memori.ai', initialContextVars, initialQuestion, ogImage, sessionID: initialSessionID, tenant, personification, authToken, AZURE_COGNITIVE_SERVICES_TTS_KEY, defaultSpeakerActive = true, disableTextEnteredEvents = false, onStateChange, additionalInfo, additionalSettings, customMediaRenderer, userAvatar, }) => {
|
|
154
154
|
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _t, _u, _v, _w, _x, _y, _z, _0, _1;
|
|
155
155
|
const { t, i18n } = useTranslation();
|
|
156
156
|
const [isClient, setIsClient] = useState(false);
|
|
@@ -323,56 +323,23 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
323
323
|
setTypingText(typingText);
|
|
324
324
|
let msg = text;
|
|
325
325
|
let gotError = false;
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const { currentState, ...response } = await postTextEnteredEvent({
|
|
334
|
-
sessionId: sessionID,
|
|
335
|
-
text: msg,
|
|
336
|
-
});
|
|
337
|
-
if (response.resultCode === 0 && currentState) {
|
|
338
|
-
const emission = useLoaderTextAsMsg && typingText
|
|
339
|
-
? typingText
|
|
340
|
-
: (_b = currentState.emission) !== null && _b !== void 0 ? _b : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
|
|
341
|
-
if (currentState.state === 'X4' && memori.giverTag) {
|
|
342
|
-
const { currentState, ...resp } = await postTagChangedEvent(sessionID, memori.giverTag);
|
|
343
|
-
if (resp.resultCode === 0) {
|
|
344
|
-
setCurrentDialogState(currentState);
|
|
345
|
-
if (emission) {
|
|
346
|
-
pushMessage({
|
|
347
|
-
text: emission,
|
|
348
|
-
emitter: currentState.emitter,
|
|
349
|
-
media: currentState.media,
|
|
350
|
-
fromUser: false,
|
|
351
|
-
questionAnswered: msg,
|
|
352
|
-
contextVars: currentState.contextVars,
|
|
353
|
-
date: currentState.currentDate,
|
|
354
|
-
placeName: currentState.currentPlaceName,
|
|
355
|
-
placeLatitude: currentState.currentLatitude,
|
|
356
|
-
placeLongitude: currentState.currentLongitude,
|
|
357
|
-
placeUncertaintyKm: currentState.currentUncertaintyKm,
|
|
358
|
-
tag: currentState.currentTag,
|
|
359
|
-
memoryTags: currentState.memoryTags,
|
|
360
|
-
});
|
|
361
|
-
speak(emission);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
console.error(response, resp);
|
|
366
|
-
toast.error(t(getErrori18nKey(resp.resultCode)));
|
|
367
|
-
gotError = true;
|
|
368
|
-
}
|
|
326
|
+
try {
|
|
327
|
+
if (translate &&
|
|
328
|
+
!instruct &&
|
|
329
|
+
isMultilanguageEnabled &&
|
|
330
|
+
userLang.toUpperCase() !== language.toUpperCase()) {
|
|
331
|
+
const translation = await getTranslation(text, language, userLang, baseUrl);
|
|
332
|
+
msg = translation.text;
|
|
369
333
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
334
|
+
const { currentState, ...response } = await postTextEnteredEvent({
|
|
335
|
+
sessionId: sessionID,
|
|
336
|
+
text: msg,
|
|
337
|
+
});
|
|
338
|
+
if (response.resultCode === 0 && currentState) {
|
|
339
|
+
const emission = useLoaderTextAsMsg && typingText
|
|
340
|
+
? typingText
|
|
341
|
+
: (_b = currentState.emission) !== null && _b !== void 0 ? _b : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
|
|
342
|
+
if (currentState.state === 'X4' && memori.giverTag) {
|
|
376
343
|
const { currentState, ...resp } = await postTagChangedEvent(sessionID, memori.giverTag);
|
|
377
344
|
if (resp.resultCode === 0) {
|
|
378
345
|
setCurrentDialogState(currentState);
|
|
@@ -401,62 +368,103 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
401
368
|
gotError = true;
|
|
402
369
|
}
|
|
403
370
|
}
|
|
371
|
+
else if (currentState.state === 'X2d' && memori.giverTag) {
|
|
372
|
+
const { currentState, ...resp } = await postTextEnteredEvent({
|
|
373
|
+
sessionId: sessionID,
|
|
374
|
+
text: Math.random().toString().substring(2, 8),
|
|
375
|
+
});
|
|
376
|
+
if (resp.resultCode === 0) {
|
|
377
|
+
const { currentState, ...resp } = await postTagChangedEvent(sessionID, memori.giverTag);
|
|
378
|
+
if (resp.resultCode === 0) {
|
|
379
|
+
setCurrentDialogState(currentState);
|
|
380
|
+
if (emission) {
|
|
381
|
+
pushMessage({
|
|
382
|
+
text: emission,
|
|
383
|
+
emitter: currentState.emitter,
|
|
384
|
+
media: currentState.media,
|
|
385
|
+
fromUser: false,
|
|
386
|
+
questionAnswered: msg,
|
|
387
|
+
contextVars: currentState.contextVars,
|
|
388
|
+
date: currentState.currentDate,
|
|
389
|
+
placeName: currentState.currentPlaceName,
|
|
390
|
+
placeLatitude: currentState.currentLatitude,
|
|
391
|
+
placeLongitude: currentState.currentLongitude,
|
|
392
|
+
placeUncertaintyKm: currentState.currentUncertaintyKm,
|
|
393
|
+
tag: currentState.currentTag,
|
|
394
|
+
memoryTags: currentState.memoryTags,
|
|
395
|
+
});
|
|
396
|
+
speak(emission);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
console.error(response, resp);
|
|
401
|
+
toast.error(t(getErrori18nKey(resp.resultCode)));
|
|
402
|
+
gotError = true;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
console.error(response, resp);
|
|
407
|
+
toast.error(t(getErrori18nKey(resp.resultCode)));
|
|
408
|
+
gotError = true;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
else if (userLang.toLowerCase() !== language.toLowerCase() &&
|
|
412
|
+
emission &&
|
|
413
|
+
!instruct &&
|
|
414
|
+
isMultilanguageEnabled) {
|
|
415
|
+
translateDialogState(currentState, userLang, msg).then(ts => {
|
|
416
|
+
if (ts.emission) {
|
|
417
|
+
speak(ts.emission);
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
}
|
|
404
421
|
else {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
422
|
+
setCurrentDialogState({
|
|
423
|
+
...currentState,
|
|
424
|
+
emission,
|
|
425
|
+
});
|
|
426
|
+
if (emission) {
|
|
427
|
+
pushMessage({
|
|
428
|
+
text: emission,
|
|
429
|
+
emitter: currentState.emitter,
|
|
430
|
+
media: currentState.media,
|
|
431
|
+
fromUser: false,
|
|
432
|
+
questionAnswered: msg,
|
|
433
|
+
generatedByAI: !!currentState.completion,
|
|
434
|
+
contextVars: currentState.contextVars,
|
|
435
|
+
date: currentState.currentDate,
|
|
436
|
+
placeName: currentState.currentPlaceName,
|
|
437
|
+
placeLatitude: currentState.currentLatitude,
|
|
438
|
+
placeLongitude: currentState.currentLongitude,
|
|
439
|
+
placeUncertaintyKm: currentState.currentUncertaintyKm,
|
|
440
|
+
tag: currentState.currentTag,
|
|
441
|
+
memoryTags: currentState.memoryTags,
|
|
442
|
+
});
|
|
443
|
+
speak(emission);
|
|
444
|
+
}
|
|
408
445
|
}
|
|
409
446
|
}
|
|
410
|
-
else if (
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
447
|
+
else if (response.resultCode === 404) {
|
|
448
|
+
setHistory(h => [...h.slice(0, h.length - 1)]);
|
|
449
|
+
reopenSession(false, memoriPwd || memori.secretToken, memoriTokens, instruct && memori.giverTag ? memori.giverTag : undefined, instruct && memori.giverPIN ? memori.giverPIN : undefined, {
|
|
450
|
+
PATHNAME: window.location.pathname,
|
|
451
|
+
ROUTE: ((_d = (_c = window.location.pathname) === null || _c === void 0 ? void 0 : _c.split('/')) === null || _d === void 0 ? void 0 : _d.pop()) || '',
|
|
452
|
+
...(initialContextVars || {}),
|
|
453
|
+
}, initialQuestion).then(state => {
|
|
454
|
+
console.info('session timeout');
|
|
455
|
+
if (state === null || state === void 0 ? void 0 : state.sessionID) {
|
|
456
|
+
setTimeout(() => {
|
|
457
|
+
sendMessage(text, media, state === null || state === void 0 ? void 0 : state.sessionID);
|
|
458
|
+
}, 500);
|
|
417
459
|
}
|
|
418
460
|
});
|
|
419
461
|
}
|
|
420
|
-
else {
|
|
421
|
-
setCurrentDialogState({
|
|
422
|
-
...currentState,
|
|
423
|
-
emission,
|
|
424
|
-
});
|
|
425
|
-
if (emission) {
|
|
426
|
-
pushMessage({
|
|
427
|
-
text: emission,
|
|
428
|
-
emitter: currentState.emitter,
|
|
429
|
-
media: currentState.media,
|
|
430
|
-
fromUser: false,
|
|
431
|
-
questionAnswered: msg,
|
|
432
|
-
generatedByAI: !!currentState.completion,
|
|
433
|
-
contextVars: currentState.contextVars,
|
|
434
|
-
date: currentState.currentDate,
|
|
435
|
-
placeName: currentState.currentPlaceName,
|
|
436
|
-
placeLatitude: currentState.currentLatitude,
|
|
437
|
-
placeLongitude: currentState.currentLongitude,
|
|
438
|
-
placeUncertaintyKm: currentState.currentUncertaintyKm,
|
|
439
|
-
tag: currentState.currentTag,
|
|
440
|
-
memoryTags: currentState.memoryTags,
|
|
441
|
-
});
|
|
442
|
-
speak(emission);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
462
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
...(initialContextVars || {}),
|
|
452
|
-
}, initialQuestion).then(state => {
|
|
453
|
-
console.info('session timeout');
|
|
454
|
-
if (state === null || state === void 0 ? void 0 : state.sessionID) {
|
|
455
|
-
setTimeout(() => {
|
|
456
|
-
sendMessage(text, media, state === null || state === void 0 ? void 0 : state.sessionID);
|
|
457
|
-
}, 500);
|
|
458
|
-
}
|
|
459
|
-
});
|
|
463
|
+
catch (error) {
|
|
464
|
+
console.error(error);
|
|
465
|
+
gotError = true;
|
|
466
|
+
setTypingText(undefined);
|
|
467
|
+
setMemoriTyping(false);
|
|
460
468
|
}
|
|
461
469
|
if (!hasBatchQueued) {
|
|
462
470
|
setTypingText(undefined);
|
|
@@ -1704,6 +1712,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1704
1712
|
sendMessage(text, undefined, undefined, false, translatedText);
|
|
1705
1713
|
};
|
|
1706
1714
|
const memoriTextEnteredHandler = useCallback((e) => {
|
|
1715
|
+
if (disableTextEnteredEvents)
|
|
1716
|
+
return;
|
|
1707
1717
|
const { text, waitForPrevious, hidden, typingText, useLoaderTextAsMsg, hasBatchQueued, } = e.detail;
|
|
1708
1718
|
if (text) {
|
|
1709
1719
|
if (waitForPrevious &&
|
|
@@ -1719,13 +1729,24 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1719
1729
|
sendMessage(text, undefined, undefined, undefined, undefined, hidden, typingText, useLoaderTextAsMsg, hasBatchQueued);
|
|
1720
1730
|
}
|
|
1721
1731
|
}
|
|
1722
|
-
}, [
|
|
1732
|
+
}, [
|
|
1733
|
+
sessionId,
|
|
1734
|
+
isPlayingAudio,
|
|
1735
|
+
memoriTyping,
|
|
1736
|
+
userLang,
|
|
1737
|
+
disableTextEnteredEvents,
|
|
1738
|
+
]);
|
|
1723
1739
|
useEffect(() => {
|
|
1724
|
-
|
|
1740
|
+
if (disableTextEnteredEvents) {
|
|
1741
|
+
document.addEventListener('MemoriTextEntered', memoriTextEnteredHandler);
|
|
1742
|
+
}
|
|
1743
|
+
else {
|
|
1744
|
+
document.removeEventListener('MemoriTextEntered', memoriTextEnteredHandler);
|
|
1745
|
+
}
|
|
1725
1746
|
return () => {
|
|
1726
1747
|
document.removeEventListener('MemoriTextEntered', memoriTextEnteredHandler);
|
|
1727
1748
|
};
|
|
1728
|
-
}, [sessionId, userLang]);
|
|
1749
|
+
}, [sessionId, userLang, disableTextEnteredEvents]);
|
|
1729
1750
|
const onClickStart = useCallback(async (session) => {
|
|
1730
1751
|
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _t, _u, _v;
|
|
1731
1752
|
const sessionID = (session === null || session === void 0 ? void 0 : session.sessionID) || sessionId;
|
|
@@ -2104,7 +2125,7 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
2104
2125
|
onClickStart: onClickStart,
|
|
2105
2126
|
initializeTTS: initializeTTS,
|
|
2106
2127
|
isUserLoggedIn: !!loginToken && !!(user === null || user === void 0 ? void 0 : user.userID),
|
|
2107
|
-
notEnoughCredits:
|
|
2128
|
+
notEnoughCredits: false,
|
|
2108
2129
|
showLogin,
|
|
2109
2130
|
setShowLoginDrawer,
|
|
2110
2131
|
user,
|