@memori.ai/memori-react 7.17.0 → 7.17.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.
- package/CHANGELOG.md +26 -0
- package/dist/components/ChatBubble/ChatBubble.js +27 -35
- package/dist/components/ChatBubble/ChatBubble.js.map +1 -1
- package/dist/components/Header/Header.js +15 -2
- package/dist/components/Header/Header.js.map +1 -1
- package/dist/components/MemoriWidget/MemoriWidget.js +13 -4
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/helpers/constants.js +2 -2
- package/esm/components/ChatBubble/ChatBubble.js +27 -35
- package/esm/components/ChatBubble/ChatBubble.js.map +1 -1
- package/esm/components/Header/Header.js +15 -2
- package/esm/components/Header/Header.js.map +1 -1
- package/esm/components/MemoriWidget/MemoriWidget.js +14 -5
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/helpers/constants.js +2 -2
- package/package.json +2 -2
- package/src/components/ChatBubble/ChatBubble.tsx +69 -65
- package/src/components/ChatBubble/__snapshots__/ChatBubble.test.tsx.snap +4169 -1325
- package/src/components/Header/Header.tsx +17 -2
- package/src/components/MemoriWidget/MemoriWidget.tsx +39 -15
- package/src/components/StartPanel/__snapshots__/StartPanel.test.tsx.snap +2 -2
- package/src/components/layouts/__snapshots__/Chat.test.tsx.snap +2 -2
- package/src/components/layouts/__snapshots__/FullPage.test.tsx.snap +4 -4
- package/src/components/layouts/__snapshots__/Totem.test.tsx.snap +2 -2
- package/src/components/layouts/__snapshots__/ZoomedFullBody.test.tsx.snap +2 -2
- package/src/helpers/constants.ts +2 -2
|
@@ -35,8 +35,16 @@ marked.use({
|
|
|
35
35
|
gfm: true,
|
|
36
36
|
pedantic: false,
|
|
37
37
|
renderer: {
|
|
38
|
-
link: ({
|
|
39
|
-
|
|
38
|
+
link: ({
|
|
39
|
+
href,
|
|
40
|
+
title,
|
|
41
|
+
text,
|
|
42
|
+
}: {
|
|
43
|
+
href: string | null;
|
|
44
|
+
title?: string | null;
|
|
45
|
+
text: string;
|
|
46
|
+
}) => {
|
|
47
|
+
const cleanHref = href ? cleanUrl(href) : null;
|
|
40
48
|
|
|
41
49
|
if (cleanHref === null) {
|
|
42
50
|
return text;
|
|
@@ -54,71 +62,69 @@ marked.use({
|
|
|
54
62
|
marked.use(markedLinkifyIt());
|
|
55
63
|
marked.use(markedExtendedTables());
|
|
56
64
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return rows.reduce((acc, row) => {
|
|
61
|
-
if (row.includes('=')) {
|
|
62
|
-
let result = '';
|
|
63
|
-
let isEscaped = false;
|
|
64
|
-
for (let i = 0; i < row.length; i++) {
|
|
65
|
-
if (row[i] === '[' && !isEscaped) {
|
|
66
|
-
result += '\\[';
|
|
67
|
-
} else if (row[i] === ']' && !isEscaped) {
|
|
68
|
-
result += '\\]';
|
|
69
|
-
} else {
|
|
70
|
-
result += row[i];
|
|
71
|
-
}
|
|
72
|
-
isEscaped = row[i] === '\\' && !isEscaped;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return acc?.length ? `${acc}\n${result}` : result;
|
|
76
|
-
} else {
|
|
77
|
-
return acc?.length ? `${acc}\n${row}` : row;
|
|
78
|
-
}
|
|
79
|
-
}, '');
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const renderMsg = (text: string, useMathFormatting = false) => {
|
|
65
|
+
// Update the renderMsg function to properly handle math formatting
|
|
66
|
+
const renderMsg = (text: string, useMathFormatting = false): string => {
|
|
83
67
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.replaceAll('\beta', '\\beta')
|
|
100
|
-
.replaceAll('cdot', '\\cdot')
|
|
101
|
-
) as string
|
|
102
|
-
).trim();
|
|
103
|
-
|
|
68
|
+
// Preprocessing del testo per gestire i delimitatori LaTeX
|
|
69
|
+
let preprocessedText = text
|
|
70
|
+
.trim()
|
|
71
|
+
.replaceAll(
|
|
72
|
+
/\[([^\]]+)\]\(([^\)]+)\)/g,
|
|
73
|
+
'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'
|
|
74
|
+
)
|
|
75
|
+
.replaceAll(/```markdown([^```]+)```/g, '$1')
|
|
76
|
+
.replaceAll('($', '( $')
|
|
77
|
+
.replaceAll(':$', ': $')
|
|
78
|
+
.replaceAll('\frac', '\\frac')
|
|
79
|
+
.replaceAll('\beta', '\\beta')
|
|
80
|
+
.replaceAll('cdot', '\\cdot');
|
|
81
|
+
|
|
82
|
+
// Correzione dei delimitatori LaTeX inconsistenti
|
|
104
83
|
if (useMathFormatting) {
|
|
105
|
-
|
|
84
|
+
// Normalizza tutti i delimitatori LaTeX per equazioni su linea separata
|
|
85
|
+
// Da \\[ ... \\] o \\[ ... ] a $$ ... $$
|
|
86
|
+
preprocessedText = preprocessedText.replace(
|
|
87
|
+
/\\+\[(.*?)\\*\]/gs,
|
|
88
|
+
(_, content) => {
|
|
89
|
+
return `$$${content}$$`;
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// Gestione dei delimitatori [ ... ] che dovrebbero essere equazioni
|
|
94
|
+
preprocessedText = preprocessedText.replace(
|
|
95
|
+
/\[([^[\]]+?)\]/g,
|
|
96
|
+
(match, content) => {
|
|
97
|
+
// Verifica se sembra una formula matematica
|
|
98
|
+
if (/[\\+a-z0-9_{}^=\-\+\*\/]+/i.test(content) &&
|
|
99
|
+
!match.startsWith('[http') &&
|
|
100
|
+
!match.includes('](')) {
|
|
101
|
+
return `$$${content}$$`;
|
|
102
|
+
}
|
|
103
|
+
return match; // Mantieni invariati i link e altre strutture
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
// Ora procedi con il parsing markdown
|
|
109
|
+
let parsedText = marked
|
|
110
|
+
.parse(preprocessedText)
|
|
111
|
+
.toString()
|
|
112
|
+
.trim();
|
|
113
|
+
|
|
114
|
+
// Sanitizza l'HTML
|
|
108
115
|
parsedText = DOMPurify.sanitize(parsedText, {
|
|
109
116
|
ADD_ATTR: ['target'],
|
|
110
117
|
});
|
|
111
118
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
);
|
|
119
|
+
// Pulizia del testo finale
|
|
120
|
+
const finalText = parsedText
|
|
121
|
+
.replace(/(<br>)+/g, '<br>')
|
|
122
|
+
.replace(/<p><\/p>/g, '<br>')
|
|
123
|
+
.replace(/<p><br><\/p>/g, '<br>');
|
|
124
|
+
|
|
125
|
+
return finalText;
|
|
120
126
|
} catch (e) {
|
|
121
|
-
console.error(e);
|
|
127
|
+
console.error('Error rendering message:', e);
|
|
122
128
|
return text;
|
|
123
129
|
}
|
|
124
130
|
};
|
|
@@ -189,16 +195,14 @@ const ChatBubble: React.FC<Props> = ({
|
|
|
189
195
|
!message.fromUser &&
|
|
190
196
|
useMathFormatting
|
|
191
197
|
) {
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
window.MathJax.typesetPromise(['.memori-chat--bubble-content']);
|
|
198
|
+
// Add type declaration for MathJax
|
|
199
|
+
const mathJax = (window as any).MathJax;
|
|
200
|
+
if (mathJax?.typesetPromise) {
|
|
201
|
+
mathJax.typesetPromise(['.memori-chat--bubble-content']);
|
|
202
|
+
}
|
|
198
203
|
}
|
|
199
204
|
}, [message.text, message.fromUser, useMathFormatting]);
|
|
200
205
|
|
|
201
|
-
|
|
202
206
|
return (
|
|
203
207
|
<>
|
|
204
208
|
{(message.initial || isFirst) && (
|