Home

Agent 消息处理

2/4/2026, 11:37:40 AM 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)

feat: us cd

Marvin
2月4日 11:37
ba8670a5

On this page