feat(generation): add validated SSE task adapter - #110
Open
xyh202131 wants to merge 2 commits into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Review summary: two issues stand out.
Findings without inline locations
frontend/src/entities/generation/index.ts:102: The complete-animation result type only preserves URLs, but the backend action frame DTO already carriesduration_msand the frontendFramemodel can storedurationMs. Once this adapter maps the task intoGenerationResult, that timing data is gone and downstream character writes will have to invent defaults.
This was referenced Aug 4, 2026
实测反馈:契约对得上,但终态不关流会无限重连;另外目前零 UI 消费者在集成分支( 1. 契约是对的,两处可以放心
2. 终态之后 EventSource 会每 3 秒重连一次,需要显式 close服务端发完终态事件就关流,但响应里带了 也就是说:任务早就结束了,前端还在每 3 秒打一次请求,且业务回调会被重复触发。 修法二选一(前者更稳):
3. 目前全仓没有调用方搜 |
This was referenced Aug 5, 2026
Closed
Co-Authored-By: Claude <noreply@anthropic.com>
xyh202131
force-pushed
the
feat/generation-sse-adapter
branch
from
August 7, 2026 10:37
b0bc0ce to
33b4863
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Generation + SSE Adapter
Refs #78
Issue #78 已补
mile3标签并关联milestone/4。本变更只实现前端 Generation实体适配器与 SSE 传输封装,并同步修正相关接口文档;不修改后端、页面、Controller
或构建产物。
变更范围
GenerationApis。createGenerationApis必须由宿主注入userId与transport;模块不写死用户身份,也不直接持有
fetch或EventSource。shared/api/stream.ts。后端 SSE 需要 Bearer Token,因此使用fetch + ReadableStream,由宿主注入 token provider;支持命名事件、主动取消、终态关闭和网络断线重连,不恢复 2 秒业务轮询。
actionType,避免把其他动作的帧误接到当前任务。resolveImageSize(projectId)提供项目画布尺寸;Generation 不直接依赖 Project,也不会回退到可能冲突的 1024 默认值。
三阶段合同
character_templatePOST /generation/imagenum_images: 4first_framePOST /generation/actionnum_frames: 1complete_animationPOST /generation/actionnum_frames: 16index排序并保留duration_msCompleteAnimationGenerationInput当前没有frameCount字段,因此无法由调用输入表达帧数。本次保守沿用后端合同默认值 16;后续若合同加入可配置字段,应改为透传输入并补充
边界校验,而不是继续保留常量。
SSE 行为
/generation/tasks/{taskId}/stream?project_id=...。task_update命名事件,事件 DTO 在 Generation 边界解析和校验。id;适配器在边界转换为前端字符串taskId。Authorization: Bearer ...,token 刷新后重连会使用新值。completed、failed都视为终态;事件先交付调用方,再由传输层关闭连接。onError必传,非法事件关闭连接时不能静默留下永远等待的工作流。AbortController中止当前 fetch 请求。没有定时 GET 或其他业务轮询。
DTO 校验
code/message/data,业务错误不会被当作成功数据。GenerationApiError,绝不降级为pending。时长格式与状态/错误一致性;完整动画保留逐帧时长,非完成任务携带结果同样视为非法合同。
测试覆盖
id → taskId、主动取消、终态关闭、事件解析错误和断线恢复语义。
验证结果
npx oxfmt --check定向检查本次前端合同与 TypeScript 文件:通过。npm run format:check全量检查:已执行,但被基线中 41 个本次所有权外文件阻断;未批量重写这些文件,以免覆盖其他工作者的修改。
npm run lint:通过。npm run typecheck:通过。npm test:在最新main合并基线上通过,20 个测试文件、91 个测试。npm run build:通过,Vite 8.1.5 共转换 105 个模块。后端
/generation/tasks/{taskId}/stream以 DireSoul PR #34 的已合并实现为准;本 PR按其完整 GenerationTask 事件和鉴权要求对齐。测试覆盖前端传输与映射,真实部署环境的
端到端联调仍应在集成分支执行。