@memori.ai/memori-react 8.6.0 → 8.6.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 (70) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/components/CompletionProviderStatus/CompletionProviderStatus.js +0 -22
  3. package/dist/components/CompletionProviderStatus/CompletionProviderStatus.js.map +1 -1
  4. package/dist/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js +13 -1
  5. package/dist/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js.map +1 -1
  6. package/dist/components/MemoriArtifactSystem/components/ArtifactPreview/ArtifactPreview.css +2 -0
  7. package/dist/components/MemoriWidget/MemoriWidget.d.ts +7 -1
  8. package/dist/components/MemoriWidget/MemoriWidget.js +7 -115
  9. package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
  10. package/dist/helpers/message.d.ts +1 -1
  11. package/dist/helpers/message.js +2 -2
  12. package/dist/helpers/message.js.map +1 -1
  13. package/dist/helpers/stt/useSTT.js +171 -73
  14. package/dist/helpers/stt/useSTT.js.map +1 -1
  15. package/dist/helpers/translations.js +10 -3
  16. package/dist/helpers/translations.js.map +1 -1
  17. package/dist/helpers/tts/useTTS.js +16 -1
  18. package/dist/helpers/tts/useTTS.js.map +1 -1
  19. package/esm/components/CompletionProviderStatus/CompletionProviderStatus.js +0 -22
  20. package/esm/components/CompletionProviderStatus/CompletionProviderStatus.js.map +1 -1
  21. package/esm/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js +14 -2
  22. package/esm/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js.map +1 -1
  23. package/esm/components/MemoriArtifactSystem/components/ArtifactPreview/ArtifactPreview.css +2 -0
  24. package/esm/components/MemoriWidget/MemoriWidget.d.ts +7 -1
  25. package/esm/components/MemoriWidget/MemoriWidget.js +7 -115
  26. package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
  27. package/esm/helpers/message.d.ts +1 -1
  28. package/esm/helpers/message.js +2 -2
  29. package/esm/helpers/message.js.map +1 -1
  30. package/esm/helpers/stt/useSTT.js +171 -73
  31. package/esm/helpers/stt/useSTT.js.map +1 -1
  32. package/esm/helpers/translations.js +10 -3
  33. package/esm/helpers/translations.js.map +1 -1
  34. package/esm/helpers/tts/useTTS.js +16 -1
  35. package/esm/helpers/tts/useTTS.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/components/CompletionProviderStatus/CompletionProviderStatus.tsx +1 -33
  38. package/src/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.tsx +23 -1
  39. package/src/components/MemoriArtifactSystem/components/ArtifactPreview/ArtifactPreview.css +2 -0
  40. package/src/components/MemoriWidget/MemoriWidget.tsx +14 -126
  41. package/src/helpers/message.ts +2 -2
  42. package/src/helpers/stt/useSTT.ts +225 -87
  43. package/src/helpers/translations.ts +12 -1
  44. package/src/helpers/tts/useTTS.ts +28 -1
  45. package/dist/components/MemoriArtifactSystem/components/ArtifactHistory/ArtifactHistory.css +0 -319
  46. package/dist/components/MemoriArtifactSystem/components/ArtifactHistory/ArtifactHistory.d.ts +0 -4
  47. package/dist/components/MemoriArtifactSystem/components/ArtifactHistory/ArtifactHistory.js +0 -50
  48. package/dist/components/MemoriArtifactSystem/components/ArtifactHistory/ArtifactHistory.js.map +0 -1
  49. package/dist/components/MemoriArtifactSystem/context/ArtifactSystemContext.d.ts +0 -12
  50. package/dist/components/MemoriArtifactSystem/context/ArtifactSystemContext.js +0 -22
  51. package/dist/components/MemoriArtifactSystem/context/ArtifactSystemContext.js.map +0 -1
  52. package/dist/components/MemoriArtifactSystem/hooks/useArtifactSystem.d.ts +0 -12
  53. package/dist/components/MemoriArtifactSystem/hooks/useArtifactSystem.js +0 -288
  54. package/dist/components/MemoriArtifactSystem/hooks/useArtifactSystem.js.map +0 -1
  55. package/dist/components/MemoriArtifactSystem/index.d.ts +0 -9
  56. package/dist/components/MemoriArtifactSystem/index.js +0 -28
  57. package/dist/components/MemoriArtifactSystem/index.js.map +0 -1
  58. package/esm/components/MemoriArtifactSystem/components/ArtifactHistory/ArtifactHistory.css +0 -319
  59. package/esm/components/MemoriArtifactSystem/components/ArtifactHistory/ArtifactHistory.d.ts +0 -4
  60. package/esm/components/MemoriArtifactSystem/components/ArtifactHistory/ArtifactHistory.js +0 -47
  61. package/esm/components/MemoriArtifactSystem/components/ArtifactHistory/ArtifactHistory.js.map +0 -1
  62. package/esm/components/MemoriArtifactSystem/context/ArtifactSystemContext.d.ts +0 -12
  63. package/esm/components/MemoriArtifactSystem/context/ArtifactSystemContext.js +0 -17
  64. package/esm/components/MemoriArtifactSystem/context/ArtifactSystemContext.js.map +0 -1
  65. package/esm/components/MemoriArtifactSystem/hooks/useArtifactSystem.d.ts +0 -12
  66. package/esm/components/MemoriArtifactSystem/hooks/useArtifactSystem.js +0 -281
  67. package/esm/components/MemoriArtifactSystem/hooks/useArtifactSystem.js.map +0 -1
  68. package/esm/components/MemoriArtifactSystem/index.d.ts +0 -9
  69. package/esm/components/MemoriArtifactSystem/index.js +0 -9
  70. package/esm/components/MemoriArtifactSystem/index.js.map +0 -1
@@ -54,39 +54,7 @@ const fetchProviderStatus = async (config: ProviderConfig): Promise<Status> => {
54
54
 
55
55
  const data = await response.json();
56
56
 
57
- // Check for active incidents first
58
- if (data.incidents && Array.isArray(data.incidents) && data.incidents.length > 0) {
59
- const activeIncidents = data.incidents.filter((incident: any) => {
60
- // Check if incident is truly active by looking at the latest update
61
- if (incident.incident_updates && incident.incident_updates.length > 0) {
62
- const latestUpdate = incident.incident_updates[incident.incident_updates.length - 1];
63
- const isResolved = ['resolved', 'completed', 'postmortem'].includes(latestUpdate.status.toLowerCase());
64
- return !isResolved;
65
- }
66
- // Fallback to incident status if no updates available
67
- return !['resolved', 'completed', 'postmortem'].includes(incident.status.toLowerCase());
68
- });
69
-
70
- if (activeIncidents.length > 0) {
71
- // If there are active incidents, determine the severity
72
- const critical = activeIncidents.some((i: { impact: string }) =>
73
- i.impact === 'critical' || i.impact === 'major'
74
- );
75
- const major = activeIncidents.some((i: { impact: string }) =>
76
- i.impact === 'moderate'
77
- );
78
-
79
- const investigating = activeIncidents.some((i: { status: string }) =>
80
- i.status === 'investigating'
81
- );
82
-
83
- if (investigating) return 'partial_outage';
84
- if (critical) return 'major_outage';
85
- if (major) return 'partial_outage';
86
- // Return degraded_performance for investigating status or any other active incident
87
- return 'degraded_performance';
88
- }
89
- }
57
+ // Skip incident checking - just rely on component status which is more reliable
90
58
 
91
59
  // If no incidents or they're all resolved, check specific API components
92
60
  if (data.components) {
@@ -8,6 +8,12 @@ import ChevronLeft from '../../../icons/ChevronLeft';
8
8
  import ChevronUp from '../../../icons/ChevronUp';
9
9
  import { Message } from '@memori.ai/memori-api-client/dist/types';
10
10
 
11
+ // Event type for artifact creation
12
+ type ArtifactCreatedEvent = CustomEvent<{
13
+ artifact: ArtifactData;
14
+ message: Message;
15
+ }>;
16
+
11
17
  interface ArtifactHandlerProps {
12
18
  isChatlogPanel?: boolean;
13
19
  message: Message;
@@ -22,6 +28,17 @@ const ArtifactHandler: React.FC<ArtifactHandlerProps> = ({
22
28
  null
23
29
  );
24
30
 
31
+ // Function to dispatch artifact created event
32
+ const dispatchArtifactCreatedEvent = useCallback((artifact: ArtifactData) => {
33
+ const event: ArtifactCreatedEvent = new CustomEvent('artifactCreated', {
34
+ detail: {
35
+ artifact,
36
+ message,
37
+ },
38
+ });
39
+ document.dispatchEvent(event);
40
+ }, [message]);
41
+
25
42
  // Auto-open artifacts when detected in new messages
26
43
  useEffect(() => {
27
44
  const messageText = message.translatedText || message.text || '';
@@ -29,6 +46,11 @@ const ArtifactHandler: React.FC<ArtifactHandlerProps> = ({
29
46
  const artifacts = detectArtifacts(messageText);
30
47
 
31
48
  if (artifacts.length > 0) {
49
+ // Dispatch event for each artifact created
50
+ artifacts.forEach(artifact => {
51
+ dispatchArtifactCreatedEvent(artifact);
52
+ });
53
+
32
54
  if(isChatlogPanel){
33
55
  // openArtifact(artifacts[0]);
34
56
  setCurrentArtifact(artifacts[0]);
@@ -40,7 +62,7 @@ const ArtifactHandler: React.FC<ArtifactHandlerProps> = ({
40
62
  }
41
63
  }
42
64
  }
43
- }, [message]);
65
+ }, [message, dispatchArtifactCreatedEvent]);
44
66
 
45
67
  // Simple artifact detection - look for <output class="memori-artifact"> tags
46
68
  const detectArtifacts = (text: string): ArtifactData[] => {
@@ -112,10 +112,12 @@
112
112
 
113
113
  /* Markdown Preview */
114
114
  .memori-artifact-preview-markdown {
115
+ height: 100%;
115
116
  padding: 1rem;
116
117
  color: var(--memori-text-color, #333);
117
118
  font-family: var(--memori-font-family);
118
119
  line-height: 1.6;
120
+ overflow-y: scroll;
119
121
  }
120
122
 
121
123
  .memori-artifact-preview-markdown h1,
@@ -16,6 +16,7 @@ import {
16
16
  ResponseSpec,
17
17
  ChatLog,
18
18
  } from '@memori.ai/memori-api-client/src/types';
19
+ import { ArtifactData } from '../MemoriArtifactSystem/types/artifact.types';
19
20
 
20
21
  // Libraries
21
22
  import React, {
@@ -290,11 +291,17 @@ const typeBatchMessages = (
290
291
 
291
292
  type MemoriNewDialogStateEvent = CustomEvent<DialogState>;
292
293
 
294
+ type ArtifactCreatedEvent = CustomEvent<{
295
+ artifact: ArtifactData;
296
+ message: Message;
297
+ }>;
298
+
293
299
  interface CustomEventMap {
294
300
  MemoriTextEntered: MemoriTextEnteredEvent;
295
301
  MemoriEndSpeak: CustomEvent;
296
302
  MemoriResetUIEffects: CustomEvent;
297
303
  MemoriNewDialogState: MemoriNewDialogStateEvent;
304
+ artifactCreated: ArtifactCreatedEvent;
298
305
  }
299
306
  declare global {
300
307
  interface Document {
@@ -721,7 +728,7 @@ const MemoriWidget = ({
721
728
  const onChangeUserMessage = (value: string) => {
722
729
  if (!value || value === '\n' || value.trim() === '') {
723
730
  setUserMessage('');
724
- resetInteractionTimeout();
731
+ // resetInteractionTimeout();
725
732
  return;
726
733
  }
727
734
  setUserMessage(value);
@@ -861,7 +868,7 @@ const MemoriWidget = ({
861
868
 
862
869
  translateDialogState(currentState, userLang, msg).then(ts => {
863
870
  let text = ts.translatedEmission || ts.emission;
864
- if (text) {
871
+ if (text && text.trim() && !speakerMuted) {
865
872
  handleSpeak(text);
866
873
  }
867
874
  });
@@ -888,7 +895,9 @@ const MemoriWidget = ({
888
895
  tag: currentState.currentTag,
889
896
  memoryTags: currentState.memoryTags,
890
897
  });
891
- handleSpeak(emission);
898
+ if (emission && emission.trim()) {
899
+ handleSpeak(emission);
900
+ }
892
901
  }
893
902
  }
894
903
  } else if (response.resultCode === 404) {
@@ -1942,124 +1951,12 @@ const MemoriWidget = ({
1942
1951
  defaultEnableAudio
1943
1952
  );
1944
1953
 
1945
- const resetInteractionTimeout = () => {
1946
- clearInteractionTimeout();
1947
- if (!isPlayingAudio && !userMessage.length && !memoriTyping && !listening)
1948
- setInteractionTimeout();
1949
- };
1950
- const handleTimeout = async () => {
1951
- if (
1952
- !hasUserActivatedSpeak ||
1953
- isPlayingAudio ||
1954
- !!userMessage.length ||
1955
- !!memoriTyping ||
1956
- listening
1957
- ) {
1958
- resetInteractionTimeout();
1959
- return;
1960
- } else if (
1961
- sessionId &&
1962
- hasUserActivatedSpeak &&
1963
- currentDialogState?.acceptsTimeout
1964
- ) {
1965
- const { currentState, ...response } = await postTimeoutEvent(sessionId);
1966
- if (response.resultCode === 0 && currentState) {
1967
- const emission = currentState.emission;
1968
- if (
1969
- isMultilanguageEnabled &&
1970
- userLang !== i18n?.language &&
1971
- emission &&
1972
- emission.length > 0
1973
- ) {
1974
- translateDialogState(
1975
- { ...currentState, emission: emission },
1976
- userLang
1977
- ).then(ts => {
1978
- let text = ts.translatedEmission || ts.emission;
1979
- if (text) {
1980
- handleSpeak(text);
1981
- }
1982
- });
1983
- } else if (emission && emission.length > 0) {
1984
- pushMessage({
1985
- text: emission,
1986
- emitter: currentState.emitter,
1987
- media: currentState.emittedMedia ?? currentState.media,
1988
- fromUser: false,
1989
- generatedByAI: !!currentState.completion,
1990
- contextVars: currentState.contextVars,
1991
- date: currentState.currentDate,
1992
- placeName: currentState.currentPlaceName,
1993
- placeLatitude: currentState.currentLatitude,
1994
- placeLongitude: currentState.currentLongitude,
1995
- placeUncertaintyKm: currentState.currentUncertaintyKm,
1996
- tag: currentState.currentTag,
1997
- memoryTags: currentState.memoryTags,
1998
- });
1999
- handleSpeak(emission);
2000
- setCurrentDialogState({
2001
- ...currentState,
2002
- hints:
2003
- currentState.hints ??
2004
- (currentState.state === 'G1' ? currentDialogState?.hints : []),
2005
- });
2006
- } else {
2007
- resetInteractionTimeout();
2008
- return;
2009
- }
2010
- }
2011
- }
2012
- };
2013
- const setInteractionTimeout = () => {
2014
- let timeout = currentDialogState?.timeout;
2015
- if (!timeout) {
2016
- let timeoutLimit = 40;
2017
- let timeoutMinLimit = 25;
2018
- timeout =
2019
- Math.floor(Math.random() * (timeoutLimit - timeoutMinLimit)) +
2020
- timeoutMinLimit;
2021
-
2022
- if (currentDialogState?.emission) {
2023
- let readTime = currentDialogState.emission.length / 26.5;
2024
- timeout = timeout + readTime;
2025
- }
2026
- }
2027
- if (forcedTimeout) {
2028
- timeout = forcedTimeout;
2029
-
2030
- if (currentDialogState?.emission) {
2031
- let readTime = currentDialogState.emission.length / 26.5;
2032
- timeout = timeout + readTime;
2033
- }
2034
- }
2035
-
2036
- let uiTimeout = setTimeout(handleTimeout, timeout * 1000);
2037
- setUserInteractionTimeout(uiTimeout);
2038
- timeoutRef.current = uiTimeout;
2039
- };
2040
- useEffect(() => {
2041
- if (!!userMessage.length || isPlayingAudio || !!memoriTyping)
2042
- clearInteractionTimeout();
2043
- if (sessionId && !!!userMessage.length) resetInteractionTimeout();
2044
- // eslint-disable-next-line react-hooks/exhaustive-deps
2045
- }, [
2046
- currentDialogState?.acceptsTimeout,
2047
- currentDialogState?.timeout,
2048
- currentDialogState?.state,
2049
- isPlayingAudio,
2050
- sessionId,
2051
- history,
2052
- userMessage,
2053
- memoriTyping,
2054
- hasUserActivatedSpeak,
2055
- ]);
2056
-
2057
1954
  /**
2058
1955
  * Enhanced handleSpeak that integrates with the improved useTTS hook
2059
1956
  * Uses promise-based approach for better reliability
2060
1957
  */
2061
1958
  const handleSpeak = async (text: string) => {
2062
- if (!text || preview || speakerMuted || !defaultEnableAudio) {
1959
+ if (!text || !text.trim() || preview || speakerMuted || !defaultEnableAudio) {
2063
1960
  const e = new CustomEvent('MemoriEndSpeak');
2064
1961
  document.dispatchEvent(e);
2065
1962
 
@@ -2070,18 +1967,9 @@ const MemoriWidget = ({
2070
1967
  stopRecording();
2071
1968
  }
2072
1969
 
2073
- setMemoriTyping(true);
2074
-
2075
1970
  const processedText = sanitizeText(text);
2076
1971
 
2077
1972
  return ttsSpeak(processedText)
2078
- .then(() => {
2079
- setMemoriTyping(false);
2080
- })
2081
- .catch(error => {
2082
- setMemoriTyping(false);
2083
- throw error;
2084
- });
2085
1973
  };
2086
1974
  /**
2087
1975
  * Integrated solution for translating dialog state and speaking
@@ -2113,7 +2001,7 @@ const MemoriWidget = ({
2113
2001
  const textToSpeak =
2114
2002
  translatedState.translatedEmission || translatedState.emission;
2115
2003
 
2116
- if (textToSpeak && !skipEmission) {
2004
+ if (textToSpeak && textToSpeak.trim() && !skipEmission && !speakerMuted) {
2117
2005
  // Update activation state before speaking for better browser interaction
2118
2006
  if (!hasUserActivatedSpeak) {
2119
2007
  setHasUserActivatedSpeak(true);
@@ -64,7 +64,7 @@ export const renderMsg = (
64
64
  text: string,
65
65
  useMathFormatting = false,
66
66
  reasoningText = 'Reasoning...',
67
- showReasoning = false
67
+ showReasoning: boolean
68
68
  ): {
69
69
  text: string;
70
70
  } => {
@@ -77,7 +77,7 @@ export const renderMsg = (
77
77
  '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'
78
78
  )
79
79
  .replaceAll(
80
- /<think>([\s\S]*?)<\/think>/g,
80
+ /<think.*?>(.*?)<\/think>/gs,
81
81
  showReasoning
82
82
  ? `<details class="memori-think"><summary>${reasoningText}</summary>$1</details>`
83
83
  : ''