支持在会话消息中打开里面的链接和本地文件

This commit is contained in:
xintaofei
2026-03-10 13:40:06 +08:00
parent 5564fdd39f
commit 13667729b9
5 changed files with 392 additions and 22 deletions

View File

@@ -28,6 +28,7 @@ import {
useState,
} from "react"
import { Streamdown } from "streamdown"
import { useStreamdownLinkSafety } from "./link-safety"
export type MessageProps = HTMLAttributes<HTMLDivElement> & {
from: UIMessage["role"]
@@ -327,17 +328,24 @@ export type MessageResponseProps = ComponentProps<typeof Streamdown>
const streamdownPlugins = { cjk, code, math, mermaid }
export const MessageResponse = memo(
({ className, ...props }: MessageResponseProps) => (
function MessageResponseImpl({ className, ...props }: MessageResponseProps) {
const linkSafety = useStreamdownLinkSafety()
return (
<Streamdown
className={cn(
"size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",
className
)}
linkSafety={linkSafety}
plugins={streamdownPlugins}
{...props}
/>
),
)
}
export const MessageResponse = memo(
MessageResponseImpl,
(prevProps, nextProps) => prevProps.children === nextProps.children
)