推进 server-rs DDD 分层与新接口接线
This commit is contained in:
@@ -4,6 +4,10 @@
|
||||
|
||||
## 文档列表
|
||||
|
||||
- [SERVER_RS_DDD_WP_SC_SPACETIME_CLIENT_REFACTOR_2026-04-29.md](./SERVER_RS_DDD_WP_SC_SPACETIME_CLIENT_REFACTOR_2026-04-29.md):冻结 `WP-SC Spacetime Client` 本次基础设施重构边界,明确只收口 `spacetime-client` 的 typed facade、错误映射和 row snapshot mapper,不预判尚未由 `WP-ST` 稳定的表、reducer、procedure 或 row shape。
|
||||
- [SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_PROGRESS_2026-04-29.md](./SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_PROGRESS_2026-04-29.md):记录 `G1 契约与路由矩阵` 已完成的本地进度、验证结果、单 owner 边界和下一批并行任务入口。
|
||||
- [SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md](./SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md):冻结 `server-rs` DDD G1 契约与路由矩阵,明确新旧 HTTP 路由去留、DTO 删除/保留/重命名、页面到 query/result DTO 映射、breaking change、API 错误 envelope 和共享契约单 owner 边界。
|
||||
- [SERVER_RS_DDD_WP_API_BFF_START_2026-04-29.md](./SERVER_RS_DDD_WP_API_BFF_START_2026-04-29.md):记录 `WP-API api-server BFF` 启动切片,先收口旧 runtime story 兼容路由挂载、错误 envelope 回归和后续依赖,不越过 `spacetime-client` 接线边界。
|
||||
- [SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md](./SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md):把 `server-rs` DDD 一次性重构拆成全局可并行工作包,覆盖 `module-*`、`spacetime-module`、`spacetime-client`、`api-server`、`platform-*`、共享契约和前端接入的依赖、边界与验收命令。
|
||||
- [SERVER_RS_DDD_FULL_REFACTOR_2026-04-28.md](./SERVER_RS_DDD_FULL_REFACTOR_2026-04-28.md):冻结 `server-rs` 一次性 DDD 重构总纲,明确 crate 依赖方向、模块目录、上下文聚合/命令/事件/读模型、SpacetimeDB adapter 映射和表结构变更约束。
|
||||
- [SPACETIMEDB_SCHEMA_CHANGE_CONSTRAINTS.md](./SPACETIMEDB_SCHEMA_CHANGE_CONSTRAINTS.md):冻结 SpacetimeDB 表结构变更约束、自动迁移可接受范围、冲突后的系统行为,以及保留旧数据的增量迁移流程;凡涉及 `spacetime publish`、表字段调整或 `migration.rs` 对齐时优先参考。
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
更新时间:`2026-04-23`
|
||||
|
||||
> 2026-04-29 补充:本文件保留为迁移期路由快照。DDD G1 后续并行工作的契约冻结口径以 [`SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md`](./SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md) 为准,尤其是新增的 Big Fish、Puzzle、profile、runtime chat、story facade 和兼容路由删除计划。
|
||||
>
|
||||
> 2026-04-29 WP-RS 进度:旧 `/api/runtime/story/*` HTTP compat 路由已从 `api-server/src/app.rs` 取消挂载,并删除 `api-server/src/runtime_story*` 兼容实现。当前 Rust `api-server` 对外 story 主链只保留 `/api/story/*`、`/api/runtime/sessions/{runtime_session_id}/inventory` 与 runtime chat 相关路由。
|
||||
|
||||
## 1. 文档目标
|
||||
|
||||
本文件记录当前 `server-rs/crates/api-server/src/app.rs` 中已挂载的 Rust Axum 路由面,用于对照 Node 后端 `96` 条路由能力基线。
|
||||
@@ -20,7 +24,7 @@
|
||||
6. custom world / agent 接口:`23` 条。
|
||||
7. llm proxy 接口:`1` 条。
|
||||
8. profile / runtime profile 接口:`12` 条。
|
||||
9. runtime story / story gameplay 接口:`15` 条。
|
||||
9. story gameplay / runtime inventory 接口:`10` 条。
|
||||
10. legacy generated 静态路径兼容:`6` 条。
|
||||
11. health check:`1` 条。
|
||||
|
||||
@@ -129,23 +133,18 @@
|
||||
11. `POST /api/profile/save-archives/{world_key}`
|
||||
12. `POST /api/runtime/profile/save-archives/{world_key}`
|
||||
|
||||
### 3.9 Runtime Story / Gameplay
|
||||
### 3.9 Story Gameplay / Runtime Inventory
|
||||
|
||||
1. `POST /api/runtime/save/snapshot`
|
||||
2. `GET /api/runtime/settings`
|
||||
3. `GET /api/runtime/story/state/{session_id}`
|
||||
4. `POST /api/runtime/story/state/resolve`
|
||||
5. `POST /api/runtime/story/actions/resolve`
|
||||
6. `POST /api/runtime/story/initial`
|
||||
7. `POST /api/runtime/story/continue`
|
||||
8. `POST /api/story/sessions`
|
||||
9. `POST /api/story/sessions/continue`
|
||||
10. `GET /api/story/sessions/{story_session_id}/state`
|
||||
11. `POST /api/story/battles`
|
||||
12. `POST /api/story/battles/resolve`
|
||||
13. `GET /api/story/battles/{battle_state_id}`
|
||||
14. `POST /api/story/npc/battle`
|
||||
15. `GET /api/runtime/sessions/{runtime_session_id}/inventory`
|
||||
3. `POST /api/story/sessions`
|
||||
4. `POST /api/story/sessions/continue`
|
||||
5. `GET /api/story/sessions/{story_session_id}/state`
|
||||
6. `POST /api/story/battles`
|
||||
7. `POST /api/story/battles/resolve`
|
||||
8. `GET /api/story/battles/{battle_state_id}`
|
||||
9. `POST /api/story/npc/battle`
|
||||
10. `GET /api/runtime/sessions/{runtime_session_id}/inventory`
|
||||
|
||||
### 3.10 Legacy Generated 路径
|
||||
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
# server-rs DDD G1 契约与路由矩阵冻结(2026-04-29)
|
||||
|
||||
## 1. 冻结范围
|
||||
|
||||
本文是 `SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md` 中 `G1 契约与路由矩阵` 的串行冻结结果。G1 只冻结契约、路由和后续并行任务边界,不实现业务逻辑,不迁移 reducer,不改前端页面。
|
||||
|
||||
G1 单 owner 文件范围:
|
||||
|
||||
1. `server-rs/crates/shared-contracts/src/**`
|
||||
2. `packages/shared/src/contracts/**`
|
||||
3. `packages/shared/src/index.ts`
|
||||
4. `docs/technical/RUST_API_SERVER_ROUTE_INDEX_2026-04-22.md`
|
||||
5. 本文档
|
||||
|
||||
后续并行任务只能消费本文冻结的 route、DTO 和 error envelope。确实需要新增或调整 DTO shape 时,先在对应工作包交接中写清变更原因,再回到 G1 owner 文件集中改动,避免多个并行线同时抢改契约。
|
||||
|
||||
## 2. HTTP 路由矩阵
|
||||
|
||||
状态含义:
|
||||
|
||||
1. `保留`:作为 DDD 改造后的主链路由继续存在。
|
||||
2. `重命名`:后续改成新的 route family,旧路径删除,不做兼容双主链。
|
||||
3. `删除`:兼容层或临时调试入口,前端迁移后物理删除。
|
||||
4. `收敛`:保留功能,但 route、DTO 或返回 envelope 需要归一到新的主链。
|
||||
|
||||
| 分组 | 当前路由 | G1 决议 | 新主链目标 | 所属后续任务 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 健康检查 | `GET /healthz` | 保留 | 不变,统一 envelope 可例外保留轻量 health payload | WP-API |
|
||||
| 管理后台页面 | `GET /admin` | 保留 | 不变 | WP-API |
|
||||
| 管理后台 API | `POST /admin/api/login`、`GET /admin/api/me`、`GET /admin/api/overview`、`POST /admin/api/debug/http` | 保留 | `Admin*` DTO 继续由 `admin.rs` 管理 | WP-A、WP-API |
|
||||
| 管理兑换码 | `POST /admin/api/profile/redeem-codes`、`POST /admin/api/profile/redeem-codes/disable` | 收敛 | 继续走 admin 路由,DTO 归入 profile/runtime 管理命令组 | WP-RT、WP-API |
|
||||
| 内部鉴权调试 | `GET /_internal/auth/claims`、`GET /_internal/auth/refresh-cookie` | 删除 | 只允许本地诊断脚本或 admin debug 能力使用,不作为前端契约 | WP-DEL |
|
||||
| 鉴权公开查询 | `GET /api/auth/login-options`、`GET /api/auth/public-users/by-code/{code}`、`GET /api/auth/public-users/by-id/{user_id}` | 保留 | `AuthLoginOptionsResponse`、`PublicUserSearchResponse` | WP-A |
|
||||
| 鉴权会话 | `GET /api/auth/me`、`GET /api/auth/sessions`、`POST /api/auth/refresh`、`POST /api/auth/logout`、`POST /api/auth/logout-all` | 保留 | `AuthMeResponse`、`AuthSessionsResponse`、`RefreshSessionResponse`、`LogoutResponse`、`LogoutAllResponse` | WP-A |
|
||||
| 鉴权登录 | `POST /api/auth/phone/send-code`、`POST /api/auth/phone/login`、`GET /api/auth/wechat/start`、`GET /api/auth/wechat/callback`、`POST /api/auth/wechat/bind-phone`、`POST /api/auth/entry`、`POST /api/auth/password/change`、`POST /api/auth/password/reset` | 保留 | TS 命名统一使用 `Auth*` 前缀,Rust 命名维持领域语义 | WP-A |
|
||||
| 旧本地生成资产代理 | `GET /generated-character-drafts/{*path}`、`/generated-characters/{*path}`、`/generated-animations/{*path}`、`/generated-big-fish-assets/{*path}`、`/generated-puzzle-assets/{*path}`、`/generated-custom-world-scenes/{*path}`、`/generated-custom-world-covers/{*path}`、`/generated-qwen-sprites/{*path}` | 删除 | 正式读取统一改为 `GET /api/assets/read-url` 或 asset object projection;本地生成路径只允许迁移窗口内存在 | WP-AS、WP-FE、WP-DEL |
|
||||
| LLM 代理 | `POST /api/llm/chat/completions` | 收敛 | 仅作为平台能力代理;玩法 prompt 不允许由前端直接传入 | WP-PF、WP-API |
|
||||
| Runtime chat | `POST /api/runtime/chat/character/suggestions`、`/summary`、`/reply/stream`、`/npc/dialogue/stream`、`/npc/turn/stream`、`/npc/recruit/stream` | 重命名 | 收敛到 session scoped story/chat 命令;请求体不得携带前端拼装的世界真相 | WP-RS、WP-RPG、WP-FE |
|
||||
| 文档输入 | `POST /api/runtime/creation-agent/document-inputs/parse` | 保留 | `ParseCreationAgentDocumentInputRequest/Response` | WP-CW、WP-BF、WP-PZ |
|
||||
| AI task | `POST /api/ai/tasks`、`/{task_id}/start`、`/{task_id}/stages/{stage_kind}/start`、`/{task_id}/chunks`、`/{task_id}/stages/{stage_kind}/complete`、`/{task_id}/references`、`/{task_id}/complete`、`/{task_id}/fail`、`/{task_id}/cancel` | 保留 | `AiTask*` 命令/result DTO;后续接 module-ai 状态机 | WP-AI |
|
||||
| Assets object | `POST /api/assets/direct-upload-tickets`、`POST /api/assets/sts-upload-credentials`、`POST /api/assets/objects/confirm`、`POST /api/assets/objects/bind`、`GET /api/assets/read-url`、`GET /api/assets/history` | 保留 | `CreateDirectUploadTicket*`、`ConfirmAssetObject*`、`BindAssetObject*`、`GetReadUrlQuery/Response`、`AssetHistory*` | WP-AS |
|
||||
| 角色资产工作流 | `POST /api/assets/character-visual/generate`、`GET /api/assets/character-visual/jobs/{task_id}`、`POST /api/assets/character-visual/publish`、`POST /api/assets/character-animation/generate`、`GET /api/assets/character-animation/jobs/{task_id}`、`POST /api/assets/character-animation/publish`、`POST /api/assets/character-animation/import-video`、`GET /api/assets/character-animation/templates`、`POST /api/assets/character-workflow-cache`、`GET /api/assets/character-workflow-cache/{character_id}`、`POST/PUT /api/runtime/custom-world/asset-studio/role/{character_id}/workflow` | 收敛 | Asset object、AI task、role workflow 三组 DTO 拆清;workflow 不再把业务真相藏在 cache body | WP-AS、WP-CW、WP-API |
|
||||
| Runtime settings/save | `GET/PUT /api/runtime/settings`、`GET/PUT/DELETE /api/runtime/save/snapshot` | 保留 | `RuntimeSettingsResponse`、`PutRuntimeSettingsRequest`、`SavedGameSnapshotResponse`、`PutSavedGameSnapshotRequest` | WP-RT |
|
||||
| RPG 作品库 | `GET /api/runtime/custom-world-library`、`GET/PUT/DELETE /api/runtime/custom-world-library/{profile_id}`、`POST /publish`、`POST /unpublish`、`GET /api/runtime/custom-world-gallery`、`GET /api/runtime/custom-world-gallery/{owner_user_id}/{profile_id}`、`GET /api/runtime/custom-world-gallery/by-code/{code}` | 收敛 | 命名后续改为 RPG creation/work route family;删除 `custom-world` 旧泛名歧义 | WP-CW、WP-FE |
|
||||
| RPG Agent | `POST /api/runtime/custom-world/agent/sessions`、`GET/DELETE /sessions/{session_id}`、`GET /result-view`、`GET /works`、`GET /cards/{card_id}`、`POST /messages`、`POST /messages/stream`、`POST /actions`、`GET /operations/{operation_id}` | 收敛 | DTO 重命名为 `RpgAgent*`,Rust 当前 `CustomWorldAgent*` 后续物理重命名 | WP-CW、WP-FE、WP-DEL |
|
||||
| Big Fish Agent/Works | `POST /api/runtime/big-fish/agent/sessions`、`GET /sessions/{session_id}`、`POST /messages`、`POST /messages/stream`、`POST /actions`、`GET /works`、`DELETE /works/{session_id}`、`GET /gallery`、`POST /sessions/{session_id}/play`、`POST /works/{session_id}/play` | 保留 | `BigFish*` DTO,`sessions/{id}/play` 与 `works/{id}/play` 后续二选一保留 | WP-BF |
|
||||
| Puzzle Agent/Works/Runtime | `POST /api/runtime/puzzle/agent/sessions`、`GET /sessions/{session_id}`、`POST /messages`、`POST /messages/stream`、`POST /actions`、`GET /works`、`GET/PUT/DELETE /works/{profile_id}`、`GET /gallery`、`GET /gallery/{profile_id}`、`POST /runs`、`POST /runs/local-next-level`、`GET /runs/{run_id}`、`POST /runs/{run_id}/swap`、`POST /runs/{run_id}/drag`、`POST /runs/{run_id}/next-level`、`POST /runs/{run_id}/leaderboard` | 保留 | `PuzzleAgent*`、`PuzzleWork*`、`PuzzleRun*` DTO | WP-PZ |
|
||||
| RPG profile/asset generation | `POST /api/runtime/custom-world/profile`、`POST /api/custom-world/entity`、`POST /api/runtime/custom-world/entity`、`POST /api/custom-world/scene-npc`、`POST /api/runtime/custom-world/scene-npc`、`POST /api/custom-world/scene-image`、`POST /api/custom-world/cover-image`、`POST /api/runtime/custom-world/cover-image`、`POST /api/custom-world/cover-upload`、`POST /api/runtime/custom-world/cover-upload` | 重命名 | 去掉非 runtime 前缀旧入口;统一到 RPG creation asset/profile route family | WP-CW、WP-AS、WP-DEL |
|
||||
| Profile | `GET/POST/DELETE /api/runtime/profile/browse-history`、`GET/POST/DELETE /api/profile/browse-history`、`GET /dashboard`、`GET /wallet-ledger`、`GET /recharge-center`、`POST /recharge/orders`、`GET /referrals/invite-center`、`POST /referrals/redeem-code`、`POST /redeem-codes/redeem`、`GET /play-stats`、`GET /save-archives`、`POST /save-archives/{world_key}` | 重命名 | 保留 `/api/runtime/profile/*` 主链,删除 `/api/profile/*` 镜像入口 | WP-RT、WP-FE、WP-DEL |
|
||||
| Runtime inventory | `GET /api/runtime/sessions/{runtime_session_id}/inventory` | 保留 | `RuntimeInventoryStateResponse` | WP-RPG、WP-RT |
|
||||
| Runtime story 旧层 | `POST /api/runtime/story/sessions`、`POST /api/runtime/story/state/resolve`、`GET /api/runtime/story/state/{session_id}`、`POST /api/runtime/story/actions/resolve`、`POST /api/runtime/story/initial`、`POST /api/runtime/story/continue` | 已删除 | 已从 `api-server` 取消挂载并删除 `api-server/src/runtime_story*` 兼容实现;后续前端迁移到 `GET/POST /api/story/*` 和 session scoped story/chat facade | WP-RS、WP-FE、WP-DEL |
|
||||
| Story/Game facade | `POST /api/story/sessions`、`GET /api/story/sessions/{story_session_id}/state`、`POST /api/story/sessions/continue`、`POST /api/story/battles`、`GET /api/story/battles/{battle_state_id}`、`POST /api/story/npc/battle`、`POST /api/story/battles/resolve` | 保留 | `BeginStorySession*`、`ContinueStory*`、battle/npc command/result DTO 后续补齐到 `shared-contracts` | WP-RPG、WP-RS |
|
||||
|
||||
## 3. DTO 冻结清单
|
||||
|
||||
### 3.1 保留
|
||||
|
||||
| 契约文件 | 保留 DTO |
|
||||
| --- | --- |
|
||||
| `shared-contracts/src/api.rs` | `ApiResponseMeta`、`ApiErrorPayload`、`ApiSuccessEnvelope<T>`、`ApiErrorEnvelope` |
|
||||
| `shared-contracts/src/admin.rs` | `AdminLoginRequest/Response`、`AdminSessionPayload`、`AdminMeResponse`、`AdminOverviewResponse`、`AdminDebugHttpRequest/Response` |
|
||||
| `shared-contracts/src/auth.rs` | `AuthLoginOptionsResponse`、`AuthUserPayload`、`PublicUserSummaryPayload`、`PublicUserSearchResponse`、`PasswordEntry*`、`PasswordChange*`、`PasswordReset*`、`AuthMeResponse`、`AuthSessionsResponse`、`RefreshSessionResponse`、`Logout*`、`Phone*`、`Wechat*` |
|
||||
| `shared-contracts/src/ai.rs` | `CreateAiTaskRequest`、`AppendAiTextChunkRequest`、`CompleteAiStageRequest`、`AttachAiResultReferenceRequest`、`FailAiTaskRequest`、`AiTask*Payload`、`AiTaskMutationResponse`、`AiTaskAcceptedResponse` |
|
||||
| `shared-contracts/src/assets.rs` | Direct upload、read url、asset object、asset binding、asset history、character visual/animation、workflow cache、role asset workflow 相关 DTO |
|
||||
| `shared-contracts/src/big_fish*.rs` | `CreateBigFishSessionRequest`、`SendBigFishMessageRequest`、`ExecuteBigFishActionRequest`、`RecordBigFishPlayRequest`、`BigFish*Response`、`BigFishWorksResponse` |
|
||||
| `shared-contracts/src/puzzle_*.rs` | `CreatePuzzleAgentSessionRequest`、`SendPuzzleAgentMessageRequest`、`ExecutePuzzleAgentActionRequest`、`PuzzleAgent*Response`、`PuzzleWork*`、`PuzzleRun*`、`PuzzleGallery*` |
|
||||
| `shared-contracts/src/runtime.rs` | runtime settings/save/profile/browse history/custom world library/agent/result view/inventory 现有 DTO 在迁移窗口保留 |
|
||||
| `shared-contracts/src/story.rs` | `BeginStorySessionRequest`、`ContinueStoryRequest`、`StorySessionPayload`、`StoryEventPayload`、`StorySessionMutationResponse`、`StorySessionStateResponse` |
|
||||
| `packages/shared/src/contracts/runtime.ts` | `RuntimeSettings`、`SavedGameSnapshot*`、profile、browse history、library/gallery DTO;迁移窗口继续作为前端消费主入口 |
|
||||
| `packages/shared/src/contracts/rpgAgent*.ts` | RPG Agent、draft、anchors、result view、work summary DTO |
|
||||
| `packages/shared/src/contracts/bigFish*.ts` | Big Fish Agent、runtime、本地作品列表 DTO |
|
||||
| `packages/shared/src/contracts/puzzle*.ts` | Puzzle Agent、work、gallery、runtime DTO |
|
||||
|
||||
### 3.2 重命名
|
||||
|
||||
| 当前 DTO | 新命名 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| Rust `CustomWorldAgent*` | `RpgAgent*` | Rust 与 TS 命名对齐,`custom world` 只作为历史目录语义,不再作为 RPG 主链契约名。 |
|
||||
| Rust `CustomWorldLibrary*` / `CustomWorldWorks*` | `RpgCreationWork*` / `RpgCreationLibrary*` | 前端已有 `RpgCreationWorkSummary`,后端后续对齐 RPG 创作域命名。 |
|
||||
| Rust `GenerateCustomWorldProfile*` | `GenerateRpgCreationProfile*` | 去掉泛化 custom world 命名,明确 RPG 创作 profile。 |
|
||||
| TS `AuthEntry*` | `PasswordEntry*` 或统一后端 `AuthPasswordEntry*` | 需要在 WP-A 中二选一收口,避免 entry 与 phone/wechat 登录语义混杂。 |
|
||||
| `RuntimeStory*` view model | `RpgRuntimeStory*` 或拆到 `Story*`、`Battle*`、`Inventory*` | 旧聚合大 DTO 后续拆分为 story session、battle、inventory、npc interaction 投影。 |
|
||||
| Profile 镜像 DTO | `RuntimeProfile*` | `/api/profile/*` 镜像删除后,契约命名跟随 `/api/runtime/profile/*`。 |
|
||||
|
||||
### 3.3 删除
|
||||
|
||||
| DTO/文件 | 删除条件 | 替代 |
|
||||
| --- | --- | --- |
|
||||
| `LegacyApiErrorResponse` | 全部路由完成 envelope 归一后 | `ApiErrorEnvelope` |
|
||||
| Rust `RuntimeStoryStateResolveRequest` | 前端切到 `GET /api/story/sessions/{story_session_id}/state` 后 | `StorySessionStateResponse` 加拆分投影 |
|
||||
| Rust/TS `RuntimeStoryBootstrapRequest/Response` | `POST /api/runtime/story/initial` 删除后 | `BeginStorySessionRequest`、`StorySessionMutationResponse` |
|
||||
| Rust/TS `RuntimeStoryAiRequest/Response` | `POST /api/runtime/story/continue` 删除后 | `ContinueStoryRequest`、`StorySessionMutationResponse` |
|
||||
| Rust/TS `RuntimeStoryActionRequest/Response` 旧总入口形态 | `POST /api/runtime/story/actions/resolve` 删除后 | story/battle/npc/inventory 分命令 result DTO |
|
||||
| TS `StoryRequestPayload`、`PlainTextPromptRequest`、`PlainTextResponse` | runtime chat 不再由前端传 prompt 后 | 后端 session scoped chat/story command |
|
||||
| TS `CreateCustomWorldSessionRequest`、`AnswerCustomWorldSessionQuestionRequest`、`CustomWorldSessionRecord` 等旧问答生成 DTO | 确认无前端运行引用后 | RPG Agent session DTO |
|
||||
| `/api/profile/*` 镜像 DTO 别名 | 前端全量迁到 `/api/runtime/profile/*` 后 | Runtime profile DTO |
|
||||
|
||||
## 4. 页面/功能到 query/result DTO 映射
|
||||
|
||||
| 页面/功能 | Query DTO | Command DTO | Result DTO |
|
||||
| --- | --- | --- | --- |
|
||||
| 管理后台登录 | 无 | `AdminLoginRequest` | `AdminLoginResponse` |
|
||||
| 管理后台概览 | 无 | 无 | `AdminMeResponse`、`AdminOverviewResponse` |
|
||||
| 管理后台 API 调试 | 无 | `AdminDebugHttpRequest` | `AdminDebugHttpResponse` |
|
||||
| 登录方式页 | 无 | 无 | `AuthLoginOptionsResponse` |
|
||||
| 手机号登录 | 无 | `PhoneSendCodeRequest`、`PhoneLoginRequest` | `PhoneSendCodeResponse`、`PhoneLoginResponse` |
|
||||
| 密码登录/改密/重置 | 无 | `PasswordEntryRequest`、`PasswordChangeRequest`、`PasswordResetRequest` | `PasswordEntryResponse`、`PasswordChangeResponse`、`PasswordResetResponse` |
|
||||
| 会话中心 | refresh cookie / bearer token | `logout`、`logout-all` 无 body | `AuthMeResponse`、`AuthSessionsResponse`、`RefreshSessionResponse`、`LogoutResponse`、`LogoutAllResponse` |
|
||||
| 公开用户卡片 | route param `code` 或 `user_id` | 无 | `PublicUserSearchResponse` |
|
||||
| 创作中心 RPG 作品货架 | bearer token | 无 | `CustomWorldWorksResponse`,后续重命名 `RpgCreationWorksResponse` |
|
||||
| RPG Agent 工作区 | route param `session_id` / `operation_id` | `CreateCustomWorldAgentSessionRequest`、`SendCustomWorldAgentMessageRequest`、`ExecuteCustomWorldAgentActionRequest` | `CustomWorldAgentSessionResponse`、`CustomWorldAgentOperationResponse`、`CustomWorldCreationResultViewResponse`,后续重命名 `RpgAgent*` |
|
||||
| RPG 结果页 | route param `session_id` | section patch/action request | `CustomWorldCreationResultViewResponse`、`CustomWorldAgentCardDetailResponse` |
|
||||
| RPG 资产工坊 | route param `character_id`、`GetReadUrlQuery` | `CharacterVisualGenerateRequest`、`CharacterAnimationGenerateRequest`、`CharacterWorkflowCacheSaveRequest`、`CharacterRoleAssetWorkflowResolveRequest` | `CharacterVisualGenerateResponse`、`CharacterAnimationGenerateResponse`、`CharacterWorkflowCacheGetResponse`、`CharacterRoleAssetWorkflowResponse` |
|
||||
| Big Fish Agent | route param `session_id` | `CreateBigFishSessionRequest`、`SendBigFishMessageRequest`、`ExecuteBigFishActionRequest` | `BigFishSessionResponse`、`BigFishActionResponse` |
|
||||
| Big Fish 广场/作品 | bearer token 或公开 gallery query | `RecordBigFishPlayRequest` | `BigFishWorksResponse`、`BigFishGalleryResponse`、`BigFishSessionResponse` |
|
||||
| Puzzle Agent | route param `session_id` | `CreatePuzzleAgentSessionRequest`、`SendPuzzleAgentMessageRequest`、`ExecutePuzzleAgentActionRequest` | `PuzzleAgentSessionResponse`、`PuzzleAgentActionResponse` |
|
||||
| Puzzle 作品/广场 | route param `profile_id` | `PutPuzzleWorkRequest` | `PuzzleWorksResponse`、`PuzzleWorkDetailResponse`、`PuzzleGalleryResponse`、`PuzzleGalleryDetailResponse` |
|
||||
| Puzzle 运行态 | route param `run_id` | `StartPuzzleRunRequest`、`AdvanceLocalPuzzleNextLevelRequest`、`SwapPuzzlePiecesRequest`、`DragPuzzlePieceRequest`、`SubmitPuzzleLeaderboardRequest` | `PuzzleRunResponse` |
|
||||
| Runtime 设置与存档 | bearer token | `PutRuntimeSettingsRequest`、`PutSavedGameSnapshotRequest`、`PutRuntimeSaveCheckpointRequest` | `RuntimeSettingsResponse`、`SavedGameSnapshotResponse`、`BasicOkResponse` |
|
||||
| 个人中心 | bearer token | `CreateProfileRechargeOrderRequest`、`RedeemProfileReferralInviteCodeRequest`、`RedeemProfileRewardCodeRequest`、`PlatformBrowseHistoryUpsertRequest` | `ProfileDashboardSummaryResponse`、`ProfileWalletLedgerResponse`、`ProfileRechargeCenterResponse`、`ProfileReferralInviteCenterResponse`、`ProfilePlayStatsResponse`、`ProfileSaveArchiveListResponse`、`PlatformBrowseHistoryResponse` |
|
||||
| RPG Story 运行态 | route param `story_session_id`、`battle_state_id` | `BeginStorySessionRequest`、`ContinueStoryRequest`,battle/npc 命令 DTO 后续补齐 | `StorySessionMutationResponse`、`StorySessionStateResponse`、`RuntimeInventoryStateResponse` |
|
||||
| Runtime chat/NPC 私聊 | route param `runtime_session_id` 或 `story_session_id` | 后续新增 session scoped chat command | 后续新增 chat turn result;旧 `rpgRuntimeChat.ts` DTO 只作为迁移参考 |
|
||||
|
||||
## 5. Breaking change 清单
|
||||
|
||||
1. 删除兼容层是本轮默认策略。旧 `/api/runtime/story/*`、`/_internal/auth/*`、`/generated-*` 和 `/api/profile/*` 镜像入口在对应前端迁移完成后物理删除。
|
||||
2. Runtime story/chat 不再接受前端拼装的 `worldType`、`character`、`monsters`、`history`、`context`、prompt 文本作为正式真相。正式命令必须以 `runtimeSessionId`、`storySessionId`、`battleStateId` 等后端 session id 为索引。
|
||||
3. `CustomWorld*` 作为 RPG 主链命名将被重命名为 `RpgCreation*` 或 `RpgAgent*`。前端可同步修改,不保留旧命名适配层。
|
||||
4. `/api/custom-world/*` 非 runtime 前缀旧入口删除,统一进入 RPG creation route family 或 asset route family。
|
||||
5. `/api/profile/*` 镜像入口删除,统一使用 `/api/runtime/profile/*`。
|
||||
6. 资产读取不再依赖 `/generated-*` 静态代理作为正式 contract,统一走 asset object、read url 或后端投影里的正式 URL 字段。
|
||||
7. LLM 代理不得作为玩法 prompt 透传入口。玩法 prompt 由 `api-server`/`platform-llm` 内部编排,前端只提交用户动作和展示态输入。
|
||||
8. API 错误体统一为 `ApiErrorEnvelope`。旧 `{ error, meta }` 只允许在已列入删除计划的旧接口中短期存在。
|
||||
|
||||
## 6. API 错误 envelope
|
||||
|
||||
所有主链 HTTP JSON 响应统一使用:
|
||||
|
||||
```json
|
||||
{
|
||||
"ok": false,
|
||||
"data": null,
|
||||
"error": {
|
||||
"code": "BAD_REQUEST",
|
||||
"message": "请求参数不合法",
|
||||
"details": {
|
||||
"message": "具体中文错误说明"
|
||||
}
|
||||
},
|
||||
"meta": {
|
||||
"apiVersion": "2026-04-08",
|
||||
"requestId": "req-xxx",
|
||||
"routeVersion": "2026-04-08",
|
||||
"operation": "POST /api/example",
|
||||
"latencyMs": 12,
|
||||
"timestamp": "2026-04-29T00:00:00Z"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
冻结规则:
|
||||
|
||||
1. 成功响应使用 `ApiSuccessEnvelope<T>`:`ok=true`、`data` 为 result DTO、`error=null`、`meta` 必填。
|
||||
2. 失败响应使用 `ApiErrorEnvelope`:`ok=false`、`data=null`、`error` 必填、`meta` 必填。
|
||||
3. `error.message` 是稳定的分类中文文案,`error.details.message` 是可展示给用户的具体中文错误。
|
||||
4. 前端展示业务错误时优先读取 `error.details.message`,再退回 `error.message`。
|
||||
5. `code` 使用稳定英文枚举值,禁止把中文错误全文塞进 `code`。
|
||||
6. `LegacyApiErrorResponse` 只服务迁移窗口,不能用于新增主链 route。
|
||||
|
||||
## 7. 后续并行任务交接
|
||||
|
||||
1. 第 1 批领域任务不得改 `shared-contracts` 和 `packages/shared/src/contracts/**`。需要新字段时先写入任务交接,等 G1 owner 合流。
|
||||
2. `WP-ST` 负责 SpacetimeDB 表、reducer/procedure 和 `migration.rs`,不得由玩法领域任务直接抢改。
|
||||
3. `WP-API` 负责 `api-server/src/app.rs` 和 route 挂载入口,领域任务只提供应用结果和错误模型。
|
||||
4. `WP-FE` 在后端新接口稳定后删除旧前端兼容层,不新增对旧 route 的二次适配。
|
||||
5. `WP-DEL` 只能在搜索确认无运行引用后删除旧 DTO、旧 route 和旧静态代理。
|
||||
@@ -0,0 +1,57 @@
|
||||
# server-rs DDD G1 契约与路由矩阵进度记录(2026-04-29)
|
||||
|
||||
## 1. 当前状态
|
||||
|
||||
`G1 契约与路由矩阵` 已完成串行冻结,当前可作为第 1 批领域规则并行任务的契约输入。
|
||||
|
||||
本次只落地文档与索引,不修改 Rust / TypeScript 契约源码,不改业务实现,不启动前端迁移。
|
||||
|
||||
## 2. 已完成内容
|
||||
|
||||
1. 新增 G1 冻结文档:[`SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md`](./SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md)。
|
||||
2. 冻结新旧 HTTP 路由清单,按 `保留`、`重命名`、`删除`、`收敛` 标记后续处理。
|
||||
3. 冻结 DTO 保留、删除、重命名清单。
|
||||
4. 冻结页面/功能到 query、command、result DTO 的映射。
|
||||
5. 冻结 breaking change 清单,明确本轮不保留旧兼容层作为约束。
|
||||
6. 冻结 API 错误 envelope,主链统一使用 `ApiSuccessEnvelope<T>` / `ApiErrorEnvelope`。
|
||||
7. 在全局并行任务清单中补充 G1 冻结文档入口和单 owner 文件边界。
|
||||
8. 在旧 Rust API route index 中补充 2026-04-29 提示,避免继续把 2026-04-23 快照当作最新契约。
|
||||
9. 在技术 README 中补充 G1 冻结文档入口。
|
||||
|
||||
## 3. 单 owner 边界
|
||||
|
||||
G1 后续合流文件:
|
||||
|
||||
1. `server-rs/crates/shared-contracts/src/**`
|
||||
2. `packages/shared/src/contracts/**`
|
||||
3. `packages/shared/src/index.ts`
|
||||
4. `docs/technical/RUST_API_SERVER_ROUTE_INDEX_2026-04-22.md`
|
||||
5. `docs/technical/SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md`
|
||||
|
||||
第 1 批并行领域任务不得直接改这些文件。确实需要新增字段或调整 DTO shape 时,先在任务交接里记录变更原因,再由 G1 owner 文件集中合流。
|
||||
|
||||
## 4. 验证结果
|
||||
|
||||
已执行:
|
||||
|
||||
```powershell
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md docs/technical/README.md docs/technical/RUST_API_SERVER_ROUTE_INDEX_2026-04-22.md
|
||||
```
|
||||
|
||||
结果:通过,4 个文档文件 UTF-8 编码检查正常。
|
||||
|
||||
## 5. 后续入口
|
||||
|
||||
下一步可以按全局清单进入第 1 批领域规则并行任务:
|
||||
|
||||
1. `WP-A Auth`
|
||||
2. `WP-AS Assets`
|
||||
3. `WP-AI AI Task`
|
||||
4. `WP-CW Custom World`
|
||||
5. `WP-BF Big Fish`
|
||||
6. `WP-PZ Puzzle`
|
||||
7. `WP-RT Runtime/Profile/Save`
|
||||
8. `WP-RPG Gameplay 域`
|
||||
9. `WP-RS Runtime Story 去兼容层`
|
||||
|
||||
进入下一批前,先以 G1 冻结文档确认 route、DTO、error envelope 和 breaking change,避免并行任务各自定义接口。
|
||||
@@ -50,15 +50,7 @@ flowchart TD
|
||||
G1 --> RT
|
||||
G1 --> RPG
|
||||
G1 --> RS
|
||||
G2 --> A
|
||||
G2 --> AS
|
||||
G2 --> AI
|
||||
G2 --> CW
|
||||
G2 --> BF
|
||||
G2 --> PZ
|
||||
G2 --> RT
|
||||
G2 --> RPG
|
||||
G2 --> RS
|
||||
G2 --> V
|
||||
A --> ST
|
||||
AS --> ST
|
||||
AI --> ST
|
||||
@@ -80,17 +72,22 @@ flowchart TD
|
||||
|
||||
## 3. 并行分批
|
||||
|
||||
### 3.1 第一批:冻结边界
|
||||
### 3.1 第 0 批:冻结边界与门禁
|
||||
|
||||
只能串行完成,避免后续并行任务各自定义接口。
|
||||
先完成边界和基础门禁,避免后续并行任务各自定义接口或绕过 DDD 骨架。
|
||||
|
||||
1. `G0 文档、边界、冻结窗口`
|
||||
2. `G1 契约与路由矩阵`
|
||||
3. `G2 module-* DDD 骨架与边界检查`
|
||||
|
||||
### 3.2 第二批:领域纯规则并行迁移
|
||||
执行口径:
|
||||
|
||||
第二批互相并行,但每个任务只能改自己的 `module-*` 和对应文档。
|
||||
1. `G1` 完成后即可开启第 1 批领域规则并行泳道。
|
||||
2. `G2` 是贯穿后续工作的边界检查门禁;当前 DDD 骨架已具备,后续每批必须继续跑检查。
|
||||
|
||||
### 3.2 第 1 批:领域规则并行
|
||||
|
||||
`G1` 完成后,可以开启下面这些并行泳道。每个任务只能改自己的 `module-*` 和对应文档;需要跨域输出时以领域事件或应用结果表达。
|
||||
|
||||
1. `WP-A Auth`
|
||||
2. `WP-AS Assets`
|
||||
@@ -102,22 +99,56 @@ flowchart TD
|
||||
8. `WP-RPG Gameplay 域`
|
||||
9. `WP-RS Runtime Story 去兼容层`
|
||||
|
||||
### 3.3 第三批:adapter 和 BFF 接线
|
||||
### 3.3 第 2 批:Adapter / BFF 接线
|
||||
|
||||
领域任务有稳定应用结果后启动。
|
||||
领域输出稳定后再启动本批。本批允许并行准备,但必须分层推进,不能让 `api-server` 先复制领域规则或绕过 `spacetime-client` 直连实现。
|
||||
|
||||
1. `WP-ST SpacetimeDB Adapter`
|
||||
2. `WP-SC Spacetime Client`
|
||||
3. `WP-PF platform side effects`
|
||||
4. `WP-API api-server BFF`
|
||||
#### 3.3.1 2A:`WP-ST SpacetimeDB Adapter`
|
||||
|
||||
### 3.4 第四批:前端与旧层删除
|
||||
按上下文接入已经稳定的领域函数,负责 table、reducer、procedure、row mapper、事务内查询和必要 event/projection table。
|
||||
|
||||
单 owner 文件:
|
||||
|
||||
1. `server-rs/crates/spacetime-module/src/lib.rs`
|
||||
2. `server-rs/crates/spacetime-module/src/migration.rs`
|
||||
3. `docs/technical/SPACETIMEDB_TABLE_CATALOG.md`
|
||||
|
||||
这些文件由 `WP-ST` 统一控制,其他工作包需要改动时先写交接说明,再由 `WP-ST` 合流。
|
||||
|
||||
#### 3.3.2 2B:`WP-SC Spacetime Client`
|
||||
|
||||
等待对应 SpacetimeDB facade 稳定后再接 mapper / facade,不提前假设 reducer、procedure 或 row shape。
|
||||
|
||||
职责:
|
||||
|
||||
1. 绑定类型到 BFF DTO 的 mapper。
|
||||
2. typed facade。
|
||||
3. SpacetimeDB 错误到 `api-server` 可消费错误的收口。
|
||||
|
||||
#### 3.3.3 2C:`WP-PF platform side effects`
|
||||
|
||||
LLM、OSS、SMS、微信等外部副作用可以独立准备,不等待 `WP-SC`。但平台层只提供能力实现和错误模型,不承载玩法领域状态机。
|
||||
|
||||
#### 3.3.4 2D:`WP-API api-server BFF`
|
||||
|
||||
等待 `WP-SC` facade 和 `WP-PF` 平台接口稳定后接 route。`api-server` 只能做 BFF 编排、鉴权、SSE、DTO 映射和平台调用。
|
||||
|
||||
单 owner 文件:
|
||||
|
||||
1. `server-rs/crates/api-server/src/app.rs`
|
||||
2. 各 route 模块的统一挂载入口。
|
||||
|
||||
`api-server/src/app.rs` 由 `WP-API` 统一控制,其他工作包不得直接抢改路由挂载。
|
||||
|
||||
### 3.4 第 3 批:前端迁移、旧层删除与验证
|
||||
|
||||
后端新接口可用后启动。
|
||||
|
||||
1. `WP-FE Frontend Clients/UI`
|
||||
2. `WP-DEL 删除旧层与命名收口`
|
||||
3. `WP-V 全链验证与发布 smoke`
|
||||
1. `WP-FE-S Frontend API client 迁移`
|
||||
2. `WP-FE-H Frontend hooks 迁移`
|
||||
3. `WP-FE-C Frontend components 接线`
|
||||
4. `WP-DEL 删除旧层与命名收口`
|
||||
5. `WP-V 全链验证与发布 smoke`
|
||||
|
||||
## 4. 工作包总表
|
||||
|
||||
@@ -126,20 +157,22 @@ flowchart TD
|
||||
| G0 文档、边界、冻结窗口 | 首个串行 | `PLAN.md`、`docs/technical/*DDD*`、`docs/planning/*` | 业务代码 | 全局任务清单、专项清单索引、阶段性交接模板 | 编码检查通过 |
|
||||
| G1 契约与路由矩阵 | G0 后 | `shared-contracts`、`packages/shared/src/contracts/*`、API 路由索引 | 领域实现 | DTO 分组、breaking change 清单、前后端路由矩阵 | shared contract 测试通过 |
|
||||
| G2 DDD 骨架与边界检查 | G0 后 | `module-*` 骨架、`scripts/check-server-rs-ddd-boundaries.mjs` | 业务重写 | 所有 `module-*` 具备 `domain/commands/application/events/errors`,检查脚本覆盖禁用依赖 | `npm.cmd run check:server-rs-ddd` |
|
||||
| WP-A Auth | G1/G2 后 | `module-auth`、`spacetime-module/src/auth*`、`api-server/src/auth*`、`platform-auth` | 其他玩法域 | 账号、会话、验证码、微信绑定领域化;真实短信/微信在 platform | `cargo test -p module-auth`,auth API 测试 |
|
||||
| WP-AS Assets | G1/G2 后 | `module-assets`、`spacetime-module/src/asset_metadata/*`、资产 API、OSS adapter | 玩法业务规则 | 资产对象与绑定规则纯化;OSS head/upload 移出领域核心 | `cargo test -p module-assets`,资产 facade 测试 |
|
||||
| WP-AI AI Task | G1/G2 后 | `module-ai`、`spacetime-module/src/ai/*`、AI task API | LLM prompt 业务规则 | AI task/stage/chunk/result 状态机领域化 | `cargo test -p module-ai`,AI task reducer/procedure smoke |
|
||||
| WP-CW Custom World | G1/G2 后 | `module-custom-world`、`spacetime-module/src/custom_world/*`、`api-server` custom world 路由、前端创作 client | Big Fish/Puzzle | profile、agent session、draft card、gallery、publish gate 领域化;LLM 留在 API/platform | `cargo test -p module-custom-world`,custom world 定向测试 |
|
||||
| WP-BF Big Fish | G1/G2 后 | `module-big-fish`、`spacetime-module/src/big_fish/*`、Big Fish API、Big Fish 前端 client | Puzzle/RPG | 会话、草稿、素材槽、运行态纯规则;草稿校验下沉 | `cargo test -p module-big-fish`,Big Fish API 测试 |
|
||||
| WP-PZ Puzzle | G1/G2 后 | `module-puzzle`、`spacetime-module/src/puzzle*`、Puzzle API、Puzzle 前端 client | Big Fish/RPG | Agent session、work profile、runtime run、排行榜规则领域化 | `cargo test -p module-puzzle`,Puzzle 定向测试 |
|
||||
| WP-RT Runtime/Profile/Save | G1/G2 后 | `module-runtime`、`spacetime-module/src/runtime/*`、runtime/save/profile API | RPG story 规则 | runtime setting、snapshot、wallet、played world、save archive 领域化 | `cargo test -p module-runtime`,runtime API 测试 |
|
||||
| WP-RPG Gameplay 域 | G1/G2 后 | `module-combat`、`module-inventory`、`module-npc`、`module-progression`、`module-quest`、`module-runtime-item`、`module-story` | 创作域 | 战斗、背包、NPC、成长、任务、宝箱、story session 纯规则与跨域事件 | 各 module 测试;跨域应用结果测试 |
|
||||
| WP-RS Runtime Story 去兼容层 | G1/G2 后 | `module-runtime-story`、`api-server/src/runtime_story/*`、`src/hooks/rpg-runtime-story/*` | 非 RPG 创作域 | 删除 compat 层、session scoped 新接口、前端匹配新接口 | 按专项文档验收 |
|
||||
| WP-ST SpacetimeDB Adapter | 领域任务输出稳定后 | `spacetime-module/src/**`、`migration.rs`、表目录 | `api-server` 业务逻辑 | table/reducer/procedure/mapper/queries 按上下文拆分;必要 event/projection table | `cargo check -p spacetime-module`,需要时 `spacetime build/generate` |
|
||||
| WP-SC Spacetime Client | WP-ST 接口稳定后 | `spacetime-client/src/**`、绑定 mapper | 领域规则 | typed facade、错误映射、row snapshot mapper | `cargo check -p spacetime-client` |
|
||||
| WP-PF platform side effects | 可与 WP-API 并行 | `platform-*`、`api-server` platform 接线 | 领域状态机 | LLM、OSS、SMS、微信等副作用统一 adapter | platform crate 测试或 API smoke |
|
||||
| WP-API api-server BFF | WP-SC/PF 可用后 | `api-server/src/**` | SpacetimeDB table 定义、领域主规则 | 路由、鉴权、SSE、请求响应映射、平台编排收口 | `cargo test -p api-server`,`cargo check -p api-server` |
|
||||
| WP-FE Frontend Clients/UI | G1 和 WP-API 接口稳定后 | `src/services/**`、`src/hooks/**`、`src/components/**` | 后端规则复刻 | API client、hooks、UI 流程对齐新 contract;删除前端正式规则 | vitest/ESLint 定向测试 |
|
||||
| WP-A Auth | G1 后 | `module-auth`、`spacetime-module/src/auth*`、`api-server/src/auth*`、`platform-auth` | 其他玩法域 | 账号、会话、验证码、微信绑定领域化;真实短信/微信在 platform | `cargo test -p module-auth`,auth API 测试 |
|
||||
| WP-AS Assets | G1 后 | `module-assets`、`spacetime-module/src/asset_metadata/*`、资产 API、OSS adapter | 玩法业务规则 | 资产对象与绑定规则纯化;OSS head/upload 移出领域核心 | `cargo test -p module-assets`,资产 facade 测试 |
|
||||
| WP-AI AI Task | G1 后 | `module-ai`、`spacetime-module/src/ai/*`、AI task API | LLM prompt 业务规则 | AI task/stage/chunk/result 状态机领域化 | `cargo test -p module-ai`,AI task reducer/procedure smoke |
|
||||
| WP-CW Custom World | G1 后 | `module-custom-world`、`spacetime-module/src/custom_world/*`、`api-server` custom world 路由、前端创作 client | Big Fish/Puzzle | profile、agent session、draft card、gallery、publish gate 领域化;LLM 留在 API/platform | `cargo test -p module-custom-world`,custom world 定向测试 |
|
||||
| WP-BF Big Fish | G1 后 | `module-big-fish`、`spacetime-module/src/big_fish/*`、Big Fish API、Big Fish 前端 client | Puzzle/RPG | 会话、草稿、素材槽、运行态纯规则;草稿校验下沉 | `cargo test -p module-big-fish`,Big Fish API 测试 |
|
||||
| WP-PZ Puzzle | G1 后 | `module-puzzle`、`spacetime-module/src/puzzle*`、Puzzle API、Puzzle 前端 client | Big Fish/RPG | Agent session、work profile、runtime run、排行榜规则领域化 | `cargo test -p module-puzzle`,Puzzle 定向测试 |
|
||||
| WP-RT Runtime/Profile/Save | G1 后 | `module-runtime`、`spacetime-module/src/runtime/*`、runtime/save/profile API | RPG story 规则 | runtime setting、snapshot、wallet、played world、save archive 领域化 | `cargo test -p module-runtime`,runtime API 测试 |
|
||||
| WP-RPG Gameplay 域 | G1 后 | `module-combat`、`module-inventory`、`module-npc`、`module-progression`、`module-quest`、`module-runtime-item`、`module-story` | 创作域 | 战斗、背包、NPC、成长、任务、宝箱、story session 纯规则与跨域事件 | 各 module 测试;跨域应用结果测试 |
|
||||
| WP-RS Runtime Story 去兼容层 | G1 后 | `module-runtime-story`、`api-server/src/runtime_story/*`、`src/hooks/rpg-runtime-story/*` | 非 RPG 创作域 | 先将历史 `module-runtime-story-compat` 迁为新主链 crate,再删除 HTTP compat 层、接 session scoped 新接口、前端匹配新接口 | `cargo test -p module-runtime-story`,runtime story/API/前端定向测试 |
|
||||
| WP-ST SpacetimeDB Adapter | 领域任务输出稳定后 | `spacetime-module/src/**`、`migration.rs`、表目录 | `api-server` 业务逻辑 | table/reducer/procedure/mapper/queries 按上下文接入领域函数;必要 event/projection table;`lib.rs/migration.rs/表目录` 单 owner 合流 | `cargo check -p spacetime-module`,需要时 `spacetime build/generate` |
|
||||
| WP-SC Spacetime Client | 对应 WP-ST facade 稳定后 | `spacetime-client/src/**`、绑定 mapper | 领域规则、未稳定 facade 的预判接线 | typed facade、错误映射、row snapshot mapper | `cargo check -p spacetime-client` |
|
||||
| WP-PF platform side effects | G1 后可独立准备;接入 API 前与 WP-API 对齐错误模型 | `platform-*`、`api-server` platform 接线 | 领域状态机 | LLM、OSS、SMS、微信等副作用统一 adapter | platform crate 测试或 API smoke |
|
||||
| WP-API api-server BFF | WP-SC facade 和 WP-PF 接口稳定后 | `api-server/src/**`,其中 `app.rs` 单 owner | SpacetimeDB table 定义、领域主规则、绕过 spacetime-client 的直连实现 | 路由、鉴权、SSE、请求响应映射、平台编排收口 | `cargo test -p api-server`,`cargo check -p api-server` |
|
||||
| WP-FE-S Frontend API client 迁移 | G1 和 WP-API 契约稳定后 | `src/services/**`、必要 contract type import | hooks / components 大改 | API client、路径常量、请求体与响应解析对齐新 contract | `npm.cmd run test -- src/services` |
|
||||
| WP-FE-H Frontend hooks 迁移 | WP-FE-S 完成且后端接口可用后 | `src/hooks/**`、必要 hook 测试 | components 大面积 UI 改版 | hooks 改为调用新 client,只保留 loading/error/transition 和 UI 临时态 | `npm.cmd run test -- src/hooks` |
|
||||
| WP-FE-C Frontend components 接线 | WP-FE-H 完成后 | `src/components/**`、组件测试 | services / hooks contract 改动 | 组件接入新 hooks 和 DTO;不新增规则说明文案 | 相关组件 vitest / 交互测试 |
|
||||
| WP-DEL 删除旧层与命名收口 | 新接口与前端迁移后 | 旧 compat、旧 facade、旧 contract、旧测试 | 新主链 | 物理删除旧入口、旧命名、旧 fixture 中非必要样本 | 搜索无运行代码引用旧层 |
|
||||
| WP-V 全链验证与发布 smoke | 最后 | 文档、测试脚本、README | 新功能扩展 | 全链命令、Maincloud smoke、文档交接 | 第 8 节命令通过或记录非本轮阻塞 |
|
||||
|
||||
@@ -147,6 +180,8 @@ flowchart TD
|
||||
|
||||
### 5.1 G1 契约与路由矩阵
|
||||
|
||||
冻结文档:[`SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md`](./SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md)。
|
||||
|
||||
必须先冻结:
|
||||
|
||||
1. 当前保留、重命名、删除的 HTTP 路由。
|
||||
@@ -157,6 +192,13 @@ flowchart TD
|
||||
|
||||
禁止在 G1 中实现业务逻辑。
|
||||
|
||||
G1 单 owner 文件:
|
||||
|
||||
1. `server-rs/crates/shared-contracts/src/**`
|
||||
2. `packages/shared/src/contracts/**`
|
||||
3. `packages/shared/src/index.ts`
|
||||
4. `docs/technical/RUST_API_SERVER_ROUTE_INDEX_2026-04-22.md`
|
||||
|
||||
### 5.2 module-* 领域任务通用规则
|
||||
|
||||
每个 `module-*` 工作包必须输出:
|
||||
@@ -189,7 +231,7 @@ server-rs/crates/spacetime-module/src/<context>/
|
||||
└─ queries.rs
|
||||
```
|
||||
|
||||
当前已有模块可渐进对齐,但新增实现不得继续堆回 `lib.rs`。
|
||||
当前已有模块可渐进对齐,但新增实现不得继续堆回 `lib.rs`。`spacetime-module/src/lib.rs`、`migration.rs` 和 SpacetimeDB 表目录必须由 `WP-ST` 单 owner 控制,避免多个并行任务同时改 schema、根入口和文档目录。
|
||||
|
||||
SpacetimeDB 硬要求:
|
||||
|
||||
@@ -210,14 +252,18 @@ SpacetimeDB 硬要求:
|
||||
4. 调用 `spacetime-client`。
|
||||
5. 调用 `platform-*`。
|
||||
6. SSE stream。
|
||||
7. 在 `WP-SC` 和 `WP-PF` 稳定后接入 route。
|
||||
|
||||
禁止:
|
||||
|
||||
1. 大段领域分支。
|
||||
2. SpacetimeDB table 定义。
|
||||
3. 为旧接口继续保留双主链。
|
||||
4. 绕过 `spacetime-client` 直接拼 SpacetimeDB 访问。
|
||||
|
||||
### 5.5 WP-FE Frontend Clients/UI
|
||||
`api-server/src/app.rs` 和各 route 统一挂载入口由 `WP-API` 单 owner 控制。
|
||||
|
||||
### 5.5 WP-FE Frontend 迁移
|
||||
|
||||
前端只负责表现:
|
||||
|
||||
@@ -233,12 +279,56 @@ SpacetimeDB 硬要求:
|
||||
3. prompt 正式组装。
|
||||
4. 绕过后端直接写真相。
|
||||
|
||||
迁移顺序必须固定为:
|
||||
|
||||
1. 先改 API client:`src/services/**`。
|
||||
2. 再改 hooks:`src/hooks/**`。
|
||||
3. 最后改组件接线:`src/components/**`。
|
||||
|
||||
前端不要抢在后端契约未稳定时大改 hooks。若后端 DTO 或路由仍在变动,`WP-FE-S` 只能先补 client adapter、路径常量、类型保护和 service 测试;`WP-FE-H` 必须等对应后端契约稳定后再启动。
|
||||
|
||||
允许按功能域并行,但每条功能域内部仍遵循 services → hooks → components:
|
||||
|
||||
1. `FE-RPG`:RPG runtime、runtime story、NPC 聊天、背包/战斗/任务展示。
|
||||
2. `FE-CREATION`:RPG 创作链路、Custom World Agent、结果页、创作中心。
|
||||
3. `FE-BIG-FISH`:Big Fish Agent、草稿、素材生成、运行态。
|
||||
4. `FE-PUZZLE`:Puzzle Agent、草稿、运行态、排行榜。
|
||||
5. `FE-AUTH-PROFILE`:Auth、Profile、会员/钱包/存档/浏览历史。
|
||||
|
||||
功能域并行边界:
|
||||
|
||||
1. 各功能域可以并行修改自己的 `src/services/<domain>/**`、`src/hooks/<domain>/**`、`src/components/<domain>/**`。
|
||||
2. 共享文件如 `src/services/aiService.ts`、`src/services/apiClient.ts`、全局路由、全局 auth provider 只能由一个任务统一维护。
|
||||
3. 若共享 client 必须调整,先完成 service 层适配,再通知 hooks 任务接线。
|
||||
4. 组件层不得为了绕过 hooks 直接拼 API 请求。
|
||||
|
||||
### 5.6 WP-DEL / WP-V 最终串行收口
|
||||
|
||||
`WP-DEL 删除旧层与命名收口` 和 `WP-V 全链验证与发布 smoke` 必须串行执行,不再拆散并行。进入这一批前必须满足:
|
||||
|
||||
1. `G1` 已冻结契约与路由矩阵。
|
||||
2. 对应 `module-*` 领域规则已完成并通过定向测试。
|
||||
3. 对应领域已完成 `spacetime-module -> spacetime-client -> api-server` 接线。
|
||||
4. 前端已按新接口完成 `services -> hooks -> components` 接入。
|
||||
5. 运行代码不再需要旧接口兜底。
|
||||
|
||||
`WP-DEL` 执行顺序:
|
||||
|
||||
1. 扫描旧入口引用:`compat`、旧 facade、旧 route、旧 contract、旧前端 client/helper。
|
||||
2. 删除后端旧 route / module / re-export。
|
||||
3. 删除前端旧 client / hook fallback。
|
||||
4. 删除旧测试 fixture 中非必要样本。
|
||||
5. 清理文档里已过期的“兼容主链”说法。
|
||||
6. 收口命名:运行代码中不再出现 `compat`;`legacy` 只允许出现在历史文档或迁移说明中。
|
||||
|
||||
`WP-V` 紧跟 `WP-DEL` 执行,不允许中途插入新功能。验证命令以第 8 节为准,后端代码变更后必须执行 `npm.cmd run api-server:maincloud`,不能改用旧后端重启命令。
|
||||
|
||||
## 6. 关键依赖与防冲突边界
|
||||
|
||||
1. `shared-contracts` 由 G1 统一所有权,其他任务只消费,不私自改 DTO shape。
|
||||
2. `spacetime-module/src/lib.rs` 由 WP-ST 统一所有权,领域任务不直接改根入口。
|
||||
2. `spacetime-module/src/lib.rs`、`server-rs/crates/spacetime-module/src/migration.rs`、`docs/technical/SPACETIMEDB_TABLE_CATALOG.md` 由 WP-ST 统一所有权,领域任务不直接改根入口、迁移和表目录。
|
||||
3. `api-server/src/app.rs` 路由挂载由 WP-API 统一所有权。
|
||||
4. `src/services/aiService.ts`、`src/services/rpg-runtime/*` 由 WP-FE 统一所有权。
|
||||
4. `src/services/aiService.ts`、`src/services/apiClient.ts`、`src/services/rpg-runtime/*` 由 `WP-FE-S` 统一所有权。
|
||||
5. `module-runtime-story` 与 runtime story 新接口由 WP-RS 所有,不和 WP-RPG 混写。
|
||||
6. 若某任务必须改别人的边界文件,先在交接记录中写明改动动机和待合流点。
|
||||
|
||||
@@ -308,3 +398,626 @@ spacetime describe <database> --json
|
||||
当前不再单独维护专项清单。`WP-RS Runtime Story 去兼容层` 已内联在本文第 4 节工作包总表中。
|
||||
|
||||
后续如果某个工作包仍存在编码级歧义,必须先在本文补齐边界;只有单个工作包过大且无法在本文清晰承载时,才新增对应专项清单。
|
||||
|
||||
## 10. 本地进度记录
|
||||
|
||||
### 2026-04-29 前置等待解除与 WP-BF 领域小步落地
|
||||
|
||||
已确认:
|
||||
|
||||
1. `G1 契约与路由矩阵` 已有冻结文档,可作为第 1 批领域规则并行任务输入。
|
||||
2. `npm.cmd run check:server-rs-ddd` 通过,当前 DDD 骨架门禁满足第 1 批启动条件。
|
||||
3. 前端第 3 批仍不可启动:`WP-API` 新接口尚未完成,`WP-FE-S` 只能等待对应后端 BFF contract 稳定后再改 `src/services/**`。
|
||||
4. 工作区同时存在其他前置任务产物,尤其是 `module-runtime-story` 新目录和旧 `module-runtime-story-compat` 删除记录;本次未回退这些并行产物。
|
||||
|
||||
本次已执行:
|
||||
|
||||
1. 启动第 1 批 `WP-BF Big Fish` 的纯领域落地。
|
||||
2. 在 `module-big-fish` 中新增发布门禁应用服务:
|
||||
- `EvaluateBigFishPublishReadinessCommand`
|
||||
- `BigFishPublishReadiness`
|
||||
- `BigFishDomainEvent::PublishReadinessEvaluated`
|
||||
- `BigFishApplicationError`
|
||||
- `evaluate_publish_readiness`
|
||||
3. 发布门禁只消费草稿和资产槽,返回可发布状态、阻塞原因和领域事件,不调用 HTTP、SpacetimeDB、OSS、图片生成或前端逻辑。
|
||||
4. 未修改 `spacetime-module`、`api-server`、`src/services/**`、`src/hooks/**`、`src/components/**`,保持第 2/3 批边界。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md docs/technical/SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md docs/technical/RUST_API_SERVER_ROUTE_INDEX_2026-04-22.md docs/technical/README.md
|
||||
cargo fmt -p module-big-fish --manifest-path server-rs/Cargo.toml --check
|
||||
cargo test -p module-big-fish --manifest-path server-rs/Cargo.toml
|
||||
```
|
||||
|
||||
结果:通过。
|
||||
|
||||
备注:
|
||||
|
||||
1. `cargo fmt --all --manifest-path server-rs/Cargo.toml --check` 当前会被工作区中缺失的 `server-rs/crates/module-ai/src/domain.rs` 阻塞;该文件缺失不是本次 WP-BF 改动引入,需由对应并行任务或 G2 owner 合流处理。
|
||||
2. 后端服务未重启,因为本次未触碰 `api-server`、SpacetimeDB table/reducer/procedure 或运行时接线。
|
||||
|
||||
### 2026-04-29 G1 契约与路由矩阵冻结确认
|
||||
|
||||
已完成:
|
||||
|
||||
1. 新增并冻结 `SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md`。
|
||||
2. G1 文档已覆盖当前 HTTP 路由的 `保留/重命名/删除/收敛` 决议。
|
||||
3. G1 文档已覆盖 DTO 的保留、重命名、删除清单。
|
||||
4. G1 文档已覆盖页面/功能到 query、command、result DTO 的映射。
|
||||
5. G1 文档已覆盖 breaking change、API 错误 envelope 和共享契约单 owner 边界。
|
||||
6. `RUST_API_SERVER_ROUTE_INDEX_2026-04-22.md` 已标记为迁移期快照,后续并行任务以 G1 文档为准。
|
||||
7. `docs/technical/README.md` 已加入 G1 文档索引。
|
||||
|
||||
当前结论:
|
||||
|
||||
1. `WP-DEL` 和 `WP-V` 仍不可执行,必须等待第 1 批领域规则、第 2 批 Adapter/BFF、第 3 批前端迁移完成。
|
||||
2. `G1` 已满足第 1 批领域规则并行启动条件。
|
||||
3. 下一步推荐从 `WP-A`、`WP-AS`、`WP-AI`、`WP-CW`、`WP-BF`、`WP-PZ`、`WP-RT`、`WP-RPG`、`WP-RS` 中按 owner 边界并行领取。
|
||||
|
||||
### 2026-04-29 WP-AI 领域层拆分进度
|
||||
|
||||
已完成:
|
||||
|
||||
1. 新增 `SERVER_RS_DDD_WP_AI_TASK_DOMAIN_REFACTOR_2026-04-29.md`,冻结 WP-AI 本次可执行范围。
|
||||
2. 将 `module-ai` 中集中在 `lib.rs` 的 AI task 领域代码拆到:
|
||||
- `src/domain.rs`
|
||||
- `src/commands.rs`
|
||||
- `src/application.rs`
|
||||
- `src/events.rs`
|
||||
- `src/errors.rs`
|
||||
3. 保持 `module_ai::*` 公开导出不变,避免影响现有 `spacetime-module` 引用。
|
||||
4. 保持 AI task 状态迁移、流式文本聚合、结果引用挂接、中文错误文案和既有测试语义不变。
|
||||
5. 更新 `server-rs/crates/module-ai/README.md`,补充 DDD 分层与本次方案文档入口。
|
||||
6. 修复前序记录中提到的 `module-ai/src/domain.rs` 缺失导致 `cargo fmt --all --check` 阻塞的问题。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
cargo test -p module-ai --manifest-path server-rs/Cargo.toml
|
||||
cargo check -p spacetime-module --manifest-path server-rs/Cargo.toml
|
||||
cargo fmt --all --check --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_WP_AI_TASK_DOMAIN_REFACTOR_2026-04-29.md server-rs/crates/module-ai/src/lib.rs server-rs/crates/module-ai/src/domain.rs server-rs/crates/module-ai/src/commands.rs server-rs/crates/module-ai/src/application.rs server-rs/crates/module-ai/src/events.rs server-rs/crates/module-ai/src/errors.rs
|
||||
npm.cmd run api-server:maincloud
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
1. `cargo test -p module-ai --manifest-path server-rs/Cargo.toml` 通过,9 个测试全部通过。
|
||||
2. `cargo fmt --all --check --manifest-path server-rs/Cargo.toml` 通过。
|
||||
3. `npm.cmd run check:server-rs-ddd` 通过。
|
||||
4. `npm.cmd run check:encoding -- ...` 通过,9 个文件编码检查通过。
|
||||
5. `npm.cmd run api-server:maincloud` 为常驻启动命令,180 秒超时前已启动 `server-rs/target/debug/api-server.exe`,并监听 `127.0.0.1:3100`;`/health` 返回 404,当前未提供通用健康路由。
|
||||
|
||||
未执行:
|
||||
|
||||
1. 未执行 SpacetimeDB 发布、绑定生成或 migration 更新,原因是本次未改 SpacetimeDB table/reducer/procedure。
|
||||
|
||||
### 2026-04-29 WP-RS 前置满足后启动执行
|
||||
|
||||
已完成:
|
||||
|
||||
1. 重新执行 `npm.cmd run check:server-rs-ddd`,确认 `G2` DDD 骨架门禁通过。
|
||||
2. 重新执行本轮触碰文档的编码检查,确认 `G1` 契约与路由矩阵文档可作为后续并行入口。
|
||||
3. 确认当前实际 crate 是历史命名 `module-runtime-story-compat`,与本轮去兼容层目标冲突。
|
||||
4. 将该 crate 迁为新主链 `module-runtime-story`:
|
||||
- `server-rs/crates/module-runtime-story-compat` 改为 `server-rs/crates/module-runtime-story`。
|
||||
- `server-rs/Cargo.toml` workspace member 改为 `crates/module-runtime-story`。
|
||||
- `server-rs/crates/api-server/Cargo.toml` 依赖改为 `module-runtime-story`。
|
||||
- `api-server` 中直接导入改为 `module_runtime_story`。
|
||||
5. 本次未修改 SpacetimeDB 表结构,未触碰 `migration.rs`。
|
||||
|
||||
下一步:
|
||||
|
||||
1. 在 `WP-RS` 内继续删除 `api-server/src/runtime_story/compat*` 的 HTTP 兼容入口。
|
||||
2. 以 `GET/POST /api/story/*` 和后续 session scoped story/chat facade 作为新主链。
|
||||
3. 前端等待后端新 route/DTO 稳定后再按 `services -> hooks -> components` 接入。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md docs/technical/RUST_API_SERVER_ROUTE_INDEX_2026-04-22.md docs/technical/README.md
|
||||
```
|
||||
|
||||
结果:通过。迁名后的 Rust 编译验证记录在下一条 WP-RS 进度中补齐。
|
||||
|
||||
### 2026-04-29 WP-RS 迁名验证与并行合流记录
|
||||
|
||||
已完成:
|
||||
|
||||
1. 完成 `module-runtime-story-compat` 到 `module-runtime-story` 的代码级迁名后,执行 Rust 定向验证。
|
||||
2. `module-runtime-story` 自身测试通过,确认迁名后的领域 crate 可编译、可运行既有纯规则测试。
|
||||
3. `api-server` 已改为依赖 `module-runtime-story` 并通过编译检查。
|
||||
4. 执行过程中发现并行 `WP-AI` 正在改 `module-ai`,曾短暂造成 `module-ai` 缺少 `application.rs` / `lib.rs` 或导出错位;已按该工作包当前分层结果补齐入口与导出,避免阻塞全局门禁。
|
||||
5. 本次仍未修改 SpacetimeDB 表结构,未触碰 `migration.rs`。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
cargo test -p module-runtime-story --manifest-path server-rs/Cargo.toml
|
||||
cargo check -p module-runtime-story --manifest-path server-rs/Cargo.toml
|
||||
cargo test -p module-ai --manifest-path server-rs/Cargo.toml
|
||||
cargo check -p api-server --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_G1_CONTRACT_AND_ROUTE_MATRIX_2026-04-29.md docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md docs/technical/RUST_API_SERVER_ROUTE_INDEX_2026-04-22.md docs/technical/README.md server-rs/crates/module-runtime-story/README.md
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
1. `module-runtime-story` 测试通过:7 个测试全部通过。
|
||||
2. `module-runtime-story` 编译通过。
|
||||
3. `module-ai` 测试通过:9 个测试全部通过。
|
||||
4. `api-server` 编译通过。
|
||||
5. `check:server-rs-ddd` 通过。
|
||||
6. 编码检查通过。
|
||||
|
||||
后端启动记录:
|
||||
|
||||
```powershell
|
||||
npm.cmd run api-server:maincloud
|
||||
```
|
||||
|
||||
结果:已按后端代码变更要求执行。命令未再出现编译错误,但在 45 秒观察窗口内超时退出,且本地未探测到 `127.0.0.1:3100/healthz` 可用;后续继续 WP-RS 接线前需要重新启动并确认 health。
|
||||
|
||||
### 2026-04-29 WP-RS 旧 HTTP compat 路由下线
|
||||
|
||||
已完成:
|
||||
|
||||
1. 从 `server-rs/crates/api-server/src/app.rs` 删除旧 `/api/runtime/story/*` 六条路由挂载:
|
||||
- `POST /api/runtime/story/sessions`
|
||||
- `POST /api/runtime/story/state/resolve`
|
||||
- `GET /api/runtime/story/state/{session_id}`
|
||||
- `POST /api/runtime/story/actions/resolve`
|
||||
- `POST /api/runtime/story/initial`
|
||||
- `POST /api/runtime/story/continue`
|
||||
2. 从 `server-rs/crates/api-server/src/main.rs` 移除 `mod runtime_story;`,旧 compat 模块不再进入运行编译树。
|
||||
3. 物理删除 `server-rs/crates/api-server/src/runtime_story.rs` 与 `server-rs/crates/api-server/src/runtime_story/compat/**`。
|
||||
4. 在 `app.rs` 新增 `runtime_story_legacy_routes_are_not_mounted` 测试,锁定旧路由返回 `404 NOT_FOUND`。
|
||||
5. 同步更新 `RUST_API_SERVER_ROUTE_INDEX_2026-04-22.md` 和 G1 契约矩阵,将 runtime story 旧层标记为已删除。
|
||||
6. 本次未修改 SpacetimeDB 表结构,未触碰 `migration.rs`。
|
||||
|
||||
当前剩余:
|
||||
|
||||
1. 前端 `src/services/rpg-runtime/rpgRuntimeStoryClient.ts` 仍指向 `/api/runtime/story`,需要在 `WP-FE-S` 中迁到新 `/api/story/*` 和 session scoped facade。
|
||||
2. `packages/shared/src/contracts/rpgRuntimeStory*` 与 `shared-contracts/src/runtime_story*` 仍保留旧 DTO,需等前端迁移完成后由 `WP-DEL` 统一删除。
|
||||
3. runtime chat 仍有 `runtimeStory` 命名和 prompt helper,需另起 session scoped chat/story facade 任务继续收口。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
cargo test -p api-server runtime_story_legacy_routes_are_not_mounted --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
```
|
||||
|
||||
结果:通过。`cargo check -p api-server --manifest-path server-rs/Cargo.toml` 曾与测试并行抢 Cargo 锁导致 120 秒超时,需在后续验证中单独重跑。
|
||||
|
||||
### 2026-04-29 前端第 3 批迁移顺序补充
|
||||
|
||||
已完成:
|
||||
|
||||
1. 将第 3 批从泛化的 `WP-FE Frontend Clients/UI` 拆成 `WP-FE-S / WP-FE-H / WP-FE-C`。
|
||||
2. 冻结前端迁移顺序:先 `src/services/**`,再 `src/hooks/**`,最后 `src/components/**`。
|
||||
3. 明确后端契约未稳定前,前端不得抢先大改 hooks。
|
||||
4. 明确功能域可并行:`FE-RPG`、`FE-CREATION`、`FE-BIG-FISH`、`FE-PUZZLE`、`FE-AUTH-PROFILE`。
|
||||
5. 明确前端只做表现和调用,不复制正式业务规则。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md
|
||||
```
|
||||
|
||||
结果:通过。
|
||||
|
||||
### 2026-04-29 第 4 批最终串行收口口径确认
|
||||
|
||||
已完成:
|
||||
|
||||
1. 确认最终收口批次不再并行拆散,固定为 `WP-DEL 删除旧层与命名收口` 后紧跟 `WP-V 全链验证与发布 smoke`。
|
||||
2. 明确进入 `WP-DEL` 前必须先完成:
|
||||
- `G1` 契约与路由矩阵。
|
||||
- 对应 `module-*` 领域规则。
|
||||
- 对应领域 `spacetime-module -> spacetime-client -> api-server` 接线。
|
||||
- 前端 `services -> hooks -> components` 新接口接入。
|
||||
3. 明确 `WP-DEL` 的删除顺序:
|
||||
- 先扫描 `compat`、旧 facade、旧 route、旧 contract、旧前端 client/helper。
|
||||
- 再删除后端旧 route / module / re-export。
|
||||
- 再删除前端旧 client / hook fallback。
|
||||
- 再删除旧测试 fixture 中非必要样本。
|
||||
- 最后清理文档中过期的“兼容主链”说法。
|
||||
4. 明确命名收口规则:运行代码中不再出现 `compat`;`legacy` 只允许出现在历史文档或迁移说明中。
|
||||
5. 明确 `WP-V` 必须紧跟 `WP-DEL` 执行,中途不插入新功能;后端代码变更后必须执行 `npm.cmd run api-server:maincloud`。
|
||||
|
||||
### 2026-04-29 第 2 批 Adapter / BFF 接线顺序校准
|
||||
|
||||
已完成:
|
||||
|
||||
1. 将原“adapter 和 BFF 接线”批次改为“第 2 批:Adapter / BFF 接线”。
|
||||
2. 明确第 2 批必须在领域输出稳定后启动,且按 `2A -> 2B -> 2C/2D` 分层推进。
|
||||
3. 补齐 `WP-ST SpacetimeDB Adapter` 的单 owner 边界:
|
||||
- `server-rs/crates/spacetime-module/src/lib.rs`
|
||||
- `server-rs/crates/spacetime-module/src/migration.rs`
|
||||
- `docs/technical/SPACETIMEDB_TABLE_CATALOG.md`
|
||||
4. 补齐 `WP-SC Spacetime Client` 等对应 SpacetimeDB facade 稳定后再接 mapper / facade 的依赖。
|
||||
5. 补齐 `WP-PF platform side effects` 可独立准备 LLM、OSS、SMS、微信等外部副作用,但不得承载玩法领域状态机。
|
||||
6. 补齐 `WP-API api-server BFF` 必须等待 `spacetime-client` facade 和 platform 接口稳定后再接 route。
|
||||
7. 明确 `server-rs/crates/api-server/src/app.rs` 和各 route 统一挂载入口由 `WP-API` 单 owner 控制。
|
||||
8. 补充禁止 `api-server` 绕过 `spacetime-client` 直接拼 SpacetimeDB 访问。
|
||||
|
||||
已验证:
|
||||
|
||||
```powershell
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md
|
||||
```
|
||||
|
||||
结果:通过。
|
||||
|
||||
### 2026-04-29 WP-API BFF 启动切片
|
||||
|
||||
已完成:
|
||||
|
||||
1. 新增 `SERVER_RS_DDD_WP_API_BFF_START_2026-04-29.md`,冻结本次 WP-API 可独立启动范围。
|
||||
2. 确认 `api-server/src/app.rs` 已不再挂载旧 `/api/runtime/story/*` 兼容入口。
|
||||
3. 保留新主链 `/api/story/*` route family,后续只通过 `spacetime-client` facade 访问 SpacetimeDB。
|
||||
4. 补充旧 runtime story 路由未挂载的回归测试,请求标准 envelope 时返回 `404 / ok=false / NOT_FOUND / 资源不存在`。
|
||||
5. 新增 `GET /api/story/sessions/{story_session_id}/runtime-projection` 占位路由,先锁定鉴权与 `501 NOT_IMPLEMENTED` envelope;真实投影等待 `WP-ST/WP-SC` facade 后接入。
|
||||
6. 本切片未修改 `spacetime-module`、`spacetime-client`、前端 services/hooks/components,也未修改 SpacetimeDB 表结构或 `migration.rs`。
|
||||
|
||||
当前边界:
|
||||
|
||||
1. `WP-API` 完整业务接线仍需等待 `WP-ST` 与 `WP-SC` facade 稳定。
|
||||
2. 不允许 `api-server` 绕过 `spacetime-client` 直接拼 SpacetimeDB 访问。
|
||||
3. 前端仍不能启动第 3 批迁移,需等待后端 route/DTO 稳定后按 `services -> hooks -> components` 推进。
|
||||
|
||||
### 2026-04-29 批次口径调整
|
||||
|
||||
已完成:
|
||||
|
||||
1. 将原“第一批冻结边界”调整为“第 0 批:冻结边界与门禁”。
|
||||
2. 将领域纯规则迁移明确为“第 1 批:领域规则并行”。
|
||||
3. 明确 `G1` 完成后即可开启第 1 批领域规则并行泳道。
|
||||
4. 明确 `G2` 是贯穿后续工作的边界检查门禁;当前 DDD 骨架已具备,后续每批继续运行 `npm.cmd run check:server-rs-ddd`。
|
||||
5. 第 1 批领域规则并行泳道固定为:
|
||||
- `WP-A Auth`
|
||||
- `WP-AS Assets`
|
||||
- `WP-AI AI Task`
|
||||
- `WP-CW Custom World`
|
||||
- `WP-BF Big Fish`
|
||||
- `WP-PZ Puzzle`
|
||||
- `WP-RT Runtime/Profile/Save`
|
||||
- `WP-RPG Gameplay 域`
|
||||
- `WP-RS Runtime Story 去兼容层`
|
||||
6. `WP-RS` 不再引用单独专项清单,验收口径收口为 `module-runtime-story`、runtime story/API 和前端定向测试。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md
|
||||
```
|
||||
|
||||
结果:通过。
|
||||
|
||||
### 2026-04-29 WP-SC Spacetime Client 基础设施收口启动
|
||||
|
||||
已完成:
|
||||
|
||||
1. 新增 `SERVER_RS_DDD_WP_SC_SPACETIME_CLIENT_REFACTOR_2026-04-29.md`,冻结本次 `WP-SC` 可执行范围。
|
||||
2. 确认 `WP-ST` 尚未完成所有新 facade,本次不预判新 table、reducer、procedure 或 row shape。
|
||||
3. 在 `spacetime-client` 中新增统一错误 helper:
|
||||
- `SpacetimeClientError::from_sdk_error`
|
||||
- `SpacetimeClientError::procedure_failed`
|
||||
- `SpacetimeClientError::missing_snapshot`
|
||||
4. 先以 `AI task` 和 `Big Fish` 现有 facade 作为示范,统一 SDK 调用错误映射。
|
||||
5. 在 mapper 中先收口资产对象和 Big Fish procedure 结果的业务错误与缺快照错误表达。
|
||||
6. 更新 `spacetime-client/README.md`,明确其 DDD 边界:只做 typed facade、row snapshot mapper 和错误收口,不承载领域规则,不定义 SpacetimeDB schema。
|
||||
|
||||
本次未修改:
|
||||
|
||||
1. `spacetime-module/src/**`
|
||||
2. `migration.rs`
|
||||
3. `shared-contracts`
|
||||
4. `api-server` 路由挂载
|
||||
5. 前端 services / hooks / components
|
||||
6. `spacetime-client/src/module_bindings/**` 生成绑定
|
||||
|
||||
后续:
|
||||
|
||||
1. 等 `WP-ST` 稳定对应 SpacetimeDB facade 后,再逐个领域补 mapper / typed facade。
|
||||
2. `WP-API` 后续只能通过 `spacetime-client` 调 SpacetimeDB,不绕过本 crate 直接使用生成绑定。
|
||||
|
||||
### 2026-04-29 WP-SC 错误映射第二批收口
|
||||
|
||||
已完成:
|
||||
|
||||
1. 继续在 `spacetime-client` 内扩展统一 SDK 错误映射使用范围。
|
||||
2. 本批已覆盖现有稳定 facade:
|
||||
- `assets`
|
||||
- `auth`
|
||||
- `story`
|
||||
- `combat`
|
||||
- `inventory`
|
||||
- `npc`
|
||||
3. mapper 中同步收口以下 procedure 结果错误:
|
||||
- 资产对象绑定与资产历史
|
||||
- 认证快照
|
||||
- AI task mutation
|
||||
- story session / story event / story state
|
||||
- runtime inventory state
|
||||
- battle state / combat action
|
||||
- NPC battle interaction
|
||||
4. 本批仍未修改 `spacetime-module`、`shared-contracts`、`api-server`、前端和生成绑定。
|
||||
|
||||
待继续:
|
||||
|
||||
1. `runtime`、`puzzle`、`custom_world` facade 仍有较多重复 SDK 错误映射,可继续按同一方式机械收口。
|
||||
2. mapper 中仍有部分历史 `Procedure(...)` 构造和旧兼容 JSON 容错逻辑,后续应结合对应工作包逐步替换,避免一次大改影响面过宽。
|
||||
|
||||
### 2026-04-29 WP-ST AI Task 事件 Adapter 切片
|
||||
|
||||
已完成:
|
||||
|
||||
1. 新增 `SERVER_RS_DDD_WP_ST_AI_TASK_EVENT_ADAPTER_2026-04-29.md`,冻结本次 WP-ST 可独立落地范围。
|
||||
2. 在 `spacetime-module/src/ai/events.rs` 新增 `ai_task_event` public event table。
|
||||
3. `ai_task_event` 当前承接:
|
||||
- `TaskCreated`
|
||||
- `TaskStatusChanged`
|
||||
- `StageStarted`
|
||||
- `StageCompleted`
|
||||
- `TextChunkAppended`
|
||||
- `ResultReferenceAttached`
|
||||
4. 在 AI task / stage / text chunk / result reference 成功写入后,同事务写入事件表。
|
||||
5. 本次不改变 `ai_task`、`ai_task_stage`、`ai_text_chunk`、`ai_result_reference` 真相表字段。
|
||||
6. 已同步 `migration.rs` 迁移白名单,加入 `ai_task_event`。
|
||||
7. 已同步 `SPACETIMEDB_TABLE_CATALOG.md` 的 AI 任务表目录和查询说明。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
cargo check -p spacetime-module --manifest-path server-rs/Cargo.toml
|
||||
cargo test -p module-ai --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_WP_ST_AI_TASK_EVENT_ADAPTER_2026-04-29.md docs/technical/SPACETIMEDB_TABLE_CATALOG.md server-rs/crates/spacetime-module/src/ai/events.rs server-rs/crates/spacetime-module/src/ai/mod.rs server-rs/crates/spacetime-module/src/ai/snapshots.rs server-rs/crates/spacetime-module/src/ai/stages.rs server-rs/crates/spacetime-module/src/ai/tasks.rs server-rs/crates/spacetime-module/src/migration.rs
|
||||
```
|
||||
|
||||
结果:通过。其中 `spacetime-module` 仍存在 3 个既有 `ambiguous glob re-exports` warning,非本次事件表引入。
|
||||
|
||||
后端启动:
|
||||
|
||||
```powershell
|
||||
npm.cmd run api-server:maincloud
|
||||
```
|
||||
|
||||
结果:已执行。`api-server` 编译完成后运行进程以 `0xffffffff` 退出,同时出现一次 Maincloud WebSocket `Close(None)`;这不是本次 Rust 编译错误,后续需要结合 Maincloud 连接与当前并行 WP-API 改动继续排查。
|
||||
|
||||
未执行:
|
||||
|
||||
```powershell
|
||||
spacetime build --project-path server-rs/crates/spacetime-module
|
||||
```
|
||||
|
||||
原因:当前环境未找到 `spacetime` CLI,可执行文件不在 PATH 中。
|
||||
|
||||
### 2026-04-29 WP-RS 新 story runtime 投影契约切片
|
||||
|
||||
已完成:
|
||||
|
||||
1. 确认前端旧 `rpgRuntimeStoryClient.ts` 仍依赖 `/api/runtime/story` 的 `snapshot / viewModel / presentation` 顶层响应,不能直接切到现有 `/api/story/*`。
|
||||
2. 明确 WP-RS 下一段必须先提供 session scoped 的后端投影契约,再由 `WP-SC -> WP-API -> WP-FE-S/H/C` 分层接入。
|
||||
3. 在 `shared-contracts/src/story.rs` 新增新主链 DTO:
|
||||
- `StoryRuntimeProjectionRequest`
|
||||
- `StoryRuntimeProjectionResponse`
|
||||
- `StoryRuntimeActorProjection`
|
||||
- `StoryRuntimeInventoryProjection`
|
||||
- `StoryRuntimeOptionProjection`
|
||||
- `StoryRuntimeStatusProjection`
|
||||
4. 新 DTO 固定挂在 `story` contract 下,后续 route 建议使用 `GET/POST /api/story/sessions/{story_session_id}/runtime-projection`,不恢复 `/api/runtime/story/*`。
|
||||
5. 新投影响应不再复制旧顶层 `snapshot / viewModel / presentation` 形状;前端只消费后端提供的展示投影字段,不在 hooks/components 重建正式业务规则。
|
||||
6. 将 `module-runtime-story/src/application.rs` 的模块注释从“兼容应用编排过渡落位”收口为新主链“runtime story 应用编排落位”。
|
||||
7. 本次未修改 SpacetimeDB 表结构,未触碰 `migration.rs`。
|
||||
|
||||
后续接线边界:
|
||||
|
||||
1. `WP-ST` 如需新增 projection table/event,必须由 `spacetime-module/src/lib.rs`、`migration.rs`、表目录单 owner 合流。
|
||||
2. `WP-SC` 在 SpacetimeDB facade 稳定后,负责读取 story session、story events、inventory/battle/npc 等快照并映射为 `StoryRuntimeProjectionResponse` 所需的 typed 中间结果。
|
||||
3. `WP-API` 只能通过 `spacetime-client` 组合响应,不得绕过 `spacetime-client` 直接访问 SpacetimeDB。
|
||||
4. `WP-FE-S` 等待 route/DTO 稳定后迁移 `src/services/rpg-runtime/rpgRuntimeStoryClient.ts`;`WP-FE-H` 和 `WP-FE-C` 继续等待 services 完成。
|
||||
5. `WP-DEL` 仍需等新接口和前端迁移完成后,再统一删除 `shared-contracts/src/runtime_story.rs`、`packages/shared/src/contracts/rpgRuntimeStory*` 和旧前端 helper。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
cargo test -p shared-contracts story_runtime_projection_response_uses_new_story_runtime_contract --manifest-path server-rs/Cargo.toml
|
||||
cargo test -p module-runtime-story --manifest-path server-rs/Cargo.toml
|
||||
cargo check -p api-server --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md server-rs/crates/shared-contracts/src/story.rs server-rs/crates/module-runtime-story/src/application.rs
|
||||
npm.cmd run api-server:maincloud
|
||||
```
|
||||
|
||||
结果:待本切片执行后补齐。
|
||||
|
||||
已验证:
|
||||
|
||||
```powershell
|
||||
cargo test -p shared-contracts story_runtime_projection_response_uses_new_story_runtime_contract --manifest-path server-rs/Cargo.toml
|
||||
cargo test -p module-runtime-story --manifest-path server-rs/Cargo.toml
|
||||
cargo check -p api-server --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md server-rs/crates/shared-contracts/src/story.rs server-rs/crates/module-runtime-story/src/application.rs
|
||||
```
|
||||
|
||||
结果:通过。`cargo check -p api-server` 仍有既有 `api-server/src/prompt/rpg/runtime_chat.rs` 未使用 prompt helper warning,非本次新增。
|
||||
|
||||
### 2026-04-29 WP-API runtime projection 接线
|
||||
|
||||
已完成:
|
||||
|
||||
1. `GET /api/story/sessions/{story_session_id}/runtime-projection` 已从 `501 NOT_IMPLEMENTED` 占位改为真实 BFF 接线。
|
||||
2. route 只读取当前 bearer token 的 `user_id`,调用 `SpacetimeClient::get_story_runtime_projection_source(story_session_id, actor_user_id)`。
|
||||
3. route 将 facade 返回的 `StoryRuntimeProjectionSource` 交给 `module_runtime_story::build_story_runtime_projection`,输出 `StoryRuntimeProjectionResponse`。
|
||||
4. `api-server` 未绕过 `spacetime-client`,未直接访问 SpacetimeDB 生成绑定,未复制 actor、inventory、option、status 等领域投影规则。
|
||||
5. 原占位测试已改为 SpacetimeDB 未发布场景下的 `502 / provider=spacetimedb` 回归测试;未登录仍返回 `401`。
|
||||
6. 本次未修改 SpacetimeDB 表结构,未触碰 `migration.rs`。
|
||||
|
||||
当前边界:
|
||||
|
||||
1. `WP-FE-S` 可以基于 `/api/story/sessions/{story_session_id}/runtime-projection` 与 `StoryRuntimeProjectionResponse` 启动 services 迁移。
|
||||
2. `WP-FE-H` 与 `WP-FE-C` 仍等待 services 迁移完成后再接入,不在 hooks/components 中重建正式业务规则。
|
||||
3. 如后续 `WP-ST` 把 runtime story 快照拆入更细 projection table,仍由 `WP-ST/WP-SC` 更新 facade,`WP-API` 保持同一 BFF 边界。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
cargo test -p api-server get_story_runtime_projection --manifest-path server-rs/Cargo.toml
|
||||
cargo test -p api-server runtime_story_legacy_routes_are_not_mounted --manifest-path server-rs/Cargo.toml
|
||||
cargo check -p api-server --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_WP_API_BFF_START_2026-04-29.md docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md server-rs/crates/api-server/src/story_sessions.rs
|
||||
```
|
||||
|
||||
结果:通过。`cargo check -p api-server` 仍有既有 `api-server/src/prompt/rpg/runtime_chat.rs` 未使用 prompt helper warning,非本次新增。
|
||||
|
||||
后端启动:
|
||||
|
||||
```powershell
|
||||
npm.cmd run api-server:maincloud
|
||||
```
|
||||
|
||||
结果:命令在 90 秒观察窗口内超时,因为 `cargo run` 前台常驻;随后确认 `127.0.0.1:3100` 已由本仓库 `server-rs/target/debug/api-server.exe` 监听。`GET /healthz` 返回 `200`,`GET /api/story/sessions/storysess_001/runtime-projection` 未登录返回 `401`,无效 bearer token 返回 `401`。
|
||||
|
||||
后端启动:
|
||||
|
||||
```powershell
|
||||
npm.cmd run api-server:maincloud
|
||||
```
|
||||
|
||||
结果:编译通过,仅有既有 prompt helper warning;运行阶段因 `127.0.0.1:3100` 端口已被既有 `api-server` 进程占用而退出,错误为 `AddrInUse / 10048`。随后探测 `http://127.0.0.1:3100/healthz` 返回 `200`,确认本地已有服务在线。
|
||||
|
||||
后端启动:
|
||||
|
||||
```powershell
|
||||
npm.cmd run api-server:maincloud
|
||||
```
|
||||
|
||||
结果:命令在 60 秒观察窗口内超时,但随后探测 `http://127.0.0.1:3100/healthz` 返回 `200`,本地存在新的 `api-server` 运行进程。本切片未触发新的 Rust 编译错误。
|
||||
|
||||
### 2026-04-29 WP-SC story runtime projection source 接线
|
||||
|
||||
已完成:
|
||||
|
||||
1. 在 `spacetime-client` 中新增 `story_runtime` facade 模块。
|
||||
2. 新增 `SpacetimeClient::get_story_runtime_projection_source(story_session_id, actor_user_id)`。
|
||||
3. 该 facade 负责:
|
||||
- 读取 `get_story_session_state`。
|
||||
- 校验 story session 属于当前用户。
|
||||
- 读取当前用户 `get_runtime_snapshot`。
|
||||
- 校验 `runtime snapshot.gameState.runtimeSessionId` 与 story session 的 `runtimeSessionId` 一致。
|
||||
- 从 `currentStory.options` 解析 `RuntimeStoryOptionView`。
|
||||
- 组装 `module-runtime-story::StoryRuntimeProjectionSource`。
|
||||
4. 该 facade 不直接输出 HTTP DTO,不复制投影规则;真正投影仍由 `module-runtime-story::build_story_runtime_projection` 完成。
|
||||
5. 本次未修改 SpacetimeDB 表结构,未触碰 `migration.rs`。
|
||||
|
||||
后续接线边界:
|
||||
|
||||
1. `WP-API` 可在新 route 中调用 `get_story_runtime_projection_source`,再调用 `build_story_runtime_projection` 输出 `StoryRuntimeProjectionResponse`。
|
||||
2. `WP-FE-S` 仍等待 route 稳定后再迁移旧 `/api/runtime/story` client。
|
||||
3. `WP-ST` 如后续把 runtime story 相关快照从 save snapshot 拆入更细 projection table,需要由 `WP-ST` 单 owner 更新 `spacetime-module/src/lib.rs`、`migration.rs` 和表目录。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
cargo test -p spacetime-client story_runtime --manifest-path server-rs/Cargo.toml
|
||||
cargo check -p api-server --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
```
|
||||
|
||||
结果:通过。`cargo check -p api-server` 仍有既有 `api-server/src/prompt/rpg/runtime_chat.rs` 未使用 prompt helper warning,非本次新增。
|
||||
|
||||
后端启动:
|
||||
|
||||
```powershell
|
||||
npm.cmd run api-server:maincloud
|
||||
```
|
||||
|
||||
结果:命令在 60 秒观察窗口内超时,但随后探测 `http://127.0.0.1:3100/healthz` 返回 `200`,本地存在 `api-server` 运行进程。本切片未触发新的 Rust 编译错误。
|
||||
|
||||
### 2026-04-29 WP-ST Big Fish 发布门禁 Adapter 切片
|
||||
|
||||
已完成:
|
||||
|
||||
1. 新增 `SERVER_RS_DDD_WP_ST_BIG_FISH_READINESS_ADAPTER_2026-04-29.md`,冻结本次 WP-ST Big Fish 可独立落地范围。
|
||||
2. 在 `spacetime-module/src/big_fish/events.rs` 新增 `big_fish_event` public event table。
|
||||
3. `big_fish_event` 当前承接 `PublishReadinessEvaluated`,用于订阅端、BFF 或审计流程感知发布门禁评估事实。
|
||||
4. `compile_big_fish_draft_tx`、`generate_big_fish_asset_tx`、`publish_big_fish_game_tx` 已改为调用 `module_big_fish::evaluate_publish_readiness`。
|
||||
5. Adapter 只负责从 SpacetimeDB row 读取草稿和资产槽、调用领域应用服务、持久化 session readiness 和事件,不再在 Adapter 中直接决定发布门禁规则。
|
||||
6. 已同步 `migration.rs` 迁移白名单,加入 `big_fish_event`。
|
||||
7. 已同步 `SPACETIMEDB_TABLE_CATALOG.md` 的 Big Fish 表目录和查询说明。
|
||||
|
||||
边界说明:
|
||||
|
||||
1. `big_fish_event` 不是作品真相表,正式作品状态仍以 `big_fish_creation_session` 和 `big_fish_asset_slot` 为准。
|
||||
2. SpacetimeDB 事务返回 `Err` 时会回滚,因此发布失败路径不会持久化事件;事件表只记录成功事务内完成的门禁评估事实。
|
||||
3. 本次未修改 `api-server`、`spacetime-client`、前端 services/hooks/components。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
cargo check -p spacetime-module --manifest-path server-rs/Cargo.toml
|
||||
cargo test -p module-big-fish --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_WP_ST_BIG_FISH_READINESS_ADAPTER_2026-04-29.md docs/technical/SPACETIMEDB_TABLE_CATALOG.md server-rs/crates/spacetime-module/src/big_fish/events.rs server-rs/crates/spacetime-module/src/big_fish/mod.rs server-rs/crates/spacetime-module/src/big_fish/assets.rs server-rs/crates/spacetime-module/src/big_fish/session.rs server-rs/crates/spacetime-module/src/migration.rs
|
||||
```
|
||||
|
||||
结果:通过。其中 `spacetime-module` 仍存在 3 个既有 `ambiguous glob re-exports` warning,非本次 Big Fish event table 引入。
|
||||
|
||||
后端启动:
|
||||
|
||||
```powershell
|
||||
npm.cmd run api-server:maincloud
|
||||
```
|
||||
|
||||
结果:已执行。命令在 60 秒观察窗口内超时,随后探测 `http://127.0.0.1:3100/healthz` 无法连接,本地未发现 `api-server` 进程;未观察到本次 Big Fish adapter 改动导致的 Rust 编译错误。
|
||||
|
||||
未执行:
|
||||
|
||||
```powershell
|
||||
spacetime build --project-path server-rs/crates/spacetime-module
|
||||
```
|
||||
|
||||
原因:当前环境未找到 `spacetime` CLI,可执行文件不在 PATH 中。
|
||||
|
||||
### 2026-04-29 WP-RS 领域投影 builder 切片
|
||||
|
||||
已完成:
|
||||
|
||||
1. 新增 `module-runtime-story/src/projection.rs`,提供纯领域函数 `build_story_runtime_projection`。
|
||||
2. 新增 `StoryRuntimeProjectionSource` 作为 BFF/SC 接线输入边界,输入只接收已取回的:
|
||||
- `StorySessionPayload`
|
||||
- `StoryEventPayload`
|
||||
- `game_state`
|
||||
- `RuntimeStoryOptionView`
|
||||
- server version / narrative / toast 等展示上下文
|
||||
3. 投影 builder 复用既有 `build_runtime_story_inventory`、状态读取和 encounter 读取逻辑,输出上一切片新增的 `StoryRuntimeProjectionResponse`。
|
||||
4. 投影层不依赖 `spacetime-client`、不导入 SpacetimeDB 生成绑定、不挂 HTTP route,保持 `WP-RS` 领域边界。
|
||||
5. 新增 `projection_builds_frontend_ready_story_runtime_shape` 测试,覆盖 actor、inventory、option、status 和 toast 的投影结果。
|
||||
6. 本次未修改 SpacetimeDB 表结构,未触碰 `migration.rs`。
|
||||
|
||||
后续接线边界:
|
||||
|
||||
1. `WP-SC` 可以在 story session 与 runtime inventory facade 稳定后,组合 `StoryRuntimeProjectionSource` 所需数据。
|
||||
2. `WP-API` 后续只负责调用 `spacetime-client` 并把中间结果传入 `build_story_runtime_projection`,不在 route 内复制领域投影规则。
|
||||
3. `WP-FE-S` 继续等待 `/api/story/sessions/{story_session_id}/runtime-projection` route 稳定后再迁移旧 client。
|
||||
|
||||
验证:
|
||||
|
||||
```powershell
|
||||
cargo test -p module-runtime-story --manifest-path server-rs/Cargo.toml
|
||||
cargo test -p shared-contracts story_runtime_projection_response_uses_new_story_runtime_contract --manifest-path server-rs/Cargo.toml
|
||||
cargo check -p api-server --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
```
|
||||
|
||||
结果:通过。`cargo check -p api-server` 仍有既有 `api-server/src/prompt/rpg/runtime_chat.rs` 未使用 prompt helper warning,非本次新增。
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
# server-rs DDD WP-AI AI Task 领域层重构方案(2026-04-29)
|
||||
|
||||
## 1. 背景
|
||||
|
||||
`G1 契约与路由矩阵` 已冻结,`WP-AI AI Task` 进入第 1 批领域规则并行泳道。当前 `module-ai` 已有 AI task 状态机、输入类型、错误和内存服务,但主要实现集中在 `src/lib.rs`,与全局 DDD 清单要求的 `domain / commands / application / events / errors` 分层不一致。
|
||||
|
||||
本次只整理 `module-ai` 纯领域层,不改 HTTP route,不改 SpacetimeDB table / reducer / procedure,不改前端。
|
||||
|
||||
## 2. 目标
|
||||
|
||||
1. 保持 `module_ai::*` 公开 API 兼容,让 `spacetime-module` 现有引用不需要跟随修改。
|
||||
2. 将 AI task 领域模型、命令、应用服务、事件、错误拆入对应文件。
|
||||
3. 保持 AI task 状态迁移规则不变:
|
||||
- `Pending -> Running`
|
||||
- `Running -> Completed / Failed / Cancelled`
|
||||
- 终态不允许继续写入阶段、文本片段、结果引用或任务结束状态
|
||||
4. 保持流式文本片段按 `sequence` 聚合到阶段输出和任务 `latest_text_output`。
|
||||
5. 保持中文错误信息,便于 HTTP adapter 与 SpacetimeDB adapter 显式映射。
|
||||
|
||||
## 3. 文件边界
|
||||
|
||||
本次允许修改:
|
||||
|
||||
1. `server-rs/crates/module-ai/src/lib.rs`
|
||||
2. `server-rs/crates/module-ai/src/domain.rs`
|
||||
3. `server-rs/crates/module-ai/src/commands.rs`
|
||||
4. `server-rs/crates/module-ai/src/application.rs`
|
||||
5. `server-rs/crates/module-ai/src/events.rs`
|
||||
6. `server-rs/crates/module-ai/src/errors.rs`
|
||||
7. `server-rs/crates/module-ai/README.md`
|
||||
8. 本文档和全局任务清单进度记录
|
||||
|
||||
本次禁止修改:
|
||||
|
||||
1. `server-rs/crates/spacetime-module/src/**`
|
||||
2. `server-rs/crates/spacetime-client/src/**`
|
||||
3. `server-rs/crates/api-server/src/**`
|
||||
4. `server-rs/crates/shared-contracts/src/**`
|
||||
5. `packages/shared/src/contracts/**`
|
||||
|
||||
## 4. 分层落点
|
||||
|
||||
| 文件 | 职责 |
|
||||
| --- | --- |
|
||||
| `domain.rs` | AI task kind/status、stage kind/status、snapshot、ID helper、文本归一 helper |
|
||||
| `commands.rs` | create/start/stage/chunk/result/fail/cancel 等写入输入,以及创建命令校验 |
|
||||
| `application.rs` | `AiTaskService`、`InMemoryAiTaskStore` 和纯内存状态迁移 |
|
||||
| `events.rs` | AI task 领域事件枚举,供后续 adapter / event table 映射 |
|
||||
| `errors.rs` | `AiTaskFieldError`、`AiTaskServiceError` 与中文 Display |
|
||||
| `lib.rs` | 模块声明、公开 re-export、既有行为测试 |
|
||||
|
||||
## 5. 验收
|
||||
|
||||
必须执行:
|
||||
|
||||
```powershell
|
||||
cargo test -p module-ai --manifest-path server-rs/Cargo.toml
|
||||
cargo fmt --all --check --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_WP_AI_TASK_DOMAIN_REFACTOR_2026-04-29.md docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md server-rs/crates/module-ai/README.md server-rs/crates/module-ai/src/lib.rs server-rs/crates/module-ai/src/domain.rs server-rs/crates/module-ai/src/commands.rs server-rs/crates/module-ai/src/application.rs server-rs/crates/module-ai/src/events.rs server-rs/crates/module-ai/src/errors.rs
|
||||
npm.cmd run api-server:maincloud
|
||||
```
|
||||
|
||||
说明:本次不改 `api-server` route、SpacetimeDB table/reducer/procedure 或前端接线,但按仓库约束,后端 Rust 代码变更后仍执行 `npm.cmd run api-server:maincloud` 重新启动后端。
|
||||
98
docs/technical/SERVER_RS_DDD_WP_API_BFF_START_2026-04-29.md
Normal file
98
docs/technical/SERVER_RS_DDD_WP_API_BFF_START_2026-04-29.md
Normal file
@@ -0,0 +1,98 @@
|
||||
# server-rs DDD WP-API BFF 启动切片(2026-04-29)
|
||||
|
||||
## 1. 背景
|
||||
|
||||
`G1 契约与路由矩阵` 已冻结,`WP-RS` 已把旧 `module-runtime-story-compat` 迁为 `module-runtime-story`,当前可以启动 `WP-API api-server BFF` 的第一段边界收口。
|
||||
|
||||
`WP-ST SpacetimeDB Adapter`、`WP-SC Spacetime Client` 与 `WP-RS` 已提供 runtime projection 所需 facade 与领域投影 builder,因此本切片继续完成 BFF 层接线:路由挂载收口、错误 envelope 门禁、健康检查、runtime projection 新主链 route 接入,不新增领域规则,不改 SpacetimeDB table/reducer/procedure,不绕过 `spacetime-client`。
|
||||
|
||||
## 2. 本切片目标
|
||||
|
||||
1. 确认旧 `/api/runtime/story/*` 兼容路由不再挂载到 `api-server/src/app.rs`。
|
||||
2. 保留新主链 `/api/story/*` route family,后续只通过 `spacetime-client` facade 访问 SpacetimeDB。
|
||||
3. 对旧 runtime story 路由补充 404 + `ApiErrorEnvelope` 回归测试,避免后续重新接回兼容入口。
|
||||
4. 保持 `/healthz` 轻量健康检查可用,并在请求方声明 envelope 时返回标准成功 envelope。
|
||||
5. 接入 story runtime projection 主链路由,固定鉴权、错误 envelope 与 `StoryRuntimeProjectionResponse` 输出。
|
||||
6. 记录 WP-API 后续接线边界与前端迁移前置条件。
|
||||
|
||||
## 3. 文件边界
|
||||
|
||||
本切片允许修改:
|
||||
|
||||
1. `server-rs/crates/api-server/src/app.rs`
|
||||
2. `server-rs/crates/api-server/src/story_sessions.rs`
|
||||
3. `docs/technical/SERVER_RS_DDD_WP_API_BFF_START_2026-04-29.md`
|
||||
4. `docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md`
|
||||
5. `docs/technical/README.md`
|
||||
|
||||
本切片不修改:
|
||||
|
||||
1. `server-rs/crates/spacetime-module/src/**`
|
||||
2. `server-rs/crates/spacetime-client/src/**`
|
||||
3. `server-rs/crates/shared-contracts/src/**`
|
||||
4. `packages/shared/src/contracts/**`
|
||||
5. `src/services/**`、`src/hooks/**`、`src/components/**`
|
||||
|
||||
## 4. 当前 API 边界
|
||||
|
||||
### 4.1 已收口
|
||||
|
||||
旧 runtime story 兼容入口不再挂载:
|
||||
|
||||
1. `POST /api/runtime/story/sessions`
|
||||
2. `POST /api/runtime/story/state/resolve`
|
||||
3. `GET /api/runtime/story/state/{session_id}`
|
||||
4. `POST /api/runtime/story/actions/resolve`
|
||||
5. `POST /api/runtime/story/initial`
|
||||
6. `POST /api/runtime/story/continue`
|
||||
|
||||
这些路径请求 `x-genarrative-response-envelope: v1` 时应返回:
|
||||
|
||||
1. HTTP status:`404`
|
||||
2. `ok=false`
|
||||
3. `error.code=NOT_FOUND`
|
||||
4. `error.message=资源不存在`
|
||||
|
||||
### 4.2 保留主链
|
||||
|
||||
当前保留的新主链入口:
|
||||
|
||||
1. `POST /api/story/sessions`
|
||||
2. `GET /api/story/sessions/{story_session_id}/state`
|
||||
3. `GET /api/story/sessions/{story_session_id}/runtime-projection`
|
||||
4. `POST /api/story/sessions/continue`
|
||||
5. `POST /api/story/battles`
|
||||
6. `GET /api/story/battles/{battle_state_id}`
|
||||
7. `POST /api/story/npc/battle`
|
||||
8. `POST /api/story/battles/resolve`
|
||||
|
||||
这些 route 只能做鉴权、请求响应 DTO 映射、错误 envelope 和 `spacetime-client` 调用,不在 `api-server` 中复制 RPG 领域规则。
|
||||
|
||||
`runtime-projection` 已接入新主链:鉴权通过后,route 只读取当前用户身份,调用 `spacetime-client::get_story_runtime_projection_source`,再交给 `module-runtime-story::build_story_runtime_projection` 输出 `StoryRuntimeProjectionResponse`。API 层不得重新挂回旧 `/api/runtime/story/*` compat 总入口,也不得复制 actor、inventory、option、status 等领域投影规则。
|
||||
|
||||
## 5. 后续依赖
|
||||
|
||||
`WP-API` 后续继续接线前必须保持:
|
||||
|
||||
1. runtime projection 只通过 `spacetime-client` facade 读取 SpacetimeDB。
|
||||
2. 投影规则只由 `module-runtime-story` 输出,`api-server` 只做 BFF 编排。
|
||||
3. `WP-PF` 稳定 LLM、OSS、SMS、微信等平台副作用错误模型。
|
||||
4. `G1` owner 合流必要 DTO shape 变更。
|
||||
|
||||
`runtime-projection` route/DTO 已可作为 `WP-FE-S` 迁移输入;前端仍需按 `services -> hooks -> components` 顺序推进,不在 hooks/components 中重建正式业务规则。
|
||||
|
||||
## 6. 验收
|
||||
|
||||
本切片验证命令:
|
||||
|
||||
```powershell
|
||||
cargo test -p api-server runtime_story_legacy_routes_are_not_mounted --manifest-path server-rs/Cargo.toml
|
||||
cargo test -p api-server healthz_returns_standard_envelope_when_requested --manifest-path server-rs/Cargo.toml
|
||||
cargo test -p api-server get_story_runtime_projection --manifest-path server-rs/Cargo.toml
|
||||
cargo check -p api-server --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_WP_API_BFF_START_2026-04-29.md docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md docs/technical/README.md server-rs/crates/api-server/src/app.rs server-rs/crates/api-server/src/story_sessions.rs
|
||||
npm.cmd run api-server:maincloud
|
||||
```
|
||||
|
||||
说明:本切片未修改 SpacetimeDB 表结构、reducer 或 procedure,因此不需要更新 `migration.rs`,也不执行绑定生成。
|
||||
@@ -0,0 +1,68 @@
|
||||
# server-rs DDD WP-SC Spacetime Client 重构方案(2026-04-29)
|
||||
|
||||
## 1. 背景
|
||||
|
||||
`WP-SC Spacetime Client` 位于 `spacetime-module` 和 `api-server` 之间,只负责把 SpacetimeDB 生成绑定、procedure / reducer 调用、row snapshot 和错误语义收口成 BFF 可消费的 typed facade。
|
||||
|
||||
当前 `spacetime-client` 已经具备连接池、生成绑定、多个领域 facade 和 mapper,但错误映射仍散落在各 facade 中,且 README 仍停留在早期占位说明。由于 `WP-ST` 尚未完成所有新 facade,本次不预判新的 table、reducer、procedure 或 row shape,只先收口已存在调用层的基础设施。
|
||||
|
||||
## 2. 本次目标
|
||||
|
||||
1. 明确 `spacetime-client` 的 DDD 边界和后续接入顺序。
|
||||
2. 新增统一的 SDK 调用错误、业务 procedure 错误、缺失快照错误 helper。
|
||||
3. 用 AI task 与 Big Fish 现有 facade 作为第一批示范,减少重复的 `SpacetimeClientError::Procedure(error.to_string())`。
|
||||
4. 保持现有公开 facade 方法和返回 record 不变,不改 `api-server` 调用方。
|
||||
5. 不修改 `spacetime-module`、`shared-contracts`、`api-server` 路由挂载或前端。
|
||||
|
||||
## 3. 文件边界
|
||||
|
||||
本次允许修改:
|
||||
|
||||
1. `server-rs/crates/spacetime-client/src/lib.rs`
|
||||
2. `server-rs/crates/spacetime-client/src/ai.rs`
|
||||
3. `server-rs/crates/spacetime-client/src/big_fish.rs`
|
||||
4. `server-rs/crates/spacetime-client/src/mapper.rs`
|
||||
5. `server-rs/crates/spacetime-client/README.md`
|
||||
6. 本文档
|
||||
7. `docs/technical/README.md`
|
||||
8. `docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md` 的进度记录
|
||||
|
||||
本次禁止修改:
|
||||
|
||||
1. `server-rs/crates/spacetime-module/src/**`
|
||||
2. `server-rs/crates/shared-contracts/src/**`
|
||||
3. `server-rs/crates/api-server/src/app.rs`
|
||||
4. `server-rs/crates/api-server/src/**` 路由行为
|
||||
5. `src/services/**`、`src/hooks/**`、`src/components/**`
|
||||
6. `server-rs/crates/spacetime-client/src/module_bindings/**` 生成绑定
|
||||
|
||||
## 4. 分层落点
|
||||
|
||||
| 层 | 职责 | 本次落点 |
|
||||
| --- | --- | --- |
|
||||
| 连接层 | 连接池、握手、超时、断线处理 | 保持现状,不改连接策略 |
|
||||
| 调用层 | procedure / reducer then 回调、SDK 错误映射 | 新增统一错误 helper,并先接 AI / Big Fish |
|
||||
| mapper 层 | 绑定类型到 BFF record / DTO 的转换 | 新增通用 procedure 失败与缺快照 helper,后续逐步替换重复代码 |
|
||||
| facade 层 | 面向 `api-server` 的 typed 方法 | 方法签名保持不变 |
|
||||
|
||||
## 5. 后续依赖
|
||||
|
||||
1. `WP-ST` 每稳定一个 SpacetimeDB facade 后,再由 `WP-SC` 接对应 mapper / facade。
|
||||
2. `WP-API` 只能通过 `spacetime-client` 调用 SpacetimeDB,不直接拼接生成绑定。
|
||||
3. 前端迁移必须等待 `WP-API` route 和 DTO 稳定后,再按 `services -> hooks -> components` 接入。
|
||||
4. 若后续改变 table / reducer / procedure,必须由 `WP-ST` 同步表目录和必要的绑定生成记录。
|
||||
|
||||
## 6. 验收
|
||||
|
||||
必须执行:
|
||||
|
||||
```powershell
|
||||
cargo fmt --all --check --manifest-path server-rs/Cargo.toml
|
||||
cargo check -p spacetime-client --manifest-path server-rs/Cargo.toml
|
||||
cargo check -p api-server --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_WP_SC_SPACETIME_CLIENT_REFACTOR_2026-04-29.md docs/technical/SERVER_RS_DDD_PARALLEL_TASKLIST_2026-04-29.md docs/technical/README.md server-rs/crates/spacetime-client/README.md server-rs/crates/spacetime-client/src/lib.rs server-rs/crates/spacetime-client/src/ai.rs server-rs/crates/spacetime-client/src/big_fish.rs server-rs/crates/spacetime-client/src/mapper.rs
|
||||
npm.cmd run api-server:maincloud
|
||||
```
|
||||
|
||||
说明:本次不改 SpacetimeDB 表、reducer、procedure,不刷新生成绑定,不同步 `migration.rs`。
|
||||
@@ -0,0 +1,78 @@
|
||||
# server-rs DDD WP-ST AI Task 事件 Adapter 落地记录(2026-04-29)
|
||||
|
||||
## 1. 背景
|
||||
|
||||
`WP-AI AI Task` 已完成领域层拆分,`WP-ST SpacetimeDB Adapter` 可以开始把稳定领域状态变化接入 SpacetimeDB。当前 AI 任务已有真相表:
|
||||
|
||||
1. `ai_task`
|
||||
2. `ai_task_stage`
|
||||
3. `ai_text_chunk`
|
||||
4. `ai_result_reference`
|
||||
|
||||
本次不改变这些真相表的字段,不改 HTTP/BFF,不改前端,只补齐 AI 任务状态变化的 SpacetimeDB 事件流。
|
||||
|
||||
## 2. 本次范围
|
||||
|
||||
允许修改:
|
||||
|
||||
1. `server-rs/crates/spacetime-module/src/ai/**`
|
||||
2. `server-rs/crates/spacetime-module/src/migration.rs`
|
||||
3. `docs/technical/SPACETIMEDB_TABLE_CATALOG.md`
|
||||
4. 本文档
|
||||
|
||||
禁止修改:
|
||||
|
||||
1. `server-rs/crates/api-server/src/**`
|
||||
2. `server-rs/crates/spacetime-client/src/**`
|
||||
3. `src/services/**`
|
||||
4. `src/hooks/**`
|
||||
5. `src/components/**`
|
||||
|
||||
## 3. 设计
|
||||
|
||||
新增 `ai_task_event` 为 `public event` 表,供订阅端和后续 BFF 增量消费 AI 任务变化。
|
||||
|
||||
事件类型:
|
||||
|
||||
1. `TaskCreated`
|
||||
2. `TaskStatusChanged`
|
||||
3. `StageStarted`
|
||||
4. `StageCompleted`
|
||||
5. `TextChunkAppended`
|
||||
6. `ResultReferenceAttached`
|
||||
|
||||
事件字段只保存用于路由和定位的轻量信息:
|
||||
|
||||
1. `task_id`
|
||||
2. `owner_user_id`
|
||||
3. `event_kind`
|
||||
4. `task_status`
|
||||
5. `stage_kind`
|
||||
6. `text_chunk_row_id`
|
||||
7. `result_reference_row_id`
|
||||
8. `occurred_at`
|
||||
|
||||
## 4. 边界说明
|
||||
|
||||
1. `ai_task_event` 不是业务真相表,不能替代 `ai_task` / `ai_task_stage` / `ai_text_chunk` / `ai_result_reference`。
|
||||
2. reducer 和 procedure 仍只在事务成功后写入事件。
|
||||
3. reducer 继续返回 `Result<(), String>`,procedure 继续返回现有 `AiTaskProcedureResult`。
|
||||
4. 本次没有引入网络、文件、外部随机数或全局可变状态。
|
||||
5. 本次新增表已同步 `migration.rs` 迁移白名单。
|
||||
|
||||
## 5. 验收命令
|
||||
|
||||
```powershell
|
||||
cargo check -p spacetime-module --manifest-path server-rs/Cargo.toml
|
||||
cargo test -p module-ai --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_WP_ST_AI_TASK_EVENT_ADAPTER_2026-04-29.md docs/technical/SPACETIMEDB_TABLE_CATALOG.md server-rs/crates/spacetime-module/src/ai/events.rs server-rs/crates/spacetime-module/src/ai/mod.rs server-rs/crates/spacetime-module/src/ai/snapshots.rs server-rs/crates/spacetime-module/src/ai/stages.rs server-rs/crates/spacetime-module/src/ai/tasks.rs server-rs/crates/spacetime-module/src/migration.rs
|
||||
```
|
||||
|
||||
若后续生成前端绑定或发布数据库,需要继续执行:
|
||||
|
||||
```powershell
|
||||
spacetime build
|
||||
spacetime generate --lang typescript --out-dir <前端绑定目录> --module-path server-rs/crates/spacetime-module
|
||||
spacetime describe <database> --json
|
||||
```
|
||||
@@ -0,0 +1,69 @@
|
||||
# server-rs DDD WP-ST Big Fish 发布门禁 Adapter 落地记录(2026-04-29)
|
||||
|
||||
## 1. 背景
|
||||
|
||||
`WP-BF Big Fish` 已在领域层新增 `evaluate_publish_readiness`,用于评估草稿和资产槽是否满足发布条件。`spacetime-module` 之前在 Big Fish adapter 内直接调用 `build_asset_coverage` 判断发布就绪,容易让门禁规则继续散落在 Adapter。
|
||||
|
||||
本次将 SpacetimeDB Adapter 的发布门禁收口到 `module-big-fish` 应用服务,并新增轻量事件表记录成功事务中的门禁评估事实。
|
||||
|
||||
## 2. 本次范围
|
||||
|
||||
允许修改:
|
||||
|
||||
1. `server-rs/crates/spacetime-module/src/big_fish/**`
|
||||
2. `server-rs/crates/spacetime-module/src/migration.rs`
|
||||
3. `docs/technical/SPACETIMEDB_TABLE_CATALOG.md`
|
||||
4. 本文档
|
||||
|
||||
禁止修改:
|
||||
|
||||
1. `server-rs/crates/api-server/src/**`
|
||||
2. `server-rs/crates/spacetime-client/src/**`
|
||||
3. `src/services/**`
|
||||
4. `src/hooks/**`
|
||||
5. `src/components/**`
|
||||
|
||||
## 3. 设计
|
||||
|
||||
新增 `big_fish_event` 为 `public event` 表,当前只承接 `PublishReadinessEvaluated`。
|
||||
|
||||
事件字段:
|
||||
|
||||
1. `session_id`
|
||||
2. `owner_user_id`
|
||||
3. `event_kind`
|
||||
4. `publish_ready`
|
||||
5. `blockers_json`
|
||||
6. `occurred_at`
|
||||
|
||||
接入点:
|
||||
|
||||
1. `compile_big_fish_draft_tx`
|
||||
2. `generate_big_fish_asset_tx`
|
||||
3. `publish_big_fish_game_tx`
|
||||
|
||||
这些接入点先从 SpacetimeDB row 读取草稿和资产槽,再调用 `module_big_fish::evaluate_publish_readiness`,最后把 readiness 回写到 `big_fish_creation_session.publish_ready` 和 `asset_coverage_json`。
|
||||
|
||||
## 4. 边界说明
|
||||
|
||||
1. `big_fish_event` 不是作品真相表,不能替代 `big_fish_creation_session` 或 `big_fish_asset_slot`。
|
||||
2. 发布门禁规则由 `module-big-fish` 领域应用服务决定,SpacetimeDB Adapter 只负责 row 映射、持久化和事件落表。
|
||||
3. 由于 SpacetimeDB 事务在 `Err` 时回滚,发布失败路径中的事件不会持久化;事件表只记录成功事务内完成的门禁评估事实。
|
||||
4. 本次没有引入 HTTP、OSS、图片生成、文件系统或外部随机数。
|
||||
5. 本次新增表已同步 `migration.rs` 迁移白名单。
|
||||
|
||||
## 5. 验收命令
|
||||
|
||||
```powershell
|
||||
cargo check -p spacetime-module --manifest-path server-rs/Cargo.toml
|
||||
cargo test -p module-big-fish --manifest-path server-rs/Cargo.toml
|
||||
npm.cmd run check:server-rs-ddd
|
||||
npm.cmd run check:encoding -- docs/technical/SERVER_RS_DDD_WP_ST_BIG_FISH_READINESS_ADAPTER_2026-04-29.md docs/technical/SPACETIMEDB_TABLE_CATALOG.md server-rs/crates/spacetime-module/src/big_fish/events.rs server-rs/crates/spacetime-module/src/big_fish/mod.rs server-rs/crates/spacetime-module/src/big_fish/assets.rs server-rs/crates/spacetime-module/src/big_fish/session.rs server-rs/crates/spacetime-module/src/migration.rs
|
||||
```
|
||||
|
||||
若后续具备 CLI 环境,需要继续执行:
|
||||
|
||||
```powershell
|
||||
spacetime build --project-path server-rs/crates/spacetime-module
|
||||
spacetime generate --lang rust --out-dir server-rs/crates/spacetime-client/src/module_bindings --module-path server-rs/crates/spacetime-module
|
||||
```
|
||||
@@ -27,9 +27,9 @@ spacetime sql <db> "SELECT * FROM custom_world_gallery_entry"
|
||||
| RPG 运行时 | `story_session`, `story_event`, `npc_state`, `inventory_slot`, `battle_state`, `treasure_record`, `quest_record`, `quest_log`, `player_progression`, `chapter_progression` |
|
||||
| 世界创作 | `custom_world_profile`, `custom_world_session`, `custom_world_agent_session`, `custom_world_agent_message`, `custom_world_agent_operation`, `custom_world_draft_card`, `custom_world_gallery_entry` |
|
||||
| 拼图 | `puzzle_agent_session`, `puzzle_agent_message`, `puzzle_work_profile`, `puzzle_runtime_run` |
|
||||
| 大鱼吃小鱼 | `big_fish_creation_session`, `big_fish_agent_message`, `big_fish_asset_slot`, `big_fish_runtime_run` |
|
||||
| 大鱼吃小鱼 | `big_fish_creation_session`, `big_fish_agent_message`, `big_fish_asset_slot`, `big_fish_event`, `big_fish_runtime_run` |
|
||||
| 资产 | `asset_object`, `asset_entity_binding` |
|
||||
| AI 任务 | `ai_task`, `ai_task_stage`, `ai_text_chunk`, `ai_result_reference` |
|
||||
| AI 任务 | `ai_task`, `ai_task_stage`, `ai_text_chunk`, `ai_result_reference`, `ai_task_event` |
|
||||
|
||||
## 认证表
|
||||
|
||||
@@ -464,6 +464,18 @@ SELECT * FROM big_fish_asset_slot WHERE slot_id = '<slot_id>';
|
||||
SELECT * FROM big_fish_asset_slot WHERE session_id = '<session_id>';
|
||||
```
|
||||
|
||||
### `big_fish_event`
|
||||
|
||||
- 作用:大鱼吃小鱼创作事件表,目前记录发布门禁评估结果,供订阅端、BFF 或审计流程感知草稿是否达到发布条件;正式作品状态仍以 `big_fish_creation_session` 和 `big_fish_asset_slot` 为准。
|
||||
- 可见性:`public event`。
|
||||
- 结构:`event_id PK: String`, `session_id: String`, `owner_user_id: String`, `event_kind: BigFishEventKind`, `publish_ready: bool`, `blockers_json: String`, `occurred_at: Timestamp`。
|
||||
- 索引:`session_id`, `owner_user_id`。
|
||||
|
||||
```sql
|
||||
SELECT * FROM big_fish_event WHERE session_id = '<session_id>' ORDER BY occurred_at ASC;
|
||||
SELECT * FROM big_fish_event WHERE owner_user_id = '<user_id>' ORDER BY occurred_at DESC;
|
||||
```
|
||||
|
||||
### `big_fish_runtime_run`
|
||||
|
||||
- 作用:大鱼吃小鱼运行态表,保存当前 run 的快照、最后输入方向和 tick。
|
||||
@@ -550,6 +562,18 @@ SELECT * FROM ai_result_reference WHERE result_reference_row_id = '<row_id>';
|
||||
SELECT * FROM ai_result_reference WHERE task_id = '<task_id>' ORDER BY created_at ASC;
|
||||
```
|
||||
|
||||
### `ai_task_event`
|
||||
|
||||
- 作用:AI 任务事件表,用于把任务创建、状态变化、阶段变化、流式文本和结果引用挂接广播给订阅端;任务真相仍以 `ai_task`、`ai_task_stage`、`ai_text_chunk` 和 `ai_result_reference` 为准。
|
||||
- 可见性:`public event`。
|
||||
- 结构:`event_id PK: String`, `task_id: String`, `owner_user_id: String`, `event_kind: AiTaskEventKind`, `task_status: Option<AiTaskStatus>`, `stage_kind: Option<AiTaskStageKind>`, `text_chunk_row_id: Option<String>`, `result_reference_row_id: Option<String>`, `occurred_at: Timestamp`。
|
||||
- 索引:`task_id`, `owner_user_id`。
|
||||
|
||||
```sql
|
||||
SELECT * FROM ai_task_event WHERE task_id = '<task_id>' ORDER BY occurred_at ASC;
|
||||
SELECT * FROM ai_task_event WHERE owner_user_id = '<user_id>' ORDER BY occurred_at DESC;
|
||||
```
|
||||
|
||||
## 当前维护风险
|
||||
|
||||
- `story_session`、`story_event`、`npc_state`、`inventory_slot`、`battle_state`、`treasure_record`、`quest_record`、`quest_log`、`player_progression`、`chapter_progression` 在 `src/lib.rs` 与 `src/gameplay/mod.rs` 都能看到表定义。当前编译入口以 `src/lib.rs` 为准;后续完成拆分时,需要删除重复定义或正式挂载子模块,并同步更新本文。
|
||||
|
||||
Reference in New Issue
Block a user