@memori.ai/memori-react 8.0.2 → 8.1.0-rc.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 (53) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/components/Chat/Chat.d.ts +0 -2
  3. package/dist/components/Chat/Chat.js +2 -2
  4. package/dist/components/Chat/Chat.js.map +1 -1
  5. package/dist/components/ChatHistoryDrawer/ChatHistory.css +32 -0
  6. package/dist/components/ChatHistoryDrawer/ChatHistory.js +104 -31
  7. package/dist/components/ChatHistoryDrawer/ChatHistory.js.map +1 -1
  8. package/dist/components/ChatInputs/ChatInputs.d.ts +0 -2
  9. package/dist/components/ChatInputs/ChatInputs.js +3 -4
  10. package/dist/components/ChatInputs/ChatInputs.js.map +1 -1
  11. package/dist/components/MemoriWidget/MemoriWidget.js +103 -329
  12. package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
  13. package/dist/helpers/stt/useSTT.d.ts +40 -0
  14. package/dist/helpers/stt/useSTT.js +362 -0
  15. package/dist/helpers/stt/useSTT.js.map +1 -0
  16. package/dist/locales/de.json +11 -0
  17. package/dist/locales/en.json +11 -0
  18. package/dist/locales/es.json +11 -0
  19. package/dist/locales/fr.json +11 -0
  20. package/dist/locales/it.json +11 -0
  21. package/esm/components/Chat/Chat.d.ts +0 -2
  22. package/esm/components/Chat/Chat.js +2 -2
  23. package/esm/components/Chat/Chat.js.map +1 -1
  24. package/esm/components/ChatHistoryDrawer/ChatHistory.css +32 -0
  25. package/esm/components/ChatHistoryDrawer/ChatHistory.js +104 -31
  26. package/esm/components/ChatHistoryDrawer/ChatHistory.js.map +1 -1
  27. package/esm/components/ChatInputs/ChatInputs.d.ts +0 -2
  28. package/esm/components/ChatInputs/ChatInputs.js +3 -4
  29. package/esm/components/ChatInputs/ChatInputs.js.map +1 -1
  30. package/esm/components/MemoriWidget/MemoriWidget.js +103 -329
  31. package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
  32. package/esm/helpers/stt/useSTT.d.ts +40 -0
  33. package/esm/helpers/stt/useSTT.js +358 -0
  34. package/esm/helpers/stt/useSTT.js.map +1 -0
  35. package/esm/locales/de.json +11 -0
  36. package/esm/locales/en.json +11 -0
  37. package/esm/locales/es.json +11 -0
  38. package/esm/locales/fr.json +11 -0
  39. package/esm/locales/it.json +11 -0
  40. package/package.json +2 -3
  41. package/src/components/Chat/Chat.test.tsx +0 -9
  42. package/src/components/Chat/Chat.tsx +0 -6
  43. package/src/components/ChatHistoryDrawer/ChatHistory.css +32 -0
  44. package/src/components/ChatHistoryDrawer/ChatHistory.tsx +114 -57
  45. package/src/components/ChatInputs/ChatInputs.test.tsx +0 -6
  46. package/src/components/ChatInputs/ChatInputs.tsx +2 -7
  47. package/src/components/MemoriWidget/MemoriWidget.tsx +152 -476
  48. package/src/helpers/stt/useSTT.ts +551 -0
  49. package/src/locales/de.json +11 -0
  50. package/src/locales/en.json +11 -0
  51. package/src/locales/es.json +11 -0
  52. package/src/locales/fr.json +11 -0
  53. package/src/locales/it.json +11 -0
@@ -14,6 +14,7 @@ import {
14
14
  Memori,
15
15
  Medium,
16
16
  Message,
17
+ ChatLogFilters,
17
18
  } from '@memori.ai/memori-api-client/dist/types';
18
19
  import Card from '../ui/Card';
19
20
  import Button from '../ui/Button';
@@ -403,6 +404,12 @@ const ChatHistoryDrawer = ({
403
404
  const [totalItems, setTotalItems] = useState(0);
404
405
  const [totalPages, setTotalPages] = useState(0);
405
406
 
407
+ // New filter for minimum messages per chat
408
+ const [minimumMessagesPerChat, setMinimumMessagesPerChat] =
409
+ useState<number>(3);
410
+
411
+ const [customMinimumMessages, setCustomMinimumMessages] = useState<number>(0);
412
+
406
413
  const formatDateForAPI = (date: Date) => {
407
414
  const year = date.getFullYear();
408
415
  const month = String(date.getMonth() + 1).padStart(2, '0');
@@ -493,29 +500,29 @@ const ChatHistoryDrawer = ({
493
500
  setIsLoading(true);
494
501
  setError(null);
495
502
  let response;
503
+ let filters: any = {
504
+ loginToken: loginToken,
505
+ memoriID: memori.engineMemoriID,
506
+ dateFrom: undefined,
507
+ dateTo: undefined,
508
+ from: calculatedIndex,
509
+ howMany: ITEMS_PER_PAGE,
510
+ minimumMessagesPerChat:
511
+ customMinimumMessages > 0
512
+ ? customMinimumMessages
513
+ : minimumMessagesPerChat,
514
+ };
496
515
  try {
497
516
  if (dateRangeValue === 'all') {
498
- response = await getUserChatLogsByTokenPaged(
499
- loginToken,
500
- memori.engineMemoriID ?? '',
501
- calculatedIndex,
502
- ITEMS_PER_PAGE,
503
- undefined,
504
- undefined,
505
- false,
506
- );
517
+ response = await getUserChatLogsByTokenPaged(filters);
507
518
  } else {
508
519
  const { dateFrom, dateTo } =
509
520
  formatDateRangeForAPI(dateRangeValue) ?? {};
510
- response = await getUserChatLogsByTokenPaged(
511
- loginToken,
512
- memori.engineMemoriID ?? '',
513
- calculatedIndex,
514
- ITEMS_PER_PAGE,
515
- dateFrom ?? undefined,
516
- dateTo ?? undefined,
517
- false,
518
- );
521
+ response = await getUserChatLogsByTokenPaged({
522
+ ...filters,
523
+ dateFrom: dateFrom ?? undefined,
524
+ dateTo: dateTo ?? undefined,
525
+ });
519
526
  }
520
527
 
521
528
  const res = response;
@@ -543,7 +550,15 @@ const ChatHistoryDrawer = ({
543
550
  setIsLoading(false);
544
551
  }
545
552
  },
546
- [loginToken, memori.engineMemoriID, currentPage, sortOrder, apiUrl]
553
+ [
554
+ loginToken,
555
+ memori.engineMemoriID,
556
+ currentPage,
557
+ sortOrder,
558
+ apiUrl,
559
+ minimumMessagesPerChat,
560
+ customMinimumMessages,
561
+ ]
547
562
  );
548
563
 
549
564
  useEffect(() => {
@@ -854,7 +869,6 @@ const ChatHistoryDrawer = ({
854
869
  sendMessage={() => {}}
855
870
  startListening={() => {}}
856
871
  stopListening={() => {}}
857
- resetTranscript={() => {}}
858
872
  listening={false}
859
873
  setEnableFocusChatInput={() => {}}
860
874
  stopAudio={() => {}}
@@ -963,47 +977,90 @@ const ChatHistoryDrawer = ({
963
977
  >
964
978
  <div className="memori-chat-history-drawer--content">
965
979
  <div className="memori-chat-history-drawer--toolbar">
966
- {/* <div className="memori-chat-history-drawer--toolbar--search">
967
- <input
968
- type="search"
969
- className="memori-chat-history-drawer--toolbar--search--input"
970
- placeholder={
971
- t('write_and_speak.searchInChatHistory') ||
972
- 'Search in chat history...'
980
+ {/* New minimum messages filter */}
981
+ <div className="memori-chat-history-drawer--toolbar--min-messages-filter">
982
+ {/* <label className={styles.filterLabel}>
983
+ {t('chatLogs.minimumMessages', { ns: 'admin' })}
984
+ </label> */}
985
+ <Select
986
+ displayValue={
987
+ minimumMessagesPerChat === 0
988
+ ? (t('chatLogs.customMinimumMessages') ||
989
+ 'Customize the number of messages') ??
990
+ 'Customize the number of messages'
991
+ : minimumMessagesPerChat === 1
992
+ ? (t('chatLogs.anyMessage') || 'Any message') ?? 'Any message'
993
+ : t('chatLogs.atLeast', { count: minimumMessagesPerChat }) ??
994
+ `At least ${minimumMessagesPerChat} messages`
973
995
  }
974
- onChange={(e: ChangeEvent<HTMLInputElement>) =>
975
- debouncedSearch(e.target.value)
996
+ placeholder={
997
+ (t('chatLogs.customMinimumMessages') ||
998
+ 'Customize the number of messages') ??
999
+ 'Customize the number of messages'
976
1000
  }
977
- />
978
- <span className="memori-chat-history-drawer--toolbar--search--icon">
979
- <svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
980
- <path
981
- strokeLinecap="round"
982
- strokeLinejoin="round"
983
- strokeWidth={2}
984
- d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
985
- />
986
- </svg>
987
- </span>
988
- </div> */}
989
- {/* <div className="memori-chat-history-drawer--toolbar--actions">
990
- <Button
991
- onClick={() => {
992
- setSortOrder(order => (order === 'asc' ? 'desc' : 'asc'));
993
- setCurrentPage(1);
1001
+ value={minimumMessagesPerChat}
1002
+ onChange={value => {
1003
+ setMinimumMessagesPerChat(value);
1004
+ window.localStorage.setItem(
1005
+ 'minimumMessagesPerChat',
1006
+ value.toString()
1007
+ );
994
1008
  }}
995
- className="memori-chat-history-drawer--toolbar--sort-button"
996
- >
997
- <ArrowUpIcon
998
- className={`memori-chat-history-drawer--toolbar--sort-button--icon ${
999
- sortOrder === 'asc' ? 'rotate-180' : ''
1000
- }`}
1009
+ className="memori-chat-history-drawer--toolbar--min-messages-filter--select"
1010
+ options={[
1011
+ {
1012
+ value: 1,
1013
+ label: t('chatLogs.anyMessage') || 'Any message',
1014
+ },
1015
+ {
1016
+ value: 2,
1017
+ label: t('chatLogs.atLeast2') || 'At least 2 messages',
1018
+ },
1019
+ {
1020
+ value: 3,
1021
+ label: t('chatLogs.atLeast3') || 'At least 3 messages',
1022
+ },
1023
+ {
1024
+ value: 5,
1025
+ label: t('chatLogs.atLeast5') || 'At least 5 messages',
1026
+ },
1027
+ {
1028
+ value: 10,
1029
+ label: t('chatLogs.atLeast10') || 'At least 10 messages',
1030
+ },
1031
+ {
1032
+ value: 15,
1033
+ label: t('chatLogs.atLeast15') || 'At least 15 messages',
1034
+ },
1035
+ {
1036
+ value: 20,
1037
+ label: t('chatLogs.atLeast20') || 'At least 20 messages',
1038
+ },
1039
+ {
1040
+ value: 0,
1041
+ label:
1042
+ t('chatLogs.customMinimumMessages') ||
1043
+ 'Customize the number of messages',
1044
+ },
1045
+ ]}
1046
+ />
1047
+ {minimumMessagesPerChat === 0 && (
1048
+ <input
1049
+ type="number"
1050
+ value={customMinimumMessages}
1051
+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
1052
+ const value = parseInt(e.target.value, 10);
1053
+ setCustomMinimumMessages(value);
1054
+ window.localStorage.setItem(
1055
+ 'customMinimumMessages',
1056
+ value.toString()
1057
+ );
1058
+ }}
1059
+ style={{ minWidth: 50 }}
1060
+ className="memori-chat-history-drawer--toolbar--min-messages-filter--input-number"
1001
1061
  />
1002
- {sortOrder === 'desc'
1003
- ? t('write_and_speak.latestFirst')
1004
- : t('write_and_speak.oldestFirst')}
1005
- </Button>
1006
- </div> */}
1062
+ )}
1063
+ </div>
1007
1064
  <div className="memori-chat-history-drawer--toolbar--actions">
1008
1065
  <Select
1009
1066
  options={[
@@ -19,7 +19,6 @@ it('renders ChatInputs unchanged', () => {
19
19
  stopAudio={jest.fn()}
20
20
  startListening={jest.fn()}
21
21
  stopListening={jest.fn()}
22
- resetTranscript={jest.fn()}
23
22
  showMicrophone={true}
24
23
  />
25
24
  );
@@ -42,7 +41,6 @@ it('renders ChatInputs with user message unchanged', () => {
42
41
  stopAudio={jest.fn()}
43
42
  startListening={jest.fn()}
44
43
  stopListening={jest.fn()}
45
- resetTranscript={jest.fn()}
46
44
  showMicrophone={true}
47
45
  />
48
46
  );
@@ -69,7 +67,6 @@ it('renders ChatInputs on instruct unchanged', () => {
69
67
  stopAudio={jest.fn()}
70
68
  startListening={jest.fn()}
71
69
  stopListening={jest.fn()}
72
- resetTranscript={jest.fn()}
73
70
  showMicrophone={true}
74
71
  />
75
72
  );
@@ -92,7 +89,6 @@ it('renders ChatInputs listening unchanged', () => {
92
89
  stopAudio={jest.fn()}
93
90
  startListening={jest.fn()}
94
91
  stopListening={jest.fn()}
95
- resetTranscript={jest.fn()}
96
92
  showMicrophone={true}
97
93
  />
98
94
  );
@@ -115,7 +111,6 @@ it('renders ChatInputs without microphone button unchanged', () => {
115
111
  stopAudio={jest.fn()}
116
112
  startListening={jest.fn()}
117
113
  stopListening={jest.fn()}
118
- resetTranscript={jest.fn()}
119
114
  showMicrophone={false}
120
115
  />
121
116
  );
@@ -141,7 +136,6 @@ it('renders ChatInputs disabled unchanged', () => {
141
136
  stopAudio={jest.fn()}
142
137
  startListening={jest.fn()}
143
138
  stopListening={jest.fn()}
144
- resetTranscript={jest.fn()}
145
139
  showMicrophone={true}
146
140
  />
147
141
  );
@@ -22,7 +22,6 @@ export interface Props {
22
22
  sendMessage: (msg: string, media?: (Medium & { type: string })[]) => void;
23
23
  onTextareaFocus: () => void;
24
24
  onTextareaBlur: () => void;
25
- resetTranscript: () => void;
26
25
  listening?: boolean;
27
26
  isPlayingAudio?: boolean;
28
27
  stopAudio: () => void;
@@ -35,7 +34,6 @@ export interface Props {
35
34
  sessionID?: string;
36
35
  memoriID?: string;
37
36
  client?: ReturnType<typeof memoriApiClient>;
38
- provider?: 'azure' | 'openai';
39
37
  }
40
38
 
41
39
  const ChatInputs: React.FC<Props> = ({
@@ -46,7 +44,6 @@ const ChatInputs: React.FC<Props> = ({
46
44
  sendMessage,
47
45
  onTextareaFocus,
48
46
  onTextareaBlur,
49
- resetTranscript,
50
47
  showMicrophone = false,
51
48
  microphoneMode = 'HOLD_TO_TALK',
52
49
  listening = false,
@@ -58,7 +55,6 @@ const ChatInputs: React.FC<Props> = ({
58
55
  authToken,
59
56
  memoriID,
60
57
  client,
61
- provider = 'azure',
62
58
  }) => {
63
59
  const { t } = useTranslation();
64
60
 
@@ -134,7 +130,6 @@ const ChatInputs: React.FC<Props> = ({
134
130
 
135
131
  setDocumentPreviewFiles([]);
136
132
  onChangeUserMessage('');
137
- resetTranscript();
138
133
  }
139
134
  };
140
135
 
@@ -209,7 +204,7 @@ const ChatInputs: React.FC<Props> = ({
209
204
  title={t('send') || 'Send'}
210
205
  icon={<Send />}
211
206
  />
212
- {provider === 'azure' && showMicrophone && microphoneMode === 'HOLD_TO_TALK' && (
207
+ {showMicrophone && microphoneMode === 'HOLD_TO_TALK' && (
213
208
  <MicrophoneButton
214
209
  listening={listening}
215
210
  startListening={startListening}
@@ -222,7 +217,7 @@ const ChatInputs: React.FC<Props> = ({
222
217
  stopAudio={stopAudio}
223
218
  />
224
219
  )}
225
- {provider === 'azure' && showMicrophone && microphoneMode === 'CONTINUOUS' && (
220
+ {showMicrophone && microphoneMode === 'CONTINUOUS' && (
226
221
  <Button
227
222
  primary
228
223
  className={cx('memori-chat-inputs--mic', {