Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | /**
* 书籍生成模块 - 类型定义
* 定义书籍、章节、任务的数据结构
*/
// ============ 核心类型 ============
/** 书籍生成阶段 */
export type BookGenStage =
| 'draft'
| 'outlining'
| 'outline_completed'
| 'content_generating'
| 'content_completed'
| 'audio_generating'
| 'audio_completed'
| 'video_generating'
| 'video_completed'
| 'failed';
/** 章节生成阶段(唯一类型定义,stage-manager.ts 从此文件导入) */
export type ChapterGenStage =
| 'idle'
| 'outline_completed'
| 'content_generating'
| 'content_completed'
| 'audio_generating'
| 'audio_completed'
| 'video_generating'
| 'video_completed'
| 'failed';
/** 书籍基础信息 */
export interface BookBase {
id: string;
title: string; // 书名
subtitle?: string; // 副标题
description: string; // 书籍描述/用户输入
targetAudience: string; // 目标受众
style: string; // 写作风格
bookScale: string; // 书籍规模:纯数字字符串,如 1000, 2000, 130000, 340000 等
totalChapters: number; // 总章节数
estimatedWords: number; // 预估总字数
genStage?: BookGenStage; // 线性阶段状态
failedStage?: string; // 失败阶段
createdAt: Date;
updatedAt: Date;
}
/** 书籍完整信息 */
export interface Book extends BookBase {
userId?: number; // 用户ID(用于配额检查)
progress: number; // 生成进度 0-100
isPublished: boolean; // 是否已公开
chapters: Chapter[]; // 章节列表
outline?: BookOutline; // 书籍大纲
metadata?: BookMetadata; // 元数据(作者、前言、后记等)
error?: string; // 错误信息
bookAnalysis?: string; // AI 书籍规划结果(planBookNode 输出)
}
/** 书籍大纲 */
export interface BookOutline {
bookType?: 'textbook' | 'novel' | 'popular' | 'essay'; // 书籍类型(AI自主判断)
mainTheme: string; // 主题主线
structureLogic: string; // 结构逻辑
chapters: OutlineChapter[]; // 章节大纲
}
/** 章节大纲(规划阶段)*/
export interface OutlineChapter {
number: number;
title: string;
summary: string; // 章节概述
keyPoints: string[]; // 核心知识点
estimatedWords: number; // 预估字数
stories?: string[]; // 故事/案例
sections?: { // 节(章下第一级)
number: number; // 节序号
title: string;
summary?: string; // 本节概述
keyPoints?: string[]; // 本节要点
estimatedWords?: number; // 本节预估字数
subsections?: { // 小节(节下第二级)
number: number; // 小节序号
title: string;
summary?: string; // 本小节概述
keyPoints?: string[]; // 本小节要点
estimatedWords?: number; // 本小节预估字数
}[];
}[];
}
/** 章节内容 */
export interface Chapter {
id: string;
bookId: string;
number: number;
title: string;
content: string; // 正文内容
summary?: string; // 本章小结
wordCount: number; // 字数
genStage?: ChapterGenStage; // 线性阶段状态
generatedAt?: Date;
error?: string;
audioUrl?: string; // 音频URL
audioDuration?: number; // 音频时长
videoUrl?: string; // 视频URL
videoDuration?: number; // 视频时长
isPublic?: boolean; // 是否公开(2026-04-14 新增)
level?: number; // 层级:1=章, 2=节, 3=小节
parentId?: number; // 父节点ID(0表示章)
}
/** 书籍元数据 */
export interface BookMetadata {
author?: string;
foreword?: string; // 前言
afterword?: string; // 后记
references?: string[]; // 参考文献
appendix?: string; // 附录
}
/** 生成任务 */
export interface GenerateTask {
id: string;
bookId: string;
chapterId?: string; // 如果是章节任务
type: 'outline' | 'chapter' | 'foreword' | 'afterword';
status: 'pending' | 'running' | 'completed' | 'failed';
progress: number;
message: string;
retryCount: number;
maxRetries: number;
createdAt: Date;
startedAt?: Date;
completedAt?: Date;
error?: string;
}
// ============ 请求/响应类型 ============
/** 创建书籍请求 */
export interface CreateBookRequest {
title: string;
subtitle?: string;
description: string; // 核心输入:用户要写的内容描述
targetAudience?: string; // 默认:通用
style?: string; // 默认:专业严谨
totalChapters?: number; // 默认:10章
language?: string; // 默认:中文
}
/** 生成章节请求 */
export interface GenerateChapterRequest {
bookId: string;
chapterNumber?: number; // 指定章节,不指定则按顺序生成
}
/** 批量生成请求 */
export interface BatchGenerateRequest {
bookId: string;
chapterNumbers?: number[]; // 指定章节号数组
}
/** 书籍响应 */
export interface BookResponse {
book: Book;
tasks: GenerateTask[];
}
/** 进度响应 */
export interface ProgressResponse {
bookId: string;
genStage: string;
progress: number;
currentTask?: {
type: string;
message: string;
};
completedChapters: number;
totalChapters: number;
}
// ============ 配置类型 ============
/** 生成配置 */
export interface GenerateConfig {
model: string; // 使用的模型
temperature: number; // 温度参数
maxTokens: number; // 最大 token 数
chapterWordRange: { // 章节字数范围
min: number;
max: number;
};
retryPolicy: {
maxRetries: number;
retryDelay: number; // ms
};
}
// ============ 提示词模板类型 ============
/** 提示词模板 */
export interface PromptTemplate {
systemPrompt: string;
outlinePrompt: string;
chapterPrompt: (chapter: OutlineChapter, context: BookOutline) => string;
forewordPrompt: (book: BookBase) => string;
afterwordPrompt: (book: BookBase) => string;
}
// ============ 存储结构 ============
/** 内存存储 */
export interface BookStore {
books: Map<string, Book>;
tasks: Map<string, GenerateTask>;
}
/** 存储键名 */
export const StoreKeys = {
BOOK_PREFIX: 'book:',
TASK_PREFIX: 'task:',
TASK_QUEUE: 'task:queue',
} as const;
|