@memori.ai/memori-react 7.2.0 → 7.3.0
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 +17 -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 +75 -42
- package/dist/components/MemoriWidget/MemoriWidget.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 +75 -42
- package/esm/components/MemoriWidget/MemoriWidget.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 +83 -49
- package/src/helpers/translations.ts +10 -2
- package/src/index.stories.tsx +3 -17
- package/src/index.tsx +4 -0
|
@@ -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,
|
|
@@ -668,6 +670,7 @@ const MemoriWidget = ({
|
|
|
668
670
|
|
|
669
671
|
try {
|
|
670
672
|
if (
|
|
673
|
+
!hidden &&
|
|
671
674
|
translate &&
|
|
672
675
|
!instruct &&
|
|
673
676
|
isMultilanguageEnabled &&
|
|
@@ -773,8 +776,9 @@ const MemoriWidget = ({
|
|
|
773
776
|
isMultilanguageEnabled
|
|
774
777
|
) {
|
|
775
778
|
translateDialogState(currentState, userLang, msg).then(ts => {
|
|
776
|
-
|
|
777
|
-
|
|
779
|
+
let text = ts.translatedEmission || ts.emission;
|
|
780
|
+
if (text) {
|
|
781
|
+
speak(text);
|
|
778
782
|
}
|
|
779
783
|
});
|
|
780
784
|
} else {
|
|
@@ -881,45 +885,66 @@ const MemoriWidget = ({
|
|
|
881
885
|
};
|
|
882
886
|
}
|
|
883
887
|
} 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
|
-
|
|
888
|
+
try {
|
|
889
|
+
const t = await getTranslation(emission, userLang, language, baseUrl);
|
|
890
|
+
if (state.hints && state.hints.length > 0) {
|
|
891
|
+
const translatedHints = await Promise.all(
|
|
892
|
+
(state.hints ?? []).map(async hint => {
|
|
893
|
+
const tHint = await getTranslation(
|
|
894
|
+
hint,
|
|
895
|
+
userLang,
|
|
896
|
+
language,
|
|
897
|
+
baseUrl
|
|
898
|
+
);
|
|
899
|
+
return {
|
|
900
|
+
text: tHint?.text ?? hint,
|
|
901
|
+
originalText: hint,
|
|
902
|
+
} as TranslatedHint;
|
|
903
|
+
})
|
|
904
|
+
);
|
|
905
|
+
translatedState = {
|
|
906
|
+
...state,
|
|
907
|
+
emission: t.text,
|
|
908
|
+
translatedHints,
|
|
909
|
+
};
|
|
910
|
+
} else {
|
|
911
|
+
translatedState = {
|
|
912
|
+
...state,
|
|
913
|
+
emission: emission,
|
|
914
|
+
translatedEmission: t.text,
|
|
915
|
+
hints:
|
|
916
|
+
state.hints ??
|
|
917
|
+
(state.state === 'G1' ? currentDialogState?.hints : []),
|
|
918
|
+
};
|
|
919
|
+
}
|
|
914
920
|
|
|
915
|
-
|
|
921
|
+
if (t.text.length > 0)
|
|
922
|
+
translatedMsg = {
|
|
923
|
+
text: emission,
|
|
924
|
+
translatedText: t.text,
|
|
925
|
+
emitter: state.emitter,
|
|
926
|
+
media: state.media,
|
|
927
|
+
fromUser: false,
|
|
928
|
+
questionAnswered: msg,
|
|
929
|
+
generatedByAI: !!state.completion,
|
|
930
|
+
contextVars: state.contextVars,
|
|
931
|
+
date: state.currentDate,
|
|
932
|
+
placeName: state.currentPlaceName,
|
|
933
|
+
placeLatitude: state.currentLatitude,
|
|
934
|
+
placeLongitude: state.currentLongitude,
|
|
935
|
+
placeUncertaintyKm: state.currentUncertaintyKm,
|
|
936
|
+
tag: state.currentTag,
|
|
937
|
+
memoryTags: state.memoryTags,
|
|
938
|
+
};
|
|
939
|
+
} catch (error) {
|
|
940
|
+
console.error(error);
|
|
941
|
+
translatedState = { ...state, emission };
|
|
916
942
|
translatedMsg = {
|
|
917
|
-
text:
|
|
943
|
+
text: emission,
|
|
918
944
|
emitter: state.emitter,
|
|
919
945
|
media: state.media,
|
|
920
946
|
fromUser: false,
|
|
921
947
|
questionAnswered: msg,
|
|
922
|
-
generatedByAI: !!state.completion,
|
|
923
948
|
contextVars: state.contextVars,
|
|
924
949
|
date: state.currentDate,
|
|
925
950
|
placeName: state.currentPlaceName,
|
|
@@ -929,6 +954,7 @@ const MemoriWidget = ({
|
|
|
929
954
|
tag: state.currentTag,
|
|
930
955
|
memoryTags: state.memoryTags,
|
|
931
956
|
};
|
|
957
|
+
}
|
|
932
958
|
}
|
|
933
959
|
|
|
934
960
|
setCurrentDialogState(translatedState);
|
|
@@ -1453,8 +1479,9 @@ const MemoriWidget = ({
|
|
|
1453
1479
|
{ ...currentState, emission: emission },
|
|
1454
1480
|
userLang
|
|
1455
1481
|
).then(ts => {
|
|
1456
|
-
|
|
1457
|
-
|
|
1482
|
+
let text = ts.translatedEmission || ts.emission;
|
|
1483
|
+
if (text) {
|
|
1484
|
+
speak(text);
|
|
1458
1485
|
}
|
|
1459
1486
|
});
|
|
1460
1487
|
} else if (emission && emission.length > 0) {
|
|
@@ -2589,8 +2616,9 @@ const MemoriWidget = ({
|
|
|
2589
2616
|
|
|
2590
2617
|
translateDialogState(session.dialogState, userLang)
|
|
2591
2618
|
.then(ts => {
|
|
2592
|
-
|
|
2593
|
-
|
|
2619
|
+
let text = ts.translatedEmission || ts.emission;
|
|
2620
|
+
if (text) {
|
|
2621
|
+
speak(text);
|
|
2594
2622
|
}
|
|
2595
2623
|
})
|
|
2596
2624
|
.finally(() => {
|
|
@@ -2646,8 +2674,9 @@ const MemoriWidget = ({
|
|
|
2646
2674
|
if (session && session.resultCode === 0) {
|
|
2647
2675
|
translateDialogState(session.currentState, userLang)
|
|
2648
2676
|
.then(ts => {
|
|
2649
|
-
|
|
2650
|
-
|
|
2677
|
+
let text = ts.translatedEmission || ts.emission;
|
|
2678
|
+
if (text) {
|
|
2679
|
+
speak(text);
|
|
2651
2680
|
}
|
|
2652
2681
|
})
|
|
2653
2682
|
.finally(() => {
|
|
@@ -2699,8 +2728,9 @@ const MemoriWidget = ({
|
|
|
2699
2728
|
if (session && session.resultCode === 0) {
|
|
2700
2729
|
translateDialogState(session.currentState, userLang)
|
|
2701
2730
|
.then(ts => {
|
|
2702
|
-
|
|
2703
|
-
|
|
2731
|
+
let text = ts.translatedEmission || ts.emission;
|
|
2732
|
+
if (text) {
|
|
2733
|
+
speak(text);
|
|
2704
2734
|
}
|
|
2705
2735
|
})
|
|
2706
2736
|
.finally(() => {
|
|
@@ -2752,8 +2782,9 @@ const MemoriWidget = ({
|
|
|
2752
2782
|
if (session && session.resultCode === 0) {
|
|
2753
2783
|
translateDialogState(session.currentState, userLang)
|
|
2754
2784
|
.then(ts => {
|
|
2755
|
-
|
|
2756
|
-
|
|
2785
|
+
let text = ts.translatedEmission || ts.emission;
|
|
2786
|
+
if (text) {
|
|
2787
|
+
speak(text);
|
|
2757
2788
|
}
|
|
2758
2789
|
})
|
|
2759
2790
|
.finally(() => {
|
|
@@ -2788,8 +2819,9 @@ const MemoriWidget = ({
|
|
|
2788
2819
|
// no need to change tag
|
|
2789
2820
|
translateDialogState(currentState, userLang)
|
|
2790
2821
|
.then(ts => {
|
|
2791
|
-
|
|
2792
|
-
|
|
2822
|
+
let text = ts.translatedEmission || ts.emission;
|
|
2823
|
+
if (text) {
|
|
2824
|
+
speak(text);
|
|
2793
2825
|
}
|
|
2794
2826
|
})
|
|
2795
2827
|
.finally(() => {
|
|
@@ -2808,8 +2840,9 @@ const MemoriWidget = ({
|
|
|
2808
2840
|
// everything is fine, just translate dialog state and activate chat
|
|
2809
2841
|
translateDialogState(dialogState!, userLang)
|
|
2810
2842
|
.then(ts => {
|
|
2811
|
-
|
|
2812
|
-
|
|
2843
|
+
let text = ts.translatedEmission || ts.emission;
|
|
2844
|
+
if (text) {
|
|
2845
|
+
speak(text);
|
|
2813
2846
|
}
|
|
2814
2847
|
})
|
|
2815
2848
|
.finally(() => {
|
|
@@ -3039,6 +3072,7 @@ const MemoriWidget = ({
|
|
|
3039
3072
|
showAIicon,
|
|
3040
3073
|
showWhyThisAnswer,
|
|
3041
3074
|
showCopyButton,
|
|
3075
|
+
showTranslationOriginal,
|
|
3042
3076
|
client,
|
|
3043
3077
|
selectReceiverTag,
|
|
3044
3078
|
preview,
|
|
@@ -14,17 +14,25 @@ export const dialogKeywords = [
|
|
|
14
14
|
'non mi è piaciuto',
|
|
15
15
|
];
|
|
16
16
|
|
|
17
|
+
const stripOutputTags = (text: string) => {
|
|
18
|
+
return text.replaceAll(/<output.*?>(.*?)<\/output>/g, '');
|
|
19
|
+
};
|
|
20
|
+
|
|
17
21
|
export const getTranslation = async (
|
|
18
22
|
text: string,
|
|
19
23
|
to: string,
|
|
20
24
|
from?: string,
|
|
21
25
|
baseUrl?: string
|
|
22
26
|
): Promise<DeeplTranslation> => {
|
|
27
|
+
let textToTranslate = stripOutputTags(text);
|
|
28
|
+
|
|
23
29
|
const isReservedKeyword = dialogKeywords.indexOf(text.toLowerCase()) > -1;
|
|
24
30
|
const fromLanguage = isReservedKeyword ? 'IT' : from?.toUpperCase();
|
|
25
31
|
const deeplResult = await fetch(
|
|
26
|
-
`${
|
|
27
|
-
|
|
32
|
+
`${
|
|
33
|
+
baseUrl || 'https://www.aisuru.com'
|
|
34
|
+
}/api/translate?text=${encodeURIComponent(
|
|
35
|
+
textToTranslate
|
|
28
36
|
)}&target_lang=${to.toUpperCase()}${
|
|
29
37
|
fromLanguage ? `&source_lang=${fromLanguage}` : ''
|
|
30
38
|
}`,
|
package/src/index.stories.tsx
CHANGED
|
@@ -30,7 +30,7 @@ Anonymous.args = {
|
|
|
30
30
|
memoriName: 'Nicola',
|
|
31
31
|
tenantID: 'aisuru.com',
|
|
32
32
|
apiURL: 'https://backend.memori.ai',
|
|
33
|
-
baseURL: 'https://aisuru.com',
|
|
33
|
+
baseURL: 'https://www.aisuru.com',
|
|
34
34
|
uiLang: 'it',
|
|
35
35
|
showShare: true,
|
|
36
36
|
showSettings: true,
|
|
@@ -82,20 +82,6 @@ Staging.args = {
|
|
|
82
82
|
layout: 'FULLPAGE',
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
export const StagingTokenized = Template.bind({});
|
|
86
|
-
StagingTokenized.args = {
|
|
87
|
-
memoriName: 'Test',
|
|
88
|
-
ownerUserName: 'nicola',
|
|
89
|
-
memoriID: '36798f8a-7018-4cf7-9be4-e681949a46a3',
|
|
90
|
-
ownerUserID: '585ec0ff-e805-495e-b8fc-5b0b8dd288ff',
|
|
91
|
-
tenantID: 'aisuru-staging-tokenized.aclambda.online',
|
|
92
|
-
apiURL: 'https://backend-staging.memori.ai',
|
|
93
|
-
baseURL: 'https://aisuru-staging-tokenized.aclambda.online',
|
|
94
|
-
uiLang: 'EN',
|
|
95
|
-
lang: 'IT',
|
|
96
|
-
layout: 'FULLPAGE',
|
|
97
|
-
};
|
|
98
|
-
|
|
99
85
|
const TemplateWithBatchButton: Story<Props> = args => (
|
|
100
86
|
<div>
|
|
101
87
|
<button
|
|
@@ -136,7 +122,7 @@ WithBatch.args = {
|
|
|
136
122
|
memoriName: 'Nicola',
|
|
137
123
|
tenantID: 'aisuru.com',
|
|
138
124
|
apiURL: 'https://backend.memori.ai',
|
|
139
|
-
baseURL: 'https://aisuru.com',
|
|
125
|
+
baseURL: 'https://www.aisuru.com',
|
|
140
126
|
uiLang: 'it',
|
|
141
127
|
showShare: true,
|
|
142
128
|
showSettings: true,
|
|
@@ -148,7 +134,7 @@ WithCustomUserAvatar.args = {
|
|
|
148
134
|
memoriName: 'Nicola',
|
|
149
135
|
tenantID: 'aisuru.com',
|
|
150
136
|
apiURL: 'https://backend.memori.ai',
|
|
151
|
-
baseURL: 'https://aisuru.com',
|
|
137
|
+
baseURL: 'https://www.aisuru.com',
|
|
152
138
|
uiLang: 'it',
|
|
153
139
|
showShare: true,
|
|
154
140
|
showSettings: true,
|
package/src/index.tsx
CHANGED
|
@@ -29,6 +29,7 @@ export interface Props {
|
|
|
29
29
|
customLayout?: WidgetProps['customLayout'];
|
|
30
30
|
showShare?: boolean;
|
|
31
31
|
showCopyButton?: boolean;
|
|
32
|
+
showTranslationOriginal?: boolean;
|
|
32
33
|
showInstruct?: boolean;
|
|
33
34
|
showInputs?: boolean;
|
|
34
35
|
showDates?: boolean;
|
|
@@ -90,6 +91,7 @@ const Memori: React.FC<Props> = ({
|
|
|
90
91
|
customLayout,
|
|
91
92
|
showShare = true,
|
|
92
93
|
showCopyButton = true,
|
|
94
|
+
showTranslationOriginal = false,
|
|
93
95
|
showSettings = true,
|
|
94
96
|
showInstruct = false,
|
|
95
97
|
showTypingText = false,
|
|
@@ -242,6 +244,7 @@ const Memori: React.FC<Props> = ({
|
|
|
242
244
|
sessionID={sessionID}
|
|
243
245
|
showShare={showShare}
|
|
244
246
|
showCopyButton={showCopyButton}
|
|
247
|
+
showTranslationOriginal={showTranslationOriginal}
|
|
245
248
|
showSettings={showSettings}
|
|
246
249
|
showInstruct={showInstruct}
|
|
247
250
|
showTypingText={showTypingText}
|
|
@@ -318,6 +321,7 @@ Memori.propTypes = {
|
|
|
318
321
|
customLayout: PropTypes.any,
|
|
319
322
|
showShare: PropTypes.bool,
|
|
320
323
|
showCopyButton: PropTypes.bool,
|
|
324
|
+
showTranslationOriginal: PropTypes.bool,
|
|
321
325
|
showInstruct: PropTypes.bool,
|
|
322
326
|
showInputs: PropTypes.bool,
|
|
323
327
|
showDates: PropTypes.bool,
|