@waterwx/dsh-novel-forge 1.2.0 → 1.2.1-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 +237 -349
- package/lib/client.js +54447 -10560
- package/lib/index.js +12008 -5071
- package/lib/types/action-guard.d.ts +61 -0
- package/lib/types/ai-scan.d.ts +36 -0
- package/lib/types/assets.d.ts +18 -3
- package/lib/types/assistant.d.ts +29 -0
- package/lib/types/author-assets.d.ts +25 -0
- package/lib/types/bookshelf.d.ts +11 -1
- package/lib/types/client/api.d.ts +147 -9
- package/lib/types/client/docx.d.ts +2 -0
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/llmLive.d.ts +33 -0
- package/lib/types/client/locales.d.ts +28 -11
- package/lib/types/client/panel/AdaptModeView.d.ts +5 -0
- package/lib/types/client/panel/AiTag.d.ts +1 -0
- package/lib/types/client/panel/AssistantTab.d.ts +4 -1
- package/lib/types/client/panel/AuthorAssetsView.d.ts +4 -0
- package/lib/types/client/panel/AuthorHome.d.ts +34 -0
- package/lib/types/client/panel/BookAnalysisView.d.ts +4 -0
- package/lib/types/client/panel/CmdPalette.d.ts +12 -0
- package/lib/types/client/panel/CreateBookView.d.ts +5 -1
- package/lib/types/client/panel/DirectorView.d.ts +7 -0
- package/lib/types/client/panel/GlobalAssetLibraryView.d.ts +4 -0
- package/lib/types/client/panel/IdeaInspirationView.d.ts +6 -0
- package/lib/types/client/panel/ImportModal.d.ts +7 -0
- package/lib/types/client/panel/KnowledgeBaseView.d.ts +4 -0
- package/lib/types/client/panel/LiveFeedLog.d.ts +8 -0
- package/lib/types/client/panel/MarketRadarView.d.ts +5 -0
- package/lib/types/client/panel/ModelManager.d.ts +14 -0
- package/lib/types/client/panel/NovelPanel.d.ts +6 -1
- package/lib/types/client/panel/PageHeader.d.ts +18 -0
- package/lib/types/client/panel/ProgressConsole.d.ts +17 -0
- package/lib/types/client/panel/ProgressHomeView.d.ts +5 -0
- package/lib/types/client/panel/ReasoningSection.d.ts +10 -0
- package/lib/types/client/panel/SettingsView.d.ts +19 -0
- package/lib/types/client/panel/ShelfView.d.ts +12 -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/client/run-status.d.ts +19 -0
- package/lib/types/client/text.d.ts +9 -0
- package/lib/types/docx-core.d.ts +16 -0
- package/lib/types/docx.d.ts +2 -3
- package/lib/types/engine.d.ts +146 -40
- package/lib/types/global-assets.d.ts +6 -0
- package/lib/types/index.d.ts +18 -2
- package/lib/types/llm-live.d.ts +44 -0
- package/lib/types/market-radar-scan.d.ts +19 -0
- package/lib/types/market-radar-sources.d.ts +31 -0
- package/lib/types/migrate-output.d.ts +25 -0
- package/lib/types/novel-context.d.ts +80 -0
- package/lib/types/prompt-utils.d.ts +35 -0
- package/lib/types/prompting.d.ts +10 -0
- package/lib/types/protocol.d.ts +1029 -123
- package/lib/types/review-policy.d.ts +97 -0
- package/lib/types/routes.d.ts +4 -0
- package/lib/types/run.d.ts +3 -1
- package/lib/types/stage-contract.d.ts +60 -0
- package/package.json +51 -27
- package/scripts/patch-schemastery.mjs +47 -0
- package/src/action-guard.ts +127 -0
- package/src/ai-scan.ts +179 -0
- package/src/assets.ts +1774 -520
- package/src/assistant.ts +1082 -770
- package/src/author-assets.ts +149 -0
- package/src/bookshelf.ts +187 -151
- package/src/client/api.ts +684 -410
- package/src/client/docx.ts +37 -69
- package/src/client/index.ts +3 -1
- package/src/client/llmLive.ts +101 -0
- package/src/client/locales.ts +418 -383
- package/src/client/mount.tsx +1 -1
- package/src/client/panel/AdaptModeView.tsx +535 -0
- package/src/client/panel/AiTag.tsx +7 -0
- package/src/client/panel/AssetsTab.tsx +448 -458
- package/src/client/panel/AssistantTab.tsx +355 -301
- package/src/client/panel/AuthorAssetsView.tsx +206 -0
- package/src/client/panel/AuthorHome.tsx +309 -0
- package/src/client/panel/BookAnalysisView.tsx +63 -0
- package/src/client/panel/CmdPalette.tsx +102 -0
- package/src/client/panel/CreateBookView.tsx +366 -348
- package/src/client/panel/DirectorView.tsx +200 -0
- package/src/client/panel/GlobalAssetLibraryView.tsx +168 -0
- package/src/client/panel/IdeaInspirationView.tsx +76 -0
- package/src/client/panel/ImportModal.tsx +303 -0
- package/src/client/panel/KnowledgeBaseView.tsx +125 -0
- package/src/client/panel/LiveFeedLog.tsx +67 -0
- package/src/client/panel/MarketRadarView.tsx +377 -0
- package/src/client/panel/ModelManager.tsx +205 -0
- package/src/client/panel/NovelPanel.tsx +5403 -4597
- package/src/client/panel/PageHeader.tsx +37 -0
- package/src/client/panel/ProgressConsole.tsx +63 -0
- package/src/client/panel/ReaderView.tsx +306 -306
- package/src/client/panel/ReasoningSection.tsx +31 -0
- package/src/client/panel/RunPanel.tsx +223 -204
- package/src/client/panel/SettingsView.tsx +305 -0
- package/src/client/panel/ShelfView.tsx +266 -236
- package/src/client/panel/SubPage.tsx +42 -0
- package/src/client/panel/WorldTab.tsx +202 -202
- package/src/client/panel/panel.module.css +5764 -2941
- package/src/client/panel/toast.ts +51 -0
- package/src/client/panel/views.tsx +401 -314
- package/src/client/run-status.ts +143 -0
- package/src/client/sidebar-entry.ts +1 -1
- package/src/client/text.ts +28 -0
- package/src/docx-core.ts +53 -0
- package/src/docx.ts +44 -83
- package/src/engine.ts +4231 -2787
- package/src/global-assets.ts +59 -0
- package/src/index.ts +311 -252
- package/src/llm-live.ts +68 -0
- package/src/market-radar-scan.ts +41 -0
- package/src/market-radar-sources.ts +173 -0
- package/src/migrate-output.ts +76 -0
- package/src/novel-context.ts +286 -0
- package/src/prompting.ts +26 -0
- package/src/protocol.ts +2072 -1182
- package/src/review-policy.ts +161 -0
- package/src/routes.ts +3405 -2151
- package/src/run.ts +342 -330
- package/src/stage-contract.ts +189 -0
- package/lib/client.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/src/client/panel/BookshelfBar.tsx +0 -170
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 阶段契约(Stage Contract)——宿主计算的「当前阶段 → 本轮允许的动作」。
|
|
3
|
+
*
|
|
4
|
+
* 设计来源(借鉴 dsh-ai-novel-writer 的「作者请求中的当前阶段决定唯一允许命令」):
|
|
5
|
+
* 允许的动作必须由宿主根据真实项目状态算出,而不是指望模型记住或自律。
|
|
6
|
+
* 宿主计算结果同时用于三处:
|
|
7
|
+
* 1) 注入助手系统提示词:模型知道自己在哪一步、下一步该做什么;
|
|
8
|
+
* 2) 通用续写指令(「继续 / 下一步」)下的写操作白名单强约束(阶段即唯一命令);
|
|
9
|
+
* 3) 拒绝写操作时给出可执行的、阶段相关的理由,而不是一句「不允许」。
|
|
10
|
+
*
|
|
11
|
+
* 注意:作者显式点名的写操作永远优先于阶段白名单(作者终审权);
|
|
12
|
+
* 阶段强约束只在作者没有指定具体对象(通用续写)时生效。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { ChapterPlan, ProjectState, StageInfo } from './protocol.ts'
|
|
16
|
+
|
|
17
|
+
/** 创作阶段标识(线上形状见 protocol.ts 的 StageInfo)。 */
|
|
18
|
+
export type BookStageId = StageInfo['id']
|
|
19
|
+
|
|
20
|
+
/** 一个阶段契约。 */
|
|
21
|
+
export type BookStage = StageInfo
|
|
22
|
+
|
|
23
|
+
/** 大纲视为「已开书」的最短长度。 */
|
|
24
|
+
const MIN_OUTLINE_CHARS = 50
|
|
25
|
+
|
|
26
|
+
/** 通用续写指令(作者没有指定具体对象时,阶段白名单成为唯一命令)。 */
|
|
27
|
+
const GENERIC_CONTINUE = /^(继续|下一步|接着来|接着写|往下|往下走|继续吧|go\s*on|continue|next)[。.!!??\s]*$/i
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 作者这一轮是否只说了「继续/下一步」这类没有具体对象的指令。
|
|
31
|
+
*
|
|
32
|
+
* @param message 本轮用户消息。
|
|
33
|
+
* @returns 是通用续写指令时为 true。
|
|
34
|
+
*/
|
|
35
|
+
export function isGenericContinue(message: string): boolean {
|
|
36
|
+
return GENERIC_CONTINUE.test((message ?? '').trim())
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 根据项目真实状态计算当前创作阶段。
|
|
41
|
+
*
|
|
42
|
+
* @param project 当前项目(未加载时为 undefined)。
|
|
43
|
+
* @returns 阶段契约(推荐动作 + 写操作白名单 + 判定理由)。
|
|
44
|
+
*/
|
|
45
|
+
export function computeBookStage(project: ProjectState | undefined): BookStage {
|
|
46
|
+
if (project === undefined || (project.outline ?? '').trim().length < MIN_OUTLINE_CHARS) {
|
|
47
|
+
return {
|
|
48
|
+
id: 'outline',
|
|
49
|
+
label: '开书',
|
|
50
|
+
recommend: ['outline_replace'],
|
|
51
|
+
allow: ['outline_replace'],
|
|
52
|
+
reason: project === undefined ? '尚无项目' : '大纲为空或过短',
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (project.bible === undefined) {
|
|
56
|
+
return {
|
|
57
|
+
id: 'bible',
|
|
58
|
+
label: '立设定',
|
|
59
|
+
recommend: ['bible_set_rule', 'bible_set_redline'],
|
|
60
|
+
allow: ['bible_set_rule', 'bible_set_redline'],
|
|
61
|
+
reason: '已有大纲,尚未提炼道藏',
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const chapters = project.chapters ?? []
|
|
65
|
+
if (chapters.length === 0) {
|
|
66
|
+
return {
|
|
67
|
+
id: 'plan',
|
|
68
|
+
label: '排章节',
|
|
69
|
+
recommend: [],
|
|
70
|
+
// 章节规划不在助手的动作集里:通用「继续」不应被解释成改写总纲或设定。
|
|
71
|
+
allow: [],
|
|
72
|
+
reason: '有道藏但还没有章节计划(规划在「小说工坊」面板或生产单里执行)',
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const generating = chapters.filter(c => c.status === 'generating')
|
|
76
|
+
if (generating.length > 0) {
|
|
77
|
+
return {
|
|
78
|
+
id: 'wait',
|
|
79
|
+
label: '等待中',
|
|
80
|
+
recommend: [],
|
|
81
|
+
allow: [],
|
|
82
|
+
reason: `第 ${generating.map(c => c.no).join('、')} 章正在生成,等它结束后再安排下一步`,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const errored = chapters.filter(c => c.status === 'error')
|
|
86
|
+
if (errored.length > 0) {
|
|
87
|
+
return {
|
|
88
|
+
id: 'write',
|
|
89
|
+
label: '逐章编译',
|
|
90
|
+
recommend: ['chapter_generate'],
|
|
91
|
+
allow: ['chapter_generate', 'chapter_rewrite', 'chapter_review'],
|
|
92
|
+
reason: `第 ${errored.map(c => c.no).join('、')} 章生成失败,需要重写`,
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const rejected = chapters.filter(c => c.status === 'rejected')
|
|
96
|
+
if (rejected.length > 0) {
|
|
97
|
+
return {
|
|
98
|
+
id: 'revise',
|
|
99
|
+
label: '修订循环',
|
|
100
|
+
recommend: ['chapter_rewrite'],
|
|
101
|
+
allow: ['chapter_rewrite', 'chapter_review'],
|
|
102
|
+
reason: `第 ${rejected.map(c => c.no).join('、')} 章审稿未过,需要按意见修订`,
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const awaitingReview = chapters.filter(c => c.status === 'written' || c.status === 'reviewing')
|
|
106
|
+
if (awaitingReview.length > 0) {
|
|
107
|
+
return {
|
|
108
|
+
id: 'review',
|
|
109
|
+
label: '审稿',
|
|
110
|
+
recommend: ['chapter_review'],
|
|
111
|
+
allow: ['chapter_review', 'chapter_rewrite'],
|
|
112
|
+
reason: `第 ${awaitingReview.map(c => c.no).join('、')} 章已写出但尚未审稿`,
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const pending = chapters.filter(c => c.status === 'pending')
|
|
116
|
+
if (pending.length > 0) {
|
|
117
|
+
return {
|
|
118
|
+
id: 'write',
|
|
119
|
+
label: '逐章编译',
|
|
120
|
+
recommend: ['chapter_generate'],
|
|
121
|
+
allow: ['chapter_generate', 'chapter_rewrite', 'chapter_review'],
|
|
122
|
+
reason: `还有 ${pending.length} 章待写(下一章:第 ${pending[0]!.no} 章)`,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
id: 'export',
|
|
127
|
+
label: '定稿导出',
|
|
128
|
+
recommend: ['export_txt', 'blurb'],
|
|
129
|
+
// 全部通过后不再允许在「继续」下改写正文:要改必须由作者点名章节。
|
|
130
|
+
allow: ['export_txt', 'blurb'],
|
|
131
|
+
reason: `全书 ${chapters.length} 章均已通过审稿`,
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 判断某写操作是否在当前阶段的允许白名单内。
|
|
137
|
+
*
|
|
138
|
+
* @param stage 阶段契约。
|
|
139
|
+
* @param tool 助手工具名。
|
|
140
|
+
* @returns 允许时为 true。
|
|
141
|
+
*/
|
|
142
|
+
export function stageAllows(stage: BookStage, tool: string): boolean {
|
|
143
|
+
return stage.allow.includes(tool)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 按阶段把一组动作分成「本阶段可用」与「阶段外」。
|
|
148
|
+
*
|
|
149
|
+
* @param stage 阶段契约。
|
|
150
|
+
* @param tools 动作名列表(通常是写操作登记表)。
|
|
151
|
+
* @returns 两个保持输入顺序的子集。
|
|
152
|
+
*/
|
|
153
|
+
export function splitByStage(stage: BookStage, tools: readonly string[]): { available: string[]; outside: string[] } {
|
|
154
|
+
const available: string[] = []
|
|
155
|
+
const outside: string[] = []
|
|
156
|
+
for (const tool of tools) {
|
|
157
|
+
if (stageAllows(stage, tool)) available.push(tool)
|
|
158
|
+
else outside.push(tool)
|
|
159
|
+
}
|
|
160
|
+
return { available, outside }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 渲染阶段契约为可注入提示词的一段文字。
|
|
165
|
+
*
|
|
166
|
+
* @param stage 阶段契约。
|
|
167
|
+
* @returns 多行文本。
|
|
168
|
+
*/
|
|
169
|
+
export function renderStageContract(stage: BookStage): string {
|
|
170
|
+
const recommend = stage.recommend.length > 0 ? stage.recommend.join('、') : '无(等待或由作者指定)'
|
|
171
|
+
const allow = stage.allow.length > 0 ? stage.allow.join('、') : '无'
|
|
172
|
+
return [
|
|
173
|
+
'==================== 当前创作阶段(宿主根据项目真实状态计算) ====================',
|
|
174
|
+
`阶段:${stage.label}(${stage.id})`,
|
|
175
|
+
`判定依据:${stage.reason}`,
|
|
176
|
+
`建议下一步:${recommend}`,
|
|
177
|
+
`本阶段允许的写操作:${allow}`,
|
|
178
|
+
'阶段纪律:作者只说了「继续/下一步」而没指定具体对象时,只有上面的写操作会被执行,其余写操作一律拒绝;作者显式点名某个操作时以作者指令为准。',
|
|
179
|
+
].join('\n')
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** 汇总章节状态计数(供面板/提示词展示,避免各处重复统计)。 */
|
|
183
|
+
export function summarizeChapters(chapters: ChapterPlan[]): Record<string, number> {
|
|
184
|
+
const summary: Record<string, number> = {}
|
|
185
|
+
for (const chapter of chapters) {
|
|
186
|
+
summary[chapter.status] = (summary[chapter.status] ?? 0) + 1
|
|
187
|
+
}
|
|
188
|
+
return summary
|
|
189
|
+
}
|