feat: 富文本消息类型支持 — Markdown/代码块安全渲染 + 审查解析器
添加 review_parser.go 从 LLM 输出中提取 Markdown 和代码块,创建独立 ReviewMessage 类型 (markdown/code/search_result)。前端新增安全 Markdown 渲染器 (HTML 转义优先),代码块以深色背景+语言标签展示。Markdown/代码 类型禁止断句拆分,避免格式损坏。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+17
-3
@@ -209,7 +209,7 @@ ws://<gateway>/ws/chat?token=<jwt>&session_id=<optional>&client_id=<optional>&de
|
||||
"text": "string (完整文本)",
|
||||
"content": "string (增量文本/完整内容)",
|
||||
"role": "user|assistant|action|system",
|
||||
"msg_type": "chat|action|thinking|tool_progress|system_info (后端始终填充,前端无需自行解析)",
|
||||
"msg_type": "chat|action|thinking|tool_progress|system_info|markdown|code (后端始终填充,前端无需自行解析)",
|
||||
"session_id": "string",
|
||||
"error": "string (仅错误时)",
|
||||
"timestamp": 1717000000000,
|
||||
@@ -221,7 +221,7 @@ ws://<gateway>/ws/chat?token=<jwt>&session_id=<optional>&client_id=<optional>&de
|
||||
"system_info": { "level": "info|warning|error", "message": "string", "action": "string" },
|
||||
"notification": { "id": "string", "type": "info|warning|success|thinking|reminder", "title": "string", "body": "string", "timestamp": "string", "data": {} },
|
||||
"multi_message": { "messages": [ { "index": 0, "content": "string", "msg_type": "chat|action|system_info" } ] },
|
||||
"review_messages": [ { "type": "action|chat", "content": "string", "delay_ms": 0 } ],
|
||||
"review_messages": [ { "type": "action|chat|markdown|code|search_result", "content": "string", "delay_ms": 0, "metadata": { "language": "string (code 类型时)", "url": "string (search_result 类型时)" } } ],
|
||||
"client_info": { "client_id": "string", "device_name": "string", "user_agent": "string" },
|
||||
"full_audio_url": "string",
|
||||
"response_mode": "string"
|
||||
@@ -255,9 +255,23 @@ ws://<gateway>/ws/chat?token=<jwt>&session_id=<optional>&client_id=<optional>&de
|
||||
> `msg_type` 可选值:
|
||||
> - `chat` — 普通聊天消息
|
||||
> - `action` — 动作/旁白消息(如 `(昔涟轻轻推开窗户)`),前端以斜体灰色样式渲染
|
||||
> - `markdown` — Markdown 格式消息,前端使用安全渲染器转换后显示(支持标题、列表、表格、代码块、链接等)
|
||||
> - `code` — 独立代码块消息,前端以深色背景 + 语言标签渲染,可包含 `metadata.language` 指明编程语言
|
||||
> - `thinking` — 后台思考过程,前端显示为可折叠详情块
|
||||
> - `tool_progress` — 工具执行进度,前端显示进度条
|
||||
> - `system_info` — 系统通知,前端居中显示为 toast 样式
|
||||
>
|
||||
> **`review` 消息类型详情:**
|
||||
>
|
||||
> 当 AI 回复包含多种格式内容(如工具调用结果中的 Markdown 文档或代码片段)时,后端解析器将回复拆分为多条 `review_messages`,每条独立指定 `type` 和 `content`:
|
||||
>
|
||||
> - `action` — 动作/旁白文本,不做 Markdown 渲染,禁止断句拆分
|
||||
> - `chat` — 普通聊天文本,可按句长断句
|
||||
> - `markdown` — Markdown 格式文本,禁止断句拆分,前端使用安全渲染器(先 HTML 转义再转换 Markdown 语法)
|
||||
> - `code` — 代码块,禁止断句拆分,前端深色背景渲染,`metadata.language` 字段携带语言标识
|
||||
> - `search_result` — 搜索工具调用结果摘要(后端内部使用,通常转为 `markdown` 或 `chat` 类型展示)
|
||||
>
|
||||
> Markdown 渲染器支持语法:标题 (h1-h6)、粗体/斜体、行内代码/围栏代码块、链接、图片、无序/有序列表、引用块、表格、水平线。
|
||||
|
||||
---
|
||||
|
||||
@@ -358,7 +372,7 @@ Client Gateway Voice-Service
|
||||
"id": 1,
|
||||
"session_id": "string",
|
||||
"role": "user|assistant|system|action",
|
||||
"msg_type": "chat|action",
|
||||
"msg_type": "chat|action|markdown|code",
|
||||
"content": "string",
|
||||
"created_at": 1717000000000
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user