AI 小说工坊:主编 + 作家多模型协作写作应用

- Nuxt 4 + Nuxt UI 4 + AI SDK 7 + Drizzle/SQLite
- 主编规划大纲与章节简报、选派作家;作家流式写入章节文件并实时推送前端
- 逐章确认模式(默认)与自动模式;摘要与故事记忆
- 酒馆角色卡(PNG/JSON,V1-V3)与世界书导入
- 自定义最高优先级系统提示词、审稿/修改/多版本、任务日志与提示词检视
- 模拟 LLM 服务与端到端测试脚本

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jocay
2026-10-18 02:04:40 +08:00
commit 3c9b65d982
106 changed files with 16286 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
import { and, eq } from 'drizzle-orm'
import { z } from 'zod'
/** 切换章节的当前版本 */
export default defineEventHandler(async (event) => {
const chapter = getChapter(param(event))
const { versionId } = await readJson(event, z.object({ versionId: z.string() }))
const v = useDb().select().from(tables.chapterVersions)
.where(and(eq(tables.chapterVersions.id, versionId), eq(tables.chapterVersions.chapterId, chapter.id))).get()
if (!v) throw createError({ statusCode: 404, message: '版本不存在' })
if (v.status === 'writing') throw createError({ statusCode: 400, message: '该版本仍在写作中' })
useDb().update(tables.chapters).set({
activeVersionId: v.id,
// 切换版本后需要重新确认,以便重新生成摘要
status: chapter.status === 'approved' ? 'written' : chapter.status === 'writing' ? chapter.status : 'written'
}).where(eq(tables.chapters.id, chapter.id)).run()
emitProject(chapter.projectId, { type: 'chapter', chapterId: chapter.id })
return { ok: true }
})
+13
View File
@@ -0,0 +1,13 @@
import { z } from 'zod'
/** 确认章节:生成摘要、更新故事记忆;continue=true 时接着写下一章 */
export default defineEventHandler(async (event) => {
const chapter = getChapter(param(event))
const { continue: next } = await readJson(event, z.object({ continue: z.boolean().default(false) }))
if (!chapter.activeVersionId) throw createError({ statusCode: 400, message: '本章还没有正文' })
runExclusive(chapter.projectId, next ? `确认第${chapter.index}章并继续` : `确认第${chapter.index}章`, async (signal) => {
await approveChapter(chapter.projectId, chapter.id, signal)
if (next) await runPipeline(chapter.projectId, signal)
})
return { started: true }
})
+7
View File
@@ -0,0 +1,7 @@
/** 让主编为本章生成简报并指派作家 */
export default defineEventHandler((event) => {
const chapter = getChapter(param(event))
if (chapter.status === 'writing') throw createError({ statusCode: 409, message: '本章正在写作中' })
runExclusive(chapter.projectId, `第${chapter.index}章简报`, signal => generateBrief(chapter.projectId, chapter.id, signal))
return { started: true }
})
+10
View File
@@ -0,0 +1,10 @@
import { eq } from 'drizzle-orm'
/** 撤销确认:已确认的章节回到“待确认”状态 */
export default defineEventHandler((event) => {
const chapter = getChapter(param(event))
if (chapter.status !== 'approved') return { ok: true }
useDb().update(tables.chapters).set({ status: 'written' }).where(eq(tables.chapters.id, chapter.id)).run()
emitProject(chapter.projectId, { type: 'chapter', chapterId: chapter.id })
return { ok: true }
})
+7
View File
@@ -0,0 +1,7 @@
/** 主编审稿 */
export default defineEventHandler((event) => {
const chapter = getChapter(param(event))
if (!chapter.activeVersionId) throw createError({ statusCode: 400, message: '本章还没有正文' })
runExclusive(chapter.projectId, `审阅第${chapter.index}章`, signal => reviewChapter(chapter.projectId, chapter.id, signal))
return { started: true }
})
+18
View File
@@ -0,0 +1,18 @@
import { z } from 'zod'
const schema = z.object({
/** 指定作家;不传则使用章节已指派的作家 */
writerAgentId: z.string().nullable().optional(),
/** 修改意见 */
feedback: z.string().optional(),
/** true:在当前版本基础上按意见修改;false:重新写一版 */
revise: z.boolean().optional()
})
export default defineEventHandler(async (event) => {
const chapter = getChapter(param(event))
const body = await readJson(event, schema)
if (body.revise && !chapter.activeVersionId) throw createError({ statusCode: 400, message: '本章还没有可修改的版本' })
runExclusive(chapter.projectId, `第${chapter.index}章写作`, signal => writeChapter(chapter.projectId, chapter.id, signal, body))
return { started: true }
})