import { Streamdown, type Components } from "streamdown";
import { memo } from "react";
import { AiMessageCodeBlock } from "./ai-message-code-block";
import "streamdown/styles.css";
type AIMessageMarkdownProps = {
children: string;
isStreaming?: boolean;
className?: string;
};
function buildComponents(isStreaming: boolean): Components {
return {
h1: ({ children, ...props }) =>
{children}
,
h2: ({ children, ...props }) => {children}
,
h3: ({ children, ...props }) => {children}
,
h4: ({ children, ...props }) => {children}
,
p: ({ children, ...props }) => {children}
,
ul: ({ children, ...props }) => ,
ol: ({ children, ...props }) => {children}
,
li: ({ children, ...props }) => {children},
blockquote: ({ children, ...props }) => {children}
,
pre: ({ children, ...props }) => {children},
code: ({ children, className, ...props }) => {children},
a: ({ children, ...props }) => {children},
hr: (props) =>
,
table: ({ children, ...props }) => ,
th: ({ children, ...props }) => {children} | ,
td: ({ children, ...props }) => {children} | ,
input: ({ ...props }) => ,
};
}
const staticComponents = buildComponents(false);
const streamingComponents = buildComponents(true);
export const AIMessageMarkdown = memo(function AIMessageMarkdown({ children, isStreaming = false, className = "" }: AIMessageMarkdownProps) {
if (!children.trim()) return null;
return (
{children}
);
});