@waterwx/dsh-novel-forge 1.2.1-alpha → 1.3.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 (52) hide show
  1. package/README.md +4 -5
  2. package/lib/client.js +2470 -858
  3. package/lib/index.js +2155 -388
  4. package/lib/types/action-guard.d.ts +1 -1
  5. package/lib/types/assets.d.ts +7 -7
  6. package/lib/types/client/api.d.ts +31 -1
  7. package/lib/types/client/llmLive.d.ts +12 -14
  8. package/lib/types/client/panel/LiveFeedLog.d.ts +5 -0
  9. package/lib/types/client/panel/ModelManager.d.ts +2 -2
  10. package/lib/types/client/panel/PromptSlotsView.d.ts +11 -0
  11. package/lib/types/client/panel/TensionView.d.ts +14 -0
  12. package/lib/types/client/panel/TimelineView.d.ts +14 -0
  13. package/lib/types/engine.d.ts +40 -2
  14. package/lib/types/index.d.ts +4 -0
  15. package/lib/types/llm-live.d.ts +65 -34
  16. package/lib/types/llm-retry.d.ts +38 -0
  17. package/lib/types/market-radar-sources.d.ts +1 -1
  18. package/lib/types/prompt-slots.d.ts +57 -0
  19. package/lib/types/prompting.d.ts +2 -2
  20. package/lib/types/protocol.d.ts +283 -3
  21. package/lib/types/snapshots.d.ts +46 -0
  22. package/lib/types/stage-contract.d.ts +1 -1
  23. package/lib/types/tension.d.ts +65 -0
  24. package/lib/types/timeline.d.ts +37 -0
  25. package/package.json +3 -2
  26. package/src/action-guard.ts +1 -1
  27. package/src/assets.ts +300 -268
  28. package/src/assistant.ts +45 -29
  29. package/src/client/api.ts +76 -2
  30. package/src/client/llmLive.ts +26 -16
  31. package/src/client/panel/AssetsTab.tsx +2 -2
  32. package/src/client/panel/LiveFeedLog.tsx +204 -67
  33. package/src/client/panel/ModelManager.tsx +2 -2
  34. package/src/client/panel/NovelPanel.tsx +127 -13
  35. package/src/client/panel/PromptSlotsView.tsx +97 -0
  36. package/src/client/panel/SettingsView.tsx +35 -0
  37. package/src/client/panel/TensionView.tsx +196 -0
  38. package/src/client/panel/TimelineView.tsx +192 -0
  39. package/src/engine.ts +549 -108
  40. package/src/index.ts +12 -0
  41. package/src/llm-live.ts +260 -68
  42. package/src/llm-retry.ts +77 -0
  43. package/src/market-radar-sources.ts +173 -173
  44. package/src/prompt-slots.ts +125 -0
  45. package/src/prompting.ts +8 -8
  46. package/src/protocol.ts +314 -3
  47. package/src/routes.ts +325 -6
  48. package/src/run.ts +4 -0
  49. package/src/snapshots.ts +174 -0
  50. package/src/stage-contract.ts +189 -189
  51. package/src/tension.ts +240 -0
  52. package/src/timeline.ts +159 -0
@@ -1,173 +1,173 @@
1
- /**
2
- * 「热门题材雷达」真实榜单抓取源(移植自 AI-Novel-Writing-Assistant marketRadarSources)。
3
- * 用全局 fetch 抓取公开榜单移动版页面,正则抽取元数据;无第三方依赖。
4
- */
5
- export type MarketRadarPlatform = 'fanqie' | 'qidian' | 'jinjiang'
6
-
7
- export interface MarketRadarListSource {
8
- platform: MarketRadarPlatform
9
- platformLabel: string
10
- listKey: string
11
- listLabel: string
12
- channel: string
13
- sourceUrl: string
14
- }
15
-
16
- export interface CollectedRankingItem {
17
- rank: number
18
- title: string
19
- author?: string
20
- category?: string
21
- tags: string[]
22
- synopsis?: string
23
- heatLabel?: string
24
- serialStatus?: string
25
- sourceUrl: string
26
- }
27
-
28
- export const MARKET_RADAR_SOURCES: MarketRadarListSource[] = [
29
- { platform: 'fanqie', platformLabel: '番茄小说', listKey: 'reading', listLabel: '阅读榜', channel: 'general', sourceUrl: 'https://fanqienovel.com/rank' },
30
- { platform: 'fanqie', platformLabel: '番茄小说', listKey: 'new_book', listLabel: '新书榜', channel: 'general', sourceUrl: 'https://fanqienovel.com/rank/1_1' },
31
- { platform: 'qidian', platformLabel: '起点中文网', listKey: 'hotsales', listLabel: '畅销榜', channel: 'male', sourceUrl: 'https://m.qidian.com/rank/hotsales/' },
32
- { platform: 'qidian', platformLabel: '起点中文网', listKey: 'monthly_ticket', listLabel: '月票榜', channel: 'male', sourceUrl: 'https://m.qidian.com/rank/yuepiao/' },
33
- { platform: 'qidian', platformLabel: '起点中文网', listKey: 'new_book', listLabel: '新书榜', channel: 'male', sourceUrl: 'https://m.qidian.com/rank/' },
34
- { platform: 'jinjiang', platformLabel: '晋江文学城', listKey: 'monthly', listLabel: '月度榜', channel: 'female', sourceUrl: 'https://m.jjwxc.net/rank/naturalmore/5' },
35
- { platform: 'jinjiang', platformLabel: '晋江文学城', listKey: 'quarterly', listLabel: '季度榜', channel: 'female', sourceUrl: 'https://m.jjwxc.net/rank/naturalmore/6' },
36
- { platform: 'jinjiang', platformLabel: '晋江文学城', listKey: 'new_author', listLabel: '新晋作者榜', channel: 'female', sourceUrl: 'https://m.jjwxc.net/rank/naturalmore/29' },
37
- ]
38
-
39
- const NAMED_ENTITIES: Record<string, string> = {
40
- amp: '&', apos: "'", gt: '>', lt: '<', nbsp: ' ', quot: '"',
41
- }
42
-
43
- function decodeEntities(value: string): string {
44
- return value.replace(/&(#x?[0-9a-f]+|[a-z]+);/gi, (_, key: string) => {
45
- if (key.startsWith('#')) {
46
- const hexadecimal = key[1]?.toLowerCase() === 'x'
47
- const code = Number.parseInt(key.slice(hexadecimal ? 2 : 1), hexadecimal ? 16 : 10)
48
- return Number.isFinite(code) ? String.fromCodePoint(code) : ''
49
- }
50
- return NAMED_ENTITIES[key.toLowerCase()] ?? ''
51
- })
52
- }
53
-
54
- function plainText(value: string | undefined): string {
55
- return decodeEntities((value ?? '').replace(/<[^>]*>/g, ' ')).replace(/\s+/g, ' ').trim()
56
- }
57
-
58
- function absoluteUrl(base: string, value: string): string {
59
- return new URL(value.startsWith('//') ? `https:${value}` : value, base).toString()
60
- }
61
-
62
- function extractTags(synopsis: string): string[] {
63
- const bracketed = synopsis.match(/^[【〖\[]([^】〗\]]+)[】〗\]]/g) ?? []
64
- return bracketed.flatMap((part) => plainText(part).replace(/^[【〖\[]|[】〗\]]$/g, '').split(/[++、|]/))
65
- .map((tag) => tag.trim()).filter(Boolean).slice(0, 12)
66
- }
67
-
68
- export function hasPrivateUseCharacters(value: string | null | undefined): boolean {
69
- return /[\uE000-\uF8FF]/u.test(value ?? '')
70
- }
71
-
72
- export function parseFanqieRanking(html: string, source: MarketRadarListSource): CollectedRankingItem[] {
73
- const blocks = html.match(/<div class="rank-book-item">[\s\S]*?(?=<div class="rank-book-item">|<\/main>|<footer|<\/body>)/g) ?? []
74
- return blocks.slice(0, 30).flatMap((block, index) => {
75
- const titleMatch = block.match(/<div class="title">\s*<a href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/)
76
- if (!titleMatch) return []
77
- const synopsis = plainText(block.match(/<div class="desc abstract[^>]*>([\s\S]*?)<\/div>/)?.[1])
78
- const footer = plainText(block.match(/<div class="book-item-footer">([\s\S]*?)<\/div>/)?.[1])
79
- return [{
80
- rank: Number(block.match(/book-item-index"><h1>(\d+)<\/h1>/)?.[1] ?? index + 1),
81
- title: plainText(titleMatch[2]),
82
- author: plainText(block.match(/<div class="author">[\s\S]*?<span[^>]*>([\s\S]*?)<\/span>/)?.[1]),
83
- tags: extractTags(synopsis),
84
- synopsis: synopsis.slice(0, 800),
85
- heatLabel: footer.match(/在读[^\s,。]*/)?.[0],
86
- serialStatus: footer.match(/连载中|已完结/)?.[0],
87
- sourceUrl: absoluteUrl(source.sourceUrl, titleMatch[1]),
88
- }]
89
- })
90
- }
91
-
92
- export function parseFanqieDetail(html: string, item: CollectedRankingItem): CollectedRankingItem {
93
- const title = plainText(html.match(/<h1[^>]*>([\s\S]*?)<\/h1>/)?.[1])
94
- const author = plainText(html.match(/author-name-text[^>]*>([\s\S]*?)<\/a>/)?.[1])
95
- const synopsis = plainText(html.match(/<div class="page-abstract-content"[^>]*>\s*<p[^>]*>([\s\S]*?)<\/p>/)?.[1])
96
- if (!title || hasPrivateUseCharacters(title)) throw new Error('作品详情页未提供可读书名')
97
- return {
98
- ...item,
99
- title,
100
- author: author && !hasPrivateUseCharacters(author) ? author : undefined,
101
- synopsis: synopsis && !hasPrivateUseCharacters(synopsis) ? synopsis.slice(0, 800) : undefined,
102
- tags: synopsis && !hasPrivateUseCharacters(synopsis) ? extractTags(synopsis) : [],
103
- }
104
- }
105
-
106
- export function parseQidianRanking(html: string, source: MarketRadarListSource): CollectedRankingItem[] {
107
- const escapedLabel = source.listLabel.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
108
- const itemPattern = new RegExp(`<a[^>]+href="([^"]*\\/book\\/[^"?]+)[^"]*"[^>]*>[\\s\\S]*?<h2[^>]+title="${escapedLabel}第(\\d+)位"[^>]*>([\\s\\S]*?)<\\/h2>[\\s\\S]*?<p[^>]*class="[^"]*subTitle[^"]*"[^>]*>([\\s\\S]*?)<\\/p>[\\s\\S]*?<\\/a>`, 'g')
109
- return Array.from(html.matchAll(itemPattern)).slice(0, 30).map((match) => {
110
- const subTitle = plainText(match[4])
111
- const parts = subTitle.split('·').map((part) => part.trim()).filter(Boolean)
112
- return {
113
- rank: Number(match[2]),
114
- title: plainText(match[3]),
115
- author: parts[0],
116
- category: parts[1],
117
- tags: parts[1] ? [parts[1]] : [],
118
- heatLabel: parts[2],
119
- sourceUrl: absoluteUrl(source.sourceUrl, match[1]),
120
- }
121
- })
122
- }
123
-
124
- export function parseJinjiangRanking(html: string, source: MarketRadarListSource): CollectedRankingItem[] {
125
- const items = Array.from(html.matchAll(/<li[^>]*>\s*<a href="(\/book2\/\d+)"[^>]*>([\s\S]*?)<\/a>[\s\S]*?<\/li>/g))
126
- return items.slice(0, 30).map((match, index) => ({
127
- rank: index + 1,
128
- title: plainText(match[2]),
129
- tags: [],
130
- sourceUrl: absoluteUrl(source.sourceUrl, match[1]),
131
- }))
132
- }
133
-
134
- async function fetchHtml(url: string): Promise<string> {
135
- const response = await fetch(url, {
136
- headers: { 'user-agent': 'Mozilla/5.0 (compatible; AI-Novel-Market-Radar/1.0; public-ranking-metadata-only)' },
137
- signal: AbortSignal.timeout(20_000),
138
- })
139
- if (!response.ok) throw new Error(`榜单页面返回 HTTP ${response.status}`)
140
- const bytes = await response.arrayBuffer()
141
- const headerCharset = response.headers.get('content-type')?.match(/charset=([^;]+)/i)?.[1]?.trim()
142
- const metaProbe = new TextDecoder('latin1').decode(bytes.slice(0, 4096))
143
- const metaCharset = metaProbe.match(/charset\s*=\s*["']?([\w-]+)/i)?.[1]
144
- const charset = headerCharset || metaCharset || 'utf-8'
145
- return new TextDecoder(charset).decode(bytes)
146
- }
147
-
148
- async function hydrateFanqieItems(items: CollectedRankingItem[]): Promise<CollectedRankingItem[]> {
149
- const hydrated: CollectedRankingItem[] = []
150
- for (let offset = 0; offset < items.length; offset += 4) {
151
- const batch = await Promise.all(items.slice(offset, offset + 4).map(async (item) => {
152
- const containsObfuscatedText = [item.title, item.author, item.synopsis].some(hasPrivateUseCharacters)
153
- if (!containsObfuscatedText) return item
154
- try { return parseFanqieDetail(await fetchHtml(item.sourceUrl), item) }
155
- catch { return null }
156
- }))
157
- hydrated.push(...batch.filter((item): item is CollectedRankingItem => item !== null))
158
- }
159
- return hydrated
160
- }
161
-
162
- export async function collectMarketSource(source: MarketRadarListSource): Promise<CollectedRankingItem[]> {
163
- const html = await fetchHtml(source.sourceUrl)
164
- const parsers: Record<MarketRadarPlatform, (value: string, item: MarketRadarListSource) => CollectedRankingItem[]> = {
165
- fanqie: parseFanqieRanking,
166
- qidian: parseQidianRanking,
167
- jinjiang: parseJinjiangRanking,
168
- }
169
- const parsed = parsers[source.platform](html, source)
170
- const items = source.platform === 'fanqie' ? await hydrateFanqieItems(parsed) : parsed
171
- if (items.length === 0) throw new Error('榜单页面结构可能已变化,未识别到公开作品元数据')
172
- return items
173
- }
1
+ /**
2
+ * 「热门题材雷达」真实榜单抓取源(公开榜单页面的地址与选择器,属事实性配置)。
3
+ * 用全局 fetch 抓取公开榜单移动版页面,正则抽取元数据;无第三方依赖。
4
+ */
5
+ export type MarketRadarPlatform = 'fanqie' | 'qidian' | 'jinjiang'
6
+
7
+ export interface MarketRadarListSource {
8
+ platform: MarketRadarPlatform
9
+ platformLabel: string
10
+ listKey: string
11
+ listLabel: string
12
+ channel: string
13
+ sourceUrl: string
14
+ }
15
+
16
+ export interface CollectedRankingItem {
17
+ rank: number
18
+ title: string
19
+ author?: string
20
+ category?: string
21
+ tags: string[]
22
+ synopsis?: string
23
+ heatLabel?: string
24
+ serialStatus?: string
25
+ sourceUrl: string
26
+ }
27
+
28
+ export const MARKET_RADAR_SOURCES: MarketRadarListSource[] = [
29
+ { platform: 'fanqie', platformLabel: '番茄小说', listKey: 'reading', listLabel: '阅读榜', channel: 'general', sourceUrl: 'https://fanqienovel.com/rank' },
30
+ { platform: 'fanqie', platformLabel: '番茄小说', listKey: 'new_book', listLabel: '新书榜', channel: 'general', sourceUrl: 'https://fanqienovel.com/rank/1_1' },
31
+ { platform: 'qidian', platformLabel: '起点中文网', listKey: 'hotsales', listLabel: '畅销榜', channel: 'male', sourceUrl: 'https://m.qidian.com/rank/hotsales/' },
32
+ { platform: 'qidian', platformLabel: '起点中文网', listKey: 'monthly_ticket', listLabel: '月票榜', channel: 'male', sourceUrl: 'https://m.qidian.com/rank/yuepiao/' },
33
+ { platform: 'qidian', platformLabel: '起点中文网', listKey: 'new_book', listLabel: '新书榜', channel: 'male', sourceUrl: 'https://m.qidian.com/rank/' },
34
+ { platform: 'jinjiang', platformLabel: '晋江文学城', listKey: 'monthly', listLabel: '月度榜', channel: 'female', sourceUrl: 'https://m.jjwxc.net/rank/naturalmore/5' },
35
+ { platform: 'jinjiang', platformLabel: '晋江文学城', listKey: 'quarterly', listLabel: '季度榜', channel: 'female', sourceUrl: 'https://m.jjwxc.net/rank/naturalmore/6' },
36
+ { platform: 'jinjiang', platformLabel: '晋江文学城', listKey: 'new_author', listLabel: '新晋作者榜', channel: 'female', sourceUrl: 'https://m.jjwxc.net/rank/naturalmore/29' },
37
+ ]
38
+
39
+ const NAMED_ENTITIES: Record<string, string> = {
40
+ amp: '&', apos: "'", gt: '>', lt: '<', nbsp: ' ', quot: '"',
41
+ }
42
+
43
+ function decodeEntities(value: string): string {
44
+ return value.replace(/&(#x?[0-9a-f]+|[a-z]+);/gi, (_, key: string) => {
45
+ if (key.startsWith('#')) {
46
+ const hexadecimal = key[1]?.toLowerCase() === 'x'
47
+ const code = Number.parseInt(key.slice(hexadecimal ? 2 : 1), hexadecimal ? 16 : 10)
48
+ return Number.isFinite(code) ? String.fromCodePoint(code) : ''
49
+ }
50
+ return NAMED_ENTITIES[key.toLowerCase()] ?? ''
51
+ })
52
+ }
53
+
54
+ function plainText(value: string | undefined): string {
55
+ return decodeEntities((value ?? '').replace(/<[^>]*>/g, ' ')).replace(/\s+/g, ' ').trim()
56
+ }
57
+
58
+ function absoluteUrl(base: string, value: string): string {
59
+ return new URL(value.startsWith('//') ? `https:${value}` : value, base).toString()
60
+ }
61
+
62
+ function extractTags(synopsis: string): string[] {
63
+ const bracketed = synopsis.match(/^[【〖\[]([^】〗\]]+)[】〗\]]/g) ?? []
64
+ return bracketed.flatMap((part) => plainText(part).replace(/^[【〖\[]|[】〗\]]$/g, '').split(/[++、|]/))
65
+ .map((tag) => tag.trim()).filter(Boolean).slice(0, 12)
66
+ }
67
+
68
+ export function hasPrivateUseCharacters(value: string | null | undefined): boolean {
69
+ return /[\uE000-\uF8FF]/u.test(value ?? '')
70
+ }
71
+
72
+ export function parseFanqieRanking(html: string, source: MarketRadarListSource): CollectedRankingItem[] {
73
+ const blocks = html.match(/<div class="rank-book-item">[\s\S]*?(?=<div class="rank-book-item">|<\/main>|<footer|<\/body>)/g) ?? []
74
+ return blocks.slice(0, 30).flatMap((block, index) => {
75
+ const titleMatch = block.match(/<div class="title">\s*<a href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/)
76
+ if (!titleMatch) return []
77
+ const synopsis = plainText(block.match(/<div class="desc abstract[^>]*>([\s\S]*?)<\/div>/)?.[1])
78
+ const footer = plainText(block.match(/<div class="book-item-footer">([\s\S]*?)<\/div>/)?.[1])
79
+ return [{
80
+ rank: Number(block.match(/book-item-index"><h1>(\d+)<\/h1>/)?.[1] ?? index + 1),
81
+ title: plainText(titleMatch[2]),
82
+ author: plainText(block.match(/<div class="author">[\s\S]*?<span[^>]*>([\s\S]*?)<\/span>/)?.[1]),
83
+ tags: extractTags(synopsis),
84
+ synopsis: synopsis.slice(0, 800),
85
+ heatLabel: footer.match(/在读[^\s,。]*/)?.[0],
86
+ serialStatus: footer.match(/连载中|已完结/)?.[0],
87
+ sourceUrl: absoluteUrl(source.sourceUrl, titleMatch[1]),
88
+ }]
89
+ })
90
+ }
91
+
92
+ export function parseFanqieDetail(html: string, item: CollectedRankingItem): CollectedRankingItem {
93
+ const title = plainText(html.match(/<h1[^>]*>([\s\S]*?)<\/h1>/)?.[1])
94
+ const author = plainText(html.match(/author-name-text[^>]*>([\s\S]*?)<\/a>/)?.[1])
95
+ const synopsis = plainText(html.match(/<div class="page-abstract-content"[^>]*>\s*<p[^>]*>([\s\S]*?)<\/p>/)?.[1])
96
+ if (!title || hasPrivateUseCharacters(title)) throw new Error('作品详情页未提供可读书名')
97
+ return {
98
+ ...item,
99
+ title,
100
+ author: author && !hasPrivateUseCharacters(author) ? author : undefined,
101
+ synopsis: synopsis && !hasPrivateUseCharacters(synopsis) ? synopsis.slice(0, 800) : undefined,
102
+ tags: synopsis && !hasPrivateUseCharacters(synopsis) ? extractTags(synopsis) : [],
103
+ }
104
+ }
105
+
106
+ export function parseQidianRanking(html: string, source: MarketRadarListSource): CollectedRankingItem[] {
107
+ const escapedLabel = source.listLabel.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
108
+ const itemPattern = new RegExp(`<a[^>]+href="([^"]*\\/book\\/[^"?]+)[^"]*"[^>]*>[\\s\\S]*?<h2[^>]+title="${escapedLabel}第(\\d+)位"[^>]*>([\\s\\S]*?)<\\/h2>[\\s\\S]*?<p[^>]*class="[^"]*subTitle[^"]*"[^>]*>([\\s\\S]*?)<\\/p>[\\s\\S]*?<\\/a>`, 'g')
109
+ return Array.from(html.matchAll(itemPattern)).slice(0, 30).map((match) => {
110
+ const subTitle = plainText(match[4])
111
+ const parts = subTitle.split('·').map((part) => part.trim()).filter(Boolean)
112
+ return {
113
+ rank: Number(match[2]),
114
+ title: plainText(match[3]),
115
+ author: parts[0],
116
+ category: parts[1],
117
+ tags: parts[1] ? [parts[1]] : [],
118
+ heatLabel: parts[2],
119
+ sourceUrl: absoluteUrl(source.sourceUrl, match[1]),
120
+ }
121
+ })
122
+ }
123
+
124
+ export function parseJinjiangRanking(html: string, source: MarketRadarListSource): CollectedRankingItem[] {
125
+ const items = Array.from(html.matchAll(/<li[^>]*>\s*<a href="(\/book2\/\d+)"[^>]*>([\s\S]*?)<\/a>[\s\S]*?<\/li>/g))
126
+ return items.slice(0, 30).map((match, index) => ({
127
+ rank: index + 1,
128
+ title: plainText(match[2]),
129
+ tags: [],
130
+ sourceUrl: absoluteUrl(source.sourceUrl, match[1]),
131
+ }))
132
+ }
133
+
134
+ async function fetchHtml(url: string): Promise<string> {
135
+ const response = await fetch(url, {
136
+ headers: { 'user-agent': 'Mozilla/5.0 (compatible; dsh-novel-forge-radar/1.0; public-ranking-metadata-only)' },
137
+ signal: AbortSignal.timeout(20_000),
138
+ })
139
+ if (!response.ok) throw new Error(`榜单页面返回 HTTP ${response.status}`)
140
+ const bytes = await response.arrayBuffer()
141
+ const headerCharset = response.headers.get('content-type')?.match(/charset=([^;]+)/i)?.[1]?.trim()
142
+ const metaProbe = new TextDecoder('latin1').decode(bytes.slice(0, 4096))
143
+ const metaCharset = metaProbe.match(/charset\s*=\s*["']?([\w-]+)/i)?.[1]
144
+ const charset = headerCharset || metaCharset || 'utf-8'
145
+ return new TextDecoder(charset).decode(bytes)
146
+ }
147
+
148
+ async function hydrateFanqieItems(items: CollectedRankingItem[]): Promise<CollectedRankingItem[]> {
149
+ const hydrated: CollectedRankingItem[] = []
150
+ for (let offset = 0; offset < items.length; offset += 4) {
151
+ const batch = await Promise.all(items.slice(offset, offset + 4).map(async (item) => {
152
+ const containsObfuscatedText = [item.title, item.author, item.synopsis].some(hasPrivateUseCharacters)
153
+ if (!containsObfuscatedText) return item
154
+ try { return parseFanqieDetail(await fetchHtml(item.sourceUrl), item) }
155
+ catch { return null }
156
+ }))
157
+ hydrated.push(...batch.filter((item): item is CollectedRankingItem => item !== null))
158
+ }
159
+ return hydrated
160
+ }
161
+
162
+ export async function collectMarketSource(source: MarketRadarListSource): Promise<CollectedRankingItem[]> {
163
+ const html = await fetchHtml(source.sourceUrl)
164
+ const parsers: Record<MarketRadarPlatform, (value: string, item: MarketRadarListSource) => CollectedRankingItem[]> = {
165
+ fanqie: parseFanqieRanking,
166
+ qidian: parseQidianRanking,
167
+ jinjiang: parseJinjiangRanking,
168
+ }
169
+ const parsed = parsers[source.platform](html, source)
170
+ const items = source.platform === 'fanqie' ? await hydrateFanqieItems(parsed) : parsed
171
+ if (items.length === 0) throw new Error('榜单页面结构可能已变化,未识别到公开作品元数据')
172
+ return items
173
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * 提示词槽位:给作者留几个**安全可改**的位置,用来微调本书的写作偏好。
3
+ *
4
+ * 设计边界(很重要):
5
+ * * 槽位只追加"作者偏好",**不允许覆盖**规则工程与合规红线——道藏、写作红线、
6
+ * 九条内容合规红线、反 AI 规则、阶段契约都由宿主锁定,槽位碰不到;
7
+ * * 槽位内容随项目保存(`novel-project.json`),换书即换槽位;
8
+ * * 每个槽位有长度上限,超长直接截断并标记(沿用「截断显式化」的规则)。
9
+ */
10
+
11
+ import type { ProjectState, PromptSlotId } from './protocol.ts'
12
+
13
+ /** 单个槽位的元信息。 */
14
+ export interface PromptSlotSpec {
15
+ id: PromptSlotId
16
+ /** 面板显示名。 */
17
+ label: string
18
+ /** 一句话说明它影响什么。 */
19
+ hint: string
20
+ /** 示例(面板占位符)。 */
21
+ placeholder: string
22
+ /** 字符上限。 */
23
+ maxChars: number
24
+ }
25
+
26
+ /** 允许作者编辑的槽位(白名单;不在此列表的提示词一律不可改)。 */
27
+ export const PROMPT_SLOTS: readonly PromptSlotSpec[] = [
28
+ {
29
+ id: 'styleExtra',
30
+ label: '文风补充',
31
+ hint: '追加到写作提示词末尾的风格偏好(句式、叙述习惯、用词倾向)。',
32
+ placeholder: '例如:多用短句和对话推进,少用成语;环境描写只写能影响动作的部分。',
33
+ maxChars: 1200,
34
+ },
35
+ {
36
+ id: 'antiAiExtra',
37
+ label: '反 AI 补充',
38
+ hint: '本书额外的"别这么写"清单,与内置反 AI 规则叠加(不能覆盖内置规则)。',
39
+ placeholder: '例如:不要每段都用比喻;不要用"空气中弥漫着"这类句式。',
40
+ maxChars: 1200,
41
+ },
42
+ {
43
+ id: 'dialogueExtra',
44
+ label: '对话补充',
45
+ hint: '角色说话方式的额外约束,写入时会与角色卡一起注入。',
46
+ placeholder: '例如:长辈说话带方言词;主角对熟人用绰号称呼。',
47
+ maxChars: 800,
48
+ },
49
+ {
50
+ id: 'endingHookExtra',
51
+ label: '章末钩子偏好',
52
+ hint: '对结尾钩子的额外要求(与章节计划里的 endingHook 叠加)。',
53
+ placeholder: '例如:结尾尽量落在一个未闭合的选择上,而不是新出现的敌人。',
54
+ maxChars: 600,
55
+ },
56
+ ]
57
+
58
+ /** 槽位 id → 规格。 */
59
+ const SLOT_BY_ID = new Map(PROMPT_SLOTS.map(s => [s.id, s] as const))
60
+
61
+ /** 单个槽位的渲染结果。 */
62
+ export interface RenderedSlot {
63
+ id: PromptSlotId
64
+ label: string
65
+ text: string
66
+ /** 是否因超长被截断。 */
67
+ truncated: boolean
68
+ /** 原文长度(截断前)。 */
69
+ chars: number
70
+ }
71
+
72
+ /**
73
+ * 读取并规整项目里的槽位内容(去空白、按上限截断)。
74
+ *
75
+ * @param project 项目状态。
76
+ * @returns 非空槽位列表(保持 PROMPT_SLOTS 的声明顺序)。
77
+ */
78
+ export function readPromptSlots(project: ProjectState): RenderedSlot[] {
79
+ const stored = project.promptSlots ?? {}
80
+ const out: RenderedSlot[] = []
81
+ for (const spec of PROMPT_SLOTS) {
82
+ const raw = (stored[spec.id] ?? '').trim()
83
+ if (raw === '') continue
84
+ const truncated = raw.length > spec.maxChars
85
+ out.push({
86
+ id: spec.id,
87
+ label: spec.label,
88
+ text: truncated ? raw.slice(0, spec.maxChars) : raw,
89
+ truncated,
90
+ chars: raw.length,
91
+ })
92
+ }
93
+ return out
94
+ }
95
+
96
+ /**
97
+ * 把槽位渲染成注入提示词的段落。
98
+ *
99
+ * @param project 项目状态。
100
+ * @returns 提示词片段;无槽位时返回空串。
101
+ */
102
+ export function renderPromptSlots(project: ProjectState): string {
103
+ const slots = readPromptSlots(project)
104
+ if (slots.length === 0) return ''
105
+ const lines = ['==================== 作者偏好(本书自定义,优先级低于道藏/红线/合规) ====================']
106
+ for (const slot of slots) {
107
+ lines.push(`【${slot.label}】${slot.text}${slot.truncated ? `(已按 ${SLOT_BY_ID.get(slot.id)?.maxChars ?? 0} 字上限截断,原 ${slot.chars} 字)` : ''}`)
108
+ }
109
+ lines.push('以上偏好只影响表达方式;与道藏、写作红线、内容合规红线冲突时,一律以后者为准。')
110
+ return lines.join('\n')
111
+ }
112
+
113
+ /**
114
+ * 校验并规整一次槽位写入。
115
+ *
116
+ * @param id 槽位 id。
117
+ * @param value 内容(空串表示清空该槽位)。
118
+ * @returns 归一化后的内容。
119
+ * @throws 槽位 id 不在白名单时抛错。
120
+ */
121
+ export function normalizeSlotValue(id: string, value: string): string {
122
+ const spec = SLOT_BY_ID.get(id as PromptSlotId)
123
+ if (spec === undefined) throw new Error(`未知提示词槽位:${id}`)
124
+ return value.replace(/\r\n/g, '\n').trim()
125
+ }
package/src/prompting.ts CHANGED
@@ -1,5 +1,5 @@
1
- /** 章节写作约束:官方 writer 骨架渲染成可附加到现有系统提示词末尾的必达/禁止/自查块。 */
2
- export function renderOfficialChapterWriterSkeleton(meta: {
1
+ /** 章节写作约束:把写作骨架渲染成可附加到系统提示词末尾的必达/禁止/自查块。 */
2
+ export function renderChapterWriterSkeleton(meta: {
3
3
  targetChars: number
4
4
  minChars: number
5
5
  maxChars: number
@@ -13,14 +13,14 @@ export function renderOfficialChapterWriterSkeleton(meta: {
13
13
  const hook = meta.endingHookPreference ?? '章末留一个明确的钩子(新信息、新风险或未闭合的选择)。'
14
14
  const antiAi = meta.antiAiRules ?? ''
15
15
  return [
16
- '==================== 官方生成骨架(必达 / 禁止 / 输出前自查) ====================',
16
+ '==================== 章节生成骨架(必达 / 禁止 / 输出前自查) ====================',
17
17
  '【叙事视角】' + pov,
18
- '【本章必达】本章必须发生实质变化(局面、关系、信息、风险、决策至少一项);开头迅速进入情境,禁止复述上一章。',
19
- '【禁止事项】不得写总结/复盘/解释性段落为主;不得引入新的核心角色或与上下文冲突的设定;不得为空凑字数。',
20
- '【篇幅】目标 ' + meta.targetChars + ' 字,区间 ' + meta.minChars + '-' + meta.maxChars + ' 字;不够就继续推进有效情节,禁止草草收尾。',
18
+ '【本章必达】本章必须发生实质变化——局面、关系、信息、风险、决策至少动一项;开篇直接进入情境,不复述上一章。',
19
+ '【禁止事项】不写以总结、复盘、解释为主的段落;不新增核心角色,不写入与上下文冲突的设定;不为凑字数注水。',
20
+ '【篇幅】目标 ' + meta.targetChars + ' 字,区间 ' + meta.minChars + '-' + meta.maxChars + ' 字;不够就继续推进有效情节,不许草草收尾。',
21
21
  '【结尾】' + hook,
22
- '【表达】优先用具体动作、对话与可感知细节推进;' + tone,
22
+ '【表达】用具体动作、对话与可感知细节往前推;' + tone,
23
23
  '【反 AI】' + antiAi,
24
- '【输出前自查】先确认:读者回报、关键转折、章末净变化是否可见,旧钩子责任是否回应,人物硬事实是否违背;确认通过后再输出,正文中不要输出核查结果。',
24
+ '【输出前自查】逐项确认:读者的回报、关键转折、章末净变化是否看得见?上一章留下的钩子有没有交代?人物的硬事实有没有被写反?确认无误再输出,正文里不要出现核查过程。',
25
25
  ].join('\n')
26
26
  }