Skip to content

阶段 1:流式输出 + 打字机光标 + 停止按钮 #3

@ZhouChaunge

Description

@ZhouChaunge

目的

解决目前「等待很久才一次性弹出整段回复」的体验问题,改为像 Copilot / ChatGPT 一样逐 token 流式呈现,并支持中途停止生成。

任务清单

Extension 端

  • DeepSeek API 调用改为 stream: true
  • 解析 SSE,逐 chunk 通过 postMessage({type:'stream', id, delta}) 推到 webview
  • 引入 AbortController,收到 {type:'abort'} 时中止当前请求
  • 流结束发送 {type:'stream-end', id},出错发送 {type:'stream-error', id, message}

Webview 端

  • 维护 messageBuffers[id],append 后只重渲染最后一个未闭合的 markdown 块,避免整条 re-render 闪烁
  • 在最后一个 token 后追加闪烁 光标,stream-end 时移除
  • 滚动锁定:用户滚到非底部时不强行 auto-scroll(scrollHeight - scrollTop - clientHeight < 50 判定在底部)
  • 发送按钮在生成中变为 ⏹ Stop,点击发送 abort 消息

验收标准

  • 字符像打字机一样实时出现
  • 长输出向上滚动时不被新 token 拉回底部
  • 点击 ⏹ 能立刻停止,已输出内容保留

关联

Tracking: #1
依赖:#2(基础设施)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions