@memori.ai/memori-react 2.10.0 → 2.10.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 +24 -0
- package/dist/components/ChatBubble/ChatBubble.js +31 -31
- package/dist/components/ChatBubble/ChatBubble.js.map +1 -1
- package/dist/components/MemoriWidget/MemoriWidget.d.ts +3 -2
- package/dist/components/MemoriWidget/MemoriWidget.js +213 -205
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/helpers/utils.d.ts +1 -0
- package/dist/helpers/utils.js +5 -1
- package/dist/helpers/utils.js.map +1 -1
- package/dist/helpers/utils.test.js +12 -0
- package/dist/helpers/utils.test.js.map +1 -1
- package/esm/components/ChatBubble/ChatBubble.js +31 -31
- package/esm/components/ChatBubble/ChatBubble.js.map +1 -1
- package/esm/components/MemoriWidget/MemoriWidget.d.ts +3 -2
- package/esm/components/MemoriWidget/MemoriWidget.js +214 -206
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/helpers/utils.d.ts +1 -0
- package/esm/helpers/utils.js +3 -0
- package/esm/helpers/utils.js.map +1 -1
- package/esm/helpers/utils.test.js +13 -1
- package/esm/helpers/utils.test.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ChatBubble/ChatBubble.tsx +1 -1
- package/src/components/ChatBubble/__snapshots__/ChatBubble.test.tsx.snap +3 -0
- package/src/components/MemoriWidget/MemoriWidget.tsx +291 -273
- package/src/helpers/utils.test.ts +15 -1
- package/src/helpers/utils.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [2.10.2](https://github.com/memori-ai/memori-react/compare/v2.10.1...v2.10.2) (2023-08-14)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* speech async handling, avoids double voice ([ee6e45a](https://github.com/memori-ai/memori-react/commit/ee6e45a98a948a4cc5055b84243353e0b865d2b4))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Maintenance
|
|
12
|
+
|
|
13
|
+
* restore new session mark ([883567d](https://github.com/memori-ai/memori-react/commit/883567d4ce1f2bbcea0b435c6f0788f3a742c37d))
|
|
14
|
+
|
|
15
|
+
## [2.10.1](https://github.com/memori-ai/memori-react/compare/v2.10.0...v2.10.1) (2023-08-10)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* remove emojis from spoken text ([92e2cb6](https://github.com/memori-ai/memori-react/commit/92e2cb6e5a90b228c091a41afb7b202938c03ad8))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Changes
|
|
24
|
+
|
|
25
|
+
* add waitForPrevious param to typeMessage ([6aae935](https://github.com/memori-ai/memori-react/commit/6aae935188abc388aee29dc1ef631819d73fbd0e))
|
|
26
|
+
|
|
3
27
|
## [2.10.0](https://github.com/memori-ai/memori-react/compare/v2.9.2...v2.10.0) (2023-08-10)
|
|
4
28
|
|
|
5
29
|
|
|
@@ -12,42 +12,42 @@ const FeedbackButtons_1 = tslib_1.__importDefault(require("../FeedbackButtons/Fe
|
|
|
12
12
|
const react_i18next_1 = require("react-i18next");
|
|
13
13
|
const ChatBubble = ({ message, memori, tenant, baseUrl, apiUrl, showFeedback, simulateUserPrompt, showAIicon = true, }) => {
|
|
14
14
|
const { t } = (0, react_i18next_1.useTranslation)();
|
|
15
|
-
return ((0, jsx_runtime_1.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
type: 'avatar',
|
|
21
|
-
tenantID: tenant === null || tenant === void 0 ? void 0 : tenant.id,
|
|
22
|
-
resourceURI: memori.avatarURL,
|
|
23
|
-
baseURL: baseUrl,
|
|
24
|
-
apiURL: apiUrl,
|
|
25
|
-
}) }), (0, jsx_runtime_1.jsx)("img", { className: "memori-chat--bubble-avatar-img", alt: memori.name, src: memori.avatarURL && memori.avatarURL.length > 0
|
|
26
|
-
? (0, media_1.getResourceUrl)({
|
|
15
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [message.initial && (0, jsx_runtime_1.jsx)("div", { className: "memori-chat--bubble-initial" }), (0, jsx_runtime_1.jsxs)(react_1.Transition, { show: true, appear: true, as: "div", className: (0, classnames_1.default)('memori-chat--bubble-container', {
|
|
16
|
+
'memori-chat--bubble-from-user': !!message.fromUser,
|
|
17
|
+
'memori-chat--with-addon': (message.generatedByAI && showAIicon) ||
|
|
18
|
+
(showFeedback && simulateUserPrompt),
|
|
19
|
+
}), children: [!message.fromUser && ((0, jsx_runtime_1.jsxs)(react_1.Transition.Child, { as: "picture", className: "memori-chat--bubble-avatar", enter: "transition ease-in-out duration-300", enterFrom: `opacity-0 scale-075 ${message.fromUser ? 'translate-x-15' : 'translate-x--15'}`, enterTo: "opacity-1 scale-1 translate-x-0", leave: "transition ease-in-out duration-300", leaveFrom: "opacity-1 scale-1 translate-x-0", leaveTo: `opacity-0 scale-075 ${message.fromUser ? 'translate-x-15' : 'translate-x--15'}`, children: [(0, jsx_runtime_1.jsx)("source", { src: (0, media_1.getResourceUrl)({
|
|
27
20
|
type: 'avatar',
|
|
28
21
|
tenantID: tenant === null || tenant === void 0 ? void 0 : tenant.id,
|
|
29
22
|
resourceURI: memori.avatarURL,
|
|
30
23
|
baseURL: baseUrl,
|
|
31
24
|
apiURL: apiUrl,
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
25
|
+
}) }), (0, jsx_runtime_1.jsx)("img", { className: "memori-chat--bubble-avatar-img", alt: memori.name, src: memori.avatarURL && memori.avatarURL.length > 0
|
|
26
|
+
? (0, media_1.getResourceUrl)({
|
|
27
|
+
type: 'avatar',
|
|
28
|
+
tenantID: tenant === null || tenant === void 0 ? void 0 : tenant.id,
|
|
29
|
+
resourceURI: memori.avatarURL,
|
|
30
|
+
baseURL: baseUrl,
|
|
31
|
+
apiURL: apiUrl,
|
|
32
|
+
})
|
|
33
|
+
: (0, media_1.getResourceUrl)({
|
|
34
|
+
tenantID: tenant === null || tenant === void 0 ? void 0 : tenant.id,
|
|
35
|
+
type: 'avatar',
|
|
36
|
+
baseURL: baseUrl || 'https://app.twincreator.com',
|
|
37
|
+
apiURL: apiUrl,
|
|
38
|
+
}) })] })), (0, jsx_runtime_1.jsxs)(react_1.Transition.Child, { as: "div", className: (0, classnames_1.default)('memori-chat--bubble', {
|
|
39
|
+
'memori-chat--user-bubble': !!message.fromUser,
|
|
40
|
+
'memori-chat--with-addon': (message.generatedByAI && showAIicon) ||
|
|
41
|
+
(showFeedback && simulateUserPrompt),
|
|
42
|
+
'memori-chat--ai-generated': message.generatedByAI && showAIicon,
|
|
43
|
+
'memori-chat--with-feedback': showFeedback,
|
|
44
|
+
}), enter: "transition ease-in-out duration-300", enterFrom: `opacity-0 scale-09 translate-x-${message.fromUser ? '30' : '-30'}`, enterTo: "opacity-1 scale-1 translate-x-0", leave: "transition ease-in-out duration-300", leaveFrom: "opacity-1 scale-1 translate-x-0", leaveTo: `opacity-0 scale-09 translate-x-${message.fromUser ? '30' : '-30'}`, children: [(message.translatedText || message.text)
|
|
45
|
+
.split(/\r\n|\r|\n/)
|
|
46
|
+
.map((row, index) => ((0, jsx_runtime_1.jsx)("p", { children: row }, index))), ((message.generatedByAI && showAIicon) ||
|
|
47
|
+
(showFeedback && simulateUserPrompt)) && ((0, jsx_runtime_1.jsxs)("div", { className: "memori-chat--bubble-addon", children: [showFeedback && !!simulateUserPrompt && ((0, jsx_runtime_1.jsx)(FeedbackButtons_1.default, { memori: memori, className: "memori-chat--bubble-feedback", dropdown: true, onNegativeClick: msg => {
|
|
48
|
+
if (msg)
|
|
49
|
+
simulateUserPrompt(msg);
|
|
50
|
+
} })), message.generatedByAI && showAIicon && ((0, jsx_runtime_1.jsx)(Tooltip_1.default, { align: "left", content: t('generatedByAI'), className: "memori-chat--bubble-ai-icon", children: (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(AI_1.default, { title: t('generatedByAI') || undefined }) }) }))] }))] }), message.fromUser && ((0, jsx_runtime_1.jsx)(react_1.Transition.Child, { as: "div", className: "memori-chat--bubble-avatar", enter: "transition ease-in-out duration-300", enterFrom: `opacity-0 scale-075 ${message.fromUser ? 'translate-x-15' : 'translate-x--15'}`, enterTo: "opacity-1 scale-1 translate-x-0", leave: "transition ease-in-out duration-300", leaveFrom: "opacity-1 scale-1 translate-x-0", leaveTo: `opacity-0 scale-075 ${message.fromUser ? 'translate-x-15' : 'translate-x--15'}`, children: (0, jsx_runtime_1.jsx)(User_1.default, {}) }))] })] }));
|
|
51
51
|
};
|
|
52
52
|
exports.default = ChatBubble;
|
|
53
53
|
//# sourceMappingURL=ChatBubble.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatBubble.js","sourceRoot":"","sources":["../../../src/components/ChatBubble/ChatBubble.tsx"],"names":[],"mappings":";;;;AACA,oEAA4B;AAM5B,6CAA+C;AAC/C,+CAAqD;AACrD,iEAAiC;AACjC,6DAA6B;AAC7B,oEAAoC;AACpC,iGAAiE;AACjE,iDAA+C;AAa/C,MAAM,UAAU,GAAoB,CAAC,EACnC,OAAO,EACP,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,kBAAkB,EAClB,UAAU,GAAG,IAAI,GAClB,EAAE,EAAE;IACH,MAAM,EAAE,CAAC,EAAE,GAAG,IAAA,8BAAc,GAAE,CAAC;IAE/B,OAAO,CACL,
|
|
1
|
+
{"version":3,"file":"ChatBubble.js","sourceRoot":"","sources":["../../../src/components/ChatBub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AAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,iBACxC,EAAE,EACF,OAAO,EAAC,iCAAiC,EACzC,KAAK,EAAC,qCAAqC,EAC3C,SAAS,EAAC,iCAAiC,EAC3C,OAAO,EAAE,uBACP,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,iBACxC,EAAE,YAEF,uBAAC,cAAI,KAAG,GACS,CACpB,IACU,IACZ,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,UAAU,CAAC"}
|
|
@@ -8,10 +8,11 @@ import Header, { Props as HeaderProps } from '../Header/Header';
|
|
|
8
8
|
declare const getMemoriState: (integrationId?: string | undefined) => object | null;
|
|
9
9
|
type MemoriTextEnteredEvent = CustomEvent<{
|
|
10
10
|
text: string;
|
|
11
|
+
waitForPrevious?: boolean;
|
|
11
12
|
hidden?: boolean;
|
|
12
13
|
}>;
|
|
13
|
-
declare const typeMessage: (message: string, hidden?: boolean) => void;
|
|
14
|
-
declare const typeMessageHidden: (message: string) => void;
|
|
14
|
+
declare const typeMessage: (message: string, waitForPrevious?: boolean, hidden?: boolean) => void;
|
|
15
|
+
declare const typeMessageHidden: (message: string, waitForPrevious?: boolean) => void;
|
|
15
16
|
interface CustomEventMap {
|
|
16
17
|
MemoriTextEntered: MemoriTextEnteredEvent;
|
|
17
18
|
}
|
|
@@ -46,16 +46,17 @@ const getMemoriState = (integrationId) => {
|
|
|
46
46
|
let dialogState = JSON.parse(engineState);
|
|
47
47
|
return dialogState;
|
|
48
48
|
};
|
|
49
|
-
const typeMessage = (message, hidden = false) => {
|
|
49
|
+
const typeMessage = (message, waitForPrevious = true, hidden = false) => {
|
|
50
50
|
const e = new CustomEvent('MemoriTextEntered', {
|
|
51
51
|
detail: {
|
|
52
52
|
text: message,
|
|
53
|
+
waitForPrevious,
|
|
53
54
|
hidden,
|
|
54
55
|
},
|
|
55
56
|
});
|
|
56
57
|
document.dispatchEvent(e);
|
|
57
58
|
};
|
|
58
|
-
const typeMessageHidden = (message) => typeMessage(message, true);
|
|
59
|
+
const typeMessageHidden = (message, waitForPrevious = true) => typeMessage(message, waitForPrevious, true);
|
|
59
60
|
window.getMemoriState = getMemoriState;
|
|
60
61
|
window.typeMessage = typeMessage;
|
|
61
62
|
window.typeMessageHidden = typeMessageHidden;
|
|
@@ -79,14 +80,15 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
|
|
|
79
80
|
const [instruct, setInstruct] = (0, react_1.useState)(false);
|
|
80
81
|
const [clickedStart, setClickedStart] = (0, react_1.useState)(false);
|
|
81
82
|
const [gotErrorInOpening, setGotErrorInOpening] = (0, react_1.useState)(false);
|
|
82
|
-
const language = (
|
|
83
|
+
const language = ((_c = (_b = (_a = memori.culture) === null || _a === void 0 ? void 0 : _a.split('-')) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.toUpperCase()) ||
|
|
84
|
+
((_h = (_g = (_f = (_d = memoriConfigs === null || memoriConfigs === void 0 ? void 0 : memoriConfigs.find(c => c.memoriConfigID === memori.memoriConfigurationID)) === null || _d === void 0 ? void 0 : _d.culture) === null || _f === void 0 ? void 0 : _f.split('-')) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.toUpperCase());
|
|
83
85
|
const integrationConfig = (integration === null || integration === void 0 ? void 0 : integration.customData)
|
|
84
86
|
? JSON.parse(integration.customData)
|
|
85
87
|
: null;
|
|
86
88
|
const isMultilanguageEnabled = multilingual !== undefined
|
|
87
89
|
? multilingual
|
|
88
90
|
: !!(integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.multilanguage);
|
|
89
|
-
const [userLang, setUserLang] = (0, react_1.useState)((_m = (_l = (_k = (_j =
|
|
91
|
+
const [userLang, setUserLang] = (0, react_1.useState)((_m = (_l = (_k = (_j = memoriLang !== null && memoriLang !== void 0 ? memoriLang : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.lang) !== null && _j !== void 0 ? _j : language) !== null && _k !== void 0 ? _k : integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.uiLang) !== null && _l !== void 0 ? _l : i18n.language) !== null && _m !== void 0 ? _m : 'IT');
|
|
90
92
|
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
91
93
|
const [memoriTyping, setMemoriTyping] = (0, react_1.useState)(false);
|
|
92
94
|
const selectedLayout = layout || (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.layout) || 'DEFAULT';
|
|
@@ -149,6 +151,203 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
|
|
|
149
151
|
_setPosition(venue);
|
|
150
152
|
applyPosition(venue);
|
|
151
153
|
};
|
|
154
|
+
const [userMessage, setUserMessage] = (0, react_1.useState)('');
|
|
155
|
+
const onChangeUserMessage = (value) => {
|
|
156
|
+
if (!value || value === '\n' || value.trim() === '') {
|
|
157
|
+
setUserMessage('');
|
|
158
|
+
resetInteractionTimeout();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
setUserMessage(value);
|
|
162
|
+
clearInteractionTimeout();
|
|
163
|
+
};
|
|
164
|
+
const [listening, setListening] = (0, react_1.useState)(false);
|
|
165
|
+
const [history, setHistory] = (0, react_1.useState)([]);
|
|
166
|
+
const pushMessage = (message) => {
|
|
167
|
+
setHistory(history => [...history, { ...message }]);
|
|
168
|
+
};
|
|
169
|
+
const sendMessage = async (text, media, newSessionId, translate = true, translatedText, hidden = false) => {
|
|
170
|
+
var _a, _b;
|
|
171
|
+
const sessionID = newSessionId ||
|
|
172
|
+
sessionId ||
|
|
173
|
+
((_a = window.getMemoriState()) === null || _a === void 0 ? void 0 : _a.sessionID);
|
|
174
|
+
if (!sessionID || !(text === null || text === void 0 ? void 0 : text.length))
|
|
175
|
+
return;
|
|
176
|
+
if (!hidden)
|
|
177
|
+
pushMessage({
|
|
178
|
+
text: text,
|
|
179
|
+
translatedText,
|
|
180
|
+
fromUser: true,
|
|
181
|
+
media: media !== null && media !== void 0 ? media : [],
|
|
182
|
+
initial: sessionId
|
|
183
|
+
? !!newSessionId && newSessionId !== sessionId
|
|
184
|
+
: !!newSessionId,
|
|
185
|
+
});
|
|
186
|
+
setMemoriTyping(true);
|
|
187
|
+
let msg = text;
|
|
188
|
+
if (translate &&
|
|
189
|
+
!instruct &&
|
|
190
|
+
isMultilanguageEnabled &&
|
|
191
|
+
userLang.toUpperCase() !== language.toUpperCase()) {
|
|
192
|
+
const translation = await (0, translations_1.getTranslation)(text, language, userLang, baseUrl);
|
|
193
|
+
msg = translation.text;
|
|
194
|
+
}
|
|
195
|
+
const { currentState, ...response } = await postTextEnteredEvent({
|
|
196
|
+
sessionId: sessionID,
|
|
197
|
+
text: msg,
|
|
198
|
+
});
|
|
199
|
+
if (response.resultCode === 0 && currentState) {
|
|
200
|
+
const emission = (_b = currentState.emission) !== null && _b !== void 0 ? _b : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
|
|
201
|
+
if (currentState.state === 'X4' && memori.giverTag) {
|
|
202
|
+
const { currentState, ...resp } = await postTagChangedEvent(sessionID, memori.giverTag);
|
|
203
|
+
if (resp.resultCode === 0) {
|
|
204
|
+
setCurrentDialogState(currentState);
|
|
205
|
+
if (currentState.emission) {
|
|
206
|
+
pushMessage({
|
|
207
|
+
text: currentState.emission,
|
|
208
|
+
media: currentState.media,
|
|
209
|
+
fromUser: false,
|
|
210
|
+
});
|
|
211
|
+
speak(currentState.emission);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
console.error(response, resp);
|
|
216
|
+
Message_1.default.error(t((0, error_1.getErrori18nKey)(resp.resultCode)));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else if (currentState.state === 'X2d' && memori.giverTag) {
|
|
220
|
+
const { currentState, ...resp } = await postTextEnteredEvent({
|
|
221
|
+
sessionId: sessionID,
|
|
222
|
+
text: Math.random().toString().substring(2, 8),
|
|
223
|
+
});
|
|
224
|
+
if (resp.resultCode === 0) {
|
|
225
|
+
const { currentState, ...resp } = await postTagChangedEvent(sessionID, memori.giverTag);
|
|
226
|
+
if (resp.resultCode === 0) {
|
|
227
|
+
setCurrentDialogState(currentState);
|
|
228
|
+
if (currentState.emission) {
|
|
229
|
+
pushMessage({
|
|
230
|
+
text: currentState.emission,
|
|
231
|
+
media: currentState.media,
|
|
232
|
+
fromUser: false,
|
|
233
|
+
});
|
|
234
|
+
speak(currentState.emission);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
console.error(response, resp);
|
|
239
|
+
Message_1.default.error(t((0, error_1.getErrori18nKey)(resp.resultCode)));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
console.error(response, resp);
|
|
244
|
+
Message_1.default.error(t((0, error_1.getErrori18nKey)(resp.resultCode)));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else if (userLang.toLowerCase() !== language.toLowerCase() &&
|
|
248
|
+
emission &&
|
|
249
|
+
!instruct &&
|
|
250
|
+
isMultilanguageEnabled) {
|
|
251
|
+
translateDialogState(currentState, userLang).then(ts => {
|
|
252
|
+
if (ts.emission) {
|
|
253
|
+
speak(ts.emission);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
setCurrentDialogState({
|
|
259
|
+
...currentState,
|
|
260
|
+
emission,
|
|
261
|
+
});
|
|
262
|
+
if (emission) {
|
|
263
|
+
pushMessage({
|
|
264
|
+
text: emission,
|
|
265
|
+
media: currentState.media,
|
|
266
|
+
fromUser: false,
|
|
267
|
+
generatedByAI: !!currentState.completion,
|
|
268
|
+
});
|
|
269
|
+
speak(emission);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
else if (response.resultCode === 404) {
|
|
274
|
+
setHistory(h => [...h.slice(0, h.length - 1)]);
|
|
275
|
+
reopenSession(false, memoriPwd || memori.secretToken, memoriTokens, instruct && memori.giverTag ? memori.giverTag : undefined, instruct && memori.giverPIN ? memori.giverPIN : undefined, initialContextVars, initialQuestion).then(state => {
|
|
276
|
+
console.info('session timeout');
|
|
277
|
+
if (state === null || state === void 0 ? void 0 : state.sessionID) {
|
|
278
|
+
setTimeout(() => {
|
|
279
|
+
sendMessage(text, media, state === null || state === void 0 ? void 0 : state.sessionID);
|
|
280
|
+
}, 500);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
setMemoriTyping(false);
|
|
285
|
+
};
|
|
286
|
+
const translateDialogState = async (state, userLang) => {
|
|
287
|
+
var _a, _b, _c;
|
|
288
|
+
const emission = (_a = state.emission) !== null && _a !== void 0 ? _a : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
|
|
289
|
+
let translatedState = { ...state };
|
|
290
|
+
let translatedMsg = null;
|
|
291
|
+
if (!emission ||
|
|
292
|
+
instruct ||
|
|
293
|
+
language.toUpperCase() === userLang.toUpperCase() ||
|
|
294
|
+
!isMultilanguageEnabled) {
|
|
295
|
+
translatedState = { ...state, emission };
|
|
296
|
+
if (emission) {
|
|
297
|
+
translatedMsg = {
|
|
298
|
+
text: emission,
|
|
299
|
+
media: state.media,
|
|
300
|
+
fromUser: false,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
const t = await (0, translations_1.getTranslation)(emission, userLang, language, baseUrl);
|
|
306
|
+
if (state.hints && state.hints.length > 0) {
|
|
307
|
+
const translatedHints = await Promise.all(((_b = state.hints) !== null && _b !== void 0 ? _b : []).map(async (hint) => {
|
|
308
|
+
var _a;
|
|
309
|
+
const tHint = await (0, translations_1.getTranslation)(hint, userLang, language, baseUrl);
|
|
310
|
+
return {
|
|
311
|
+
text: (_a = tHint === null || tHint === void 0 ? void 0 : tHint.text) !== null && _a !== void 0 ? _a : hint,
|
|
312
|
+
originalText: hint,
|
|
313
|
+
};
|
|
314
|
+
}));
|
|
315
|
+
translatedState = {
|
|
316
|
+
...state,
|
|
317
|
+
emission: t.text,
|
|
318
|
+
translatedHints,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
translatedState = {
|
|
323
|
+
...state,
|
|
324
|
+
emission: t.text,
|
|
325
|
+
hints: (_c = state.hints) !== null && _c !== void 0 ? _c : (state.state === 'G1' ? currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.hints : []),
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
if (t.text.length > 0)
|
|
329
|
+
translatedMsg = {
|
|
330
|
+
text: t.text,
|
|
331
|
+
media: state.media,
|
|
332
|
+
fromUser: false,
|
|
333
|
+
generatedByAI: !!state.completion,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
setCurrentDialogState(translatedState);
|
|
337
|
+
if (translatedMsg) {
|
|
338
|
+
pushMessage(translatedMsg);
|
|
339
|
+
}
|
|
340
|
+
return translatedState;
|
|
341
|
+
};
|
|
342
|
+
const minAge = memori.ageRestriction
|
|
343
|
+
? memori.ageRestriction
|
|
344
|
+
: memori.nsfw
|
|
345
|
+
? 18
|
|
346
|
+
: memori.enableCompletions
|
|
347
|
+
? 14
|
|
348
|
+
: 0;
|
|
349
|
+
const [birthDate, setBirthDate] = (0, react_1.useState)();
|
|
350
|
+
const [showAgeVerification, setShowAgeVerification] = (0, react_1.useState)(false);
|
|
152
351
|
const [sessionId, setSessionId] = (0, react_1.useState)(initialSessionID);
|
|
153
352
|
const [currentDialogState, _setCurrentDialogState] = (0, react_1.useState)();
|
|
154
353
|
const setCurrentDialogState = (state) => {
|
|
@@ -397,201 +596,6 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
|
|
|
397
596
|
restoreGiverTag();
|
|
398
597
|
};
|
|
399
598
|
}, []);
|
|
400
|
-
const [userMessage, setUserMessage] = (0, react_1.useState)('');
|
|
401
|
-
const onChangeUserMessage = (value) => {
|
|
402
|
-
if (!value || value === '\n' || value.trim() === '') {
|
|
403
|
-
setUserMessage('');
|
|
404
|
-
resetInteractionTimeout();
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
setUserMessage(value);
|
|
408
|
-
clearInteractionTimeout();
|
|
409
|
-
};
|
|
410
|
-
const [listening, setListening] = (0, react_1.useState)(false);
|
|
411
|
-
const [history, setHistory] = (0, react_1.useState)([]);
|
|
412
|
-
const pushMessage = (message) => {
|
|
413
|
-
setHistory(history => [...history, { ...message }]);
|
|
414
|
-
};
|
|
415
|
-
const sendMessage = (0, react_1.useCallback)(async (text, media, newSessionId, translate = true, translatedText, hidden = false) => {
|
|
416
|
-
var _a, _b, _c, _d, _f;
|
|
417
|
-
const sessionID = newSessionId || sessionId;
|
|
418
|
-
if (!sessionID || !(text === null || text === void 0 ? void 0 : text.length))
|
|
419
|
-
return;
|
|
420
|
-
if (!hidden)
|
|
421
|
-
pushMessage({
|
|
422
|
-
text: text,
|
|
423
|
-
translatedText,
|
|
424
|
-
fromUser: true,
|
|
425
|
-
media: media !== null && media !== void 0 ? media : [],
|
|
426
|
-
initial: !!newSessionId,
|
|
427
|
-
});
|
|
428
|
-
setMemoriTyping(true);
|
|
429
|
-
const language = (_d = (_c = (_b = (_a = memori.culture) === null || _a === void 0 ? void 0 : _a.split('-')) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : i18n.language) !== null && _d !== void 0 ? _d : 'IT';
|
|
430
|
-
let msg = text;
|
|
431
|
-
if (translate &&
|
|
432
|
-
!instruct &&
|
|
433
|
-
isMultilanguageEnabled &&
|
|
434
|
-
userLang.toUpperCase() !== language.toUpperCase()) {
|
|
435
|
-
const translation = await (0, translations_1.getTranslation)(text, language, userLang, baseUrl);
|
|
436
|
-
msg = translation.text;
|
|
437
|
-
}
|
|
438
|
-
const { currentState, ...response } = await postTextEnteredEvent({
|
|
439
|
-
sessionId: sessionID,
|
|
440
|
-
text: msg,
|
|
441
|
-
});
|
|
442
|
-
if (response.resultCode === 0 && currentState) {
|
|
443
|
-
const emission = (_f = currentState.emission) !== null && _f !== void 0 ? _f : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
|
|
444
|
-
if (currentState.state === 'X4' && memori.giverTag) {
|
|
445
|
-
const { currentState, ...resp } = await postTagChangedEvent(sessionID, memori.giverTag);
|
|
446
|
-
if (resp.resultCode === 0) {
|
|
447
|
-
setCurrentDialogState(currentState);
|
|
448
|
-
if (currentState.emission) {
|
|
449
|
-
pushMessage({
|
|
450
|
-
text: currentState.emission,
|
|
451
|
-
media: currentState.media,
|
|
452
|
-
fromUser: false,
|
|
453
|
-
});
|
|
454
|
-
speak(currentState.emission);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
console.error(response, resp);
|
|
459
|
-
Message_1.default.error(t((0, error_1.getErrori18nKey)(resp.resultCode)));
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
else if (currentState.state === 'X2d' && memori.giverTag) {
|
|
463
|
-
const { currentState, ...resp } = await postTextEnteredEvent({
|
|
464
|
-
sessionId: sessionID,
|
|
465
|
-
text: Math.random().toString().substring(2, 8),
|
|
466
|
-
});
|
|
467
|
-
if (resp.resultCode === 0) {
|
|
468
|
-
const { currentState, ...resp } = await postTagChangedEvent(sessionID, memori.giverTag);
|
|
469
|
-
if (resp.resultCode === 0) {
|
|
470
|
-
setCurrentDialogState(currentState);
|
|
471
|
-
if (currentState.emission) {
|
|
472
|
-
pushMessage({
|
|
473
|
-
text: currentState.emission,
|
|
474
|
-
media: currentState.media,
|
|
475
|
-
fromUser: false,
|
|
476
|
-
});
|
|
477
|
-
speak(currentState.emission);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
else {
|
|
481
|
-
console.error(response, resp);
|
|
482
|
-
Message_1.default.error(t((0, error_1.getErrori18nKey)(resp.resultCode)));
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
console.error(response, resp);
|
|
487
|
-
Message_1.default.error(t((0, error_1.getErrori18nKey)(resp.resultCode)));
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
else if (userLang.toLowerCase() !== language.toLowerCase() &&
|
|
491
|
-
emission &&
|
|
492
|
-
!instruct &&
|
|
493
|
-
isMultilanguageEnabled) {
|
|
494
|
-
translateDialogState(currentState, userLang).then(ts => {
|
|
495
|
-
if (ts.emission) {
|
|
496
|
-
speak(ts.emission);
|
|
497
|
-
}
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
else {
|
|
501
|
-
setCurrentDialogState({
|
|
502
|
-
...currentState,
|
|
503
|
-
emission,
|
|
504
|
-
});
|
|
505
|
-
if (emission) {
|
|
506
|
-
pushMessage({
|
|
507
|
-
text: emission,
|
|
508
|
-
media: currentState.media,
|
|
509
|
-
fromUser: false,
|
|
510
|
-
generatedByAI: !!currentState.completion,
|
|
511
|
-
});
|
|
512
|
-
speak(emission);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
else if (response.resultCode === 404) {
|
|
517
|
-
setHistory(h => [...h.slice(0, h.length - 1)]);
|
|
518
|
-
reopenSession(false, memoriPwd || memori.secretToken, memoriTokens, instruct && memori.giverTag ? memori.giverTag : undefined, instruct && memori.giverPIN ? memori.giverPIN : undefined, initialContextVars, initialQuestion).then(state => {
|
|
519
|
-
console.info('session timeout');
|
|
520
|
-
if (state === null || state === void 0 ? void 0 : state.sessionID) {
|
|
521
|
-
setTimeout(() => {
|
|
522
|
-
sendMessage(text, media, state === null || state === void 0 ? void 0 : state.sessionID);
|
|
523
|
-
}, 500);
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
setMemoriTyping(false);
|
|
528
|
-
}, [sessionId]);
|
|
529
|
-
const translateDialogState = async (state, userLang) => {
|
|
530
|
-
var _a, _b, _c, _d, _f, _g, _h;
|
|
531
|
-
const language = (_d = (_c = (_b = (_a = memori.culture) === null || _a === void 0 ? void 0 : _a.split('-')) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : i18n.language) !== null && _d !== void 0 ? _d : 'IT';
|
|
532
|
-
const emission = (_f = state.emission) !== null && _f !== void 0 ? _f : currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.emission;
|
|
533
|
-
let translatedState = { ...state };
|
|
534
|
-
let translatedMsg = null;
|
|
535
|
-
if (!emission ||
|
|
536
|
-
instruct ||
|
|
537
|
-
language.toUpperCase() === userLang.toUpperCase() ||
|
|
538
|
-
!isMultilanguageEnabled) {
|
|
539
|
-
translatedState = { ...state, emission };
|
|
540
|
-
if (emission) {
|
|
541
|
-
translatedMsg = {
|
|
542
|
-
text: emission,
|
|
543
|
-
media: state.media,
|
|
544
|
-
fromUser: false,
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
else {
|
|
549
|
-
const t = await (0, translations_1.getTranslation)(emission, userLang, language, baseUrl);
|
|
550
|
-
if (state.hints && state.hints.length > 0) {
|
|
551
|
-
const translatedHints = await Promise.all(((_g = state.hints) !== null && _g !== void 0 ? _g : []).map(async (hint) => {
|
|
552
|
-
var _a;
|
|
553
|
-
const tHint = await (0, translations_1.getTranslation)(hint, userLang, language, baseUrl);
|
|
554
|
-
return {
|
|
555
|
-
text: (_a = tHint === null || tHint === void 0 ? void 0 : tHint.text) !== null && _a !== void 0 ? _a : hint,
|
|
556
|
-
originalText: hint,
|
|
557
|
-
};
|
|
558
|
-
}));
|
|
559
|
-
translatedState = {
|
|
560
|
-
...state,
|
|
561
|
-
emission: t.text,
|
|
562
|
-
translatedHints,
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
translatedState = {
|
|
567
|
-
...state,
|
|
568
|
-
emission: t.text,
|
|
569
|
-
hints: (_h = state.hints) !== null && _h !== void 0 ? _h : (state.state === 'G1' ? currentDialogState === null || currentDialogState === void 0 ? void 0 : currentDialogState.hints : []),
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
if (t.text.length > 0)
|
|
573
|
-
translatedMsg = {
|
|
574
|
-
text: t.text,
|
|
575
|
-
media: state.media,
|
|
576
|
-
fromUser: false,
|
|
577
|
-
generatedByAI: !!state.completion,
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
setCurrentDialogState(translatedState);
|
|
581
|
-
if (translatedMsg) {
|
|
582
|
-
pushMessage(translatedMsg);
|
|
583
|
-
}
|
|
584
|
-
return translatedState;
|
|
585
|
-
};
|
|
586
|
-
const minAge = memori.ageRestriction
|
|
587
|
-
? memori.ageRestriction
|
|
588
|
-
: memori.nsfw
|
|
589
|
-
? 18
|
|
590
|
-
: memori.enableCompletions
|
|
591
|
-
? 14
|
|
592
|
-
: 0;
|
|
593
|
-
const [birthDate, setBirthDate] = (0, react_1.useState)();
|
|
594
|
-
const [showAgeVerification, setShowAgeVerification] = (0, react_1.useState)(false);
|
|
595
599
|
const [userInteractionTimeout, setUserInteractionTimeout] = (0, react_1.useState)();
|
|
596
600
|
const timeoutRef = (0, react_1.useRef)();
|
|
597
601
|
const clearInteractionTimeout = () => {
|
|
@@ -929,7 +933,7 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
|
|
|
929
933
|
source.disconnect();
|
|
930
934
|
onEndSpeakStartListen();
|
|
931
935
|
};
|
|
932
|
-
speechSynthesizer.speakSsmlAsync(`<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" xml:lang="${getCultureCodeByLanguage(userLang)}"><voice name="${getTTSVoice(userLang)}"><s>${replaceTextWithPhonemes(escapeHTML(text), userLang.toLowerCase())}</s></voice></speak>`, result => {
|
|
936
|
+
speechSynthesizer.speakSsmlAsync(`<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" xml:lang="${getCultureCodeByLanguage(userLang)}"><voice name="${getTTSVoice(userLang)}"><s>${replaceTextWithPhonemes(escapeHTML((0, utils_1.stripEmojis)(text)), userLang.toLowerCase())}</s></voice></speak>`, result => {
|
|
933
937
|
if (result) {
|
|
934
938
|
setIsPlayingAudio(true);
|
|
935
939
|
memoriSpeaking = true;
|
|
@@ -1343,25 +1347,29 @@ const MemoriWidget = ({ memori, memoriConfigs, memoriLang, multilingual, integra
|
|
|
1343
1347
|
};
|
|
1344
1348
|
const memoriTextEnteredHandler = (0, react_1.useCallback)((e) => {
|
|
1345
1349
|
var _a;
|
|
1346
|
-
const { text, hidden } = e.detail;
|
|
1350
|
+
const { text, waitForPrevious, hidden } = e.detail;
|
|
1347
1351
|
const sessionID = sessionId || ((_a = window.getMemoriState()) === null || _a === void 0 ? void 0 : _a.sessionID);
|
|
1348
1352
|
if (text) {
|
|
1349
|
-
if (
|
|
1353
|
+
if (waitForPrevious &&
|
|
1354
|
+
!speakerMuted &&
|
|
1355
|
+
(memoriSpeaking || memoriTyping)) {
|
|
1350
1356
|
setTimeout(() => {
|
|
1351
1357
|
memoriTextEnteredHandler(e);
|
|
1352
1358
|
}, 1000);
|
|
1353
1359
|
}
|
|
1354
1360
|
else {
|
|
1355
|
-
|
|
1361
|
+
stopListening();
|
|
1362
|
+
stopAudio();
|
|
1363
|
+
sendMessage(text, undefined, undefined, undefined, undefined, hidden);
|
|
1356
1364
|
}
|
|
1357
1365
|
}
|
|
1358
|
-
}, [sessionId, isPlayingAudio, memoriTyping]);
|
|
1366
|
+
}, [sessionId, isPlayingAudio, memoriTyping, userLang]);
|
|
1359
1367
|
(0, react_1.useEffect)(() => {
|
|
1360
1368
|
document.addEventListener('MemoriTextEntered', memoriTextEnteredHandler);
|
|
1361
1369
|
return () => {
|
|
1362
1370
|
document.removeEventListener('MemoriTextEntered', memoriTextEnteredHandler);
|
|
1363
1371
|
};
|
|
1364
|
-
}, []);
|
|
1372
|
+
}, [sessionId, userLang]);
|
|
1365
1373
|
const onClickStart = (0, react_1.useCallback)(async (session) => {
|
|
1366
1374
|
const sessionID = (session === null || session === void 0 ? void 0 : session.sessionID) || sessionId;
|
|
1367
1375
|
const dialogState = (session === null || session === void 0 ? void 0 : session.dialogState) || currentDialogState;
|