@memori.ai/memori-react 7.0.5 → 7.0.7
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 +15 -0
- package/README.md +1 -0
- package/dist/components/MemoriWidget/MemoriWidget.d.ts +2 -1
- package/dist/components/MemoriWidget/MemoriWidget.js +123 -102
- 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 +123 -102
- 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 +151 -126
- package/src/index.stories.tsx +14 -0
- package/src/index.tsx +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [7.0.7](https://github.com/memori-ai/memori-react/compare/v7.0.6...v7.0.7) (2024-07-12)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* typos ([6d62495](https://github.com/memori-ai/memori-react/commit/6d62495fe575942c10588ad0113d99d5836af6bd))
|
|
9
|
+
|
|
10
|
+
## [7.0.6](https://github.com/memori-ai/memori-react/compare/v7.0.5...v7.0.6) (2024-07-12)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Maintenance
|
|
14
|
+
|
|
15
|
+
* add new prop disableTextEnteredEvents to disable listeners ([b4ab8b7](https://github.com/memori-ai/memori-react/commit/b4ab8b7c88d9d79bc19a6bc64694f30bbea0c2e4))
|
|
16
|
+
* add try catch on message sending, stopping loading on error ([079bd15](https://github.com/memori-ai/memori-react/commit/079bd1504354c40cadf18c6620d9f2db49d0e72a))
|
|
17
|
+
|
|
3
18
|
## [7.0.5](https://github.com/memori-ai/memori-react/compare/v7.0.4...v7.0.5) (2024-07-11)
|
|
4
19
|
|
|
5
20
|
|
package/README.md
CHANGED
|
@@ -84,6 +84,7 @@ const App = () => (
|
|
|
84
84
|
| `spokenLang` | | `string` | | Language of the spoken text, as defaults to user selection. Example: "en" or "it" |
|
|
85
85
|
| `onStateChange` | | `function` | | Callback function called when the state of the Memori changes |
|
|
86
86
|
| `defaultSpeakerActive` | | `boolean` | `true` | Default value for the speaker activation |
|
|
87
|
+
| `disableTextEnteredEvents` | | `boolean` | `false` | Disable MemoriTextEntered events listeners for `typeMessage` functions, useful to avoid issues with multiple widgets in page. |
|
|
87
88
|
| `AZURE_COGNITIVE_SERVICES_TTS_KEY` | | `string` | | Azure Cognitive Services TTS key, used to generate the audio of the Memori and for STT recognition |
|
|
88
89
|
| `layout` | | `string` | | Layout of the Memori, can be "FULLPAGE" (default), "CHAT", "WEBSITE_ASSISTANT" or "TOTEM", see [below](#layouts) |
|
|
89
90
|
| `customLayout` | | `React.FC<LayoutProps>` | | Custom layout component, see [below](#custom-layout) |
|
|
@@ -102,6 +102,7 @@ export interface Props {
|
|
|
102
102
|
authToken?: string;
|
|
103
103
|
AZURE_COGNITIVE_SERVICES_TTS_KEY?: string;
|
|
104
104
|
defaultSpeakerActive?: boolean;
|
|
105
|
+
disableTextEnteredEvents?: boolean;
|
|
105
106
|
onStateChange?: (state?: DialogState) => void;
|
|
106
107
|
additionalInfo?: OpenSession['additionalInfo'] & {
|
|
107
108
|
[key: string]: string;
|
|
@@ -110,5 +111,5 @@ export interface Props {
|
|
|
110
111
|
additionalSettings?: JSX.Element | null;
|
|
111
112
|
userAvatar?: string | JSX.Element;
|
|
112
113
|
}
|
|
113
|
-
declare const MemoriWidget: ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenantID, memoriLang, multilingual, integration, layout, customLayout, showInstruct, showShare, preview, embed, showInputs, showDates, showContextPerLine, showSettings, showTypingText, showClear, showLogin, showOnlyLastMessages, height, secret, baseUrl, apiUrl, initialContextVars, initialQuestion, ogImage, sessionID: initialSessionID, tenant, personification, authToken, AZURE_COGNITIVE_SERVICES_TTS_KEY, defaultSpeakerActive, onStateChange, additionalInfo, additionalSettings, customMediaRenderer, userAvatar, }: Props) => JSX.Element;
|
|
114
|
+
declare const MemoriWidget: ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenantID, memoriLang, multilingual, integration, layout, customLayout, showInstruct, showShare, preview, embed, showInputs, showDates, showContextPerLine, showSettings, showTypingText, showClear, showLogin, showOnlyLastMessages, height, secret, baseUrl, apiUrl, initialContextVars, initialQuestion, ogImage, sessionID: initialSessionID, tenant, personification, authToken, AZURE_COGNITIVE_SERVICES_TTS_KEY, defaultSpeakerActive, disableTextEnteredEvents, onStateChange, additionalInfo, additionalSettings, customMediaRenderer, userAvatar, }: Props) => JSX.Element;
|
|
114
115
|
export default MemoriWidget;
|
|
@@ -153,7 +153,7 @@ let memoriPassword;
|
|
|
153
153
|
let speakerMuted = false;
|
|
154
154
|
let memoriSpeaking = false;
|
|
155
155
|
let userToken;
|
|
156
|
-
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, }) => {
|
|
156
|
+
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, }) => {
|
|
157
157
|
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;
|
|
158
158
|
const { t, i18n } = (0, react_i18next_1.useTranslation)();
|
|
159
159
|
const [isClient, setIsClient] = (0, react_1.useState)(false);
|
|
@@ -326,56 +326,23 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
326
326
|
setTypingText(typingText);
|
|
327
327
|
let msg = text;
|
|
328
328
|
let gotError = false;
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const { currentState, ...response } = await postTextEnteredEvent({
|
|
337
|
-
sessionId: sessionID,
|
|
338
|
-
text: msg,
|
|
339
|
-
});
|
|
340
|
-
if (response.resultCode === 0 && currentState) {
|
|
341
|
-
const emission = useLoaderTextAsMsg && typingText
|
|
342
|
-
? typingText
|
|
343
|
-
: (_b = currentState.emission) !== null && _b !== void 0 ? _b : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
|
|
344
|
-
if (currentState.state === 'X4' && memori.giverTag) {
|
|
345
|
-
const { currentState, ...resp } = await postTagChangedEvent(sessionID, memori.giverTag);
|
|
346
|
-
if (resp.resultCode === 0) {
|
|
347
|
-
setCurrentDialogState(currentState);
|
|
348
|
-
if (emission) {
|
|
349
|
-
pushMessage({
|
|
350
|
-
text: emission,
|
|
351
|
-
emitter: currentState.emitter,
|
|
352
|
-
media: currentState.media,
|
|
353
|
-
fromUser: false,
|
|
354
|
-
questionAnswered: msg,
|
|
355
|
-
contextVars: currentState.contextVars,
|
|
356
|
-
date: currentState.currentDate,
|
|
357
|
-
placeName: currentState.currentPlaceName,
|
|
358
|
-
placeLatitude: currentState.currentLatitude,
|
|
359
|
-
placeLongitude: currentState.currentLongitude,
|
|
360
|
-
placeUncertaintyKm: currentState.currentUncertaintyKm,
|
|
361
|
-
tag: currentState.currentTag,
|
|
362
|
-
memoryTags: currentState.memoryTags,
|
|
363
|
-
});
|
|
364
|
-
speak(emission);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
console.error(response, resp);
|
|
369
|
-
react_hot_toast_1.default.error(t((0, error_1.getErrori18nKey)(resp.resultCode)));
|
|
370
|
-
gotError = true;
|
|
371
|
-
}
|
|
329
|
+
try {
|
|
330
|
+
if (translate &&
|
|
331
|
+
!instruct &&
|
|
332
|
+
isMultilanguageEnabled &&
|
|
333
|
+
userLang.toUpperCase() !== language.toUpperCase()) {
|
|
334
|
+
const translation = await (0, translations_1.getTranslation)(text, language, userLang, baseUrl);
|
|
335
|
+
msg = translation.text;
|
|
372
336
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
337
|
+
const { currentState, ...response } = await postTextEnteredEvent({
|
|
338
|
+
sessionId: sessionID,
|
|
339
|
+
text: msg,
|
|
340
|
+
});
|
|
341
|
+
if (response.resultCode === 0 && currentState) {
|
|
342
|
+
const emission = useLoaderTextAsMsg && typingText
|
|
343
|
+
? typingText
|
|
344
|
+
: (_b = currentState.emission) !== null && _b !== void 0 ? _b : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
|
|
345
|
+
if (currentState.state === 'X4' && memori.giverTag) {
|
|
379
346
|
const { currentState, ...resp } = await postTagChangedEvent(sessionID, memori.giverTag);
|
|
380
347
|
if (resp.resultCode === 0) {
|
|
381
348
|
setCurrentDialogState(currentState);
|
|
@@ -404,62 +371,103 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
404
371
|
gotError = true;
|
|
405
372
|
}
|
|
406
373
|
}
|
|
374
|
+
else if (currentState.state === 'X2d' && memori.giverTag) {
|
|
375
|
+
const { currentState, ...resp } = await postTextEnteredEvent({
|
|
376
|
+
sessionId: sessionID,
|
|
377
|
+
text: Math.random().toString().substring(2, 8),
|
|
378
|
+
});
|
|
379
|
+
if (resp.resultCode === 0) {
|
|
380
|
+
const { currentState, ...resp } = await postTagChangedEvent(sessionID, memori.giverTag);
|
|
381
|
+
if (resp.resultCode === 0) {
|
|
382
|
+
setCurrentDialogState(currentState);
|
|
383
|
+
if (emission) {
|
|
384
|
+
pushMessage({
|
|
385
|
+
text: emission,
|
|
386
|
+
emitter: currentState.emitter,
|
|
387
|
+
media: currentState.media,
|
|
388
|
+
fromUser: false,
|
|
389
|
+
questionAnswered: msg,
|
|
390
|
+
contextVars: currentState.contextVars,
|
|
391
|
+
date: currentState.currentDate,
|
|
392
|
+
placeName: currentState.currentPlaceName,
|
|
393
|
+
placeLatitude: currentState.currentLatitude,
|
|
394
|
+
placeLongitude: currentState.currentLongitude,
|
|
395
|
+
placeUncertaintyKm: currentState.currentUncertaintyKm,
|
|
396
|
+
tag: currentState.currentTag,
|
|
397
|
+
memoryTags: currentState.memoryTags,
|
|
398
|
+
});
|
|
399
|
+
speak(emission);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
console.error(response, resp);
|
|
404
|
+
react_hot_toast_1.default.error(t((0, error_1.getErrori18nKey)(resp.resultCode)));
|
|
405
|
+
gotError = true;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
console.error(response, resp);
|
|
410
|
+
react_hot_toast_1.default.error(t((0, error_1.getErrori18nKey)(resp.resultCode)));
|
|
411
|
+
gotError = true;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
else if (userLang.toLowerCase() !== language.toLowerCase() &&
|
|
415
|
+
emission &&
|
|
416
|
+
!instruct &&
|
|
417
|
+
isMultilanguageEnabled) {
|
|
418
|
+
translateDialogState(currentState, userLang, msg).then(ts => {
|
|
419
|
+
if (ts.emission) {
|
|
420
|
+
speak(ts.emission);
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}
|
|
407
424
|
else {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
425
|
+
setCurrentDialogState({
|
|
426
|
+
...currentState,
|
|
427
|
+
emission,
|
|
428
|
+
});
|
|
429
|
+
if (emission) {
|
|
430
|
+
pushMessage({
|
|
431
|
+
text: emission,
|
|
432
|
+
emitter: currentState.emitter,
|
|
433
|
+
media: currentState.media,
|
|
434
|
+
fromUser: false,
|
|
435
|
+
questionAnswered: msg,
|
|
436
|
+
generatedByAI: !!currentState.completion,
|
|
437
|
+
contextVars: currentState.contextVars,
|
|
438
|
+
date: currentState.currentDate,
|
|
439
|
+
placeName: currentState.currentPlaceName,
|
|
440
|
+
placeLatitude: currentState.currentLatitude,
|
|
441
|
+
placeLongitude: currentState.currentLongitude,
|
|
442
|
+
placeUncertaintyKm: currentState.currentUncertaintyKm,
|
|
443
|
+
tag: currentState.currentTag,
|
|
444
|
+
memoryTags: currentState.memoryTags,
|
|
445
|
+
});
|
|
446
|
+
speak(emission);
|
|
447
|
+
}
|
|
411
448
|
}
|
|
412
449
|
}
|
|
413
|
-
else if (
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
450
|
+
else if (response.resultCode === 404) {
|
|
451
|
+
setHistory(h => [...h.slice(0, h.length - 1)]);
|
|
452
|
+
reopenSession(false, memoriPwd || memori.secretToken, memoriTokens, instruct && memori.giverTag ? memori.giverTag : undefined, instruct && memori.giverPIN ? memori.giverPIN : undefined, {
|
|
453
|
+
PATHNAME: window.location.pathname,
|
|
454
|
+
ROUTE: ((_d = (_c = window.location.pathname) === null || _c === void 0 ? void 0 : _c.split('/')) === null || _d === void 0 ? void 0 : _d.pop()) || '',
|
|
455
|
+
...(initialContextVars || {}),
|
|
456
|
+
}, initialQuestion).then(state => {
|
|
457
|
+
console.info('session timeout');
|
|
458
|
+
if (state === null || state === void 0 ? void 0 : state.sessionID) {
|
|
459
|
+
setTimeout(() => {
|
|
460
|
+
sendMessage(text, media, state === null || state === void 0 ? void 0 : state.sessionID);
|
|
461
|
+
}, 500);
|
|
420
462
|
}
|
|
421
463
|
});
|
|
422
464
|
}
|
|
423
|
-
else {
|
|
424
|
-
setCurrentDialogState({
|
|
425
|
-
...currentState,
|
|
426
|
-
emission,
|
|
427
|
-
});
|
|
428
|
-
if (emission) {
|
|
429
|
-
pushMessage({
|
|
430
|
-
text: emission,
|
|
431
|
-
emitter: currentState.emitter,
|
|
432
|
-
media: currentState.media,
|
|
433
|
-
fromUser: false,
|
|
434
|
-
questionAnswered: msg,
|
|
435
|
-
generatedByAI: !!currentState.completion,
|
|
436
|
-
contextVars: currentState.contextVars,
|
|
437
|
-
date: currentState.currentDate,
|
|
438
|
-
placeName: currentState.currentPlaceName,
|
|
439
|
-
placeLatitude: currentState.currentLatitude,
|
|
440
|
-
placeLongitude: currentState.currentLongitude,
|
|
441
|
-
placeUncertaintyKm: currentState.currentUncertaintyKm,
|
|
442
|
-
tag: currentState.currentTag,
|
|
443
|
-
memoryTags: currentState.memoryTags,
|
|
444
|
-
});
|
|
445
|
-
speak(emission);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
465
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
...(initialContextVars || {}),
|
|
455
|
-
}, initialQuestion).then(state => {
|
|
456
|
-
console.info('session timeout');
|
|
457
|
-
if (state === null || state === void 0 ? void 0 : state.sessionID) {
|
|
458
|
-
setTimeout(() => {
|
|
459
|
-
sendMessage(text, media, state === null || state === void 0 ? void 0 : state.sessionID);
|
|
460
|
-
}, 500);
|
|
461
|
-
}
|
|
462
|
-
});
|
|
466
|
+
catch (error) {
|
|
467
|
+
console.error(error);
|
|
468
|
+
gotError = true;
|
|
469
|
+
setTypingText(undefined);
|
|
470
|
+
setMemoriTyping(false);
|
|
463
471
|
}
|
|
464
472
|
if (!hasBatchQueued) {
|
|
465
473
|
setTypingText(undefined);
|
|
@@ -1707,6 +1715,8 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1707
1715
|
sendMessage(text, undefined, undefined, false, translatedText);
|
|
1708
1716
|
};
|
|
1709
1717
|
const memoriTextEnteredHandler = (0, react_1.useCallback)((e) => {
|
|
1718
|
+
if (disableTextEnteredEvents)
|
|
1719
|
+
return;
|
|
1710
1720
|
const { text, waitForPrevious, hidden, typingText, useLoaderTextAsMsg, hasBatchQueued, } = e.detail;
|
|
1711
1721
|
if (text) {
|
|
1712
1722
|
if (waitForPrevious &&
|
|
@@ -1722,13 +1732,24 @@ const MemoriWidget = ({ memori, memoriConfigs, ownerUserID, ownerUserName, tenan
|
|
|
1722
1732
|
sendMessage(text, undefined, undefined, undefined, undefined, hidden, typingText, useLoaderTextAsMsg, hasBatchQueued);
|
|
1723
1733
|
}
|
|
1724
1734
|
}
|
|
1725
|
-
}, [
|
|
1735
|
+
}, [
|
|
1736
|
+
sessionId,
|
|
1737
|
+
isPlayingAudio,
|
|
1738
|
+
memoriTyping,
|
|
1739
|
+
userLang,
|
|
1740
|
+
disableTextEnteredEvents,
|
|
1741
|
+
]);
|
|
1726
1742
|
(0, react_1.useEffect)(() => {
|
|
1727
|
-
|
|
1743
|
+
if (!disableTextEnteredEvents) {
|
|
1744
|
+
document.addEventListener('MemoriTextEntered', memoriTextEnteredHandler);
|
|
1745
|
+
}
|
|
1746
|
+
else {
|
|
1747
|
+
document.removeEventListener('MemoriTextEntered', memoriTextEnteredHandler);
|
|
1748
|
+
}
|
|
1728
1749
|
return () => {
|
|
1729
1750
|
document.removeEventListener('MemoriTextEntered', memoriTextEnteredHandler);
|
|
1730
1751
|
};
|
|
1731
|
-
}, [sessionId, userLang]);
|
|
1752
|
+
}, [sessionId, userLang, disableTextEnteredEvents]);
|
|
1732
1753
|
const onClickStart = (0, react_1.useCallback)(async (session) => {
|
|
1733
1754
|
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _t, _u, _v;
|
|
1734
1755
|
const sessionID = (session === null || session === void 0 ? void 0 : session.sessionID) || sessionId;
|