Parcourir la source

fix: 生成完成后根据实际章节状态更新书籍 genStage

之前 then() 回调只打日志不更新 genStage,导致永远卡在 outlining。
现在检查所有叶节点的 genStage 来决定最终是 content_completed 还是 audio_completed。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
MyFramework User il y a 3 mois
Parent
commit
b76f56a46b
1 fichiers modifiés avec 12 ajouts et 1 suppressions
  1. 12 1
      server/src/modules/book-generator/langgraph-controller.ts

+ 12 - 1
server/src/modules/book-generator/langgraph-controller.ts

@@ -997,8 +997,19 @@ router.post('/books/:id/generate', optionalAuth, async (ctx: Context) => {
     await bookStore.update(bookId, { genStage: 'outlining', totalChapters: 0, progress: 0 });
 
     langGraphGenerator.generate(bookId, book.description, bookScale, genLevel, userId)
-      .then(() => {
+      .then(async () => {
         console.log(`[LangGraph] 生成完成: bookId=${bookId}`);
+        // 根据实际章节状态更新书籍 genStage
+        const chapters = await bookStore.getChapterTree(bookId);
+        const leafNodes = chapters.filter((c: any) => {
+          const maxLevel = Math.max(...chapters.map((ch: any) => ch.level || 0));
+          return c.level === maxLevel;
+        });
+        const allContentDone = leafNodes.length > 0 && leafNodes.every((c: any) => c.genStage === 'content_completed' || c.genStage === 'audio_completed' || c.genStage === 'video_completed');
+        const allAudioDone = leafNodes.length > 0 && leafNodes.every((c: any) => c.genStage === 'audio_completed' || c.genStage === 'video_completed');
+        const finalStage = allAudioDone ? 'audio_completed' : allContentDone ? 'content_completed' : 'outlining';
+        await bookStore.update(bookId, { genStage: finalStage, progress: 100 });
+        console.log(`[LangGraph] 最终状态: ${finalStage}, 叶节点: ${leafNodes.length}`);
       })
       .catch(err => {
         console.error(`[LangGraph] 生成失败: bookId=${bookId}`, err);