Skip to content

Commit 9c80533

Browse files
committed
Update message.tsx
1 parent 2be2b07 commit 9c80533

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

apps/saru/components/chat/message.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import Image from "next/image";
1919
import { UseChatHelpers } from "@ai-sdk/react";
2020
import { useDocument } from "@/hooks/use-document";
2121

22-
const MENTION_RE = /@\[([^\]]+)\]\(([^)]+)\)/g;
23-
2422
function MentionChip({ title, id }: { title: string; id: string }) {
2523
const { loadDocument } = useDocument();
2624
return (
@@ -38,11 +36,11 @@ function MentionChip({ title, id }: { title: string; id: string }) {
3836
}
3937

4038
function MessageContent({ content }: { content: string }) {
41-
if (!MENTION_RE.test(content)) return <Markdown>{content}</Markdown>;
39+
if (!content.includes('@[')) return <Markdown>{content}</Markdown>;
4240

4341
const parts: React.ReactNode[] = [];
4442
let last = 0;
45-
for (const match of content.matchAll(new RegExp(MENTION_RE.source, 'g'))) {
43+
for (const match of content.matchAll(/@\[([^\]]+)\]\(([^)]+)\)/g)) {
4644
if (match.index! > last) parts.push(<Markdown key={last}>{content.slice(last, match.index)}</Markdown>);
4745
parts.push(<MentionChip key={match.index} title={match[1]} id={match[2]} />);
4846
last = match.index! + match[0].length;

0 commit comments

Comments
 (0)