@waterwx/dsh-novel-forge 1.0.0-alpha → 1.1.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +231 -231
- package/lib/client.js +9118 -7818
- package/lib/index.js +316 -112
- package/lib/types/bookshelf.d.ts +5 -0
- package/lib/types/client/api.d.ts +6 -2
- package/lib/types/client/docx.d.ts +2 -0
- package/lib/types/client/locales.d.ts +5 -5
- package/lib/types/client/panel/AiTag.d.ts +1 -0
- package/lib/types/client/panel/AuthorHome.d.ts +11 -11
- package/lib/types/client/panel/CmdPalette.d.ts +12 -0
- package/lib/types/client/panel/LiveFeedLog.d.ts +3 -0
- package/lib/types/client/panel/NovelPanel.d.ts +5 -0
- package/lib/types/client/panel/PageHeader.d.ts +18 -0
- package/lib/types/client/panel/SettingsView.d.ts +12 -9
- package/lib/types/client/panel/ShelfView.d.ts +10 -1
- package/lib/types/client/panel/SubPage.d.ts +27 -0
- package/lib/types/client/panel/toast.d.ts +2 -0
- package/lib/types/client/panel/views.d.ts +25 -7
- package/lib/types/docx-core.d.ts +16 -0
- package/lib/types/docx.d.ts +2 -3
- package/lib/types/engine.d.ts +9 -9
- package/lib/types/index.d.ts +1 -1
- package/lib/types/migrate-output.d.ts +25 -0
- package/lib/types/prompting.d.ts +1 -26
- package/lib/types/protocol.d.ts +76 -31
- package/lib/types/routes.d.ts +4 -0
- package/lib/types/run.d.ts +2 -0
- package/package.json +120 -120
- package/src/assistant.ts +3 -3
- package/src/author-assets.ts +149 -147
- package/src/bookshelf.ts +187 -167
- package/src/client/api.ts +12 -3
- package/src/client/docx.ts +37 -69
- package/src/client/llmLive.ts +101 -101
- package/src/client/locales.ts +418 -418
- package/src/client/panel/AdaptModeView.tsx +535 -535
- package/src/client/panel/AiTag.tsx +7 -0
- package/src/client/panel/AssetsTab.tsx +448 -458
- package/src/client/panel/AssistantTab.tsx +35 -35
- package/src/client/panel/AuthorAssetsView.tsx +205 -207
- package/src/client/panel/AuthorHome.tsx +309 -234
- package/src/client/panel/BookAnalysisView.tsx +63 -60
- package/src/client/panel/CmdPalette.tsx +102 -0
- package/src/client/panel/CreateBookView.tsx +366 -371
- package/src/client/panel/DirectorView.tsx +23 -23
- package/src/client/panel/GlobalAssetLibraryView.tsx +168 -172
- package/src/client/panel/IdeaInspirationView.tsx +76 -71
- package/src/client/panel/ImportModal.tsx +302 -302
- package/src/client/panel/KnowledgeBaseView.tsx +125 -73
- package/src/client/panel/LiveFeedLog.tsx +67 -67
- package/src/client/panel/MarketRadarView.tsx +377 -374
- package/src/client/panel/ModelManager.tsx +205 -205
- package/src/client/panel/NovelPanel.tsx +2761 -2100
- package/src/client/panel/PageHeader.tsx +37 -0
- package/src/client/panel/ProgressConsole.tsx +63 -63
- package/src/client/panel/ReaderView.tsx +306 -306
- package/src/client/panel/RunPanel.tsx +223 -204
- package/src/client/panel/SettingsView.tsx +305 -265
- package/src/client/panel/ShelfView.tsx +266 -242
- package/src/client/panel/SubPage.tsx +42 -0
- package/src/client/panel/WorldTab.tsx +202 -202
- package/src/client/panel/panel.module.css +5764 -4693
- package/src/client/panel/toast.ts +51 -0
- package/src/client/panel/views.tsx +401 -346
- package/src/client/run-status.ts +143 -100
- package/src/docx-core.ts +53 -0
- package/src/docx.ts +44 -83
- package/src/engine.ts +15 -90
- package/src/index.ts +311 -298
- package/src/migrate-output.ts +76 -0
- package/src/novel-context.ts +286 -287
- package/src/prompting.ts +26 -159
- package/src/protocol.ts +79 -31
- package/src/routes.ts +123 -9
- package/src/run.ts +341 -338
- package/lib/types/client/panel/FlowGuide.d.ts +0 -22
- package/lib/types/client/panel/MangaRoleLibrary.d.ts +0 -20
- package/lib/types/client/panel/MangaWorkspace.d.ts +0 -12
- package/lib/types/client/panel/ModelPicker.d.ts +0 -11
- package/lib/types/client/panel/PropLibrary.d.ts +0 -8
- package/lib/types/client/panel/SceneLibrary.d.ts +0 -16
- package/lib/types/client/panel/StoryboardTab.d.ts +0 -19
- package/lib/types/client/panel/StyleCard.d.ts +0 -8
- package/lib/types/client/panel/StyleGallery.d.ts +0 -1
- package/lib/types/comic-presets.d.ts +0 -12
- package/lib/types/manga-genre-rules.d.ts +0 -22
- package/lib/types/shot-language.d.ts +0 -46
- package/lib/types/src/ai-scan.d.ts +0 -36
- package/lib/types/src/assets.d.ts +0 -37
- package/lib/types/src/assistant.d.ts +0 -45
- package/lib/types/src/author-assets.d.ts +0 -25
- package/lib/types/src/bookshelf.d.ts +0 -42
- package/lib/types/src/client/api.d.ts +0 -234
- package/lib/types/src/client/docx.d.ts +0 -15
- package/lib/types/src/client/index.d.ts +0 -14
- package/lib/types/src/client/locales.d.ts +0 -212
- package/lib/types/src/client/mount.d.ts +0 -9
- package/lib/types/src/client/panel/AdaptModeView.d.ts +0 -5
- package/lib/types/src/client/panel/AssetsTab.d.ts +0 -12
- package/lib/types/src/client/panel/AssistantTab.d.ts +0 -7
- package/lib/types/src/client/panel/AuthorAssetsView.d.ts +0 -4
- package/lib/types/src/client/panel/AuthorHome.d.ts +0 -32
- package/lib/types/src/client/panel/BookshelfBar.d.ts +0 -11
- package/lib/types/src/client/panel/CreateBookView.d.ts +0 -9
- package/lib/types/src/client/panel/FlowGuide.d.ts +0 -22
- package/lib/types/src/client/panel/GlobalAssetLibraryView.d.ts +0 -4
- package/lib/types/src/client/panel/ImportModal.d.ts +0 -7
- package/lib/types/src/client/panel/MangaRoleLibrary.d.ts +0 -20
- package/lib/types/src/client/panel/MangaWorkspace.d.ts +0 -12
- package/lib/types/src/client/panel/ModelManager.d.ts +0 -14
- package/lib/types/src/client/panel/NovelPanel.d.ts +0 -13
- package/lib/types/src/client/panel/ProgressConsole.d.ts +0 -17
- package/lib/types/src/client/panel/ProgressHomeView.d.ts +0 -5
- package/lib/types/src/client/panel/PropLibrary.d.ts +0 -8
- package/lib/types/src/client/panel/ReaderView.d.ts +0 -8
- package/lib/types/src/client/panel/ReasoningSection.d.ts +0 -10
- package/lib/types/src/client/panel/RunPanel.d.ts +0 -5
- package/lib/types/src/client/panel/SceneLibrary.d.ts +0 -16
- package/lib/types/src/client/panel/SettingsView.d.ts +0 -16
- package/lib/types/src/client/panel/ShelfView.d.ts +0 -15
- package/lib/types/src/client/panel/StoryboardTab.d.ts +0 -19
- package/lib/types/src/client/panel/StyleCard.d.ts +0 -8
- package/lib/types/src/client/panel/StyleGallery.d.ts +0 -1
- package/lib/types/src/client/panel/WorldTab.d.ts +0 -10
- package/lib/types/src/client/panel/controller.d.ts +0 -19
- package/lib/types/src/client/panel/helpers.d.ts +0 -18
- package/lib/types/src/client/panel/views.d.ts +0 -77
- package/lib/types/src/client/sidebar-entry.d.ts +0 -13
- package/lib/types/src/client/text.d.ts +0 -9
- package/lib/types/src/comic-presets.d.ts +0 -12
- package/lib/types/src/docx.d.ts +0 -19
- package/lib/types/src/engine.d.ts +0 -402
- package/lib/types/src/index.d.ts +0 -79
- package/lib/types/src/manga-genre-rules.d.ts +0 -22
- package/lib/types/src/novel-context.d.ts +0 -80
- package/lib/types/src/prompt-utils.d.ts +0 -35
- package/lib/types/src/protocol.d.ts +0 -2176
- package/lib/types/src/review-policy.d.ts +0 -97
- package/lib/types/src/routes.d.ts +0 -29
- package/lib/types/src/run.d.ts +0 -32
- package/lib/types/src/shot-language.d.ts +0 -46
- package/lib/types/src/story-beat-language.d.ts +0 -35
- package/lib/types/src/style-library.d.ts +0 -33
- package/lib/types/story-beat-language.d.ts +0 -35
- package/lib/types/style-library.d.ts +0 -33
- package/src/client/panel/BookshelfBar.tsx +0 -170
- package/src/client/panel/ProgressHomeView.tsx +0 -87
- package/src/prompt-utils.ts +0 -73
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { homedir, tmpdir } from "node:os";
|
|
2
|
-
import { basename, extname, join } from "node:path";
|
|
2
|
+
import { basename, extname, join, resolve, sep } from "node:path";
|
|
3
3
|
import z from "schemastery";
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
|
-
import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { appendFileSync, copyFileSync, cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { randomBytes } from "node:crypto";
|
|
7
7
|
import { BlockAssembler, ReasoningEffortId, createAssistantMessage, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
8
8
|
import { strFromU8, unzipSync } from "fflate";
|
|
@@ -3222,64 +3222,9 @@ function emitLive(frame) {
|
|
|
3222
3222
|
if (buffer.length > MAX_BUFFER) buffer = buffer.slice(-400);
|
|
3223
3223
|
for (const l of listeners) l(frame);
|
|
3224
3224
|
}
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
"",
|
|
3229
|
-
"【叙事视角】{{slot.writer.pov}}",
|
|
3230
|
-
"",
|
|
3231
|
-
"【任务边界】只输出章节正文,不输出标题、提纲、解释或任何额外文本。",
|
|
3232
|
-
"",
|
|
3233
|
-
"【核心约束】",
|
|
3234
|
-
"0. 以本章任务、人物状态、伏笔指令和连续性上下文为准,避免提前揭示未来答案或写到后续章节事件。",
|
|
3235
|
-
"1. 必须推进新的剧情动作,本章必须发生实质变化(局面、关系、信息、风险、决策至少一项)。",
|
|
3236
|
-
"2. 不得写成总结、复盘、解释性段落为主的章节,正文必须以「正在发生」的内容为主。",
|
|
3237
|
-
"3. 不得引入新的核心角色、世界规则或与上下文冲突的重大设定。",
|
|
3238
|
-
"",
|
|
3239
|
-
"【结构要求】",
|
|
3240
|
-
"1. 开头必须迅速进入当前情境,不得长时间铺垫背景或复述上一章。",
|
|
3241
|
-
"2. 中段必须出现推进、变化或对抗,不能平铺直叙维持同一状态。",
|
|
3242
|
-
"3. 本章至少出现一次明确的「状态变化」(信息反转、局面升级、关系变化、风险上升或计划转向)。",
|
|
3243
|
-
"4. {{slot.writer.endingHookPreference}}",
|
|
3244
|
-
"",
|
|
3245
|
-
"【篇幅要求】",
|
|
3246
|
-
"本章目标长度:约 {{input.targetWordCount}} 字;可接受区间:{{input.minWordCount}}-{{input.maxWordCount}} 字。",
|
|
3247
|
-
"篇幅不够时必须继续推进新的有效情节、冲突、对话和动作,而不是草率收尾。",
|
|
3248
|
-
"禁止靠重复回顾、空泛心理独白、无信息量描写硬凑字数。",
|
|
3249
|
-
"",
|
|
3250
|
-
"【连续性约束】",
|
|
3251
|
-
"1. 章节开头必须与 recent_chapters 明显区分,禁止复用相同开场模式。",
|
|
3252
|
-
"2. 允许短回调,但不得大段复述已发生事件,不得复制上下文原句。",
|
|
3253
|
-
"3. 必须延续当前人物状态与局面,不得让角色行为失去动机或连续性。",
|
|
3254
|
-
"",
|
|
3255
|
-
"【表达要求】",
|
|
3256
|
-
"1. {{slot.writer.tonePreference}}",
|
|
3257
|
-
"2. 优先使用具体动作、对话与可感知细节推进,而不是抽象概述。",
|
|
3258
|
-
"3. {{slot.writer.antiAiRules}}",
|
|
3259
|
-
"4. 对话应服务推进或冲突,不得成为填充内容。",
|
|
3260
|
-
"",
|
|
3261
|
-
"【输出前自查】",
|
|
3262
|
-
"在生成正文前,先内部确认:读者回报、关键转折和章末净变化是否可见,旧钩子责任是否回应,",
|
|
3263
|
-
"结尾钩子是否成立,义务合约是否兑现,人物硬事实是否违背。确认通过后再开始输出,不需要在正文中输出核查结果。"
|
|
3264
|
-
].join("\n");
|
|
3265
|
-
[
|
|
3266
|
-
"小说:{{input.novelTitle}}",
|
|
3267
|
-
"章节:第 {{input.chapterOrder}} 章 {{input.chapterTitle}}",
|
|
3268
|
-
"",
|
|
3269
|
-
"【书级合约】{{context.book_contract}}",
|
|
3270
|
-
"【章节任务】{{context.chapter_mission}}",
|
|
3271
|
-
"【读者体验合同】{{context.reader_experience}}",
|
|
3272
|
-
"【人物硬事实】{{context.character_hard_facts}}",
|
|
3273
|
-
"【本章义务合约】{{context.obligation_contract}}",
|
|
3274
|
-
"【卷级窗口】{{context.volume_window}}",
|
|
3275
|
-
"【出场角色子集】{{context.participant_subset}}",
|
|
3276
|
-
"【当前局面】{{context.local_state}}",
|
|
3277
|
-
"【风格合约】{{context.style_contract}}",
|
|
3278
|
-
"【额外写法约束】{{slot.writer.customConstraints}}",
|
|
3279
|
-
"",
|
|
3280
|
-
"只输出章节正文。"
|
|
3281
|
-
].join("\n");
|
|
3282
|
-
/** 把官方 writer 骨架渲染成可附加到现有系统提示词末尾的约束/自查块。 */
|
|
3225
|
+
//#endregion
|
|
3226
|
+
//#region src/prompting.ts
|
|
3227
|
+
/** 章节写作约束:官方 writer 骨架渲染成可附加到现有系统提示词末尾的必达/禁止/自查块。 */
|
|
3283
3228
|
function renderOfficialChapterWriterSkeleton(meta) {
|
|
3284
3229
|
const pov = meta.pov ?? "第三人称有限视角,严格跟随主角所见所知。";
|
|
3285
3230
|
const tone = meta.tonePreference ?? "文风贴合本书设定,用具体细节与动作推进。";
|
|
@@ -3380,7 +3325,7 @@ function retrieveRelevantRoles(bible, roles, beatsText) {
|
|
|
3380
3325
|
* 检索结果不足时自动回退全量,保证不丢失关键信息。
|
|
3381
3326
|
*/
|
|
3382
3327
|
function buildChapterContext(project, chapter, outputDir, options = {}) {
|
|
3383
|
-
const {
|
|
3328
|
+
const { fullRoleCards = true, relatedFactsLimit = 15, recentFactsLimit = 20 } = options;
|
|
3384
3329
|
const bible = project.bible;
|
|
3385
3330
|
const allFacts = project.facts ?? [];
|
|
3386
3331
|
const roleNames = (project.roles ?? []).map((r) => r.name).filter((n) => typeof n === "string" && n !== "");
|
|
@@ -3531,13 +3476,13 @@ const NOVEL_API = {
|
|
|
3531
3476
|
blurb: "/api/dsh-novel-forge/blurb",
|
|
3532
3477
|
/** 重命名当前书(同步项目与书架条目)。 */
|
|
3533
3478
|
rename: "/api/dsh-novel-forge/rename",
|
|
3534
|
-
/**
|
|
3479
|
+
/** 大世界:提炼 / 保存结构化数据(境界/区域/势力)。 */
|
|
3535
3480
|
world: "/api/dsh-novel-forge/world",
|
|
3536
3481
|
/** 封面:GET 读取(dataUrl)/ POST 上传或移除。 */
|
|
3537
3482
|
cover: "/api/dsh-novel-forge/blurb/cover",
|
|
3538
3483
|
/** 剧情线管理:增删改 + 关联章节。 */
|
|
3539
3484
|
plotlines: "/api/dsh-novel-forge/plotlines",
|
|
3540
|
-
/**
|
|
3485
|
+
/** 角色库:提炼 / 采纳 / 更新 / 删除。 */
|
|
3541
3486
|
roles: "/api/dsh-novel-forge/roles",
|
|
3542
3487
|
/** 作者复盘补跑:对已写章节补齐 authorReview(全书流式 / 单章 JSON)。 */
|
|
3543
3488
|
reviewBackfill: "/api/dsh-novel-forge/review/backfill",
|
|
@@ -3547,7 +3492,7 @@ const NOVEL_API = {
|
|
|
3547
3492
|
chapterApprove: "/api/dsh-novel-forge/chapter/approve",
|
|
3548
3493
|
/** 敏感词检查:全书已写章节或指定文本。 */
|
|
3549
3494
|
sensitiveCheck: "/api/dsh-novel-forge/sensitive-check",
|
|
3550
|
-
/** 开书想法 →
|
|
3495
|
+
/** 开书想法 → 补全大纲:输入一句话想法,生成 2-3 个可选大纲方案。 */
|
|
3551
3496
|
outlineSuggest: "/api/dsh-novel-forge/outline/suggest",
|
|
3552
3497
|
/** 反推大纲:从已写章节正文反向生成全书总纲(NDJSON 流)。 */
|
|
3553
3498
|
outlineReverse: "/api/dsh-novel-forge/outline/reverse",
|
|
@@ -3560,6 +3505,10 @@ const NOVEL_API = {
|
|
|
3560
3505
|
/** 生产单状态(含进度统计与日志)。 */
|
|
3561
3506
|
runStatus: "/api/dsh-novel-forge/run/status",
|
|
3562
3507
|
config: "/api/dsh-novel-forge/config",
|
|
3508
|
+
/** 输出目录迁移:dryRun 预览 / 确认后搬文件并联动配置与书架。 */
|
|
3509
|
+
moveOutputDir: "/api/dsh-novel-forge/move-output-dir",
|
|
3510
|
+
/** 本书参数:POST {} 读取;POST {patch} 合并保存(存 novel-project.json)。 */
|
|
3511
|
+
bookSettings: "/api/dsh-novel-forge/book-settings",
|
|
3563
3512
|
openFolder: "/api/dsh-novel-forge/open-folder",
|
|
3564
3513
|
/** 插件自更新:在 DSH profile 目录拉取最新 npm 版(下载后需重启 DSH 生效)。 */
|
|
3565
3514
|
pluginUpdate: "/api/dsh-novel-forge/plugin/update",
|
|
@@ -3746,7 +3695,8 @@ function loadProject(outputDir) {
|
|
|
3746
3695
|
if (!Array.isArray(raw.facts)) raw.facts = [];
|
|
3747
3696
|
if (!Array.isArray(raw.plotlines)) raw.plotlines = [];
|
|
3748
3697
|
return raw;
|
|
3749
|
-
} catch {
|
|
3698
|
+
} catch (error) {
|
|
3699
|
+
console.error(`[novel-forge] project file unreadable/corrupt: ${file} — ${error.message}`);
|
|
3750
3700
|
return;
|
|
3751
3701
|
}
|
|
3752
3702
|
}
|
|
@@ -5020,7 +4970,7 @@ function autoLinkPlotlines(project, chapterNo, advancedLines) {
|
|
|
5020
4970
|
if (!Array.isArray(project.plotlines) || advancedLines.length === 0) return;
|
|
5021
4971
|
for (const line of project.plotlines) if (advancedLines.includes(line.name) && !line.chapters.includes(chapterNo)) line.chapters.push(chapterNo);
|
|
5022
4972
|
}
|
|
5023
|
-
/**
|
|
4973
|
+
/** 建议剧情线:基于大纲/卷计划/已写章节/编年录,提炼候选线。 */
|
|
5024
4974
|
async function suggestPlotlines(ctx, config, project) {
|
|
5025
4975
|
const system = [
|
|
5026
4976
|
"你是一位网文剧情架构师。根据本书的大纲、卷计划、已写章节标题与编年录,为作者提炼建议的剧情线(主线/支线/人物线/悬念线)。",
|
|
@@ -5069,7 +5019,7 @@ async function suggestPlotlines(ctx, config, project) {
|
|
|
5069
5019
|
}
|
|
5070
5020
|
return lines;
|
|
5071
5021
|
}
|
|
5072
|
-
/**
|
|
5022
|
+
/** 刷新单条剧情线的进度:结合编年录与各章摘要分析该线推进到哪。 */
|
|
5073
5023
|
async function refreshPlotlineProgress(ctx, config, project, line) {
|
|
5074
5024
|
const system = [
|
|
5075
5025
|
"你是一位网文剧情线管理员。请根据「剧情线信息」与「本书已写章节摘要/编年录」,判断这条线目前推进到了哪一步。",
|
|
@@ -5095,7 +5045,7 @@ async function refreshPlotlineProgress(ctx, config, project, line) {
|
|
|
5095
5045
|
}));
|
|
5096
5046
|
return typeof raw.progress === "string" ? raw.progress.trim().slice(0, 300) : "";
|
|
5097
5047
|
}
|
|
5098
|
-
/**
|
|
5048
|
+
/** AI 从全书提炼角色库:大纲 + 道藏 + 编年录 + 章节摘要 → 结构化角色清单。 */
|
|
5099
5049
|
async function extractRoles(ctx, config, project) {
|
|
5100
5050
|
const system = [
|
|
5101
5051
|
"你是一位网文角色库管理员。请根据本书的大纲、设定、编年录与章节摘要,提炼完整的角色库。",
|
|
@@ -5318,7 +5268,7 @@ async function extractRoles(ctx, config, project) {
|
|
|
5318
5268
|
}
|
|
5319
5269
|
return roles;
|
|
5320
5270
|
}
|
|
5321
|
-
/**
|
|
5271
|
+
/** AI 从全书提炼场景库:正文/编年录 → 高频重要场景的结构化视觉锚点。 */
|
|
5322
5272
|
function splitBookText(raw) {
|
|
5323
5273
|
const lines = raw.split(/\r?\n/);
|
|
5324
5274
|
const chapterHead = /^\s*(?:#\s*)?第\s*(\d+|[一二三四五六七八九十百千]+)\s*[章回节卷]\s*(.*?)\s*$/;
|
|
@@ -5904,7 +5854,7 @@ async function registerLlmModel(ctx, req) {
|
|
|
5904
5854
|
message
|
|
5905
5855
|
};
|
|
5906
5856
|
}
|
|
5907
|
-
/**
|
|
5857
|
+
/** 剧情健康检查:基于已写章节数/各线状态/编年录,判断是否需要新线及添加时机。 */
|
|
5908
5858
|
async function analyzePlotlineHealth(ctx, config, project) {
|
|
5909
5859
|
const system = [
|
|
5910
5860
|
"你是一位网文剧情架构师。请对本书的「剧情线体系」做健康检查,判断当前是否需要新增剧情线、应在多少章后添加。",
|
|
@@ -5950,7 +5900,7 @@ async function analyzePlotlineHealth(ctx, config, project) {
|
|
|
5950
5900
|
lines: lineArr
|
|
5951
5901
|
};
|
|
5952
5902
|
}
|
|
5953
|
-
/**
|
|
5903
|
+
/** 剧情方案:基于健康检查结果设计下一阶段方向与建议新线。 */
|
|
5954
5904
|
async function designPlotlinePlan(ctx, config, project, health) {
|
|
5955
5905
|
const system = [
|
|
5956
5906
|
"你是一位网文剧情架构师。请为本书设计「下一阶段的剧情方案」:给出未来 5-10 章的剧情方向,并建议 2-3 条值得新增的剧情线。",
|
|
@@ -6494,7 +6444,7 @@ async function reverseOutlineFromAdaptationText(ctx, config, chapters) {
|
|
|
6494
6444
|
})).trim();
|
|
6495
6445
|
}
|
|
6496
6446
|
/** 改编方案:由用户勾选的维度与新值,生成 LLM 映射表/规则/影响清单。 */
|
|
6497
|
-
async function proposeAdaptation(ctx, config,
|
|
6447
|
+
async function proposeAdaptation(ctx, config, _text, selections, dimensions) {
|
|
6498
6448
|
const raw = parseJsonObject(await complete(ctx, config, {
|
|
6499
6449
|
system: "你是改编策划。",
|
|
6500
6450
|
user: [
|
|
@@ -7024,7 +6974,7 @@ async function auditBook(ctx, config, project, outputDir, onProgress) {
|
|
|
7024
6974
|
}
|
|
7025
6975
|
return all.slice(0, 50);
|
|
7026
6976
|
}
|
|
7027
|
-
/**
|
|
6977
|
+
/** 小说简介:生成或按已写开头补全(面向读者的作品门面)。 */
|
|
7028
6978
|
async function generateBlurb(ctx, config, project, partial = "") {
|
|
7029
6979
|
const system = [
|
|
7030
6980
|
"你是一位网文平台编辑,擅长写抓人的作品简介。",
|
|
@@ -7186,7 +7136,7 @@ function renderWorld(world) {
|
|
|
7186
7136
|
}
|
|
7187
7137
|
return sections.join("\n");
|
|
7188
7138
|
}
|
|
7189
|
-
/**
|
|
7139
|
+
/** 提炼大世界:从大纲 + 道藏生成结构化境界体系/区域/势力。 */
|
|
7190
7140
|
async function extractWorld(ctx, config, project) {
|
|
7191
7141
|
const system = [
|
|
7192
7142
|
"你是一位网文世界观架构师。请根据小说大纲与道藏,提炼结构化「大世界」数据。",
|
|
@@ -7714,7 +7664,8 @@ function loadBookshelf() {
|
|
|
7714
7664
|
books: parsed.books,
|
|
7715
7665
|
activeBookId: parsed.activeBookId ?? null
|
|
7716
7666
|
};
|
|
7717
|
-
} catch {
|
|
7667
|
+
} catch (error) {
|
|
7668
|
+
console.error(`[novel-forge] bookshelf file unreadable/corrupt: ${file} — ${error.message}`);
|
|
7718
7669
|
return defaultStore();
|
|
7719
7670
|
}
|
|
7720
7671
|
}
|
|
@@ -7832,6 +7783,21 @@ function removeBook(id) {
|
|
|
7832
7783
|
function activeBookOutputDir() {
|
|
7833
7784
|
return activeBook(loadBookshelf())?.outputDir;
|
|
7834
7785
|
}
|
|
7786
|
+
/**
|
|
7787
|
+
* 书目录重指向:把 outputDir 等于 from 的书条目全部改为 to(目录迁移联动)。
|
|
7788
|
+
* @returns 重指向的条目数。
|
|
7789
|
+
*/
|
|
7790
|
+
function repointBookDirs(from, to) {
|
|
7791
|
+
const store = loadBookshelf();
|
|
7792
|
+
let count = 0;
|
|
7793
|
+
for (const book of store.books) if (book.outputDir === from) {
|
|
7794
|
+
book.outputDir = to;
|
|
7795
|
+
book.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7796
|
+
count += 1;
|
|
7797
|
+
}
|
|
7798
|
+
if (count > 0) saveBookshelf(store);
|
|
7799
|
+
return count;
|
|
7800
|
+
}
|
|
7835
7801
|
/** 默认输出目录推断:~/.dsh/novels/书名。 */
|
|
7836
7802
|
function defaultOutputDirFor(bookName) {
|
|
7837
7803
|
const clean = bookName.replace(/[\\/:*?"<>|]/g, "").trim().slice(0, 40) || "未命名小说";
|
|
@@ -7954,6 +7920,10 @@ var ProductionRunner = class {
|
|
|
7954
7920
|
stop() {
|
|
7955
7921
|
this.stopRequested = true;
|
|
7956
7922
|
}
|
|
7923
|
+
/** 是否有生产单正在执行(目录迁移等磁盘级操作前须为 false)。 */
|
|
7924
|
+
isWorking() {
|
|
7925
|
+
return this.working;
|
|
7926
|
+
}
|
|
7957
7927
|
/** 主循环:从 currentNo 扫描到 endNo,逐章处理;支持暂停/停止。 */
|
|
7958
7928
|
async loop() {
|
|
7959
7929
|
const config = this.deps.getConfig();
|
|
@@ -8035,7 +8005,7 @@ var ProductionRunner = class {
|
|
|
8035
8005
|
saveProject(outputDir, project);
|
|
8036
8006
|
this.log(`${wasError ? "重新生成" : "生成"} 第${no}章《${chapter.title}》…(模型 ${config.generateModel || config.model})`);
|
|
8037
8007
|
try {
|
|
8038
|
-
for await (const
|
|
8008
|
+
for await (const _step of generateChapterStream(ctx, config, project, outputDir, no));
|
|
8039
8009
|
try {
|
|
8040
8010
|
await summarizeAndExtractFacts(ctx, config, project, outputDir, no);
|
|
8041
8011
|
} catch (e) {
|
|
@@ -8049,7 +8019,7 @@ var ProductionRunner = class {
|
|
|
8049
8019
|
if (config.autoReview ?? true) {
|
|
8050
8020
|
const report = await reviewChapter(ctx, config, project, outputDir, no);
|
|
8051
8021
|
if (this.state !== null) this.state.stats[wasError ? "regenerated" : "generated"]++;
|
|
8052
|
-
this.log(`第${no}章 审稿 ${report.score}分 ${report.passed ? "
|
|
8022
|
+
this.log(`第${no}章 审稿 ${report.score}分 ${report.passed ? " 通过" : " 被拒"}(模型 ${config.reviewModel || config.model})`);
|
|
8053
8023
|
} else {
|
|
8054
8024
|
chapter.status = "approved";
|
|
8055
8025
|
mergeVolatileFromDisk(outputDir, project);
|
|
@@ -8108,7 +8078,7 @@ var ProductionRunner = class {
|
|
|
8108
8078
|
for (let round = 1; round <= 2; round++) {
|
|
8109
8079
|
const instr = "按审稿意见修订(优先处理):\n" + highs.map((h) => `[${h.severity}] ${h.item}${h.suggestion !== "" ? `\n建议:${h.suggestion}` : ""}`).join("\n\n");
|
|
8110
8080
|
try {
|
|
8111
|
-
for await (const
|
|
8081
|
+
for await (const _step of rewriteChapterStream(ctx, config, project, outputDir, no, instr, void 0));
|
|
8112
8082
|
} catch (error) {
|
|
8113
8083
|
this.log(`第${no}章 第${round}轮修订出错:${error.message}`);
|
|
8114
8084
|
continue;
|
|
@@ -8131,7 +8101,7 @@ var ProductionRunner = class {
|
|
|
8131
8101
|
this.log(`第${no}章 第${round}轮仍不过(${highs2.length} high)`);
|
|
8132
8102
|
}
|
|
8133
8103
|
if (this.state !== null) this.state.pendingManual.push(no);
|
|
8134
|
-
this.log(`第${no}章
|
|
8104
|
+
this.log(`第${no}章 两轮修订仍不过 → 保留草稿待人工`);
|
|
8135
8105
|
}
|
|
8136
8106
|
applyDraft(project, chapter, draft, report) {
|
|
8137
8107
|
const config = this.deps.getConfig();
|
|
@@ -8157,33 +8127,25 @@ var ProductionRunner = class {
|
|
|
8157
8127
|
}
|
|
8158
8128
|
};
|
|
8159
8129
|
//#endregion
|
|
8160
|
-
//#region src/docx.ts
|
|
8130
|
+
//#region src/docx-core.ts
|
|
8161
8131
|
/**
|
|
8162
|
-
* docx
|
|
8163
|
-
*
|
|
8164
|
-
*
|
|
8132
|
+
* docx 文本提取共享核心:服务端(src/docx.ts)与浏览器端(src/client/docx.ts)
|
|
8133
|
+
* 共用 XML → 纯文本的解析逻辑,避免两份实现漂移。
|
|
8134
|
+
* zip 解压入口因运行时不同(fflate vs fflate/browser,浏览器端必须走 browser
|
|
8135
|
+
* 入口以避开 node:module 的 require 探测)留在两端各自处理。
|
|
8165
8136
|
*/
|
|
8166
|
-
/**
|
|
8137
|
+
/** 解码 docx 正文实际会用到的少量 XML 实体。 */
|
|
8167
8138
|
function decodeEntities$1(text) {
|
|
8168
8139
|
return text.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\"").replace(/'/g, "'").replace(/&/g, "&").replace(/ /g, " ");
|
|
8169
8140
|
}
|
|
8170
8141
|
/**
|
|
8171
|
-
*
|
|
8172
|
-
* <w:tab>/<w:br>
|
|
8173
|
-
*
|
|
8174
|
-
* @param
|
|
8175
|
-
* @returns
|
|
8142
|
+
* 从 word/document.xml 的 XML 字符串提取纯文本:每个 <w:p> 段落一行,
|
|
8143
|
+
* <w:tab>/<w:br> 保留为空白符;表格与嵌套结构按文档顺序拍平
|
|
8144
|
+
* (它们的段落同样是 <w:p>)。
|
|
8145
|
+
* @param xml - document.xml 解码后的字符串。
|
|
8146
|
+
* @returns 正文文本(空文本时抛错)。
|
|
8176
8147
|
*/
|
|
8177
|
-
function
|
|
8178
|
-
let files;
|
|
8179
|
-
try {
|
|
8180
|
-
files = unzipSync(buffer);
|
|
8181
|
-
} catch (error) {
|
|
8182
|
-
throw new Error(`not a valid docx (zip open failed): ${error.message}`);
|
|
8183
|
-
}
|
|
8184
|
-
const document = files["word/document.xml"];
|
|
8185
|
-
if (document === void 0) throw new Error("not a valid docx (word/document.xml missing)");
|
|
8186
|
-
const xml = strFromU8(document);
|
|
8148
|
+
function extractDocxTextFromXml(xml) {
|
|
8187
8149
|
const paragraphs = [];
|
|
8188
8150
|
const parts = xml.split(/<w:p\b[^>]*>/);
|
|
8189
8151
|
for (let i = 1; i < parts.length; i++) {
|
|
@@ -8192,13 +8154,36 @@ function extractDocxText(buffer) {
|
|
|
8192
8154
|
for (const match of segment.matchAll(/<w:t(?:\s[^>]*)?>([\s\S]*?)<\/w:t>|<w:tab\b[^>]*\/>|<w:br\b[^>]*\/>/g)) if (match[0].startsWith("<w:tab")) runs.push(" ");
|
|
8193
8155
|
else if (match[0].startsWith("<w:br")) runs.push("\n");
|
|
8194
8156
|
else runs.push(decodeEntities$1(match[1] ?? ""));
|
|
8195
|
-
|
|
8196
|
-
paragraphs.push(line);
|
|
8157
|
+
paragraphs.push(runs.join("").replace(/\u00a0/g, " ").trimEnd());
|
|
8197
8158
|
}
|
|
8198
8159
|
const text = paragraphs.join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
8199
|
-
if (text.length === 0) throw new Error("docx
|
|
8160
|
+
if (text.length === 0) throw new Error("docx 中没有可提取的文本");
|
|
8200
8161
|
return text;
|
|
8201
8162
|
}
|
|
8163
|
+
//#endregion
|
|
8164
|
+
//#region src/docx.ts
|
|
8165
|
+
/**
|
|
8166
|
+
* docx outline extraction: a .docx is a zip whose word/document.xml holds the
|
|
8167
|
+
* body text in <w:t> runs inside <w:p> paragraphs. We unzip with fflate and
|
|
8168
|
+
* walk the XML with a tiny tokenizer — no heavyweight XML/DOM dependency.
|
|
8169
|
+
* XML 解析共享核心在 ./docx-core.ts(与浏览器端同源)。
|
|
8170
|
+
*/
|
|
8171
|
+
/**
|
|
8172
|
+
* Extract plain text from a docx buffer: one line per <w:p> paragraph.
|
|
8173
|
+
* @param buffer - the raw .docx bytes.
|
|
8174
|
+
* @returns the body text.
|
|
8175
|
+
*/
|
|
8176
|
+
function extractDocxText(buffer) {
|
|
8177
|
+
let files;
|
|
8178
|
+
try {
|
|
8179
|
+
files = unzipSync(buffer);
|
|
8180
|
+
} catch (error) {
|
|
8181
|
+
throw new Error(`不是有效的 docx(zip 解压失败):${error.message}`);
|
|
8182
|
+
}
|
|
8183
|
+
const document = files["word/document.xml"];
|
|
8184
|
+
if (document === void 0) throw new Error("不是有效的 docx(缺少 word/document.xml)");
|
|
8185
|
+
return extractDocxTextFromXml(strFromU8(document));
|
|
8186
|
+
}
|
|
8202
8187
|
/**
|
|
8203
8188
|
* Read and extract a docx outline from disk.
|
|
8204
8189
|
* @param path - absolute path to the .docx file.
|
|
@@ -8392,7 +8377,7 @@ function assistantSystemPrompt(project) {
|
|
|
8392
8377
|
"- knowledge_list:无参数。**列出本书全部知识库文档**(标题+内容)。作者说\"收集/汇总/列出所有知识库\"时调用它。",
|
|
8393
8378
|
"- breakdown:{\"scope\": \"recent|all|volume:N\"(可选,默认 recent), \"preset\": \"quick|standard\"(可选)}。书内拆书分析:对本书已写章节做结构/人物/文风/卖点体检。",
|
|
8394
8379
|
"- audit:无参数。全书一致性质检(分批扫描章节+设定+事实库,聚合矛盾)。",
|
|
8395
|
-
"- blurb:{\"partial\": \"已写开头(可选)\"}
|
|
8380
|
+
"- blurb:{\"partial\": \"已写开头(可选)\"}。生成/补全小说简介并保存到本书。",
|
|
8396
8381
|
"",
|
|
8397
8382
|
"回答质量要求(非常重要):",
|
|
8398
8383
|
"- 具体:回答必须引用项目里的真实内容(人名、境界、章节、暗线、设定),禁止空泛套话。快照里没有的信息,先调用工具获取(chapter_text / outline_text)再回答。",
|
|
@@ -8913,7 +8898,7 @@ async function* runAssistantTurn(ctx, config, project, outputDir, userMessage) {
|
|
|
8913
8898
|
};
|
|
8914
8899
|
/** 本轮已放行过写操作:后续写操作(生成→审稿→修订闭环)不再逐个拦截。 */
|
|
8915
8900
|
let writeUnlocked = false;
|
|
8916
|
-
const guardWrite = (name,
|
|
8901
|
+
const guardWrite = (name, _userMessage) => {
|
|
8917
8902
|
if (writeUnlocked) return true;
|
|
8918
8903
|
const key = WRITE_TOOL_KEYS[name];
|
|
8919
8904
|
if (key === void 0) return true;
|
|
@@ -9104,6 +9089,77 @@ async function* runAssistantTurn(ctx, config, project, outputDir, userMessage) {
|
|
|
9104
9089
|
}
|
|
9105
9090
|
}
|
|
9106
9091
|
//#endregion
|
|
9092
|
+
//#region src/migrate-output.ts
|
|
9093
|
+
/**
|
|
9094
|
+
* 输出目录迁移(Migrate Output Dir)— 把一本书/默认输出目录的内容搬到新位置。
|
|
9095
|
+
*
|
|
9096
|
+
* 安全纪律(数据零丢失排序):
|
|
9097
|
+
* 1. copy 全部内容到新目录(源目录始终原样保留);
|
|
9098
|
+
* 2. 调用方完成配置写入 / 书架重指向后,最后一步才删源目录;
|
|
9099
|
+
* 3. 中途任何失败,最坏情况只是新目录多一份副本,源数据零丢失。
|
|
9100
|
+
*/
|
|
9101
|
+
/** 规范化路径用于比较(统一分隔符,Windows 忽略大小写)。 */
|
|
9102
|
+
function normalizeDir(dir) {
|
|
9103
|
+
const r = resolve(dir.trim());
|
|
9104
|
+
return process.platform === "win32" ? r.toLowerCase() : r;
|
|
9105
|
+
}
|
|
9106
|
+
/** 列出目录全部内容(递归;子目录以 `name/` 形式占位列出)。 */
|
|
9107
|
+
function listDirContents(dir) {
|
|
9108
|
+
const files = [];
|
|
9109
|
+
let bytes = 0;
|
|
9110
|
+
const walk = (rel) => {
|
|
9111
|
+
const abs = rel === "" ? dir : join(dir, rel);
|
|
9112
|
+
for (const name of readdirSync(abs, { withFileTypes: true })) {
|
|
9113
|
+
const childRel = rel === "" ? name.name : `${rel}/${name.name}`;
|
|
9114
|
+
if (name.isDirectory()) {
|
|
9115
|
+
files.push(`${childRel}/`);
|
|
9116
|
+
walk(childRel);
|
|
9117
|
+
} else {
|
|
9118
|
+
files.push(childRel);
|
|
9119
|
+
try {
|
|
9120
|
+
bytes += statSync(join(dir, childRel)).size;
|
|
9121
|
+
} catch {}
|
|
9122
|
+
}
|
|
9123
|
+
}
|
|
9124
|
+
};
|
|
9125
|
+
if (existsSync(dir)) walk("");
|
|
9126
|
+
return {
|
|
9127
|
+
files,
|
|
9128
|
+
bytes
|
|
9129
|
+
};
|
|
9130
|
+
}
|
|
9131
|
+
/**
|
|
9132
|
+
* 把 from 全部内容复制到 to(源目录保留,删除由调用方在收尾执行)。
|
|
9133
|
+
* 目标必须不存在或为空目录(防覆盖无关数据);禁止互相嵌套的目录对。
|
|
9134
|
+
* @returns 复制的顶层条目数。
|
|
9135
|
+
*/
|
|
9136
|
+
function copyDirContents(from, to) {
|
|
9137
|
+
if (!existsSync(from)) throw new Error(`源目录不存在:${from}`);
|
|
9138
|
+
const nf = normalizeDir(from);
|
|
9139
|
+
const nt = normalizeDir(to);
|
|
9140
|
+
if (nf === nt) throw new Error("新目录与当前目录相同");
|
|
9141
|
+
if (nt.startsWith(nf + sep.toLowerCase()) || nf.startsWith(nt + sep.toLowerCase()) || nt.startsWith(nf + "/") || nf.startsWith(nt + "/")) throw new Error("新目录不能是当前目录的子目录(或反之)");
|
|
9142
|
+
if (existsSync(to)) {
|
|
9143
|
+
const entries = readdirSync(to);
|
|
9144
|
+
if (entries.length > 0) throw new Error(`目标目录非空(${entries.length} 个条目),为防覆盖已中止:${to}`);
|
|
9145
|
+
} else mkdirSync(to, { recursive: true });
|
|
9146
|
+
const entries = readdirSync(from);
|
|
9147
|
+
if (entries.length === 0) return 0;
|
|
9148
|
+
cpSync(from, to, {
|
|
9149
|
+
recursive: true,
|
|
9150
|
+
errorOnExist: true,
|
|
9151
|
+
force: false
|
|
9152
|
+
});
|
|
9153
|
+
return entries.length;
|
|
9154
|
+
}
|
|
9155
|
+
/** 删除源目录(仅复制 + 配置/书架重指向全部成功后调用)。 */
|
|
9156
|
+
function removeDir(dir) {
|
|
9157
|
+
if (existsSync(dir)) rmSync(dir, {
|
|
9158
|
+
recursive: true,
|
|
9159
|
+
force: true
|
|
9160
|
+
});
|
|
9161
|
+
}
|
|
9162
|
+
//#endregion
|
|
9107
9163
|
//#region src/author-assets.ts
|
|
9108
9164
|
/**
|
|
9109
9165
|
* 作者资产库/总数据(跨书)— 按作者维度聚合的可复用资产。
|
|
@@ -9135,7 +9191,8 @@ function loadAuthorAssets() {
|
|
|
9135
9191
|
version: 1,
|
|
9136
9192
|
items: parsed.items
|
|
9137
9193
|
};
|
|
9138
|
-
} catch {
|
|
9194
|
+
} catch (error) {
|
|
9195
|
+
console.error(`[novel-forge] author assets file unreadable/corrupt: ${file} — ${error.message}`);
|
|
9139
9196
|
return defaultLibrary();
|
|
9140
9197
|
}
|
|
9141
9198
|
}
|
|
@@ -11327,7 +11384,7 @@ function makeRoutes(deps) {
|
|
|
11327
11384
|
writeJson(res, 200, { bible: project.bible });
|
|
11328
11385
|
}
|
|
11329
11386
|
};
|
|
11330
|
-
/**
|
|
11387
|
+
/** 小说简介:生成/补全,或手动保存。 */
|
|
11331
11388
|
const blurbRoute = {
|
|
11332
11389
|
kind: "exact",
|
|
11333
11390
|
path: NOVEL_API.blurb,
|
|
@@ -11434,7 +11491,7 @@ function makeRoutes(deps) {
|
|
|
11434
11491
|
writeJson(res, 405, { error: "method not allowed (expected GET or POST)" });
|
|
11435
11492
|
}
|
|
11436
11493
|
};
|
|
11437
|
-
/**
|
|
11494
|
+
/** 大世界:提炼或手动保存(境界体系/区域/势力)。 */
|
|
11438
11495
|
const worldRoute = {
|
|
11439
11496
|
kind: "exact",
|
|
11440
11497
|
path: NOVEL_API.world,
|
|
@@ -11540,7 +11597,7 @@ function makeRoutes(deps) {
|
|
|
11540
11597
|
});
|
|
11541
11598
|
return;
|
|
11542
11599
|
} catch (error) {
|
|
11543
|
-
writeJson(res, 500, { error:
|
|
11600
|
+
writeJson(res, 500, { error: `建议失败:${error.message}` });
|
|
11544
11601
|
return;
|
|
11545
11602
|
}
|
|
11546
11603
|
else if (op === "refresh" && body?.id !== void 0) {
|
|
@@ -11642,7 +11699,7 @@ function makeRoutes(deps) {
|
|
|
11642
11699
|
});
|
|
11643
11700
|
}
|
|
11644
11701
|
};
|
|
11645
|
-
/**
|
|
11702
|
+
/** 角色库:提炼 / 采纳 / 更新 / 删除。 */
|
|
11646
11703
|
const rolesRoute = {
|
|
11647
11704
|
kind: "exact",
|
|
11648
11705
|
path: NOVEL_API.roles,
|
|
@@ -12085,6 +12142,137 @@ function makeRoutes(deps) {
|
|
|
12085
12142
|
ctx,
|
|
12086
12143
|
getConfig
|
|
12087
12144
|
});
|
|
12145
|
+
/**
|
|
12146
|
+
* 输出目录迁移:dryRun 预览;确认后 copy 全部内容 → 书架重指向 → settings
|
|
12147
|
+
* 默认目录同步(仅当默认目录就是被搬目录)→ 最后删源目录(数据零丢失排序)。
|
|
12148
|
+
*/
|
|
12149
|
+
const moveOutputDirRoute = {
|
|
12150
|
+
kind: "exact",
|
|
12151
|
+
path: NOVEL_API.moveOutputDir,
|
|
12152
|
+
handler: async (req, res) => {
|
|
12153
|
+
if (!guard(req, res, "POST")) return;
|
|
12154
|
+
const from = getConfig().outputDir;
|
|
12155
|
+
const body = await readJsonBody(req);
|
|
12156
|
+
if (body?.dryRun === true) {
|
|
12157
|
+
try {
|
|
12158
|
+
const contents = listDirContents(from);
|
|
12159
|
+
writeJson(res, 200, {
|
|
12160
|
+
from,
|
|
12161
|
+
files: contents.files.slice(0, 300),
|
|
12162
|
+
bytes: contents.bytes,
|
|
12163
|
+
movedBooks: 0,
|
|
12164
|
+
defaultUpdated: false
|
|
12165
|
+
});
|
|
12166
|
+
} catch (error) {
|
|
12167
|
+
writeJson(res, 400, { error: error.message });
|
|
12168
|
+
}
|
|
12169
|
+
return;
|
|
12170
|
+
}
|
|
12171
|
+
if (runner.isWorking()) {
|
|
12172
|
+
writeJson(res, 409, { error: "生产单正在运行中,请先停止后再迁移目录" });
|
|
12173
|
+
return;
|
|
12174
|
+
}
|
|
12175
|
+
const to = body?.to?.trim() ?? "";
|
|
12176
|
+
if (to === "") {
|
|
12177
|
+
writeJson(res, 400, { error: "新目录路径不能为空" });
|
|
12178
|
+
return;
|
|
12179
|
+
}
|
|
12180
|
+
if (normalizeDir(to) === normalizeDir(from)) {
|
|
12181
|
+
writeJson(res, 400, { error: "新目录与当前目录相同" });
|
|
12182
|
+
return;
|
|
12183
|
+
}
|
|
12184
|
+
try {
|
|
12185
|
+
copyDirContents(from, to);
|
|
12186
|
+
} catch (error) {
|
|
12187
|
+
writeJson(res, 400, { error: `迁移中止:${error.message}` });
|
|
12188
|
+
return;
|
|
12189
|
+
}
|
|
12190
|
+
let movedBooks = 0;
|
|
12191
|
+
let repointError = "";
|
|
12192
|
+
try {
|
|
12193
|
+
movedBooks = repointBookDirs(from, to);
|
|
12194
|
+
} catch (error) {
|
|
12195
|
+
repointError = error.message;
|
|
12196
|
+
}
|
|
12197
|
+
let defaultUpdated = false;
|
|
12198
|
+
let defaultError = "";
|
|
12199
|
+
const raw = deps.rawConfig?.();
|
|
12200
|
+
if (raw !== void 0 && raw.outputDir !== void 0 && raw.outputDir !== "" && normalizeDir(raw.outputDir) === normalizeDir(from)) try {
|
|
12201
|
+
await patchConfig({ outputDir: to });
|
|
12202
|
+
defaultUpdated = true;
|
|
12203
|
+
} catch (error) {
|
|
12204
|
+
defaultError = error.message;
|
|
12205
|
+
}
|
|
12206
|
+
if (repointError === "" && defaultError === "") {
|
|
12207
|
+
removeDir(from);
|
|
12208
|
+
const contents = listDirContents(to);
|
|
12209
|
+
writeJson(res, 200, {
|
|
12210
|
+
from,
|
|
12211
|
+
to,
|
|
12212
|
+
files: contents.files.slice(0, 300),
|
|
12213
|
+
bytes: contents.bytes,
|
|
12214
|
+
movedBooks,
|
|
12215
|
+
defaultUpdated
|
|
12216
|
+
});
|
|
12217
|
+
return;
|
|
12218
|
+
}
|
|
12219
|
+
writeJson(res, 500, {
|
|
12220
|
+
error: `文件已复制到 ${to},但收尾未完成${repointError !== "" ? `(书架重指向失败:${repointError})` : ""}${defaultError !== "" ? `(默认目录更新失败:${defaultError})` : ""}。源目录已保留,请检查后重试或手动处理。`,
|
|
12221
|
+
from,
|
|
12222
|
+
to,
|
|
12223
|
+
movedBooks,
|
|
12224
|
+
defaultUpdated
|
|
12225
|
+
});
|
|
12226
|
+
}
|
|
12227
|
+
};
|
|
12228
|
+
/**
|
|
12229
|
+
* 本书参数:POST {} 读取当前书的 settings + 生效配置(全局+本书回退链);
|
|
12230
|
+
* POST {patch} 白名单合并保存到 novel-project.json.bookSettings。
|
|
12231
|
+
*/
|
|
12232
|
+
const bookSettingsRoute = {
|
|
12233
|
+
kind: "exact",
|
|
12234
|
+
path: NOVEL_API.bookSettings,
|
|
12235
|
+
handler: async (req, res) => {
|
|
12236
|
+
if (!guard(req, res, "POST")) return;
|
|
12237
|
+
const outputDir = getConfig().outputDir;
|
|
12238
|
+
const body = await readJsonBody(req);
|
|
12239
|
+
if (body?.patch !== void 0) {
|
|
12240
|
+
const project = loadProject(outputDir);
|
|
12241
|
+
if (project === void 0) {
|
|
12242
|
+
writeJson(res, 400, { error: "当前没有打开的书(未找到 novel-project.json)" });
|
|
12243
|
+
return;
|
|
12244
|
+
}
|
|
12245
|
+
const cur = project.bookSettings ?? {};
|
|
12246
|
+
const p = body.patch;
|
|
12247
|
+
const next = { ...cur };
|
|
12248
|
+
for (const key of [
|
|
12249
|
+
"provider",
|
|
12250
|
+
"model",
|
|
12251
|
+
"reasoningEffort",
|
|
12252
|
+
"analysisReasoning",
|
|
12253
|
+
"chapterChars",
|
|
12254
|
+
"maxTokens",
|
|
12255
|
+
"reviewPassScore",
|
|
12256
|
+
"autoReview",
|
|
12257
|
+
"autoAuthorReview",
|
|
12258
|
+
"autoReviewAfterRevise"
|
|
12259
|
+
]) {
|
|
12260
|
+
const v = p[key];
|
|
12261
|
+
if (v === null) delete next[key];
|
|
12262
|
+
else if (v !== void 0) next[key] = v;
|
|
12263
|
+
}
|
|
12264
|
+
project.bookSettings = next;
|
|
12265
|
+
project.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
12266
|
+
saveProject(outputDir, project);
|
|
12267
|
+
}
|
|
12268
|
+
const project = loadProject(outputDir);
|
|
12269
|
+
writeJson(res, 200, {
|
|
12270
|
+
settings: project?.bookSettings ?? {},
|
|
12271
|
+
effective: getConfig(),
|
|
12272
|
+
hasBook: project !== void 0
|
|
12273
|
+
});
|
|
12274
|
+
}
|
|
12275
|
+
};
|
|
12088
12276
|
const runStartRoute = {
|
|
12089
12277
|
kind: "exact",
|
|
12090
12278
|
path: NOVEL_API.runStart,
|
|
@@ -12537,6 +12725,8 @@ function makeRoutes(deps) {
|
|
|
12537
12725
|
chapterResetRoute,
|
|
12538
12726
|
chapterApproveRoute,
|
|
12539
12727
|
configRoute,
|
|
12728
|
+
moveOutputDirRoute,
|
|
12729
|
+
bookSettingsRoute,
|
|
12540
12730
|
openFolderRoute,
|
|
12541
12731
|
pluginUpdateRoute,
|
|
12542
12732
|
outlineSuggestRoute,
|
|
@@ -12725,11 +12915,24 @@ function apply(ctx, config) {
|
|
|
12725
12915
|
const resolve = () => {
|
|
12726
12916
|
const resolved = resolveConfig(current());
|
|
12727
12917
|
const shelfDir = activeBookOutputDir();
|
|
12728
|
-
if (shelfDir
|
|
12918
|
+
if (shelfDir === void 0) return resolved;
|
|
12919
|
+
const bs = loadProject(shelfDir)?.bookSettings;
|
|
12920
|
+
const book = {
|
|
12729
12921
|
...resolved,
|
|
12730
12922
|
outputDir: shelfDir
|
|
12731
12923
|
};
|
|
12732
|
-
return
|
|
12924
|
+
if (bs === void 0) return book;
|
|
12925
|
+
if (bs.provider !== void 0) book.provider = bs.provider;
|
|
12926
|
+
if (bs.model !== void 0) book.model = bs.model;
|
|
12927
|
+
if (bs.reasoningEffort !== void 0) book.reasoningEffort = bs.reasoningEffort;
|
|
12928
|
+
if (bs.analysisReasoning !== void 0) book.analysisReasoning = bs.analysisReasoning;
|
|
12929
|
+
if (bs.chapterChars !== void 0) book.chapterChars = bs.chapterChars;
|
|
12930
|
+
if (bs.maxTokens !== void 0) book.maxTokens = bs.maxTokens;
|
|
12931
|
+
if (bs.reviewPassScore !== void 0) book.reviewPassScore = bs.reviewPassScore;
|
|
12932
|
+
if (bs.autoReview !== void 0) book.autoReview = bs.autoReview;
|
|
12933
|
+
if (bs.autoAuthorReview !== void 0) book.autoAuthorReview = bs.autoAuthorReview;
|
|
12934
|
+
if (bs.autoReviewAfterRevise !== void 0) book.autoReviewAfterRevise = bs.autoReviewAfterRevise;
|
|
12935
|
+
return book;
|
|
12733
12936
|
};
|
|
12734
12937
|
const patchConfig = async (patch) => {
|
|
12735
12938
|
const next = {};
|
|
@@ -12781,7 +12984,8 @@ function apply(ctx, config) {
|
|
|
12781
12984
|
const routes = makeRoutes({
|
|
12782
12985
|
ctx,
|
|
12783
12986
|
getConfig: resolve,
|
|
12784
|
-
patchConfig
|
|
12987
|
+
patchConfig,
|
|
12988
|
+
rawConfig: () => current()
|
|
12785
12989
|
});
|
|
12786
12990
|
disposeRoutes = ctx.effect(() => {
|
|
12787
12991
|
const disposers = routes.map((route) => ctx.webServer.register(route));
|