3.4 KiB
Paper Draft Streaming Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Stream paper draft markdown into the paper draft page as it is generated, then save the completed draft.
Architecture: Add a dedicated streaming paper draft endpoint that reuses the existing prompt builder and forwards DeepSeek streaming deltas to the browser. The frontend uses fetch with ReadableStream so authorization headers and JSON request bodies continue to work.
Tech Stack: Spring Boot 2.5, StreamingResponseBody, DeepSeek chat completions streaming, Vue 3, fetch streams, existing paper persistence API.
Task 1: Backend Streaming Contract
Files:
-
Modify:
ruoyi-generator/src/main/java/com/ruoyi/generator/service/front/IDeepSeekClient.java -
Modify:
ruoyi-generator/src/main/java/com/ruoyi/generator/service/front/HttpDeepSeekClient.java -
Test:
ruoyi-generator/src/test/java/com/ruoyi/generator/service/front/HttpDeepSeekClientTest.java -
Add a
StreamHandlercallback contract toIDeepSeekClient. -
Write a failing test that feeds SSE lines with
choices[0].delta.contentand verifies chunks are emitted in order. -
Implement DeepSeek
stream: trueparsing fordata:lines and[DONE]. -
Keep the existing non-streaming
chatbehavior unchanged.
Task 2: Paper Draft Stream Service And Controller
Files:
-
Modify:
ruoyi-generator/src/main/java/com/ruoyi/generator/service/front/IAiGenerateService.java -
Modify:
ruoyi-generator/src/main/java/com/ruoyi/generator/service/front/AiGenerateServiceImpl.java -
Modify:
ruoyi-admin/src/main/java/com/ruoyi/web/controller/front/FrontProjectController.java -
Test:
ruoyi-generator/src/test/java/com/ruoyi/generator/service/front/AiGenerateServiceImplTest.java -
Add
streamPaperDraft(userId, projectId, request, handler)to the AI service. -
Write a failing test proving
streamPaperDraftreuses the paper draft prompt and emits sanitized chunks. -
Add
POST /front/project/{projectId}/paper-draft/streamreturningtext/plain;charset=UTF-8as a streaming response. -
Ensure exceptions are propagated so the frontend can show failure instead of saving partial text as completed output.
Task 3: Frontend Stream Consumption
Files:
-
Modify:
easycode-web/src/api/project.js -
Modify:
easycode-web/src/views/PaperDraftView.vue -
Test:
easycode-web/src/views/paperDraftView.test.mjs -
Add
streamPaperDraft(projectId, data, handlers)usingfetch,Authorization, andReadableStream. -
Update
handleGenerateDraftto clear old text, stream chunks intodraftMarkdown, keep the preview tab active, then callsavePaperDraft({ silent: true }). -
Add an abort controller and show a Stop button while streaming.
-
Add source-level tests checking the stream API is imported, the stop action exists, and the old synchronous
generatePaperDraftpath is no longer used by the page.
Task 4: Verification
Files:
-
Test commands only.
-
Run
node --test easycode-web/src/views/paperDraftView.test.mjs easycode-web/src/utils/markdown.test.mjs. -
Run
mvn -pl ruoyi-generator "-Dtest=AiGenerateServiceImplTest#generatePaper*,HttpDeepSeekClientTest" test. -
Report any unrelated existing red tests separately from the focused streaming checks.