@memori.ai/memori-react 8.14.0 → 8.14.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/components/Chat/Chat.js +21 -11
  3. package/dist/components/Chat/Chat.js.map +1 -1
  4. package/dist/components/ChatInputs/ChatInputs.css +0 -1
  5. package/dist/components/MediaWidget/MediaItemWidget.js +4 -2
  6. package/dist/components/MediaWidget/MediaItemWidget.js.map +1 -1
  7. package/dist/components/MemoriWidget/MemoriWidget.css +4 -2
  8. package/dist/components/MemoriWidget/MemoriWidget.js +16 -16
  9. package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
  10. package/dist/components/PoweredBy/PoweredBy.css +3 -2
  11. package/dist/components/layouts/website-assistant.css +1 -0
  12. package/dist/helpers/translations.d.ts +1 -1
  13. package/dist/helpers/translations.js +2 -20
  14. package/dist/helpers/translations.js.map +1 -1
  15. package/esm/components/Chat/Chat.js +22 -12
  16. package/esm/components/Chat/Chat.js.map +1 -1
  17. package/esm/components/ChatInputs/ChatInputs.css +0 -1
  18. package/esm/components/MediaWidget/MediaItemWidget.js +4 -2
  19. package/esm/components/MediaWidget/MediaItemWidget.js.map +1 -1
  20. package/esm/components/MemoriWidget/MemoriWidget.css +4 -2
  21. package/esm/components/MemoriWidget/MemoriWidget.js +16 -16
  22. package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
  23. package/esm/components/PoweredBy/PoweredBy.css +3 -2
  24. package/esm/components/layouts/website-assistant.css +1 -0
  25. package/esm/helpers/translations.d.ts +1 -1
  26. package/esm/helpers/translations.js +2 -20
  27. package/esm/helpers/translations.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/components/Chat/Chat.tsx +33 -13
  30. package/src/components/Chat/__snapshots__/Chat.test.tsx.snap +343 -275
  31. package/src/components/ChatInputs/ChatInputs.css +0 -1
  32. package/src/components/MediaWidget/MediaItemWidget.tsx +9 -2
  33. package/src/components/MemoriWidget/MemoriWidget.css +4 -2
  34. package/src/components/MemoriWidget/MemoriWidget.tsx +4 -4
  35. package/src/components/PoweredBy/PoweredBy.css +3 -2
  36. package/src/components/layouts/layouts.stories.tsx +29 -3
  37. package/src/components/layouts/website-assistant.css +1 -0
  38. package/src/helpers/translations.ts +2 -25
@@ -4,14 +4,15 @@
4
4
  bottom: 1rem;
5
5
  left: 0;
6
6
  display: inline-flex;
7
- flex-wrap: wrap;
7
+ flex-wrap: nowrap;
8
8
  align-items: center;
9
- padding: 0.25rem 0.5rem;
9
+ padding: 0.25rem 1rem;
10
10
  border-radius: 10px;
11
11
  background-color: var(--memori-inner-bg, transparent);
12
12
  box-shadow: var(--memori-button-box-shadow);
13
13
  color: var(--memori-text-color, rgba(0, 0, 0, 0.85)) !important;
14
14
  font-size: 0.7em;
15
+ white-space: nowrap;
15
16
  }
16
17
 
17
18
  @media (max-width: 768px) {
@@ -114,6 +114,7 @@
114
114
  top: calc(100% + 10px);
115
115
  right: auto;
116
116
  left: 0;
117
+ background-color: transparent !important;
117
118
  }
118
119
 
119
120
  .memori-widget.memori-layout-website_assistant {
@@ -3,4 +3,4 @@ export type DeeplTranslation = {
3
3
  text: string;
4
4
  };
5
5
  export declare const dialogKeywords: string[];
6
- export declare const getTranslation: (text: string, to: string, from?: string, baseUrl?: string) => Promise<DeeplTranslation>;
6
+ export declare const getTranslation: (text: string, to: string, from?: string, _baseUrl?: string) => Promise<DeeplTranslation>;
@@ -14,30 +14,12 @@ const stripOutputTags = (text) => {
14
14
  const stripThinkTags = (text) => {
15
15
  return text.replaceAll(/<think.*?>(.*?)<\/think>/gs, '');
16
16
  };
17
- export const getTranslation = async (text, to, from, baseUrl) => {
18
- var _a, _b, _c, _d;
17
+ export const getTranslation = async (text, to, from, _baseUrl) => {
19
18
  let textToTranslate = stripOutputTags(stripThinkTags(text));
20
19
  const justTheThinkTags = text.match(/<think.*?>(.*?)<\/think>/gs);
21
20
  const isReservedKeyword = dialogKeywords.indexOf(text.toLowerCase()) > -1;
22
21
  const fromLanguage = isReservedKeyword ? 'IT' : from === null || from === void 0 ? void 0 : from.toUpperCase();
23
22
  const toLanguage = to.toUpperCase();
24
- const deeplResult = await fetch(`${baseUrl || 'https://www.aisuru.com'}/api/translate`, {
25
- cache: 'no-cache',
26
- method: 'POST',
27
- body: JSON.stringify({
28
- text: textToTranslate,
29
- target_lang: toLanguage,
30
- source_lang: fromLanguage,
31
- }),
32
- headers: {
33
- Accept: '*/*',
34
- 'Content-Type': 'application/json',
35
- },
36
- });
37
- const deeplResponse = await deeplResult.json();
38
- if (deeplResponse && deeplResponse.translations && deeplResponse.translations[0]) {
39
- deeplResponse.translations[0].text = (justTheThinkTags ? `<think>${justTheThinkTags}</think>` : '') + ((_b = (_a = deeplResponse === null || deeplResponse === void 0 ? void 0 : deeplResponse.translations) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.text);
40
- }
41
- return (_d = (_c = deeplResponse === null || deeplResponse === void 0 ? void 0 : deeplResponse.translations) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : { text: textToTranslate };
23
+ return Promise.resolve({ text: textToTranslate });
42
24
  };
43
25
  //# sourceMappingURL=translations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"translations.js","sourceRoot":"","sources":["../../src/helpers/translations.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,SAAS;IACT,WAAW;IACX,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,aAAa;IACb,eAAe;IACf,mBAAmB;CACpB,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,EAAE;IACvC,OAAO,IAAI,CAAC,UAAU,CAAC,6BAA6B,EAAE,EAAE,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,EAAE;IACtC,OAAO,IAAI,CAAC,UAAU,CAAC,4B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,MAAM,UAAU,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;IAEpC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,eAAe,EAAsB,CAAC,CAAC;AACxE,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "8.14.0",
2
+ "version": "8.14.2",
3
3
  "name": "@memori.ai/memori-react",
4
4
  "author": "Memori Srl",
5
5
  "main": "dist/index.js",
@@ -1,4 +1,4 @@
1
- import React, { useEffect, memo, useState } from 'react';
1
+ import React, { useCallback, useEffect, memo, useRef, useState } from 'react';
2
2
  import cx from 'classnames';
3
3
  import {
4
4
  DialogState,
@@ -129,18 +129,32 @@ const Chat: React.FC<Props> = ({
129
129
  const [isTextareaExpanded, setIsTextareaExpanded] = useState(false);
130
130
  const [isDragging, setIsDragging] = useState(false);
131
131
  const { t } = useTranslation();
132
- const scrollToBottom = () => {
132
+ const scrollToBottom = useCallback(() => {
133
133
  if (isHistoryView) return;
134
134
  setTimeout(() => {
135
- let userMsgs = document.querySelectorAll(
136
- '.memori-chat-scroll-item'
137
- );
135
+ let userMsgs = document.querySelectorAll('.memori-chat-scroll-item');
138
136
  userMsgs[userMsgs.length - 1]?.scrollIntoView?.();
139
137
  }, 200);
140
- };
138
+ }, [isHistoryView]);
139
+
140
+ // Avoid re-scrolling when `history` is recreated with same content (e.g. on every keystroke).
141
+ const lastAutoscrollSignatureRef = useRef<string | null>(null);
142
+ const lastMessage = history?.[history.length - 1];
143
+ const lastMessageSignature = `${history?.length ?? 0}|${
144
+ lastMessage?.timestamp ?? ''
145
+ }|${lastMessage?.fromUser ? 'u' : 'm'}|${
146
+ lastMessage?.text?.length ?? 0
147
+ }|${lastMessage?.translatedText?.length ?? 0}`;
141
148
  useEffect(() => {
142
- !preview && !isHistoryView && scrollToBottom();
143
- }, [history, preview, isHistoryView]);
149
+ // if we are in preview mode or in history view, don't scroll to the bottom
150
+ if (preview || isHistoryView) return;
151
+ // if the last message signature is the same as the previous one, don't scroll to the bottom
152
+ if (lastAutoscrollSignatureRef.current === lastMessageSignature) return;
153
+ // set the last autoscroll signature to the current one
154
+ lastAutoscrollSignatureRef.current = lastMessageSignature;
155
+ // scroll to the bottom
156
+ scrollToBottom();
157
+ }, [preview, isHistoryView, lastMessageSignature, scrollToBottom]);
144
158
 
145
159
  // Scroll to bottom when textarea is expanded
146
160
  // useEffect(() => {
@@ -385,11 +399,18 @@ const Chat: React.FC<Props> = ({
385
399
 
386
400
  <MediaWidget
387
401
  simulateUserPrompt={simulateUserPrompt}
402
+ links={
403
+ (message?.media
404
+ ?.filter(m => !m.properties?.functionSignature)
405
+ ?.filter(m => m.mimeType === 'text/html' && !!m.url) ||
406
+ []) as Medium[]
407
+ }
388
408
  media={[
389
- // Filter out HTML and plain text media items from the message
390
- ...(message?.media?.filter(
391
- m => !m.properties?.functionSignature
392
- ) || []),
409
+ // Non-function-cache media items (exclude HTML links; those go into `links`)
410
+ ...(message?.media
411
+ ?.filter(m => !m.properties?.functionSignature)
412
+ ?.filter(m => !(m.mimeType === 'text/html' && !!m.url)) ||
413
+ []),
393
414
 
394
415
  // Extract document attachments that are embedded in the message text
395
416
  ...(() => {
@@ -435,7 +456,6 @@ const Chat: React.FC<Props> = ({
435
456
  return attachments;
436
457
  })(),
437
458
  ]}
438
- // links={message?.media?.filter(m => m.mimeType === 'text/html')}
439
459
  sessionID={sessionID}
440
460
  baseUrl={baseUrl}
441
461
  apiUrl={apiUrl}