mirror of
https://github.com/kuaifan/dootask.git
synced 2026-07-31 10:25:59 +00:00
2.3 KiB
2.3 KiB
id, title, type, feature, scope, locale, aliases, related_tools, related_pages, prerequisites, negative, last_verified
| id | title | type | feature | scope | locale | aliases | related_tools | related_pages | prerequisites | negative | last_verified | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ai-assistant.streaming.concept | AI 助手流式输出 | concept | ai-assistant | end-user | zh |
|
|
v1.7.90 |
AI 助手流式输出
定义
AI 助手通过 SSE(Server-Sent Events) 接收上游 LLM 的逐 token 输出,每收到一个 chunk 就追加到当前 message 的 rawOutput,呈现 ChatGPT 般「边写边出」的效果。
数据流
POST api/assistant/auth→ 拿 stream_keyEventSource ai/invoke/stream/{stream_key}- 监听三类事件:
append→ 追加(entry.rawOutput += chunk)replace→ 整段替换(entry.rawOutput = chunk)done→ 流结束(entry.status = 'completed')
- 断流 / 异常 →
handleStreamFailed
事件类型
| 事件 | 用途 |
|---|---|
append |
普通增量 token(最常见) |
replace |
整段替换(工具结果回填、思考链重写) |
done |
流结束,payload 含 error 字段表示上游报错 |
状态机
每条 AI message 4 个状态:
waiting→ 已发出但首个 chunk 未到streaming→ 正在接收 chunkcompleted→done正常收到error→ 上游错误、连接失败、用户中断
并发与归属
- 每个流绑定
owner = {sessionKey, sessionId, localId} - 用户切到其他会话后,原流仍后台跑,结束时写回原会话存储
- 发新问题前会清掉同会话的所有活跃流,防止两段对话错位
中断恢复保护
- 关浮窗 / 页面崩溃后,下次加载会话发现 message 仍是
streaming/waiting则归一为error - 避免「永远转圈」(
sanitizeResponsesForPersist)
滚动行为
- 视图在最底部时新 chunk 自动
scrollToBottom - 用户向上翻历史时(距底 > 20px)不强制下拉
不支持
- 不支持 WebSocket
- 不支持 chunk 级别撤销
- 不支持自动重试断流