Agent 消息处理
12/2/2025, 12:51:38 PM modified by Marvin分析 Agent 消息格式,并给出富文本渲染组件的设计。
本文原含可执行示例,迁移至 Fumadocs 后仅保留核心代码与思路。
细化处理单个消息
type Content =
| {
type: 'text'
text: string
}
| {
type: 'agent'
agent: string // custom html tag, just like <agent attr="attr"></agent>
}映射富文本组件
Markdown 也是富文本的一种。
const components: Components & {
agent?: React.ElementType
} = {
agent: ({ node, ...props }) => <Agent {...props} />,
}
<Markdown rehypePlugins={[rehypeRaw]} components={components}>
{contentValue}
</Markdown>rehypeRaw 允许解析 HTML,components 允许自定义组件。
Git Commit History(1 commits)
fix: 简化zod form
Marvin
12月2日 12:51
e0cadf68