@memori.ai/memori-react 7.1.2 → 7.2.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +1 -0
  3. package/dist/components/Chat/Chat.d.ts +1 -0
  4. package/dist/components/Chat/Chat.js +2 -2
  5. package/dist/components/Chat/Chat.js.map +1 -1
  6. package/dist/components/ChatBubble/ChatBubble.css +15 -10
  7. package/dist/components/ChatBubble/ChatBubble.d.ts +1 -0
  8. package/dist/components/ChatBubble/ChatBubble.js +14 -4
  9. package/dist/components/ChatBubble/ChatBubble.js.map +1 -1
  10. package/dist/components/MemoriWidget/MemoriWidget.d.ts +2 -1
  11. package/dist/components/MemoriWidget/MemoriWidget.js +17 -16
  12. package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
  13. package/dist/components/icons/Code.d.ts +5 -0
  14. package/dist/components/icons/Code.js +6 -0
  15. package/dist/components/icons/Code.js.map +1 -0
  16. package/dist/components/icons/Copy.js +1 -1
  17. package/dist/components/icons/Copy.js.map +1 -1
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +3 -2
  20. package/dist/index.js.map +1 -1
  21. package/dist/locales/en.json +1 -0
  22. package/dist/locales/it.json +1 -0
  23. package/esm/components/Chat/Chat.d.ts +1 -0
  24. package/esm/components/Chat/Chat.js +2 -2
  25. package/esm/components/Chat/Chat.js.map +1 -1
  26. package/esm/components/ChatBubble/ChatBubble.css +15 -10
  27. package/esm/components/ChatBubble/ChatBubble.d.ts +1 -0
  28. package/esm/components/ChatBubble/ChatBubble.js +14 -4
  29. package/esm/components/ChatBubble/ChatBubble.js.map +1 -1
  30. package/esm/components/MemoriWidget/MemoriWidget.d.ts +2 -1
  31. package/esm/components/MemoriWidget/MemoriWidget.js +17 -16
  32. package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
  33. package/esm/components/icons/Code.d.ts +5 -0
  34. package/esm/components/icons/Code.js +4 -0
  35. package/esm/components/icons/Code.js.map +1 -0
  36. package/esm/components/icons/Copy.js +2 -2
  37. package/esm/components/icons/Copy.js.map +1 -1
  38. package/esm/index.d.ts +1 -0
  39. package/esm/index.js +3 -2
  40. package/esm/index.js.map +1 -1
  41. package/esm/locales/en.json +1 -0
  42. package/esm/locales/it.json +1 -0
  43. package/package.json +1 -1
  44. package/src/components/Chat/Chat.tsx +3 -0
  45. package/src/components/Chat/__snapshots__/Chat.test.tsx.snap +1672 -44
  46. package/src/components/ChatBubble/ChatBubble.css +15 -10
  47. package/src/components/ChatBubble/ChatBubble.stories.tsx +11 -0
  48. package/src/components/ChatBubble/ChatBubble.test.tsx +16 -0
  49. package/src/components/ChatBubble/ChatBubble.tsx +39 -1
  50. package/src/components/ChatBubble/__snapshots__/ChatBubble.test.tsx.snap +764 -11
  51. package/src/components/MediaWidget/__snapshots__/MediaItemWidget.test.tsx.snap +30 -4
  52. package/src/components/MemoriWidget/MemoriWidget.tsx +18 -15
  53. package/src/components/Snippet/__snapshots__/Snippet.test.tsx.snap +120 -16
  54. package/src/components/icons/Code.tsx +24 -0
  55. package/src/components/icons/Copy.tsx +8 -2
  56. package/src/index.tsx +4 -0
  57. package/src/locales/en.json +1 -0
  58. package/src/locales/it.json +1 -0
@@ -101,7 +101,7 @@
101
101
  }
102
102
  }
103
103
 
104
- .memori-chat--bubble p + p {
104
+ .memori-chat--bubble p+p {
105
105
  margin-top: 0.5em;
106
106
  }
107
107
 
@@ -148,18 +148,18 @@
148
148
  margin-left: auto;
149
149
  }
150
150
 
151
- .memori-chat--bubble.memori-chat--with-addon .memori-chat--bubble-action-icon {
151
+ .memori-chat--bubble .memori-chat--bubble-action-icon {
152
152
  display: flex;
153
153
  justify-content: flex-end;
154
154
  padding: 0;
155
155
  text-align: right;
156
156
  }
157
157
 
158
- .memori-chat--bubble.memori-chat--with-addon .memori-chat--bubble-action-icon.memori-chat--bubble-action-icon--ai {
158
+ .memori-chat--bubble .memori-chat--bubble-action-icon.memori-chat--bubble-action-icon--ai {
159
159
  padding: 3px;
160
160
  }
161
161
 
162
- .memori-chat--bubble.memori-chat--with-addon .memori-chat--bubble-action-icon svg {
162
+ .memori-chat--bubble .memori-chat--bubble-action-icon svg {
163
163
  overflow: visible;
164
164
  width: 1rem;
165
165
  height: 1rem;
@@ -182,16 +182,20 @@
182
182
  color: #333;
183
183
  }
184
184
 
185
+ .memori-chat--bubble .memori-chat--bubble-action-icon.memori-chat--bubble-action-icon--ai svg {
186
+ width: 0.85rem;
187
+ height: 0.85rem;
188
+ }
189
+
190
+ .memori-chat--bubble-addon button.memori-chat--bubble-action-icon {
191
+ padding: 2.5px;
192
+ }
193
+
185
194
  .memori-chat--bubble-addon .memori-chat--feedback button .memori-button--icon svg {
186
195
  width: 0.9rem;
187
196
  height: 0.9rem;
188
197
  }
189
198
 
190
- .memori-chat--bubble.memori-chat--with-addon .memori-chat--bubble-action-icon.memori-chat--bubble-action-icon--ai svg {
191
- width: 0.85rem;
192
- height: 0.85rem;
193
- }
194
-
195
199
  .memori-chat--bubble-addon-separator {
196
200
  width: 1px;
197
201
  height: 1.5em;
@@ -262,6 +266,7 @@
262
266
  }
263
267
 
264
268
  @keyframes wave {
269
+
265
270
  0%,
266
271
  60%,
267
272
  100% {
@@ -279,4 +284,4 @@
279
284
 
280
285
  .memori-chat--bubble mjx-container[jax='CHTML'][display='true'] {
281
286
  text-align: left;
282
- }
287
+ }
@@ -79,6 +79,17 @@ Initial.args = {
79
79
  },
80
80
  };
81
81
 
82
+ export const CopyDisabled = Template.bind({});
83
+ CopyDisabled.args = {
84
+ memori,
85
+ tenant,
86
+ message: {
87
+ fromUser: false,
88
+ text: 'Proin libero ante, dignissim sit amet turpis a, pretium condimentum dolor.',
89
+ },
90
+ showCopyButton: false,
91
+ };
92
+
82
93
  export const GeneratedByAI = Template.bind({});
83
94
  GeneratedByAI.args = {
84
95
  memori,
@@ -57,6 +57,22 @@ it('renders ChatBubble with user msg unchanged', () => {
57
57
  expect(container).toMatchSnapshot();
58
58
  });
59
59
 
60
+ it('renders ChatBubble with copy disabled unchanged', () => {
61
+ const { container } = render(
62
+ <ChatBubble
63
+ memori={memori}
64
+ tenant={tenant}
65
+ sessionID={sessionID}
66
+ message={{
67
+ fromUser: false,
68
+ text: 'Proin libero ante, dignissim sit amet turpis a, pretium condimentum dolor.',
69
+ }}
70
+ showCopyButton={false}
71
+ />
72
+ );
73
+ expect(container).toMatchSnapshot();
74
+ });
75
+
60
76
  it('renders ChatBubble with msg generated by AI unchanged', () => {
61
77
  const { container } = render(
62
78
  <ChatBubble
@@ -20,7 +20,10 @@ import DOMPurify from 'dompurify';
20
20
  import { cleanUrl } from '../../helpers/utils';
21
21
  import Button from '../ui/Button';
22
22
  import QuestionHelp from '../icons/QuestionHelp';
23
+ import Copy from '../icons/Copy';
24
+ import Code from '../icons/Code';
23
25
  import WhyThisAnswer from '../WhyThisAnswer/WhyThisAnswer';
26
+ import { stripEmojis, escapeHTML, stripMarkdown } from '../../helpers/utils';
24
27
 
25
28
  import markedLinkifyIt from 'marked-linkify-it';
26
29
  import markedKatex from 'marked-katex-extension';
@@ -35,6 +38,7 @@ export interface Props {
35
38
  apiUrl?: string;
36
39
  showFeedback?: boolean;
37
40
  showWhyThisAnswer?: boolean;
41
+ showCopyButton?: boolean;
38
42
  simulateUserPrompt?: (msg: string) => void;
39
43
  showAIicon?: boolean;
40
44
  isFirst?: boolean;
@@ -81,6 +85,7 @@ const ChatBubble: React.FC<Props> = ({
81
85
  sessionID,
82
86
  showFeedback,
83
87
  showWhyThisAnswer = true,
88
+ showCopyButton = true,
84
89
  simulateUserPrompt,
85
90
  showAIicon = true,
86
91
  isFirst = false,
@@ -126,6 +131,12 @@ const ChatBubble: React.FC<Props> = ({
126
131
  .replace(/<p><\/p>/g, '<br>')
127
132
  .replace(/<p><br><\/p>/g, '<br>');
128
133
 
134
+ const plainText = message.fromUser
135
+ ? message.translatedText || message.text
136
+ : escapeHTML(
137
+ stripMarkdown(stripEmojis(message.translatedText || message.text))
138
+ );
139
+
129
140
  useLayoutEffect(() => {
130
141
  if (typeof window !== 'undefined' && !message.fromUser) {
131
142
  // @ts-ignore
@@ -228,6 +239,7 @@ const ChatBubble: React.FC<Props> = ({
228
239
  className={cx('memori-chat--bubble', {
229
240
  'memori-chat--user-bubble': !!message.fromUser,
230
241
  'memori-chat--with-addon':
242
+ (!message.fromUser && showCopyButton) ||
231
243
  (message.generatedByAI && showAIicon) ||
232
244
  (showFeedback && simulateUserPrompt),
233
245
  'memori-chat--ai-generated': message.generatedByAI && showAIicon,
@@ -249,9 +261,35 @@ const ChatBubble: React.FC<Props> = ({
249
261
  className="memori-chat--bubble-content"
250
262
  dangerouslySetInnerHTML={{ __html: renderedText }}
251
263
  />
252
- {((message.generatedByAI && showAIicon) ||
264
+ {((!message.fromUser && showCopyButton) ||
265
+ (message.generatedByAI && showAIicon) ||
253
266
  (showFeedback && simulateUserPrompt)) && (
254
267
  <div className="memori-chat--bubble-addon">
268
+ {!message.fromUser && showCopyButton && (
269
+ <Button
270
+ ghost
271
+ shape="circle"
272
+ title={t('copy') || 'Copy'}
273
+ className="memori-chat--bubble-action-icon"
274
+ icon={<Copy aria-label={t('copy') || 'Copy'} />}
275
+ onClick={() => navigator.clipboard.writeText(plainText)}
276
+ />
277
+ )}
278
+ {!message.fromUser &&
279
+ showCopyButton &&
280
+ plainText !== message.text && (
281
+ <Button
282
+ ghost
283
+ shape="circle"
284
+ title={t('copyRawCode') || 'Copy raw code'}
285
+ className="memori-chat--bubble-action-icon"
286
+ icon={
287
+ <Code aria-label={t('copyRawCode') || 'Copy raw code'} />
288
+ }
289
+ onClick={() => navigator.clipboard.writeText(message.text)}
290
+ />
291
+ )}
292
+
255
293
  {showFeedback && !!simulateUserPrompt && (
256
294
  <FeedbackButtons
257
295
  memori={memori}