@waterwx/dsh-novel-forge 1.0.0 → 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.
Files changed (125) hide show
  1. package/README.md +231 -206
  2. package/lib/client.js +55052 -4393
  3. package/lib/index.js +12013 -2524
  4. package/lib/types/ai-scan.d.ts +36 -0
  5. package/lib/types/assets.d.ts +19 -4
  6. package/lib/types/assistant.d.ts +6 -0
  7. package/lib/types/author-assets.d.ts +25 -0
  8. package/lib/types/bookshelf.d.ts +11 -1
  9. package/lib/types/client/api.d.ts +210 -4
  10. package/lib/types/client/docx.d.ts +2 -0
  11. package/lib/types/client/index.d.ts +1 -1
  12. package/lib/types/client/llmLive.d.ts +33 -0
  13. package/lib/types/client/locales.d.ts +102 -29
  14. package/lib/types/client/panel/AdaptModeView.d.ts +5 -0
  15. package/lib/types/client/panel/AiTag.d.ts +1 -0
  16. package/lib/types/client/panel/AuthorAssetsView.d.ts +4 -0
  17. package/lib/types/client/panel/AuthorHome.d.ts +34 -0
  18. package/lib/types/client/panel/BookAnalysisView.d.ts +4 -0
  19. package/lib/types/client/panel/CmdPalette.d.ts +12 -0
  20. package/lib/types/client/panel/CreateBookView.d.ts +13 -0
  21. package/lib/types/client/panel/DirectorView.d.ts +7 -0
  22. package/lib/types/client/panel/GlobalAssetLibraryView.d.ts +4 -0
  23. package/lib/types/client/panel/IdeaInspirationView.d.ts +6 -0
  24. package/lib/types/client/panel/ImportModal.d.ts +7 -0
  25. package/lib/types/client/panel/KnowledgeBaseView.d.ts +4 -0
  26. package/lib/types/client/panel/LiveFeedLog.d.ts +8 -0
  27. package/lib/types/client/panel/MarketRadarView.d.ts +5 -0
  28. package/lib/types/client/panel/ModelManager.d.ts +14 -0
  29. package/lib/types/client/panel/NovelPanel.d.ts +6 -1
  30. package/lib/types/client/panel/PageHeader.d.ts +18 -0
  31. package/lib/types/client/panel/ProgressConsole.d.ts +17 -0
  32. package/lib/types/client/panel/ProgressHomeView.d.ts +5 -0
  33. package/lib/types/client/panel/ReaderView.d.ts +8 -0
  34. package/lib/types/client/panel/ReasoningSection.d.ts +10 -0
  35. package/lib/types/client/panel/RunPanel.d.ts +5 -0
  36. package/lib/types/client/panel/SettingsView.d.ts +19 -0
  37. package/lib/types/client/panel/ShelfView.d.ts +24 -0
  38. package/lib/types/client/panel/SubPage.d.ts +27 -0
  39. package/lib/types/client/panel/WorldTab.d.ts +10 -0
  40. package/lib/types/client/panel/helpers.d.ts +10 -0
  41. package/lib/types/client/panel/toast.d.ts +2 -0
  42. package/lib/types/client/panel/views.d.ts +95 -0
  43. package/lib/types/client/run-status.d.ts +19 -0
  44. package/lib/types/client/text.d.ts +9 -0
  45. package/lib/types/docx-core.d.ts +16 -0
  46. package/lib/types/docx.d.ts +2 -3
  47. package/lib/types/engine.d.ts +228 -5
  48. package/lib/types/global-assets.d.ts +6 -0
  49. package/lib/types/index.d.ts +24 -2
  50. package/lib/types/llm-live.d.ts +44 -0
  51. package/lib/types/market-radar-scan.d.ts +19 -0
  52. package/lib/types/market-radar-sources.d.ts +31 -0
  53. package/lib/types/migrate-output.d.ts +25 -0
  54. package/lib/types/novel-context.d.ts +80 -0
  55. package/lib/types/prompt-utils.d.ts +35 -0
  56. package/lib/types/prompting.d.ts +10 -0
  57. package/lib/types/protocol.d.ts +1418 -7
  58. package/lib/types/review-policy.d.ts +97 -0
  59. package/lib/types/routes.d.ts +4 -0
  60. package/lib/types/run.d.ts +34 -0
  61. package/package.json +120 -93
  62. package/scripts/patch-schemastery.mjs +47 -0
  63. package/src/ai-scan.ts +179 -0
  64. package/src/assets.ts +1774 -518
  65. package/src/assistant.ts +915 -568
  66. package/src/author-assets.ts +149 -0
  67. package/src/bookshelf.ts +187 -148
  68. package/src/client/api.ts +675 -289
  69. package/src/client/docx.ts +37 -69
  70. package/src/client/index.ts +3 -1
  71. package/src/client/llmLive.ts +101 -0
  72. package/src/client/locales.ts +418 -271
  73. package/src/client/mount.tsx +1 -1
  74. package/src/client/panel/AdaptModeView.tsx +535 -0
  75. package/src/client/panel/AiTag.tsx +7 -0
  76. package/src/client/panel/AssetsTab.tsx +448 -456
  77. package/src/client/panel/AssistantTab.tsx +339 -188
  78. package/src/client/panel/AuthorAssetsView.tsx +206 -0
  79. package/src/client/panel/AuthorHome.tsx +309 -0
  80. package/src/client/panel/BookAnalysisView.tsx +63 -0
  81. package/src/client/panel/CmdPalette.tsx +102 -0
  82. package/src/client/panel/CreateBookView.tsx +366 -0
  83. package/src/client/panel/DirectorView.tsx +200 -0
  84. package/src/client/panel/GlobalAssetLibraryView.tsx +168 -0
  85. package/src/client/panel/IdeaInspirationView.tsx +76 -0
  86. package/src/client/panel/ImportModal.tsx +303 -0
  87. package/src/client/panel/KnowledgeBaseView.tsx +125 -0
  88. package/src/client/panel/LiveFeedLog.tsx +67 -0
  89. package/src/client/panel/MarketRadarView.tsx +377 -0
  90. package/src/client/panel/ModelManager.tsx +205 -0
  91. package/src/client/panel/NovelPanel.tsx +5374 -2159
  92. package/src/client/panel/PageHeader.tsx +37 -0
  93. package/src/client/panel/ProgressConsole.tsx +63 -0
  94. package/src/client/panel/ReaderView.tsx +306 -0
  95. package/src/client/panel/ReasoningSection.tsx +31 -0
  96. package/src/client/panel/RunPanel.tsx +223 -0
  97. package/src/client/panel/SettingsView.tsx +305 -0
  98. package/src/client/panel/ShelfView.tsx +266 -0
  99. package/src/client/panel/SubPage.tsx +42 -0
  100. package/src/client/panel/WorldTab.tsx +202 -0
  101. package/src/client/panel/helpers.ts +50 -0
  102. package/src/client/panel/panel.module.css +5764 -1698
  103. package/src/client/panel/toast.ts +51 -0
  104. package/src/client/panel/views.tsx +401 -0
  105. package/src/client/run-status.ts +143 -0
  106. package/src/client/sidebar-entry.ts +1 -1
  107. package/src/client/text.ts +28 -0
  108. package/src/docx-core.ts +53 -0
  109. package/src/docx.ts +44 -83
  110. package/src/engine.ts +4155 -1233
  111. package/src/global-assets.ts +59 -0
  112. package/src/index.ts +311 -184
  113. package/src/llm-live.ts +68 -0
  114. package/src/market-radar-scan.ts +41 -0
  115. package/src/market-radar-sources.ts +173 -0
  116. package/src/migrate-output.ts +76 -0
  117. package/src/novel-context.ts +286 -0
  118. package/src/prompting.ts +26 -0
  119. package/src/protocol.ts +2046 -623
  120. package/src/review-policy.ts +161 -0
  121. package/src/routes.ts +3391 -1172
  122. package/src/run.ts +341 -0
  123. package/lib/client.js.map +0 -1
  124. package/lib/index.js.map +0 -1
  125. package/src/client/panel/BookshelfBar.tsx +0 -170
@@ -0,0 +1,37 @@
1
+ /** 墨案统一页头:eyebrow(11 大写窄) + 衬线大标题 + 一句说明 + 主/次动作。
2
+ * 每个视图只用一个 PageHeader,消灭"各自为政"的页面标题。
3
+ * 图标用 lucide 16 (单色),标题旁禁止 emoji;标题用衬线 Display(书卷感)。 */
4
+ import type { ReactNode } from 'react'
5
+ import css from './panel.module.css'
6
+
7
+ export function PageHeader({ eyebrow, title, icon, sub, actions, right }: {
8
+ /** 页眉小标(大写窄,可选,如 "BOOKSHELF")。 */
9
+ eyebrow?: string
10
+ /** 页面大标题(衬线 Display)。 */
11
+ title: string
12
+ /** lucide 图标(单色,16px),可选。 */
13
+ icon?: ReactNode
14
+ /** 一句话辅助说明(meta)。 */
15
+ sub?: string
16
+ /** 右侧主/次按钮组。 */
17
+ actions?: ReactNode
18
+ /** 标题右上(如 AI 微签)。 */
19
+ right?: ReactNode
20
+ }): JSX.Element {
21
+ return (
22
+ <div className={css.pageHeader}>
23
+ <div className={css.pageHeaderMain}>
24
+ {eyebrow !== undefined && eyebrow !== '' && (
25
+ <div className={css.pageHeaderEyebrow}>{eyebrow}</div>
26
+ )}
27
+ <div className={css.pageHeaderTitle}>
28
+ {icon}
29
+ {title}
30
+ {right}
31
+ </div>
32
+ {sub !== undefined && sub !== '' && <div className={css.pageHeaderSub}>{sub}</div>}
33
+ </div>
34
+ {actions !== undefined && actions !== null && <div className={css.pageHeaderActions}>{actions}</div>}
35
+ </div>
36
+ )
37
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * 共享「AI 进度」实时控制台:当前任务大进度条 + 全量活动日志。
3
+ * 书内与首页共用一个表现,内容来自同一份进度状态。
4
+ */
5
+ import { useEffect, useRef } from 'react'
6
+ import css from './panel.module.css'
7
+
8
+ export interface ProgressLine {
9
+ id: number;
10
+ text: string;
11
+ kind: 'info' | 'done' | 'error';
12
+ live?: boolean;
13
+ ratio?: number;
14
+ }
15
+
16
+ export function ProgressConsole({ progress, busy, busyLabel, liveBar, onClear }: {
17
+ progress: ProgressLine[];
18
+ busy: boolean;
19
+ busyLabel: string;
20
+ liveBar: { text: string; ratio?: number } | null;
21
+ onClear: () => void;
22
+ }) {
23
+ const endRef = useRef<HTMLDivElement | null>(null);
24
+ useEffect(() => {
25
+ endRef.current?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
26
+ }, [progress]);
27
+
28
+ return (
29
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-10)', minHeight: 0 }}>
30
+ <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
31
+ <span style={{ fontWeight: 600 }}> AI 进度</span>
32
+ <button type="button" className={css.button + ' ' + css.buttonSmall} onClick={onClear} title="清空活动记录">清空</button>
33
+ </div>
34
+ {(busy && (busyLabel !== '' || liveBar !== null)) && (
35
+ <div style={{ border: '1px solid var(--nf-accent)', borderRadius: 'var(--nf-radius-10)', padding: 'var(--nf-space-8) var(--nf-space-12)', display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-6)', background: 'color-mix(in srgb, var(--nf-accent) 6%, transparent)' }}>
36
+ <span style={{ fontSize: 'var(--nf-fs-12)', fontWeight: 600, color: 'var(--nf-accent)' }}> {busyLabel !== '' ? busyLabel : (liveBar?.text ?? '任务进行中')}…</span>
37
+ {liveBar?.ratio !== undefined && (
38
+ <div className={css.bigProgressBar}><div className={css.bigProgressBarFill} style={{ width: Math.round(liveBar.ratio * 100) + '%' }} /></div>
39
+ )}
40
+ {liveBar?.text !== undefined && <span className={css.liveText}>{liveBar.text}</span>}
41
+ </div>
42
+ )}
43
+ <div className={css.progress} style={{ flex: '0 1 auto', maxHeight: '42%', minHeight: 0, overflowY: 'auto', border: '1px solid var(--nf-border)', borderRadius: 'var(--nf-radius-10)', background: 'var(--nf-bg-inset)', padding: 'var(--nf-space-8)', display: 'flex', flexDirection: 'column' }}>
44
+ {progress.length === 0 ? (
45
+ <div style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-6)', color: 'var(--nf-text-3)', fontSize: 'var(--nf-fs-12)', padding: 'var(--nf-space-4) 2px' }}>
46
+ <span></span>
47
+ <span>暂无活动记录,生成、审稿等操作会显示在这里</span>
48
+ </div>
49
+ ) : (
50
+ progress.map(line => (
51
+ <div key={line.id} className={line.kind === 'done' ? css.progressLineDone : line.kind === 'error' ? css.progressLineError : line.live === true ? css.progressLineLive : css.progressLine}>
52
+ {line.live === true && (
53
+ <span className={css.progressBar}><span className={css.progressBarFill} style={{ width: Math.round((line.ratio ?? 0) * 100) + '%' }} /></span>
54
+ )}
55
+ {line.text}
56
+ </div>
57
+ ))
58
+ )}
59
+ <div ref={endRef} />
60
+ </div>
61
+ </div>
62
+ );
63
+ }
@@ -0,0 +1,306 @@
1
+ /**
2
+ * 阅读页:沉浸式章节阅读(纯只读,零 LLM 消耗)。
3
+ * 布局:顶部工具栏 + 左侧可折叠目录栏(按卷分组)+ 阅读区。
4
+ * 轻量渲染:去掉 md 首行标题,按行分段;字号/主题/阅读进度 localStorage 记忆。
5
+ */
6
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
7
+ import type { NovelApi } from '../api.ts'
8
+ import type { ProjectState, ChapterPlan } from '../../protocol.ts'
9
+ import css from './panel.module.css'
10
+
11
+ const FONT_SIZES = [
12
+ { id: 'sm', px: 15, label: 'A-' },
13
+ { id: 'md', px: 17, label: 'A' },
14
+ { id: 'lg', px: 20, label: 'A+' },
15
+ ] as const
16
+
17
+ const THEMES = [
18
+ { id: 'paper', label: ' 纸白', bg: '#f7f1e3', fg: '#3b3226', accent: '#8b6f47', dim: '#8a7d66' },
19
+ { id: 'eye', label: ' 护眼', bg: '#e8f0e3', fg: '#2f3d2e', accent: '#5f7d5a', dim: '#6f836b' },
20
+ { id: 'night', label: ' 夜间', bg: '#1d2226', fg: '#c9d1d9', accent: '#8aa5c0', dim: '#6d7882' },
21
+ ] as const
22
+
23
+ type FontId = typeof FONT_SIZES[number]['id']
24
+ type ThemeId = typeof THEMES[number]['id']
25
+
26
+ function readPref<T>(key: string, fallback: T): T {
27
+ try {
28
+ const raw = window.localStorage.getItem(key)
29
+ if (raw !== null) return JSON.parse(raw) as T
30
+ } catch { /* ignore */ }
31
+ return fallback
32
+ }
33
+
34
+ function writePref(key: string, value: unknown): void {
35
+ try { window.localStorage.setItem(key, JSON.stringify(value)) } catch { /* ignore */ }
36
+ }
37
+
38
+ /** 章节状态小标(阅读视角)。 */
39
+ function statusBadge(ch: ChapterPlan): { label: string; cls: string } {
40
+ switch (ch.status) {
41
+ case 'approved': return { label: '', cls: css.badgeDone }
42
+ case 'written': return { label: '', cls: css.badgeWritten }
43
+ case 'rejected': return { label: '', cls: css.badgePending }
44
+ default: return { label: '', cls: css.badgePending }
45
+ }
46
+ }
47
+
48
+ /** 目录分组:按卷区间过滤可读章节;卷外章节归入「未分卷」。 */
49
+ function buildGroups(project: ProjectState, readable: ChapterPlan[]): Array<{ title: string; no: number; chapters: ChapterPlan[] }> {
50
+ const vols = project.volumes ?? []
51
+ if (vols.length === 0) return [{ title: '全部章节', no: 0, chapters: readable }]
52
+ const groups: Array<{ title: string; no: number; chapters: ChapterPlan[] }> = []
53
+ for (const v of vols) {
54
+ const inVol = readable.filter(c => c.no >= v.chapterStart && c.no <= v.chapterEnd)
55
+ if (inVol.length > 0) groups.push({ title: `第${v.no}卷 ${v.title}`, no: v.no, chapters: inVol })
56
+ }
57
+ const rest = readable.filter(c => !vols.some(v => c.no >= v.chapterStart && c.no <= v.chapterEnd))
58
+ if (rest.length > 0) groups.push({ title: '未分卷', no: 0, chapters: rest })
59
+ return groups
60
+ }
61
+
62
+ export function ReaderView({
63
+ api,
64
+ project,
65
+ onBack,
66
+ onOpenWorkspace,
67
+ }: {
68
+ api: NovelApi
69
+ project: ProjectState
70
+ onBack: () => void
71
+ onOpenWorkspace: () => void
72
+ }) {
73
+ const prefKey = useMemo(() => {
74
+ const id = project.bookName || 'book'
75
+ return `dsh-novel-forge.reader.${id}`
76
+ }, [project.bookName])
77
+
78
+ /** 可读章节(有正文落盘):approved / written / rejected。 */
79
+ const readable = useMemo(() => project.chapters.filter(c =>
80
+ c.status === 'approved' || c.status === 'written' || c.status === 'rejected',
81
+ ), [project.chapters])
82
+
83
+ const groups = useMemo(() => buildGroups(project, readable), [project, readable])
84
+
85
+ const [currentNo, setCurrentNo] = useState<number>(() => {
86
+ const saved = readPref<number | null>(`${prefKey}.no`, null)
87
+ if (saved !== null && readable.some(c => c.no === saved)) return saved
88
+ // 无记忆 → 最后一章已通过
89
+ const lastApproved = [...readable].reverse().find(c => c.status === 'approved')
90
+ return lastApproved?.no ?? readable[0]?.no ?? 0
91
+ })
92
+ const [markdown, setMarkdown] = useState<string>('')
93
+ const [loading, setLoading] = useState(false)
94
+ const [loadError, setLoadError] = useState<string>('')
95
+ const [font, setFont] = useState<FontId>(() => readPref(`${prefKey}.font`, 'md'))
96
+ const [theme, setTheme] = useState<ThemeId>(() => readPref(`${prefKey}.theme`, 'paper'))
97
+ const [navOpen, setNavOpen] = useState<boolean>(() => readPref(`${prefKey}.nav`, true))
98
+ /** 折叠的卷号(点击卷标题切换;记忆在 localStorage)。 */
99
+ const [collapsedVols, setCollapsedVols] = useState<number[]>(() => readPref(`${prefKey}.collapsed`, []))
100
+ const sidebarRef = useRef<HTMLDivElement>(null)
101
+
102
+ const toggleVol = useCallback((no: number) => {
103
+ setCollapsedVols(prev => {
104
+ const next = prev.includes(no) ? prev.filter(v => v !== no) : [...prev, no]
105
+ writePref(`${prefKey}.collapsed`, next)
106
+ return next
107
+ })
108
+ }, [prefKey])
109
+
110
+ const current = useMemo(() => project.chapters.find(c => c.no === currentNo), [project.chapters, currentNo])
111
+ const idx = readable.findIndex(c => c.no === currentNo)
112
+ const prevCh = idx > 0 ? readable[idx - 1] : undefined
113
+ const nextCh = idx >= 0 && idx < readable.length - 1 ? readable[idx + 1] : undefined
114
+
115
+ const load = useCallback(async (no: number) => {
116
+ if (no === 0) return
117
+ setLoading(true)
118
+ setLoadError('')
119
+ try {
120
+ const res = await api.chapter(no)
121
+ setMarkdown(res.markdown)
122
+ setCurrentNo(no)
123
+ writePref(`${prefKey}.no`, no)
124
+ } catch (err) {
125
+ setLoadError((err as Error).message)
126
+ } finally {
127
+ setLoading(false)
128
+ }
129
+ }, [api, prefKey])
130
+
131
+ // 初始加载
132
+ const initialNo = useRef<number>(0)
133
+ useEffect(() => {
134
+ if (initialNo.current === currentNo && markdown !== '') return
135
+ if (currentNo === 0) return
136
+ initialNo.current = currentNo
137
+ void load(currentNo)
138
+ }, [currentNo, load, markdown])
139
+
140
+ // 键盘翻章
141
+ useEffect(() => {
142
+ const onKey = (e: KeyboardEvent) => {
143
+ if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) return
144
+ if (e.key === 'ArrowLeft' && prevCh !== undefined) void load(prevCh.no)
145
+ if (e.key === 'ArrowRight' && nextCh !== undefined) void load(nextCh.no)
146
+ }
147
+ window.addEventListener('keydown', onKey)
148
+ return () => window.removeEventListener('keydown', onKey)
149
+ }, [prevCh, nextCh, load])
150
+
151
+ // 当前章滚动到可见(目录栏内)
152
+ useEffect(() => {
153
+ sidebarRef.current?.querySelector<HTMLElement>(`[data-no="${currentNo}"]`)?.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
154
+ }, [currentNo])
155
+
156
+ const themeMeta = THEMES.find(t => t.id === theme) ?? THEMES[0]
157
+ const fontMeta = FONT_SIZES.find(f => f.id === font) ?? FONT_SIZES[1]
158
+
159
+ /** 轻量渲染:去标题行、按行分段(网文每行一段)。 */
160
+ const paragraphs = useMemo(() => {
161
+ return markdown
162
+ .split(/\r?\n/)
163
+ .map(l => l.replace(/^#{1,6}\s*/, '').trim())
164
+ .filter(Boolean)
165
+ }, [markdown])
166
+
167
+ const itemBg = theme === 'night' ? 'rgba(255,255,255,0.03)' : 'rgba(0,0,0,0.025)'
168
+
169
+ return (
170
+ <div className={css.readerView} style={{ background: themeMeta.bg, color: themeMeta.fg }}>
171
+ {/* 顶部栏 */}
172
+ <div className={css.readerHeader} style={{ borderColor: themeMeta.dim }}>
173
+ <button type="button" className={css.iconButton} title="返回书架" aria-label="返回书架" onClick={onBack}>←</button>
174
+ <span className={css.readerTitle}> 《{project.bookName}》</span>
175
+ <span className={css.meta} style={{ color: themeMeta.dim }}>
176
+ {readable.length > 0 && currentNo > 0 ? `第 ${currentNo} 章 · ${idx + 1}/${readable.length}` : ''}
177
+ </span>
178
+ <button
179
+ type="button"
180
+ className={`${css.button} ${css.buttonSmall} ${navOpen ? css.buttonPrimary : ''}`}
181
+ style={{ marginLeft: 'var(--nf-space-4)' }}
182
+ onClick={() => { setNavOpen(v => { const next = !v; writePref(`${prefKey}.nav`, next); return next }) }}
183
+ title={navOpen ? '收起目录' : '展开目录'}
184
+ >
185
+ ☰ 目录
186
+ </button>
187
+ <div style={{ flex: 1 }} />
188
+ <span className={css.meta} style={{ color: themeMeta.dim }}>字号</span>
189
+ <div className={css.readerSeg}>
190
+ {FONT_SIZES.map(f => (
191
+ <button
192
+ key={f.id}
193
+ type="button"
194
+ className={`${css.readerSegBtn} ${font === f.id ? css.readerSegActive : ''}`}
195
+ style={font === f.id ? { background: themeMeta.accent, color: themeMeta.bg } : undefined}
196
+ onClick={() => { setFont(f.id); writePref(`${prefKey}.font`, f.id) }}
197
+ title={`字号 ${f.label}`}
198
+ >
199
+ {f.label}
200
+ </button>
201
+ ))}
202
+ </div>
203
+ <div className={css.readerSeg} style={{ marginLeft: 'var(--nf-space-8)' }}>
204
+ {THEMES.map(t => (
205
+ <button
206
+ key={t.id}
207
+ type="button"
208
+ className={`${css.readerSegBtn} ${theme === t.id ? css.readerSegActive : ''}`}
209
+ style={theme === t.id ? { background: themeMeta.accent, color: themeMeta.bg } : undefined}
210
+ onClick={() => { setTheme(t.id); writePref(`${prefKey}.theme`, t.id) }}
211
+ title={t.label}
212
+ >
213
+ {t.label}
214
+ </button>
215
+ ))}
216
+ </div>
217
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} style={{ marginLeft: 'var(--nf-space-10)' }} onClick={onOpenWorkspace} title="回到创作工作台">
218
+ 去工作台
219
+ </button>
220
+ </div>
221
+
222
+ {/* 主体:左目录 + 右阅读区 */}
223
+ <div className={css.readerBody}>
224
+ {navOpen && (
225
+ <aside className={css.readerSidebar} style={{ borderColor: themeMeta.dim, background: theme === 'night' ? 'rgba(0,0,0,0.25)' : 'rgba(255,255,255,0.35)' }} ref={sidebarRef}>
226
+ {groups.length === 0 ? (
227
+ <div className={css.meta} style={{ color: themeMeta.dim, padding: 'var(--nf-space-12)' }}>还没有已写章节,先去工作台创作吧</div>
228
+ ) : groups.map(g => {
229
+ const collapsed = collapsedVols.includes(g.no)
230
+ return (
231
+ <div key={g.no} className={css.readerGroup}>
232
+ <button
233
+ type="button"
234
+ className={css.readerGroupTitle}
235
+ style={{ color: themeMeta.accent }}
236
+ onClick={() => { toggleVol(g.no) }}
237
+ title={collapsed ? `展开${g.title}` : `收起${g.title}`}
238
+ >
239
+ <span className={css.readerGroupArrow}>{collapsed ? '▸' : '▾'}</span>
240
+ <span>{g.title}</span>
241
+ <span className={css.readerGroupCount}>{g.chapters.length}</span>
242
+ </button>
243
+ {!collapsed && g.chapters.map(ch => {
244
+ const badge = statusBadge(ch)
245
+ const active = ch.no === currentNo
246
+ return (
247
+ <button
248
+ key={ch.no}
249
+ type="button"
250
+ data-no={ch.no}
251
+ className={`${css.readerItem} ${active ? css.readerItemActive : ''}`}
252
+ style={active ? { background: themeMeta.accent, color: themeMeta.bg, borderColor: themeMeta.accent } : { borderColor: 'transparent', color: themeMeta.fg }}
253
+ onClick={() => { void load(ch.no) }}
254
+ title={`第${ch.no}章 ${ch.title}`}
255
+ >
256
+ <span className={css.readerItemNo}>{ch.no}</span>
257
+ <span className={css.readerItemTitle}>{ch.title}</span>
258
+ {badge.label !== '' && <span className={css.readerItemBadge}>{badge.label}</span>}
259
+ </button>
260
+ )
261
+ })}
262
+ </div>
263
+ )
264
+ })}
265
+ </aside>
266
+ )}
267
+
268
+ {/* 阅读区 */}
269
+ <div className={css.readerMain} style={{ background: itemBg }}>
270
+ {loadError !== '' ? (
271
+ <div className={css.readerError}>{loadError}</div>
272
+ ) : loading && markdown === '' ? (
273
+ <div className={css.readerLoading}>⏳ 加载中…</div>
274
+ ) : current !== undefined && currentNo > 0 ? (
275
+ <article className={css.readerArticle} style={{ maxWidth: 720 }}>
276
+ <h1 className={css.readerChapterTitle} style={{ color: themeMeta.accent }}>{current.title}</h1>
277
+ <div className={css.readerChapterMeta} style={{ color: themeMeta.dim }}>
278
+ <span>{statusBadge(current).label}</span>
279
+ <span>第 {current.no} 章</span>
280
+ {current.chars !== undefined && <span> · {current.chars.toLocaleString()} 字</span>}
281
+ </div>
282
+ <div className={css.readerText} style={{ fontSize: fontMeta.px, lineHeight: 1.9 }}>
283
+ {paragraphs.map((p, i) => <p key={i} className={css.readerPara}>{p}</p>)}
284
+ </div>
285
+ <div className={css.readerFoot}>
286
+ {prevCh !== undefined && (
287
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} style={{ borderColor: themeMeta.dim, color: themeMeta.fg }} onClick={() => { void load(prevCh.no) }} title="← 上一章">
288
+ ← 第{prevCh.no}章
289
+ </button>
290
+ )}
291
+ <span className={css.meta} style={{ color: themeMeta.dim }}>← → 键盘翻章</span>
292
+ {nextCh !== undefined && (
293
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} style={{ borderColor: themeMeta.accent, color: themeMeta.accent }} onClick={() => { void load(nextCh.no) }} title="下一章 →">
294
+ 第{nextCh.no}章 →
295
+ </button>
296
+ )}
297
+ </div>
298
+ </article>
299
+ ) : (
300
+ <div className={css.readerLoading}>暂无内容</div>
301
+ )}
302
+ </div>
303
+ </div>
304
+ </div>
305
+ )
306
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 推理强度(思考强度)独立容器:写作类/分析类两个 reasoningEffort 下拉。
3
+ */
4
+ import { Brain } from 'lucide-react'
5
+ import type { NovelConfig } from '../../protocol.ts'
6
+ import { tt } from './helpers.ts'
7
+ import css from './panel.module.css'
8
+
9
+ const REASONING_OPTIONS = ['off', 'low', 'high', 'max'] as const
10
+ const REASONING_LABEL: Record<string, string> = {
11
+ off: tt('settings.reasoning.off'),
12
+ low: tt('settings.reasoning.low'),
13
+ high: tt('settings.reasoning.high'),
14
+ max: tt('settings.reasoning.max'),
15
+ }
16
+
17
+ export interface ReasoningSectionProps {
18
+ reasoningEffort: NovelConfig['reasoningEffort']
19
+ analysisReasoning: NovelConfig['analysisReasoning']
20
+ onChange: (patch: { reasoningEffort?: NovelConfig['reasoningEffort']; analysisReasoning?: NovelConfig['analysisReasoning'] }) => void
21
+ }
22
+
23
+ export function ReasoningSection({ reasoningEffort, analysisReasoning, onChange }: ReasoningSectionProps): JSX.Element {
24
+ return (
25
+ <div className={css.card + ' ' + css.settingsCard} style={{ gap: 'var(--nf-space-24)' }}>
26
+ <span className={css.cardTitle}><Brain size={18} style={{ verticalAlign: -3 }} /> {tt('settings.reasoningSection')}</span>
27
+ <div className={css.field}><label className={css.fieldLabel}>{tt('settings.reasoningEffort')}</label><select className={css.input} value={reasoningEffort ?? 'off'} onChange={e => onChange({ reasoningEffort: e.target.value as NovelConfig['reasoningEffort'] })}>{REASONING_OPTIONS.map(v => <option key={v} value={v}>{REASONING_LABEL[v]}</option>)}</select><span className={css.meta}>{tt('settings.reasoningHint')}</span></div>
28
+ <div className={css.field}><label className={css.fieldLabel}>{tt('settings.analysisReasoning')}</label><select className={css.input} value={analysisReasoning ?? 'low'} onChange={e => onChange({ analysisReasoning: e.target.value as NovelConfig['analysisReasoning'] })}>{REASONING_OPTIONS.map(v => <option key={v} value={v}>{REASONING_LABEL[v]}</option>)}</select><span className={css.meta}>{tt('settings.analysisReasoningHint')}</span></div>
29
+ </div>
30
+ )
31
+ }
@@ -0,0 +1,223 @@
1
+ /**
2
+ * 生产单面板:区间批量生产(计划补足 → 逐章生成 → 被拒分级处理 → 断点续跑)。
3
+ * 与「AI进度」悬浮窗不同:这是标准流水线设备,一键下单、实时进度、日志可查。
4
+ */
5
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
6
+ import type { NovelApi } from '../api.ts'
7
+ import type { RunState } from '../../protocol.ts'
8
+ import css from './panel.module.css'
9
+ import { PageHeader } from './PageHeader.tsx'
10
+
11
+ export function RunPanel({ api, totalChapters }: { api: NovelApi; totalChapters: number }) {
12
+ const [run, setRun] = useState<RunState | null>(null)
13
+ const [startNo, setStartNo] = useState<number>(1)
14
+ const [endNo, setEndNo] = useState<number>(0)
15
+ const [count, setCount] = useState<number>(30)
16
+ const [mode, setMode] = useState<'count' | 'range'>('count')
17
+ const [busy, setBusy] = useState(false)
18
+ const [err, setErr] = useState('')
19
+ const logRef = useRef<HTMLDivElement>(null)
20
+
21
+ // 默认起点:最后一章 + 1;count 模式终点 = 起点 + count - 1
22
+ useEffect(() => {
23
+ setStartNo(totalChapters + 1)
24
+ setEndNo(totalChapters + 30)
25
+ }, [totalChapters])
26
+
27
+ const poll = useCallback(async () => {
28
+ try {
29
+ const s = await api.runStatus()
30
+ setRun(s)
31
+ } catch { /* 静默 */ }
32
+ }, [api])
33
+
34
+ // 运行期间每 5 秒轮询一次状态。
35
+ useEffect(() => {
36
+ void poll()
37
+ const timer = window.setInterval(() => { void poll() }, 5000)
38
+ return () => window.clearInterval(timer)
39
+ }, [poll])
40
+
41
+ // 日志自动滚底。
42
+ useEffect(() => {
43
+ logRef.current?.scrollTo({ top: logRef.current.scrollHeight })
44
+ }, [run?.log.length])
45
+
46
+
47
+ const handleStart = async (): Promise<void> => {
48
+ setBusy(true)
49
+ setErr('')
50
+ try {
51
+ const req = mode === 'count'
52
+ ? { startNo, count }
53
+ : { startNo, endNo }
54
+ const s = await api.runStart(req)
55
+ setRun(s)
56
+ } catch (e) {
57
+ setErr((e as Error).message)
58
+ } finally {
59
+ setBusy(false)
60
+ }
61
+ }
62
+
63
+ const handleControl = async (action: 'pause' | 'resume' | 'stop'): Promise<void> => {
64
+ setBusy(true)
65
+ setErr('')
66
+ try {
67
+ const s = await api.runControl(action)
68
+ if (s !== null) setRun(s)
69
+ } catch (e) {
70
+ setErr((e as Error).message)
71
+ } finally {
72
+ setBusy(false)
73
+ }
74
+ }
75
+
76
+ const statusLabel = useMemo(() => {
77
+ if (run === null) return '未启动'
78
+ return {
79
+ running: ' 生产中',
80
+ paused: '⏸ 已暂停',
81
+ done: ' 已完成',
82
+ stopped: '⏹ 已停止',
83
+ error: ' 异常',
84
+ }[run.status] ?? run.status
85
+ }, [run])
86
+
87
+ const ratio = run !== null && run.endNo > run.startNo
88
+ ? Math.min(Math.max((run.currentNo - run.startNo) / (run.endNo - run.startNo), 0), 1)
89
+ : 0
90
+
91
+ return (
92
+ <div className={css.card} style={{ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-10)' }}>
93
+ <PageHeader
94
+ eyebrow="Production"
95
+ title="生产单"
96
+ actions={(
97
+ <span className={`${css.badge} ${run?.status === 'running' ? css.badgeWritten : run?.status === 'done' ? css.badgeDone : css.badgePending}`}>{statusLabel}</span>
98
+ )}
99
+ />
100
+ {run === null || run.status !== 'running' ? (
101
+ <span className={css.meta}>标准流水线:计划 → 生成 → 审稿 → 分级处理。一键下单,自动补计划,逐章过质量门(生成→摘要+事实→审稿→作者复盘),被拒章分级处理,中断可断点续跑。</span>
102
+ ) : null}
103
+
104
+ {/* v4 B4 控制台折叠:生产中下单区收起为一行状态摘要,进度与日志成为主体。 */}
105
+ {run !== null && run.status === 'running' ? (
106
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap', gap: 'var(--nf-space-8)' }}>
107
+ <span className={css.meta}> 生产中 · 第 {run.startNo}-{run.endNo} 章 · 当前第 {run.currentNo} 章 · {Math.round(ratio * 100)}%</span>
108
+ <div className={css.row} style={{ gap: 'var(--nf-space-6)' }}>
109
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={busy} onClick={() => { void handleControl('pause') }}>
110
+ ⏸ 暂停
111
+ </button>
112
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={busy} onClick={() => { void handleControl('stop') }}>
113
+ ⏹ 停止
114
+ </button>
115
+ </div>
116
+ </div>
117
+ ) : (
118
+ <>
119
+ {/* 下单区 */}
120
+ <div className={css.row} style={{ flexWrap: 'wrap', gap: 'var(--nf-space-8)', alignItems: 'flex-end' }}>
121
+ <div style={{ display: 'flex', gap: 'var(--nf-space-4)', alignItems: 'center' }}>
122
+ <button
123
+ type="button"
124
+ className={`${css.button} ${css.buttonSmall} ${mode === 'count' ? css.buttonPrimary : ''}`}
125
+ onClick={() => { setMode('count') }}
126
+ title="从当前末章 +1 起,新增 N 章"
127
+ >
128
+ 新增 N 章
129
+ </button>
130
+ <button
131
+ type="button"
132
+ className={`${css.button} ${css.buttonSmall} ${mode === 'range' ? css.buttonPrimary : ''}`}
133
+ onClick={() => { setMode('range') }}
134
+ title="指定起止章号区间"
135
+ >
136
+ 指定区间
137
+ </button>
138
+ </div>
139
+ {mode === 'count' ? (
140
+ <>
141
+ <div className={css.field} style={{ flex: 'none', minWidth: 90 }}>
142
+ <label className={css.fieldLabel}>起始章</label>
143
+ <input className={css.input} type="number" min={1} value={startNo} onChange={e => { setStartNo(Math.max(1, Number(e.target.value) || 1)) }} />
144
+ </div>
145
+ <div className={css.field} style={{ flex: 'none', minWidth: 90 }}>
146
+ <label className={css.fieldLabel}>新增章数</label>
147
+ <input className={css.input} type="number" min={1} max={200} value={count} onChange={e => { setCount(Math.max(1, Math.min(200, Number(e.target.value) || 1))) }} />
148
+ </div>
149
+ </>
150
+ ) : (
151
+ <>
152
+ <div className={css.field} style={{ flex: 'none', minWidth: 90 }}>
153
+ <label className={css.fieldLabel}>起始章</label>
154
+ <input className={css.input} type="number" min={1} value={startNo} onChange={e => { setStartNo(Math.max(1, Number(e.target.value) || 1)) }} />
155
+ </div>
156
+ <div className={css.field} style={{ flex: 'none', minWidth: 90 }}>
157
+ <label className={css.fieldLabel}>结束章</label>
158
+ <input className={css.input} type="number" min={1} value={endNo} onChange={e => { setEndNo(Math.max(1, Number(e.target.value) || 1)) }} />
159
+ </div>
160
+ </>
161
+ )}
162
+ <button type="button" className={`${css.button} ${css.buttonPrimary}`} disabled={busy || (run?.status === 'running')} onClick={() => { void handleStart() }} title="启动生产单">
163
+ {run?.status === 'running' ? '生产中…' : run?.status === 'paused' ? '▶ 继续' : '▶ 下单生产'}
164
+ </button>
165
+ {run !== null && run.status !== 'done' && (
166
+ <>
167
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={busy || run.status !== 'running'} onClick={() => { void handleControl('pause') }}>
168
+ ⏸ 暂停
169
+ </button>
170
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={busy || run.status === 'stopped'} onClick={() => { void handleControl('stop') }}>
171
+ ⏹ 停止
172
+ </button>
173
+ </>
174
+ )}
175
+ {run !== null && run.status === 'paused' && (
176
+ <button type="button" className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`} disabled={busy} onClick={() => { void handleControl('resume') }}>
177
+ ▶ 继续
178
+ </button>
179
+ )}
180
+ </div>
181
+ </>
182
+ )}
183
+
184
+ {err !== '' && <div style={{ color: 'var(--nf-error)', fontSize: 'var(--nf-fs-12)' }}>{err}</div>}
185
+
186
+ {/* 进度区 */}
187
+ {run !== null && (
188
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-6)' }}>
189
+ <div className={css.row} style={{ flexWrap: 'wrap', gap: 'var(--nf-space-8)' }}>
190
+ <span className={css.meta}>范围:第 {run.startNo} - {run.endNo} 章 · 当前:第 {run.currentNo} 章</span>
191
+ <span className={css.meta}>新生成 {run.stats?.generated ?? 0} · 修订通过 {run.stats?.revised ?? 0} · 豁免 {run.stats?.exempted ?? 0} · 重生成 {run.stats?.regenerated ?? 0} · 失败 {run.stats?.error ?? 0}</span>
192
+ </div>
193
+ <div className={css.bigProgressBar}>
194
+ <div className={css.bigProgressBarFill} style={{ width: `${Math.round(ratio * 100)}%` }} />
195
+ </div>
196
+ {run.pendingManual.length > 0 && (
197
+ <div className={css.meta} style={{ color: 'var(--nf-warn)' }}>
198
+ 待人工:第 {run.pendingManual.join('、')} 章(两轮修订仍不过,保留草稿,可在章节列表处理)
199
+ </div>
200
+ )}
201
+ {run.status === 'done' && <div className={css.meta} style={{ color: 'var(--nf-success)' }}> 生产单完成:{run.startNo}-{run.endNo} 章处理完毕,待人工 {run.pendingManual.length} 章。</div>}
202
+ {run.error !== undefined && <div className={css.meta} style={{ color: 'var(--nf-error)' }}>异常:{run.error}</div>}
203
+ </div>
204
+ )}
205
+
206
+ {/* 日志区(终端风) */}
207
+ <div className={`${css.meta} ${css.titleBlock}`} style={{ gap: 0 }}>
208
+ <span className={css.eyebrow}>Run Log</span>
209
+ <span className={css.cardTitle}>运行日志({run?.log.length ?? 0})</span>
210
+ </div>
211
+ <div ref={logRef} className={css.runLog}>
212
+ {run === null || run.log.length === 0 ? (
213
+ <span className={css.meta}>尚无日志——下单后这里会实时显示每章进度。</span>
214
+ ) : run.log.map((l, i) => (
215
+ <div key={i} className={css.runLogLine}>
216
+ <span className={css.runLogTime}>{new Date(l.at).toLocaleTimeString('zh-CN', { hour12: false })}</span>
217
+ <span>{l.text}</span>
218
+ </div>
219
+ ))}
220
+ </div>
221
+ </div>
222
+ )
223
+ }