@memori.ai/memori-react 7.2.0 → 7.3.1
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/README.md +1 -0
- package/dist/components/Chat/Chat.d.ts +1 -0
- package/dist/components/Chat/Chat.js +2 -2
- package/dist/components/Chat/Chat.js.map +1 -1
- package/dist/components/ChatBubble/ChatBubble.d.ts +1 -0
- package/dist/components/ChatBubble/ChatBubble.js +12 -7
- package/dist/components/ChatBubble/ChatBubble.js.map +1 -1
- package/dist/components/MemoriWidget/MemoriWidget.d.ts +2 -1
- package/dist/components/MemoriWidget/MemoriWidget.js +77 -45
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/components/StartPanel/StartPanel.d.ts +1 -0
- package/dist/components/StartPanel/StartPanel.js +2 -2
- package/dist/components/StartPanel/StartPanel.js.map +1 -1
- package/dist/helpers/translations.js +5 -1
- package/dist/helpers/translations.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/Chat/Chat.d.ts +1 -0
- package/esm/components/Chat/Chat.js +2 -2
- package/esm/components/Chat/Chat.js.map +1 -1
- package/esm/components/ChatBubble/ChatBubble.d.ts +1 -0
- package/esm/components/ChatBubble/ChatBubble.js +12 -7
- package/esm/components/ChatBubble/ChatBubble.js.map +1 -1
- package/esm/components/MemoriWidget/MemoriWidget.d.ts +2 -1
- package/esm/components/MemoriWidget/MemoriWidget.js +77 -45
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/components/StartPanel/StartPanel.d.ts +1 -0
- package/esm/components/StartPanel/StartPanel.js +2 -2
- package/esm/components/StartPanel/StartPanel.js.map +1 -1
- package/esm/helpers/translations.js +5 -1
- package/esm/helpers/translations.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 +2 -2
- package/src/components/Chat/Chat.tsx +3 -0
- package/src/components/ChatBubble/ChatBubble.stories.tsx +14 -0
- package/src/components/ChatBubble/ChatBubble.test.tsx +19 -0
- package/src/components/ChatBubble/ChatBubble.tsx +31 -7
- package/src/components/ChatBubble/__snapshots__/ChatBubble.test.tsx.snap +132 -0
- package/src/components/MemoriWidget/MemoriWidget.tsx +86 -53
- package/src/components/StartPanel/StartPanel.test.tsx +20 -0
- package/src/components/StartPanel/StartPanel.tsx +3 -2
- package/src/components/StartPanel/__snapshots__/StartPanel.test.tsx.snap +101 -0
- package/src/helpers/translations.ts +10 -2
- package/src/index.stories.tsx +3 -17
- package/src/index.tsx +4 -0
|
@@ -104,6 +104,20 @@ GeneratedByAI.args = {
|
|
|
104
104
|
},
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
+
export const WithTranslationAndOriginal = Template.bind({});
|
|
108
|
+
WithTranslationAndOriginal.args = {
|
|
109
|
+
memori,
|
|
110
|
+
tenant,
|
|
111
|
+
message: {
|
|
112
|
+
fromUser: false,
|
|
113
|
+
text: 'Hello, this is a translated text so you can talk to me in different languages',
|
|
114
|
+
initial: false,
|
|
115
|
+
translatedText:
|
|
116
|
+
'Ciao, questo è un testo tradotto in modo che tu possa parlarmi in diverse lingue',
|
|
117
|
+
},
|
|
118
|
+
showTranslationOriginal: true,
|
|
119
|
+
};
|
|
120
|
+
|
|
107
121
|
export const WithLongLink = Template.bind({});
|
|
108
122
|
WithLongLink.args = {
|
|
109
123
|
memori,
|
|
@@ -92,6 +92,25 @@ it('renders ChatBubble with msg generated by AI unchanged', () => {
|
|
|
92
92
|
expect(container).toMatchSnapshot();
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
+
it('renders ChatBubble with translation and original unchanged', () => {
|
|
96
|
+
const { container } = render(
|
|
97
|
+
<ChatBubble
|
|
98
|
+
memori={memori}
|
|
99
|
+
tenant={tenant}
|
|
100
|
+
sessionID={sessionID}
|
|
101
|
+
showTranslationOriginal={true}
|
|
102
|
+
message={{
|
|
103
|
+
fromUser: false,
|
|
104
|
+
text: 'Hello, this is a translated text so you can talk to me in different languages',
|
|
105
|
+
initial: false,
|
|
106
|
+
translatedText:
|
|
107
|
+
'Ciao, questo è un testo tradotto in modo che tu possa parlarmi in diverse lingue',
|
|
108
|
+
}}
|
|
109
|
+
/>
|
|
110
|
+
);
|
|
111
|
+
expect(container).toMatchSnapshot();
|
|
112
|
+
});
|
|
113
|
+
|
|
95
114
|
it('renders ChatBubble with msg from BoE expert unchanged', () => {
|
|
96
115
|
const { container } = render(
|
|
97
116
|
<ChatBubble
|
|
@@ -12,6 +12,7 @@ import { Transition } from '@headlessui/react';
|
|
|
12
12
|
import { getResourceUrl } from '../../helpers/media';
|
|
13
13
|
import UserIcon from '../icons/User';
|
|
14
14
|
import AI from '../icons/AI';
|
|
15
|
+
import Translation from '../icons/Translation';
|
|
15
16
|
import Tooltip from '../ui/Tooltip';
|
|
16
17
|
import FeedbackButtons from '../FeedbackButtons/FeedbackButtons';
|
|
17
18
|
import { useTranslation } from 'react-i18next';
|
|
@@ -39,6 +40,7 @@ export interface Props {
|
|
|
39
40
|
showFeedback?: boolean;
|
|
40
41
|
showWhyThisAnswer?: boolean;
|
|
41
42
|
showCopyButton?: boolean;
|
|
43
|
+
showTranslationOriginal?: boolean;
|
|
42
44
|
simulateUserPrompt?: (msg: string) => void;
|
|
43
45
|
showAIicon?: boolean;
|
|
44
46
|
isFirst?: boolean;
|
|
@@ -86,6 +88,7 @@ const ChatBubble: React.FC<Props> = ({
|
|
|
86
88
|
showFeedback,
|
|
87
89
|
showWhyThisAnswer = true,
|
|
88
90
|
showCopyButton = true,
|
|
91
|
+
showTranslationOriginal = false,
|
|
89
92
|
simulateUserPrompt,
|
|
90
93
|
showAIicon = true,
|
|
91
94
|
isFirst = false,
|
|
@@ -93,15 +96,18 @@ const ChatBubble: React.FC<Props> = ({
|
|
|
93
96
|
userAvatar,
|
|
94
97
|
experts,
|
|
95
98
|
}) => {
|
|
96
|
-
const { t } = useTranslation();
|
|
99
|
+
const { t, i18n } = useTranslation();
|
|
100
|
+
const lang = i18n.language || 'en';
|
|
97
101
|
const [showingWhyThisAnswer, setShowingWhyThisAnswer] = useState(false);
|
|
98
102
|
|
|
103
|
+
const text = message.translatedText || message.text;
|
|
104
|
+
|
|
99
105
|
const renderedText = message.fromUser
|
|
100
|
-
?
|
|
106
|
+
? text
|
|
101
107
|
: DOMPurify.sanitize(
|
|
102
108
|
(
|
|
103
109
|
marked.parse(
|
|
104
|
-
|
|
110
|
+
text
|
|
105
111
|
// remove leading and trailing whitespaces
|
|
106
112
|
.trim()
|
|
107
113
|
// remove markdown links
|
|
@@ -132,10 +138,8 @@ const ChatBubble: React.FC<Props> = ({
|
|
|
132
138
|
.replace(/<p><br><\/p>/g, '<br>');
|
|
133
139
|
|
|
134
140
|
const plainText = message.fromUser
|
|
135
|
-
?
|
|
136
|
-
: escapeHTML(
|
|
137
|
-
stripMarkdown(stripEmojis(message.translatedText || message.text))
|
|
138
|
-
);
|
|
141
|
+
? text
|
|
142
|
+
: escapeHTML(stripMarkdown(stripEmojis(text)));
|
|
139
143
|
|
|
140
144
|
useLayoutEffect(() => {
|
|
141
145
|
if (typeof window !== 'undefined' && !message.fromUser) {
|
|
@@ -313,6 +317,26 @@ const ChatBubble: React.FC<Props> = ({
|
|
|
313
317
|
</Tooltip>
|
|
314
318
|
)}
|
|
315
319
|
|
|
320
|
+
{showTranslationOriginal &&
|
|
321
|
+
message.translatedText &&
|
|
322
|
+
message.translatedText !== message.text && (
|
|
323
|
+
<Tooltip
|
|
324
|
+
align="left"
|
|
325
|
+
content={`${
|
|
326
|
+
lang === 'it' ? 'Testo originale' : 'Original text'
|
|
327
|
+
}: ${message.text}`}
|
|
328
|
+
className="memori-chat--bubble-action-icon memori-chat--bubble-action-icon--ai"
|
|
329
|
+
>
|
|
330
|
+
<span>
|
|
331
|
+
<Translation
|
|
332
|
+
aria-label={
|
|
333
|
+
lang === 'it' ? 'Testo originale' : 'Original text'
|
|
334
|
+
}
|
|
335
|
+
/>
|
|
336
|
+
</span>
|
|
337
|
+
</Tooltip>
|
|
338
|
+
)}
|
|
339
|
+
|
|
316
340
|
{!message.fromUser &&
|
|
317
341
|
message.questionAnswered &&
|
|
318
342
|
apiUrl &&
|
|
@@ -4328,6 +4328,138 @@ exports[`renders ChatBubble with msg generated by AI unchanged 1`] = `
|
|
|
4328
4328
|
</div>
|
|
4329
4329
|
`;
|
|
4330
4330
|
|
|
4331
|
+
exports[`renders ChatBubble with translation and original unchanged 1`] = `
|
|
4332
|
+
<div>
|
|
4333
|
+
<div
|
|
4334
|
+
class="memori-chat--bubble-container"
|
|
4335
|
+
>
|
|
4336
|
+
<picture
|
|
4337
|
+
class="memori-chat--bubble-avatar transition ease-in-out duration-300 opacity-0 scale-075 translate-x--15"
|
|
4338
|
+
title="Memori"
|
|
4339
|
+
>
|
|
4340
|
+
<img
|
|
4341
|
+
alt="Memori"
|
|
4342
|
+
class="memori-chat--bubble-avatar-img"
|
|
4343
|
+
src="https://aisuru.com/images/aisuru/square_logo.png"
|
|
4344
|
+
/>
|
|
4345
|
+
</picture>
|
|
4346
|
+
<div
|
|
4347
|
+
class="memori-chat--bubble memori-chat--with-addon transition ease-in-out duration-300 opacity-0 scale-09 translate-x--30"
|
|
4348
|
+
>
|
|
4349
|
+
<div
|
|
4350
|
+
class="memori-chat--bubble-content"
|
|
4351
|
+
dir="auto"
|
|
4352
|
+
>
|
|
4353
|
+
<p>
|
|
4354
|
+
Ciao, questo è un testo tradotto in modo che tu possa parlarmi in diverse lingue
|
|
4355
|
+
</p>
|
|
4356
|
+
</div>
|
|
4357
|
+
<div
|
|
4358
|
+
class="memori-chat--bubble-addon"
|
|
4359
|
+
>
|
|
4360
|
+
<button
|
|
4361
|
+
class="memori-button memori-button--ghost memori-button--circle memori-button--padded memori-button--icon-only memori-chat--bubble-action-icon"
|
|
4362
|
+
title="copy"
|
|
4363
|
+
>
|
|
4364
|
+
<span
|
|
4365
|
+
class="memori-button--icon"
|
|
4366
|
+
>
|
|
4367
|
+
<svg
|
|
4368
|
+
aria-hidden="true"
|
|
4369
|
+
fill="none"
|
|
4370
|
+
focusable="false"
|
|
4371
|
+
role="img"
|
|
4372
|
+
stroke="currentColor"
|
|
4373
|
+
stroke-linecap="round"
|
|
4374
|
+
stroke-linejoin="round"
|
|
4375
|
+
stroke-width="1.5"
|
|
4376
|
+
viewBox="0 0 24 24"
|
|
4377
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
4378
|
+
>
|
|
4379
|
+
<rect
|
|
4380
|
+
height="14"
|
|
4381
|
+
rx="2"
|
|
4382
|
+
ry="2"
|
|
4383
|
+
width="14"
|
|
4384
|
+
x="8"
|
|
4385
|
+
y="8"
|
|
4386
|
+
/>
|
|
4387
|
+
<path
|
|
4388
|
+
d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"
|
|
4389
|
+
/>
|
|
4390
|
+
</svg>
|
|
4391
|
+
</span>
|
|
4392
|
+
</button>
|
|
4393
|
+
<button
|
|
4394
|
+
class="memori-button memori-button--ghost memori-button--circle memori-button--padded memori-button--icon-only memori-chat--bubble-action-icon"
|
|
4395
|
+
title="copyRawCode"
|
|
4396
|
+
>
|
|
4397
|
+
<span
|
|
4398
|
+
class="memori-button--icon"
|
|
4399
|
+
>
|
|
4400
|
+
<svg
|
|
4401
|
+
aria-hidden="true"
|
|
4402
|
+
fill="none"
|
|
4403
|
+
focusable="false"
|
|
4404
|
+
role="img"
|
|
4405
|
+
stroke="currentColor"
|
|
4406
|
+
stroke-linecap="round"
|
|
4407
|
+
stroke-linejoin="round"
|
|
4408
|
+
stroke-width="1.5"
|
|
4409
|
+
viewBox="0 0 24 24"
|
|
4410
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
4411
|
+
>
|
|
4412
|
+
<path
|
|
4413
|
+
d="M10 9.5 8 12l2 2.5"
|
|
4414
|
+
/>
|
|
4415
|
+
<path
|
|
4416
|
+
d="m14 9.5 2 2.5-2 2.5"
|
|
4417
|
+
/>
|
|
4418
|
+
<rect
|
|
4419
|
+
height="18"
|
|
4420
|
+
rx="2"
|
|
4421
|
+
width="18"
|
|
4422
|
+
x="3"
|
|
4423
|
+
y="3"
|
|
4424
|
+
/>
|
|
4425
|
+
</svg>
|
|
4426
|
+
</span>
|
|
4427
|
+
</button>
|
|
4428
|
+
<div
|
|
4429
|
+
class="memori-tooltip memori-tooltip--align-left memori-chat--bubble-action-icon memori-chat--bubble-action-icon--ai"
|
|
4430
|
+
>
|
|
4431
|
+
<div
|
|
4432
|
+
class="memori-tooltip--content"
|
|
4433
|
+
>
|
|
4434
|
+
Original text: Hello, this is a translated text so you can talk to me in different languages
|
|
4435
|
+
</div>
|
|
4436
|
+
<div
|
|
4437
|
+
class="memori-tooltip--trigger"
|
|
4438
|
+
>
|
|
4439
|
+
<span>
|
|
4440
|
+
<svg
|
|
4441
|
+
aria-hidden="true"
|
|
4442
|
+
focusable="false"
|
|
4443
|
+
role="img"
|
|
4444
|
+
viewBox="0 0 1024 1024"
|
|
4445
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
4446
|
+
>
|
|
4447
|
+
<path
|
|
4448
|
+
d="M140 188h584v164h76V144c0-17.7-14.3-32-32-32H96c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h544v-76H140V188z"
|
|
4449
|
+
/>
|
|
4450
|
+
<path
|
|
4451
|
+
d="M414.3 256h-60.6c-3.4 0-6.4 2.2-7.6 5.4L219 629.4c-.3.8-.4 1.7-.4 2.6 0 4.4 3.6 8 8 8h55.1c3.4 0 6.4-2.2 7.6-5.4L322 540h196.2L422 261.4c-1.3-3.2-4.3-5.4-7.7-5.4zm12.4 228h-85.5L384 360.2 426.7 484zM936 528H800v-93c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v93H592c-13.3 0-24 10.7-24 24v176c0 13.3 10.7 24 24 24h136v152c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V752h136c13.3 0 24-10.7 24-24V552c0-13.3-10.7-24-24-24zM728 680h-88v-80h88v80zm160 0h-88v-80h88v80z"
|
|
4452
|
+
/>
|
|
4453
|
+
</svg>
|
|
4454
|
+
</span>
|
|
4455
|
+
</div>
|
|
4456
|
+
</div>
|
|
4457
|
+
</div>
|
|
4458
|
+
</div>
|
|
4459
|
+
</div>
|
|
4460
|
+
</div>
|
|
4461
|
+
`;
|
|
4462
|
+
|
|
4331
4463
|
exports[`renders ChatBubble with user msg unchanged 1`] = `
|
|
4332
4464
|
<div>
|
|
4333
4465
|
<div
|
|
@@ -338,6 +338,7 @@ export interface Props {
|
|
|
338
338
|
customLayout?: React.FC<LayoutProps>;
|
|
339
339
|
showShare?: boolean;
|
|
340
340
|
showCopyButton?: boolean;
|
|
341
|
+
showTranslationOriginal?: boolean;
|
|
341
342
|
showInstruct?: boolean;
|
|
342
343
|
showInputs?: boolean;
|
|
343
344
|
showDates?: boolean;
|
|
@@ -390,6 +391,7 @@ const MemoriWidget = ({
|
|
|
390
391
|
preview = false,
|
|
391
392
|
embed = false,
|
|
392
393
|
showCopyButton = true,
|
|
394
|
+
showTranslationOriginal = false,
|
|
393
395
|
showInputs = true,
|
|
394
396
|
showDates = false,
|
|
395
397
|
showContextPerLine = false,
|
|
@@ -473,10 +475,8 @@ const MemoriWidget = ({
|
|
|
473
475
|
const integrationConfig = integration?.customData
|
|
474
476
|
? JSON.parse(integration.customData)
|
|
475
477
|
: null;
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
? multilingual
|
|
479
|
-
: !!integrationConfig?.multilanguage;
|
|
478
|
+
|
|
479
|
+
const isMultilanguageEnabled = multilingual !== undefined ? multilingual : !!integrationConfig?.multilanguage;
|
|
480
480
|
const forcedTimeout = integrationConfig?.forcedTimeout as number | undefined;
|
|
481
481
|
const [userLang, setUserLang] = useState(
|
|
482
482
|
memoriLang ??
|
|
@@ -668,6 +668,7 @@ const MemoriWidget = ({
|
|
|
668
668
|
|
|
669
669
|
try {
|
|
670
670
|
if (
|
|
671
|
+
!hidden &&
|
|
671
672
|
translate &&
|
|
672
673
|
!instruct &&
|
|
673
674
|
isMultilanguageEnabled &&
|
|
@@ -773,8 +774,9 @@ const MemoriWidget = ({
|
|
|
773
774
|
isMultilanguageEnabled
|
|
774
775
|
) {
|
|
775
776
|
translateDialogState(currentState, userLang, msg).then(ts => {
|
|
776
|
-
|
|
777
|
-
|
|
777
|
+
let text = ts.translatedEmission || ts.emission;
|
|
778
|
+
if (text) {
|
|
779
|
+
speak(text);
|
|
778
780
|
}
|
|
779
781
|
});
|
|
780
782
|
} else {
|
|
@@ -881,45 +883,66 @@ const MemoriWidget = ({
|
|
|
881
883
|
};
|
|
882
884
|
}
|
|
883
885
|
} else {
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
886
|
+
try {
|
|
887
|
+
const t = await getTranslation(emission, userLang, language, baseUrl);
|
|
888
|
+
if (state.hints && state.hints.length > 0) {
|
|
889
|
+
const translatedHints = await Promise.all(
|
|
890
|
+
(state.hints ?? []).map(async hint => {
|
|
891
|
+
const tHint = await getTranslation(
|
|
892
|
+
hint,
|
|
893
|
+
userLang,
|
|
894
|
+
language,
|
|
895
|
+
baseUrl
|
|
896
|
+
);
|
|
897
|
+
return {
|
|
898
|
+
text: tHint?.text ?? hint,
|
|
899
|
+
originalText: hint,
|
|
900
|
+
} as TranslatedHint;
|
|
901
|
+
})
|
|
902
|
+
);
|
|
903
|
+
translatedState = {
|
|
904
|
+
...state,
|
|
905
|
+
emission: t.text,
|
|
906
|
+
translatedHints,
|
|
907
|
+
};
|
|
908
|
+
} else {
|
|
909
|
+
translatedState = {
|
|
910
|
+
...state,
|
|
911
|
+
emission: emission,
|
|
912
|
+
translatedEmission: t.text,
|
|
913
|
+
hints:
|
|
914
|
+
state.hints ??
|
|
915
|
+
(state.state === 'G1' ? currentDialogState?.hints : []),
|
|
916
|
+
};
|
|
917
|
+
}
|
|
914
918
|
|
|
915
|
-
|
|
919
|
+
if (t.text.length > 0)
|
|
920
|
+
translatedMsg = {
|
|
921
|
+
text: emission,
|
|
922
|
+
translatedText: t.text,
|
|
923
|
+
emitter: state.emitter,
|
|
924
|
+
media: state.media,
|
|
925
|
+
fromUser: false,
|
|
926
|
+
questionAnswered: msg,
|
|
927
|
+
generatedByAI: !!state.completion,
|
|
928
|
+
contextVars: state.contextVars,
|
|
929
|
+
date: state.currentDate,
|
|
930
|
+
placeName: state.currentPlaceName,
|
|
931
|
+
placeLatitude: state.currentLatitude,
|
|
932
|
+
placeLongitude: state.currentLongitude,
|
|
933
|
+
placeUncertaintyKm: state.currentUncertaintyKm,
|
|
934
|
+
tag: state.currentTag,
|
|
935
|
+
memoryTags: state.memoryTags,
|
|
936
|
+
};
|
|
937
|
+
} catch (error) {
|
|
938
|
+
console.error(error);
|
|
939
|
+
translatedState = { ...state, emission };
|
|
916
940
|
translatedMsg = {
|
|
917
|
-
text:
|
|
941
|
+
text: emission,
|
|
918
942
|
emitter: state.emitter,
|
|
919
943
|
media: state.media,
|
|
920
944
|
fromUser: false,
|
|
921
945
|
questionAnswered: msg,
|
|
922
|
-
generatedByAI: !!state.completion,
|
|
923
946
|
contextVars: state.contextVars,
|
|
924
947
|
date: state.currentDate,
|
|
925
948
|
placeName: state.currentPlaceName,
|
|
@@ -929,6 +952,7 @@ const MemoriWidget = ({
|
|
|
929
952
|
tag: state.currentTag,
|
|
930
953
|
memoryTags: state.memoryTags,
|
|
931
954
|
};
|
|
955
|
+
}
|
|
932
956
|
}
|
|
933
957
|
|
|
934
958
|
setCurrentDialogState(translatedState);
|
|
@@ -1453,8 +1477,9 @@ const MemoriWidget = ({
|
|
|
1453
1477
|
{ ...currentState, emission: emission },
|
|
1454
1478
|
userLang
|
|
1455
1479
|
).then(ts => {
|
|
1456
|
-
|
|
1457
|
-
|
|
1480
|
+
let text = ts.translatedEmission || ts.emission;
|
|
1481
|
+
if (text) {
|
|
1482
|
+
speak(text);
|
|
1458
1483
|
}
|
|
1459
1484
|
});
|
|
1460
1485
|
} else if (emission && emission.length > 0) {
|
|
@@ -2589,8 +2614,9 @@ const MemoriWidget = ({
|
|
|
2589
2614
|
|
|
2590
2615
|
translateDialogState(session.dialogState, userLang)
|
|
2591
2616
|
.then(ts => {
|
|
2592
|
-
|
|
2593
|
-
|
|
2617
|
+
let text = ts.translatedEmission || ts.emission;
|
|
2618
|
+
if (text) {
|
|
2619
|
+
speak(text);
|
|
2594
2620
|
}
|
|
2595
2621
|
})
|
|
2596
2622
|
.finally(() => {
|
|
@@ -2646,8 +2672,9 @@ const MemoriWidget = ({
|
|
|
2646
2672
|
if (session && session.resultCode === 0) {
|
|
2647
2673
|
translateDialogState(session.currentState, userLang)
|
|
2648
2674
|
.then(ts => {
|
|
2649
|
-
|
|
2650
|
-
|
|
2675
|
+
let text = ts.translatedEmission || ts.emission;
|
|
2676
|
+
if (text) {
|
|
2677
|
+
speak(text);
|
|
2651
2678
|
}
|
|
2652
2679
|
})
|
|
2653
2680
|
.finally(() => {
|
|
@@ -2699,8 +2726,9 @@ const MemoriWidget = ({
|
|
|
2699
2726
|
if (session && session.resultCode === 0) {
|
|
2700
2727
|
translateDialogState(session.currentState, userLang)
|
|
2701
2728
|
.then(ts => {
|
|
2702
|
-
|
|
2703
|
-
|
|
2729
|
+
let text = ts.translatedEmission || ts.emission;
|
|
2730
|
+
if (text) {
|
|
2731
|
+
speak(text);
|
|
2704
2732
|
}
|
|
2705
2733
|
})
|
|
2706
2734
|
.finally(() => {
|
|
@@ -2752,8 +2780,9 @@ const MemoriWidget = ({
|
|
|
2752
2780
|
if (session && session.resultCode === 0) {
|
|
2753
2781
|
translateDialogState(session.currentState, userLang)
|
|
2754
2782
|
.then(ts => {
|
|
2755
|
-
|
|
2756
|
-
|
|
2783
|
+
let text = ts.translatedEmission || ts.emission;
|
|
2784
|
+
if (text) {
|
|
2785
|
+
speak(text);
|
|
2757
2786
|
}
|
|
2758
2787
|
})
|
|
2759
2788
|
.finally(() => {
|
|
@@ -2788,8 +2817,9 @@ const MemoriWidget = ({
|
|
|
2788
2817
|
// no need to change tag
|
|
2789
2818
|
translateDialogState(currentState, userLang)
|
|
2790
2819
|
.then(ts => {
|
|
2791
|
-
|
|
2792
|
-
|
|
2820
|
+
let text = ts.translatedEmission || ts.emission;
|
|
2821
|
+
if (text) {
|
|
2822
|
+
speak(text);
|
|
2793
2823
|
}
|
|
2794
2824
|
})
|
|
2795
2825
|
.finally(() => {
|
|
@@ -2808,8 +2838,9 @@ const MemoriWidget = ({
|
|
|
2808
2838
|
// everything is fine, just translate dialog state and activate chat
|
|
2809
2839
|
translateDialogState(dialogState!, userLang)
|
|
2810
2840
|
.then(ts => {
|
|
2811
|
-
|
|
2812
|
-
|
|
2841
|
+
let text = ts.translatedEmission || ts.emission;
|
|
2842
|
+
if (text) {
|
|
2843
|
+
speak(text);
|
|
2813
2844
|
}
|
|
2814
2845
|
})
|
|
2815
2846
|
.finally(() => {
|
|
@@ -2998,6 +3029,7 @@ const MemoriWidget = ({
|
|
|
2998
3029
|
instruct: instruct,
|
|
2999
3030
|
sessionId: sessionId,
|
|
3000
3031
|
clickedStart: clickedStart,
|
|
3032
|
+
isMultilanguageEnabled: isMultilanguageEnabled,
|
|
3001
3033
|
onClickStart: onClickStart,
|
|
3002
3034
|
initializeTTS: initializeTTS,
|
|
3003
3035
|
isUserLoggedIn: !!loginToken && !!user?.userID,
|
|
@@ -3039,6 +3071,7 @@ const MemoriWidget = ({
|
|
|
3039
3071
|
showAIicon,
|
|
3040
3072
|
showWhyThisAnswer,
|
|
3041
3073
|
showCopyButton,
|
|
3074
|
+
showTranslationOriginal,
|
|
3042
3075
|
client,
|
|
3043
3076
|
selectReceiverTag,
|
|
3044
3077
|
preview,
|
|
@@ -238,6 +238,26 @@ it('renders StartPanel with integrationConfig unchanged', () => {
|
|
|
238
238
|
expect(container).toMatchSnapshot();
|
|
239
239
|
});
|
|
240
240
|
|
|
241
|
+
it('renders StartPanel with multilangual unchanged', () => {
|
|
242
|
+
const { container } = render(
|
|
243
|
+
<StartPanel
|
|
244
|
+
memori={memori}
|
|
245
|
+
tenant={tenant}
|
|
246
|
+
isMultilanguageEnabled
|
|
247
|
+
language="it"
|
|
248
|
+
userLang="en"
|
|
249
|
+
setUserLang={() => {}}
|
|
250
|
+
openPositionDrawer={() => {}}
|
|
251
|
+
instruct={false}
|
|
252
|
+
sessionId={sessionID}
|
|
253
|
+
clickedStart={false}
|
|
254
|
+
onClickStart={() => {}}
|
|
255
|
+
setShowLoginDrawer={jest.fn()}
|
|
256
|
+
/>
|
|
257
|
+
);
|
|
258
|
+
expect(container).toMatchSnapshot();
|
|
259
|
+
});
|
|
260
|
+
|
|
241
261
|
it('renders StartPanel with completion provider down unchanged', () => {
|
|
242
262
|
const { container } = render(
|
|
243
263
|
<StartPanel
|
|
@@ -45,6 +45,7 @@ export interface Props {
|
|
|
45
45
|
showLogin?: boolean;
|
|
46
46
|
setShowLoginDrawer: (show: boolean) => void;
|
|
47
47
|
notEnoughCredits?: boolean;
|
|
48
|
+
isMultilanguageEnabled?: boolean | undefined;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
const StartPanel: React.FC<Props> = ({
|
|
@@ -58,7 +59,6 @@ const StartPanel: React.FC<Props> = ({
|
|
|
58
59
|
apiUrl,
|
|
59
60
|
position,
|
|
60
61
|
openPositionDrawer,
|
|
61
|
-
integrationConfig,
|
|
62
62
|
instruct = false,
|
|
63
63
|
clickedStart,
|
|
64
64
|
onClickStart,
|
|
@@ -69,6 +69,7 @@ const StartPanel: React.FC<Props> = ({
|
|
|
69
69
|
showLogin = false,
|
|
70
70
|
setShowLoginDrawer,
|
|
71
71
|
notEnoughCredits = false,
|
|
72
|
+
isMultilanguageEnabled
|
|
72
73
|
}) => {
|
|
73
74
|
const { t, i18n } = useTranslation();
|
|
74
75
|
const [translatedDescription, setTranslatedDescription] = useState(
|
|
@@ -233,7 +234,7 @@ const StartPanel: React.FC<Props> = ({
|
|
|
233
234
|
)}
|
|
234
235
|
</p>
|
|
235
236
|
|
|
236
|
-
{
|
|
237
|
+
{isMultilanguageEnabled && !instruct && (
|
|
237
238
|
<div className="memori--language-chooser">
|
|
238
239
|
<label id="user-lang-pref-label" htmlFor="user-lang-pref">
|
|
239
240
|
{t('write_and_speak.iWantToTalkToIn', {
|