@waterwx/dsh-novel-forge 1.3.1 → 1.3.2-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 +288 -279
- package/lib/client.js +56309 -12221
- package/lib/index.js +14239 -5595
- package/lib/types/action-guard.d.ts +61 -0
- package/lib/types/ai-scan.d.ts +36 -0
- package/lib/types/assets.d.ts +24 -9
- 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 +186 -10
- package/lib/types/client/chip-prefs.d.ts +36 -0
- 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 +31 -0
- package/lib/types/client/locales.d.ts +28 -67
- 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 +13 -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/PromptSlotsView.d.ts +11 -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/TensionView.d.ts +18 -0
- package/lib/types/client/panel/TimelineView.d.ts +18 -0
- package/lib/types/client/panel/helpers.d.ts +5 -3
- 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 +21 -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 +186 -45
- package/lib/types/global-assets.d.ts +6 -0
- package/lib/types/index.d.ts +22 -8
- package/lib/types/llm-live.d.ts +75 -0
- package/lib/types/llm-retry.d.ts +38 -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-slots.d.ts +57 -0
- package/lib/types/prompt-utils.d.ts +35 -0
- package/lib/types/prompting.d.ts +10 -0
- package/lib/types/protocol.d.ts +1362 -166
- package/lib/types/review-policy.d.ts +97 -0
- package/lib/types/revision.d.ts +76 -0
- package/lib/types/routes.d.ts +4 -0
- package/lib/types/run.d.ts +23 -1
- package/lib/types/snapshots.d.ts +46 -0
- package/lib/types/stage-contract.d.ts +60 -0
- package/lib/types/tension.d.ts +53 -0
- package/lib/types/timeline.d.ts +37 -0
- package/package.json +52 -28
- package/src/action-guard.ts +127 -0
- package/src/ai-scan.ts +179 -0
- package/src/assets.ts +1806 -520
- package/src/assistant.ts +1098 -770
- package/src/author-assets.ts +149 -0
- package/src/bookshelf.ts +187 -151
- package/src/client/api.ts +378 -21
- package/src/client/chip-prefs.ts +121 -0
- package/src/client/docx.ts +37 -69
- package/src/client/index.ts +3 -1
- package/src/client/llmLive.ts +111 -0
- package/src/client/locales.ts +28 -253
- 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 +204 -0
- package/src/client/panel/MarketRadarView.tsx +377 -0
- package/src/client/panel/ModelManager.tsx +205 -0
- package/src/client/panel/NovelPanel.tsx +3135 -2651
- package/src/client/panel/PageHeader.tsx +37 -0
- package/src/client/panel/ProgressConsole.tsx +63 -0
- package/src/client/panel/PromptSlotsView.tsx +97 -0
- package/src/client/panel/ReaderView.tsx +306 -306
- package/src/client/panel/ReasoningSection.tsx +31 -0
- package/src/client/panel/RunPanel.tsx +64 -32
- package/src/client/panel/SettingsView.tsx +354 -0
- package/src/client/panel/ShelfView.tsx +266 -236
- package/src/client/panel/SubPage.tsx +42 -0
- package/src/client/panel/TensionView.tsx +212 -0
- package/src/client/panel/TimelineView.tsx +208 -0
- package/src/client/panel/WorldTab.tsx +202 -202
- package/src/client/panel/helpers.ts +7 -5
- package/src/client/panel/panel.module.css +4481 -1655
- package/src/client/panel/toast.ts +51 -0
- package/src/client/panel/views.tsx +401 -314
- package/src/client/run-status.ts +171 -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 +4672 -2943
- package/src/global-assets.ts +59 -0
- package/src/index.ts +89 -33
- package/src/llm-live.ts +260 -0
- package/src/llm-retry.ts +77 -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/prompt-slots.ts +125 -0
- package/src/prompting.ts +26 -0
- package/src/protocol.ts +1388 -158
- package/src/review-policy.ts +161 -0
- package/src/revision.ts +283 -0
- package/src/routes.ts +1934 -434
- package/src/run.ts +118 -21
- package/src/snapshots.ts +174 -0
- package/src/stage-contract.ts +189 -0
- package/src/tension.ts +251 -0
- package/src/timeline.ts +159 -0
- package/lib/client.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/comic-presets.d.ts +0 -12
- package/scripts/assistant-frames.txt +0 -8
- package/scripts/diagnose-adapter.mts +0 -81
- package/scripts/diagnose-assistant.mjs +0 -58
- package/scripts/diagnose-bible.mjs +0 -72
- package/scripts/diagnose-harness.mts +0 -75
- package/scripts/novel-forge-restart.log +0 -10
- package/scripts/novel-forge-web.stderr.log +0 -2
- package/scripts/novel-forge-web.stdout.log +0 -1
- package/scripts/outline-sample.txt +0 -449
- package/scripts/probe.mjs +0 -6
- package/scripts/restart-web.ps1 +0 -88
- package/scripts/smoke.mts +0 -72
- package/scripts/upload-github.ps1 +0 -51
- package/src/client/panel/BookshelfBar.tsx +0 -170
- package/src/comic-presets.ts +0 -67
|
@@ -1,348 +1,366 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 开书向导:独立页面视图 —— 书名 + 大纲(选择 docx / 拖拽 / 粘贴),
|
|
3
|
-
* 实时书名识别与题材提示,开书即建项目并进入工作台。
|
|
4
|
-
* 另含「想法 → AI 大纲」:输入一句话想法生成 2-3 个方案,可暂留换批,选中后回填大纲框。
|
|
5
|
-
*/
|
|
6
|
-
import { useRef, useState } from 'react'
|
|
7
|
-
import type { NovelApi } from '../api.ts'
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
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
|
-
const [
|
|
58
|
-
const [
|
|
59
|
-
const [
|
|
60
|
-
const [
|
|
61
|
-
const [
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
const
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
{
|
|
271
|
-
<
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
>
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
</span>
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 开书向导:独立页面视图 —— 书名 + 大纲(选择 docx / 拖拽 / 粘贴),
|
|
3
|
+
* 实时书名识别与题材提示,开书即建项目并进入工作台。
|
|
4
|
+
* 另含「想法 → AI 大纲」:输入一句话想法生成 2-3 个方案,可暂留换批,选中后回填大纲框。
|
|
5
|
+
*/
|
|
6
|
+
import { useRef, useState } from 'react'
|
|
7
|
+
import type { NovelApi } from '../api.ts'
|
|
8
|
+
import { setCurrentBook } from '../api.ts'
|
|
9
|
+
import type { OutlineCandidate } from '../../protocol.ts'
|
|
10
|
+
import { extractDocxTextFromBuffer } from '../docx.ts'
|
|
11
|
+
import css from './panel.module.css'
|
|
12
|
+
import { SubPage } from './SubPage.tsx'
|
|
13
|
+
|
|
14
|
+
/** 从大纲首行推断书名(与服务端 inferBookName 一致,供实时预览)。 */
|
|
15
|
+
function inferBookNamePreview(outline: string): string {
|
|
16
|
+
const line = outline.split('\n').map(l => l.trim()).find(l => l.length > 0)
|
|
17
|
+
if (line === undefined) return ''
|
|
18
|
+
return line.replace(/^《/, '').replace(/》.*$/, '').slice(0, 40)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 简单题材识别(提示用)。 */
|
|
22
|
+
function guessGenre(outline: string): string | null {
|
|
23
|
+
const map: Array<[string, string[]]> = [
|
|
24
|
+
['仙侠修真', ['仙', '修', '灵根', '元婴', '宗门', '飞升']],
|
|
25
|
+
['都市', ['都市', '公司', '外卖', '职场', '总裁']],
|
|
26
|
+
['玄幻', ['斗气', '魂力', '大陆', '斗罗', '神']],
|
|
27
|
+
['悬疑', ['悬疑', '密室', '案件', '推理', '凶']],
|
|
28
|
+
['科幻', ['机甲', '星舰', 'AI', '未来', '星际']],
|
|
29
|
+
['历史', ['朝代', '皇帝', '将军', '古代', '王朝']],
|
|
30
|
+
['游戏', ['游戏', '副本', '装备', '等级', '职业']],
|
|
31
|
+
]
|
|
32
|
+
for (const [genre, keywords] of map) {
|
|
33
|
+
if (keywords.some(k => outline.includes(k))) return genre
|
|
34
|
+
}
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 开书向导页。 */
|
|
39
|
+
export function CreateBookView({
|
|
40
|
+
api,
|
|
41
|
+
onBack,
|
|
42
|
+
onCreated,
|
|
43
|
+
initialIdea,
|
|
44
|
+
initialName,
|
|
45
|
+
}: {
|
|
46
|
+
api: NovelApi
|
|
47
|
+
/** 返回书架。 */
|
|
48
|
+
onBack: () => void
|
|
49
|
+
/** 开书成功:进入新书工作台。 */
|
|
50
|
+
onCreated: (id: string) => void
|
|
51
|
+
/** 从「创意灵感」带过来的起步想法(预填到「一句话想法」输入框)。 */
|
|
52
|
+
initialIdea?: string
|
|
53
|
+
/** 从「创意灵感」带过来的初始书名。 */
|
|
54
|
+
initialName?: string
|
|
55
|
+
}) {
|
|
56
|
+
const [name, setName] = useState(initialName ?? '')
|
|
57
|
+
const [outlineText, setOutlineText] = useState('')
|
|
58
|
+
const [outlineName, setOutlineName] = useState('')
|
|
59
|
+
const [dragActive, setDragActive] = useState(false)
|
|
60
|
+
const [busy, setBusy] = useState(false)
|
|
61
|
+
const [error, setError] = useState('')
|
|
62
|
+
const outlineFileRef = useRef<HTMLInputElement | null>(null)
|
|
63
|
+
|
|
64
|
+
// ---- 想法 → AI 大纲状态 ----
|
|
65
|
+
const hasPrefill = initialIdea !== undefined && initialIdea.trim() !== ''
|
|
66
|
+
const [ideaOpen, setIdeaOpen] = useState(hasPrefill)
|
|
67
|
+
const [idea, setIdea] = useState(initialIdea ?? '')
|
|
68
|
+
const [suggesting, setSuggesting] = useState(false)
|
|
69
|
+
const [candidates, setCandidates] = useState<OutlineCandidate[]>([])
|
|
70
|
+
const [pinned, setPinned] = useState<string[]>([])
|
|
71
|
+
/** 回填后提示(如「已填入方案A,可继续修改」)。 */
|
|
72
|
+
const [fillNotice, setFillNotice] = useState('')
|
|
73
|
+
/** 选定方案自带的题材(创建后自动预填到本书创作资产)。 */
|
|
74
|
+
const [selectedGenre, setSelectedGenre] = useState('')
|
|
75
|
+
|
|
76
|
+
const autoName = inferBookNamePreview(outlineText)
|
|
77
|
+
const effectiveName = name.trim() !== '' ? name.trim() : autoName
|
|
78
|
+
const genre = guessGenre(outlineText)
|
|
79
|
+
|
|
80
|
+
const handlePickOutlineFile = async (file: File | undefined): Promise<void> => {
|
|
81
|
+
if (file === undefined) return
|
|
82
|
+
try {
|
|
83
|
+
const buffer = await file.arrayBuffer()
|
|
84
|
+
const text = extractDocxTextFromBuffer(buffer)
|
|
85
|
+
if (text.length < 50) {
|
|
86
|
+
setError('大纲内容过短(<50 字符),请检查文件')
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
setOutlineText(text)
|
|
90
|
+
setOutlineName(file.name)
|
|
91
|
+
if (name.trim() === '') setName(inferBookNamePreview(text))
|
|
92
|
+
setError('')
|
|
93
|
+
} catch (err) {
|
|
94
|
+
setError(`读取大纲失败:${(err as Error).message}`)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** 生成/换批:只补未暂留的空槽;exclude 传已暂留方案的卖点方向。 */
|
|
99
|
+
const handleSuggest = async (): Promise<void> => {
|
|
100
|
+
if (idea.trim().length < 10) {
|
|
101
|
+
setError('想法太短(<10 字):至少写一句完整想法,如「男主穿越修仙界靠做菜无敌」')
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
setSuggesting(true)
|
|
105
|
+
setError('')
|
|
106
|
+
try {
|
|
107
|
+
const exclude = candidates
|
|
108
|
+
.filter(c => pinned.includes(c.id))
|
|
109
|
+
.map(c => `${c.bookName}:${c.sellingPoint}${c.genre !== '' ? `(${c.genre})` : ''}`)
|
|
110
|
+
const count = Math.max(1, 3 - pinned.length)
|
|
111
|
+
const result = await api.outlineSuggest(idea.trim(), count, exclude)
|
|
112
|
+
// 换批合并:已暂留的原地保留,新生成的补充进空槽。
|
|
113
|
+
setCandidates(prev => {
|
|
114
|
+
const kept = prev.filter(c => pinned.includes(c.id))
|
|
115
|
+
return [...kept, ...result.candidates].slice(0, 3)
|
|
116
|
+
})
|
|
117
|
+
setFillNotice('')
|
|
118
|
+
} catch (err) {
|
|
119
|
+
setError((err as Error).message)
|
|
120
|
+
} finally {
|
|
121
|
+
setSuggesting(false)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** 暂留/取消暂留。 */
|
|
126
|
+
const togglePin = (id: string): void => {
|
|
127
|
+
setPinned(prev => prev.includes(id) ? prev.filter(x => x !== id) : [...prev, id])
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** 选中方案:回填大纲框 + 书名,滚动到上方。 */
|
|
131
|
+
const handlePick = (candidate: OutlineCandidate): void => {
|
|
132
|
+
setOutlineText(candidate.outline)
|
|
133
|
+
setName(candidate.bookName)
|
|
134
|
+
setSelectedGenre(candidate.genre ?? '')
|
|
135
|
+
setFillNotice(`已填入方案《${candidate.bookName}》(${candidate.genre}),可继续修改后开书`)
|
|
136
|
+
setIdeaOpen(false)
|
|
137
|
+
window.scrollTo({ top: 0, behavior: 'smooth' })
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const handleCreate = async (): Promise<void> => {
|
|
141
|
+
if (effectiveName === '') {
|
|
142
|
+
setError('请填写书名,或提供大纲自动识别')
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
setBusy(true)
|
|
146
|
+
setError('')
|
|
147
|
+
try {
|
|
148
|
+
const snapshot = await api.bookCreate(effectiveName, undefined, outlineText.trim() !== '' ? outlineText.trim() : undefined)
|
|
149
|
+
const created = snapshot.books.find(b => b.id === snapshot.activeBookId)
|
|
150
|
+
if (created !== undefined) {
|
|
151
|
+
// 选定方案自带题材,或从大纲关键词识别到题材 → 创建后自动预填到本书创作资产(失败不阻断开书)。
|
|
152
|
+
const detectedGenre = selectedGenre.trim() !== '' ? selectedGenre.trim() : (guessGenre(outlineText) ?? '')
|
|
153
|
+
if (detectedGenre !== '') {
|
|
154
|
+
try {
|
|
155
|
+
setCurrentBook(created.id)
|
|
156
|
+
await api.patchAssets({ genre: { name: detectedGenre, description: '', children: [] } })
|
|
157
|
+
} catch { /* ignore */ }
|
|
158
|
+
}
|
|
159
|
+
onCreated(created.id)
|
|
160
|
+
} else {
|
|
161
|
+
setError('开书失败:未找到新书')
|
|
162
|
+
}
|
|
163
|
+
} catch (err) {
|
|
164
|
+
setError((err as Error).message)
|
|
165
|
+
} finally {
|
|
166
|
+
setBusy(false)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<SubPage
|
|
172
|
+
title="开书向导"
|
|
173
|
+
meta="把一份大纲「编译」成一本完整的小说"
|
|
174
|
+
back={{ label: '书架', onClick: onBack }}
|
|
175
|
+
>
|
|
176
|
+
<div className={css.createBookInner}>
|
|
177
|
+
{error !== '' && (
|
|
178
|
+
<div className={css.card} style={{ borderColor: 'var(--nf-error)', padding: 'var(--nf-space-8) var(--nf-space-12)' }}>
|
|
179
|
+
<span style={{ color: 'var(--nf-error)', fontSize: 'var(--nf-fs-12)' }}>{error}</span>
|
|
180
|
+
</div>
|
|
181
|
+
)}
|
|
182
|
+
|
|
183
|
+
{fillNotice !== '' && (
|
|
184
|
+
<div className={css.card} style={{ borderColor: 'var(--nf-success)', padding: 'var(--nf-space-8) var(--nf-space-12)' }}>
|
|
185
|
+
<span style={{ color: 'var(--nf-success)', fontSize: 'var(--nf-fs-12)' }}> {fillNotice}</span>
|
|
186
|
+
</div>
|
|
187
|
+
)}
|
|
188
|
+
|
|
189
|
+
<div className={css.field}>
|
|
190
|
+
<label className={css.fieldLabel}>书名</label>
|
|
191
|
+
<input
|
|
192
|
+
className={css.input}
|
|
193
|
+
placeholder={autoName !== '' ? `自动识别:${autoName}` : '输入书名(提供大纲后自动识别)'}
|
|
194
|
+
value={name}
|
|
195
|
+
onChange={e => { setName(e.target.value) }}
|
|
196
|
+
onKeyDown={e => { if (e.key === 'Enter') void handleCreate() }}
|
|
197
|
+
autoFocus
|
|
198
|
+
/>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<div className={css.field}>
|
|
202
|
+
<label className={css.fieldLabel}>大纲</label>
|
|
203
|
+
<div
|
|
204
|
+
className={`${css.dropzone} ${dragActive ? css.dropzoneActive : ''}`}
|
|
205
|
+
role="button"
|
|
206
|
+
tabIndex={0}
|
|
207
|
+
aria-label="选择或拖入 docx 大纲文件"
|
|
208
|
+
onClick={() => { outlineFileRef.current?.click() }}
|
|
209
|
+
onKeyDown={e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); outlineFileRef.current?.click() } }}
|
|
210
|
+
onDragOver={e => { e.preventDefault(); setDragActive(true) }}
|
|
211
|
+
onDragLeave={() => { setDragActive(false) }}
|
|
212
|
+
onDrop={e => {
|
|
213
|
+
e.preventDefault()
|
|
214
|
+
setDragActive(false)
|
|
215
|
+
void handlePickOutlineFile(e.dataTransfer.files?.[0])
|
|
216
|
+
}}
|
|
217
|
+
>
|
|
218
|
+
<span className={css.dropzoneIcon}></span>
|
|
219
|
+
<span>{outlineName !== '' ? `已选择:${outlineName}` : '点击选择 docx 大纲,或将文件拖到这里'}</span>
|
|
220
|
+
<span className={css.meta}>推荐提供大纲:开书即建立项目,书名自动识别</span>
|
|
221
|
+
<input
|
|
222
|
+
ref={outlineFileRef}
|
|
223
|
+
type="file"
|
|
224
|
+
accept=".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
|
225
|
+
style={{ display: 'none' }}
|
|
226
|
+
onChange={e => {
|
|
227
|
+
void handlePickOutlineFile(e.target.files?.[0])
|
|
228
|
+
e.target.value = ''
|
|
229
|
+
}}
|
|
230
|
+
/>
|
|
231
|
+
</div>
|
|
232
|
+
<textarea
|
|
233
|
+
className={css.textarea}
|
|
234
|
+
style={{ minHeight: 130 }}
|
|
235
|
+
placeholder="或直接粘贴大纲文本(50 字以上)…"
|
|
236
|
+
value={outlineText}
|
|
237
|
+
onChange={e => { setOutlineText(e.target.value) }}
|
|
238
|
+
spellCheck={false}
|
|
239
|
+
/>
|
|
240
|
+
</div>
|
|
241
|
+
|
|
242
|
+
{(outlineText.trim().length > 0 || effectiveName !== '') && (
|
|
243
|
+
<div className={css.row} style={{ flexWrap: 'wrap' }}>
|
|
244
|
+
{outlineText.trim().length > 0 && <span className={css.meta}>大纲 {outlineText.length} 字</span>}
|
|
245
|
+
{effectiveName !== '' && <span className={css.meta}>书名:{effectiveName}</span>}
|
|
246
|
+
{genre !== null && <span className={css.meta}>题材:{genre}</span>}
|
|
247
|
+
</div>
|
|
248
|
+
)}
|
|
249
|
+
|
|
250
|
+
{/* 想法 → AI 大纲(可折叠) */}
|
|
251
|
+
<div className={css.ideaCard}>
|
|
252
|
+
<button
|
|
253
|
+
type="button"
|
|
254
|
+
className={css.ideaToggle}
|
|
255
|
+
onClick={() => { setIdeaOpen(v => !v) }}
|
|
256
|
+
aria-expanded={ideaOpen}
|
|
257
|
+
>
|
|
258
|
+
{ideaOpen ? '▾' : '▸'} 没有大纲?用一句话想法让 生成
|
|
259
|
+
</button>
|
|
260
|
+
{ideaOpen && (
|
|
261
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-8)' }}>
|
|
262
|
+
<textarea
|
|
263
|
+
className={css.textarea}
|
|
264
|
+
style={{ minHeight: 60 }}
|
|
265
|
+
placeholder="例如:现代外卖员被雷劈穿越到修仙世界,靠祖传古玉捡漏发育,苟着苟着成了大佬…(≥50 字)"
|
|
266
|
+
value={idea}
|
|
267
|
+
onChange={e => { setIdea(e.target.value) }}
|
|
268
|
+
spellCheck={false}
|
|
269
|
+
/>
|
|
270
|
+
<div className={css.row} style={{ flexWrap: 'wrap' }}>
|
|
271
|
+
<button
|
|
272
|
+
type="button"
|
|
273
|
+
className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`}
|
|
274
|
+
disabled={suggesting || idea.trim().length < 10}
|
|
275
|
+
onClick={() => { void handleSuggest() }}
|
|
276
|
+
title="生成 3 个方向不同的大纲方案供选择(约消耗 6-8k token)"
|
|
277
|
+
>
|
|
278
|
+
{suggesting ? '⏳ 生成中…' : candidates.length === 0 ? ' 生成大纲方案' : `↻ 换一批(${Math.max(1, 3 - pinned.length)} 个)`}
|
|
279
|
+
</button>
|
|
280
|
+
{candidates.length > 0 && (
|
|
281
|
+
<span className={css.meta}>
|
|
282
|
+
已暂留 {pinned.length}/3 · 换批保留已暂留,只补新方案
|
|
283
|
+
</span>
|
|
284
|
+
)}
|
|
285
|
+
</div>
|
|
286
|
+
|
|
287
|
+
{/* 方案卡 */}
|
|
288
|
+
{candidates.length > 0 && (
|
|
289
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-8)' }}>
|
|
290
|
+
{candidates.map(candidate => {
|
|
291
|
+
const isPinned = pinned.includes(candidate.id)
|
|
292
|
+
return (
|
|
293
|
+
<div
|
|
294
|
+
key={candidate.id}
|
|
295
|
+
className={css.ideaCandidate}
|
|
296
|
+
style={isPinned ? { borderColor: 'var(--nf-accent)', boxShadow: '0 0 0 2px var(--nf-accent-soft)' } : undefined}
|
|
297
|
+
>
|
|
298
|
+
<div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap', gap: 'var(--nf-space-6)' }}>
|
|
299
|
+
<span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-8)', flexWrap: 'wrap' }}>
|
|
300
|
+
<b>《{candidate.bookName}》</b>
|
|
301
|
+
{candidate.genre !== '' && <span className={css.badge} style={{ borderColor: 'var(--nf-accent)', color: 'var(--nf-accent)' }}>{candidate.genre}</span>}
|
|
302
|
+
{isPinned && <span className={css.badge} style={{ borderColor: 'var(--nf-warn)', color: 'var(--nf-warn)' }}>★ 已暂留</span>}
|
|
303
|
+
</span>
|
|
304
|
+
<span style={{ display: 'flex', gap: 'var(--nf-space-6)' }}>
|
|
305
|
+
<button
|
|
306
|
+
type="button"
|
|
307
|
+
className={`${css.button} ${css.buttonSmall} ${isPinned ? '' : css.buttonPrimary}`}
|
|
308
|
+
onClick={() => { togglePin(candidate.id) }}
|
|
309
|
+
title={isPinned ? '取消暂留:下次换批会覆盖此槽位' : '暂留此方案:换批时保留,继续对比新方案'}
|
|
310
|
+
>
|
|
311
|
+
{isPinned ? '★ 取消暂留' : '☆ 暂留'}
|
|
312
|
+
</button>
|
|
313
|
+
<button
|
|
314
|
+
type="button"
|
|
315
|
+
className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`}
|
|
316
|
+
onClick={() => { handlePick(candidate) }}
|
|
317
|
+
title="将这份大纲填入上方大纲框(可继续修改后开书)"
|
|
318
|
+
>
|
|
319
|
+
选这个
|
|
320
|
+
</button>
|
|
321
|
+
</span>
|
|
322
|
+
</div>
|
|
323
|
+
{candidate.sellingPoint !== '' && (
|
|
324
|
+
<div className={css.meta}><b>卖点:</b>{candidate.sellingPoint}</div>
|
|
325
|
+
)}
|
|
326
|
+
<div
|
|
327
|
+
className={css.meta}
|
|
328
|
+
style={{
|
|
329
|
+
display: '-webkit-box',
|
|
330
|
+
WebkitLineClamp: 4,
|
|
331
|
+
WebkitBoxOrient: 'vertical',
|
|
332
|
+
overflow: 'hidden',
|
|
333
|
+
whiteSpace: 'pre-wrap',
|
|
334
|
+
}}
|
|
335
|
+
title={candidate.outline}
|
|
336
|
+
>
|
|
337
|
+
{candidate.outline}
|
|
338
|
+
</div>
|
|
339
|
+
</div>
|
|
340
|
+
)
|
|
341
|
+
})}
|
|
342
|
+
{pinned.length >= 3 && (
|
|
343
|
+
<span className={css.meta}>已暂留全部方案——直接挑一个「选这个」即可;换批需先取消某个暂留。</span>
|
|
344
|
+
)}
|
|
345
|
+
</div>
|
|
346
|
+
)}
|
|
347
|
+
</div>
|
|
348
|
+
)}
|
|
349
|
+
</div>
|
|
350
|
+
|
|
351
|
+
<button
|
|
352
|
+
type="button"
|
|
353
|
+
className={`${css.button} ${css.buttonPrimary}`}
|
|
354
|
+
style={{ width: '100%', padding: 'var(--nf-space-10) 0', fontSize: 'var(--nf-fs-14)' }}
|
|
355
|
+
disabled={busy || effectiveName === ''}
|
|
356
|
+
onClick={() => { void handleCreate() }}
|
|
357
|
+
>
|
|
358
|
+
开书并进入工作台
|
|
359
|
+
</button>
|
|
360
|
+
<span className={css.meta} style={{ textAlign: 'center' }}>
|
|
361
|
+
未提供大纲也能开书,稍后可在大纲页导入
|
|
362
|
+
</span>
|
|
363
|
+
</div>
|
|
364
|
+
</SubPage>
|
|
365
|
+
)
|
|
366
|
+
}
|