feat: optimize WebUI stream output and sanitize user-facing answers

This commit is contained in:
2026-03-13 13:14:37 +08:00
parent 8dc5354fa4
commit 33c357a1de
8 changed files with 228 additions and 45 deletions

View File

@@ -57,12 +57,14 @@ data: {"type":"final","content":"当前目录是 C:/Project/MyProject","step":2}
事件类型:
- `thought`: 模型思考过程
- `tool_call`: 工具调用请求
- `tool_result`: 工具返回结果
- `final`: 最终回答
- `error`: 错误信息
说明:
- 当前 WebUI 默认只向前端返回 `final``error`
- 中间推理轨迹(如 `thought``tool_call``tool_result` 以及对应的 `step`)会写入服务端 `debug` 日志,不再直接返回给用户界面。
## 4. 连接生命周期
- 正常结束: 收到 `type=final` 后结束渲染,连接可由浏览器自然关闭。
@@ -71,10 +73,8 @@ data: {"type":"final","content":"当前目录是 C:/Project/MyProject","step":2}
## 5. 前端渲染建议
推荐将一次请求的事件按 `step` 分组后渲染,典型展示区块:
推荐前端仅处理两类结果:
- 思考区: 逐条显示 `thought`
- 工具区: 成对显示 `tool_call``tool_result`
- 答案区: 显示最后一个 `final`
- 错误区: 显示 `error`
@@ -88,7 +88,7 @@ data: {"type":"final","content":"当前目录是 C:/Project/MyProject","step":2}
## 6. TypeScript 对接示例 (fetch + ReadableStream)
```ts
type StreamEventType = 'thought' | 'tool_call' | 'tool_result' | 'final' | 'error';
type StreamEventType = 'final' | 'error';
interface StreamEvent {
type: StreamEventType;
@@ -165,6 +165,7 @@ export async function streamChat(
- step?: number
- tool_name?: string
5) 收到 final 视为本轮完成;收到 error 视为失败
6) 不要再假设前端会收到 thought/tool_call/tool_result这些内部轨迹已改为服务端 debug 日志
你的改造要求:
1) 保留现有 UI 风格和组件结构,不做无关重构