Skip to content

Commit a5f1571

Browse files
committed
fix: properly parse mentions with regex
1 parent d729d28 commit a5f1571

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

apps/saru/components/chat/message.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,24 @@ function formatMessageWithMentions(content: string) {
2525
const formattedContent = [];
2626
let match;
2727
let lastIndex = 0;
28-
const regex = /@([a-zA-Z0-9\s_-]+)/g;
28+
const regex = /@\[([^\]]+)\]\(([^)]+)\)/g;
2929

3030
while ((match = regex.exec(content)) !== null) {
3131
if (match.index > lastIndex) {
3232
formattedContent.push(content.substring(lastIndex, match.index));
3333
}
3434

35-
const documentName = match[1];
35+
const title = match[1];
36+
const id = match[2];
3637
formattedContent.push(
37-
`<span class="inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 text-sm font-medium">
38+
`<a href="/documents/${id}" class="inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 text-sm font-medium hover:bg-blue-200 dark:hover:bg-blue-900/50 transition-colors no-underline">
3839
<span class="text-blue-500 dark:text-blue-400">
3940
<svg width="12" height="12" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
4041
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.5 13.5V6.5V5.41421C14.5 5.149 14.3946 4.89464 14.2071 4.70711L9.79289 0.292893C9.60536 0.105357 9.351 0 9.08579 0H8H3H1.5V1.5V13.5C1.5 14.8807 2.61929 16 4 16H12C13.3807 16 14.5 14.8807 14.5 13.5ZM13 13.5V6.5H9.5H8V5V1.5H3V13.5C3 14.0523 3.44772 14.5 4 14.5H12C12.5523 14.5 13 14.0523 13 13.5ZM9.5 5V2.12132L12.3787 5H9.5Z" fill="currentColor"/>
4142
</svg>
4243
</span>
43-
${documentName}
44-
</span>`
44+
${title}
45+
</a>`
4546
);
4647

4748
lastIndex = match.index + match[0].length;

apps/saru/components/chat/multimodal-input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function PureMultimodalInput({
204204
contextData.mentionedDocumentIds = confirmedMentions.map(doc => doc.id);
205205
}
206206

207-
const parts: any[] = [{ type: 'text', text: plainTextValue || inputValue }];
207+
const parts: any[] = [{ type: 'text', text: inputValue }];
208208

209209
const requestBody = {
210210
chatId: chatId,

apps/saru/components/document/editor.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ function PureEditor({
261261
onStatusChange(newSaveState);
262262
}
263263

264-
// Handle debounced version creation when content changes (only for current version)
265-
if (transaction.docChanged && isCurrentVersion) {
264+
if (transaction.docChanged && isCurrentVersion && !transaction.getMeta('external')) {
266265
const currentContent = buildContentFromDocument(newState.doc);
267266
debouncedVersionHandler(currentContent);
268267
}

apps/saru/components/suggestion-overlay.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ export default function SuggestionOverlay({
334334
break;
335335

336336
case "suggestion-delta":
337-
setSuggestion((prev) =>
338-
normalizeSuggestionText(`${prev}${String(data.content ?? "")}`)
339-
);
337+
setSuggestion((prev) => `${prev}${String(data.content ?? "")}`);
340338
break;
341339

342340
case "error":

0 commit comments

Comments
 (0)