Home

Agent 消息处理

1/27/2026, 1:17: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: dep

Marvin
1月27日 13:17
b6e70fbd

On this page