diff.txt 1.5 KB

123456789101112131415161718192021222324252627282930
  1. diff --git a/server/src/modules/book-generator/langgraph-generator.ts b/server/src/modules/book-generator/langgraph-generator.ts
  2. index 3f502c6..5128bdc 100644
  3. --- a/server/src/modules/book-generator/langgraph-generator.ts
  4. +++ b/server/src/modules/book-generator/langgraph-generator.ts
  5. @@ -335,7 +335,25 @@ async function writeChaptersNode(state: typeof GraphState.State): Promise<Partia
  6. let currentWordCount = await getGeneratedWordCount(state.bookId);
  7. console.log(`[LangGraph] 当前已生成字数: ${currentWordCount}`);
  8. + // 查询已完成的章节,支持断点续传
  9. + const completedChapterNumbers = new Set<number>();
  10. + for (const ch of book.outline.chapters) {
  11. + const chapter = await bookStore.getChapter(state.bookId, ch.number);
  12. + if (chapter && chapter.status === 'completed') {
  13. + completedChapterNumbers.add(ch.number);
  14. + }
  15. + }
  16. +
  17. + if (completedChapterNumbers.size > 0) {
  18. + console.log(`[LangGraph] ✅ 跳过 ${completedChapterNumbers.size} 个已完成的章节: [${Array.from(completedChapterNumbers).join(', ')}]`);
  19. + }
  20. +
  21. for (const chapterOutline of book.outline.chapters) {
  22. + // 跳过已完成的章节
  23. + if (completedChapterNumbers.has(chapterOutline.number)) {
  24. + console.log(`[LangGraph] 跳过第${chapterOutline.number}章(已完成)`);
  25. + continue;
  26. + }
  27. // ===== 额度监控:在生成章节前检查额度 =====
  28. console.log(`[LangGraph] 检查第${chapterOutline.number}章额度,当前累计: ${currentWordCount}字`);
  29. try {