@waterwx/dsh-novel-forge 2.0.0-alpha.1 → 2.0.0

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 (206) hide show
  1. package/README.md +286 -285
  2. package/lib/client.js +19561 -19439
  3. package/lib/index.js +8159 -4456
  4. package/lib/types/action-guard.d.ts +61 -0
  5. package/lib/types/ai-scan.d.ts +0 -6
  6. package/lib/types/assets.d.ts +20 -9
  7. package/lib/types/assistant.d.ts +29 -0
  8. package/lib/types/author-assets.d.ts +1 -3
  9. package/lib/types/bookshelf.d.ts +13 -3
  10. package/lib/types/client/api.d.ts +136 -27
  11. package/lib/types/client/chip-prefs.d.ts +36 -0
  12. package/lib/types/client/docx.d.ts +2 -2
  13. package/lib/types/client/llmLive.d.ts +31 -0
  14. package/lib/types/client/locales.d.ts +15 -70
  15. package/lib/types/client/mount.d.ts +0 -2
  16. package/lib/types/client/panel/AiTag.d.ts +1 -0
  17. package/lib/types/client/panel/AssistantTab.d.ts +4 -1
  18. package/lib/types/client/panel/AuthorHome.d.ts +13 -11
  19. package/lib/types/client/panel/BookAnalysisView.d.ts +4 -0
  20. package/lib/types/client/panel/CmdPalette.d.ts +12 -0
  21. package/lib/types/client/panel/CreateBookView.d.ts +5 -1
  22. package/lib/types/client/panel/DirectorView.d.ts +7 -0
  23. package/lib/types/client/panel/IdeaInspirationView.d.ts +6 -0
  24. package/lib/types/client/panel/KnowledgeBaseView.d.ts +4 -0
  25. package/lib/types/client/panel/LiveFeedLog.d.ts +13 -0
  26. package/lib/types/client/panel/MarketRadarView.d.ts +5 -0
  27. package/lib/types/client/panel/ModelManager.d.ts +2 -2
  28. package/lib/types/client/panel/NovelPanel.d.ts +6 -1
  29. package/lib/types/client/panel/PageHeader.d.ts +18 -0
  30. package/lib/types/client/panel/PromptSlotsView.d.ts +11 -0
  31. package/lib/types/client/panel/SettingsView.d.ts +12 -9
  32. package/lib/types/client/panel/ShelfView.d.ts +10 -1
  33. package/lib/types/client/panel/SubPage.d.ts +27 -0
  34. package/lib/types/client/panel/TensionView.d.ts +18 -0
  35. package/lib/types/client/panel/TimelineView.d.ts +18 -0
  36. package/lib/types/client/panel/helpers.d.ts +5 -3
  37. package/lib/types/client/panel/market-radar-state.d.ts +56 -0
  38. package/lib/types/client/panel/toast.d.ts +2 -0
  39. package/lib/types/client/panel/views.d.ts +21 -35
  40. package/lib/types/client/run-status.d.ts +21 -0
  41. package/lib/types/client/sidebar-entry.d.ts +0 -2
  42. package/lib/types/docx-core.d.ts +16 -0
  43. package/lib/types/docx.d.ts +2 -3
  44. package/lib/types/engine.d.ts +78 -103
  45. package/lib/types/global-assets.d.ts +6 -0
  46. package/lib/types/home.d.ts +11 -0
  47. package/lib/types/index.d.ts +26 -12
  48. package/lib/types/llm-live.d.ts +70 -0
  49. package/lib/types/llm-retry.d.ts +38 -0
  50. package/lib/types/market-radar-scan.d.ts +18 -0
  51. package/lib/types/market-radar-sources.d.ts +31 -0
  52. package/lib/types/migrate-output.d.ts +25 -0
  53. package/lib/types/model-capability.d.ts +93 -0
  54. package/lib/types/output-budget.d.ts +86 -0
  55. package/lib/types/prompt-slots.d.ts +57 -0
  56. package/lib/types/prompting.d.ts +10 -0
  57. package/lib/types/protocol.d.ts +816 -601
  58. package/lib/types/revision.d.ts +76 -0
  59. package/lib/types/routes.d.ts +9 -3
  60. package/lib/types/run.d.ts +23 -1
  61. package/lib/types/settings-persist.d.ts +59 -0
  62. package/lib/types/snapshots.d.ts +46 -0
  63. package/lib/types/stage-contract.d.ts +58 -0
  64. package/lib/types/tension.d.ts +53 -0
  65. package/lib/types/timeline.d.ts +37 -0
  66. package/package.json +50 -25
  67. package/src/action-guard.ts +127 -0
  68. package/src/ai-scan.ts +0 -24
  69. package/src/assets.ts +1801 -879
  70. package/src/assistant.ts +1098 -770
  71. package/src/author-assets.ts +131 -147
  72. package/src/bookshelf.ts +193 -167
  73. package/src/client/api.ts +767 -617
  74. package/src/client/chip-prefs.ts +121 -0
  75. package/src/client/docx.ts +32 -69
  76. package/src/client/index.ts +2 -0
  77. package/src/client/llmLive.ts +111 -0
  78. package/src/client/locales.ts +15 -274
  79. package/src/client/mount.tsx +3 -2
  80. package/src/client/panel/AdaptModeView.tsx +535 -520
  81. package/src/client/panel/AiTag.tsx +7 -0
  82. package/src/client/panel/AssetsTab.tsx +448 -458
  83. package/src/client/panel/AssistantTab.tsx +355 -301
  84. package/src/client/panel/AuthorAssetsView.tsx +205 -207
  85. package/src/client/panel/AuthorHome.tsx +309 -204
  86. package/src/client/panel/BookAnalysisView.tsx +63 -0
  87. package/src/client/panel/CmdPalette.tsx +102 -0
  88. package/src/client/panel/CreateBookView.tsx +366 -352
  89. package/src/client/panel/DirectorView.tsx +200 -0
  90. package/src/client/panel/GlobalAssetLibraryView.tsx +168 -172
  91. package/src/client/panel/IdeaInspirationView.tsx +76 -0
  92. package/src/client/panel/ImportModal.tsx +302 -302
  93. package/src/client/panel/KnowledgeBaseView.tsx +125 -0
  94. package/src/client/panel/LiveFeedLog.tsx +204 -0
  95. package/src/client/panel/MarketRadarView.tsx +415 -0
  96. package/src/client/panel/ModelManager.tsx +205 -205
  97. package/src/client/panel/NovelPanel.tsx +3144 -2205
  98. package/src/client/panel/PageHeader.tsx +37 -0
  99. package/src/client/panel/ProgressConsole.tsx +63 -64
  100. package/src/client/panel/PromptSlotsView.tsx +97 -0
  101. package/src/client/panel/ReaderView.tsx +306 -306
  102. package/src/client/panel/RunPanel.tsx +56 -24
  103. package/src/client/panel/SettingsView.tsx +175 -106
  104. package/src/client/panel/ShelfView.tsx +63 -39
  105. package/src/client/panel/SubPage.tsx +42 -0
  106. package/src/client/panel/TensionView.tsx +212 -0
  107. package/src/client/panel/TimelineView.tsx +208 -0
  108. package/src/client/panel/WorldTab.tsx +202 -202
  109. package/src/client/panel/helpers.ts +7 -5
  110. package/src/client/panel/market-radar-state.ts +79 -0
  111. package/src/client/panel/panel.module.css +5767 -4360
  112. package/src/client/panel/toast.ts +51 -0
  113. package/src/client/panel/views.tsx +316 -314
  114. package/src/client/run-status.ts +171 -0
  115. package/src/client/sidebar-entry.ts +3 -3
  116. package/src/docx-core.ts +53 -0
  117. package/src/docx.ts +44 -83
  118. package/src/engine.ts +1197 -1638
  119. package/src/global-assets.ts +58 -0
  120. package/src/home.ts +33 -0
  121. package/src/index.ts +181 -101
  122. package/src/llm-live.ts +245 -0
  123. package/src/llm-retry.ts +77 -0
  124. package/src/market-radar-scan.ts +35 -0
  125. package/src/market-radar-sources.ts +173 -0
  126. package/src/migrate-output.ts +76 -0
  127. package/src/model-capability.ts +215 -0
  128. package/src/novel-context.ts +286 -287
  129. package/src/output-budget.ts +147 -0
  130. package/src/prompt-slots.ts +125 -0
  131. package/src/prompting.ts +26 -0
  132. package/src/protocol.ts +835 -614
  133. package/src/revision.ts +283 -0
  134. package/src/routes.ts +1286 -910
  135. package/src/run.ts +113 -17
  136. package/src/settings-persist.ts +114 -0
  137. package/src/snapshots.ts +174 -0
  138. package/src/stage-contract.ts +186 -0
  139. package/src/tension.ts +251 -0
  140. package/src/timeline.ts +159 -0
  141. package/assets/styles/arcane-thick-3d.webp +0 -0
  142. package/assets/styles/chinese-ink.webp +0 -0
  143. package/assets/styles/clay-stopmotion-3d.webp +0 -0
  144. package/assets/styles/dark-ghibli.webp +0 -0
  145. package/assets/styles/dark-gothic-3d.webp +0 -0
  146. package/assets/styles/film-photo.webp +0 -0
  147. package/assets/styles/guofeng-heavy.webp +0 -0
  148. package/assets/styles/guoman-2d-gufeng.webp +0 -0
  149. package/assets/styles/guoman-3d-tianyuan.webp +0 -0
  150. package/assets/styles/guoman-3d-xuanhuan.webp +0 -0
  151. package/assets/styles/horror-game-3d.webp +0 -0
  152. package/assets/styles/hyperreal-3d.webp +0 -0
  153. package/assets/styles/japan-cel-dark.webp +0 -0
  154. package/assets/styles/korean-webtoon.webp +0 -0
  155. package/assets/styles/low-cyberpunk-3d.webp +0 -0
  156. package/assets/styles/nextgen-cg.webp +0 -0
  157. package/assets/styles/noir-film.webp +0 -0
  158. package/assets/styles/openworld-survival.webp +0 -0
  159. package/assets/styles/paper-cut-3d.webp +0 -0
  160. package/assets/styles/pixar-adult-3d.webp +0 -0
  161. package/assets/styles/pop-marvel-2d.webp +0 -0
  162. package/assets/styles/sandiao-qban.webp +0 -0
  163. package/assets/styles/shinkai-anime.webp +0 -0
  164. package/assets/styles/tactical-stealth.webp +0 -0
  165. package/assets/styles/urban-lightreal-3d.webp +0 -0
  166. package/assets/styles/vaporwave-3d.webp +0 -0
  167. package/assets/styles/vhs90.webp +0 -0
  168. package/lib/types/client/panel/BookshelfBar.d.ts +0 -11
  169. package/lib/types/client/panel/FlowGuide.d.ts +0 -22
  170. package/lib/types/client/panel/MangaRoleLibrary.d.ts +0 -20
  171. package/lib/types/client/panel/MangaWorkspace.d.ts +0 -12
  172. package/lib/types/client/panel/ModelPicker.d.ts +0 -11
  173. package/lib/types/client/panel/ProgressHomeView.d.ts +0 -5
  174. package/lib/types/client/panel/PropLibrary.d.ts +0 -8
  175. package/lib/types/client/panel/SceneLibrary.d.ts +0 -16
  176. package/lib/types/client/panel/StoryboardTab.d.ts +0 -19
  177. package/lib/types/client/panel/StyleCard.d.ts +0 -8
  178. package/lib/types/client/panel/StyleGallery.d.ts +0 -1
  179. package/lib/types/comic-presets.d.ts +0 -12
  180. package/lib/types/manga-genre-rules.d.ts +0 -22
  181. package/lib/types/prompt-utils.d.ts +0 -35
  182. package/lib/types/review-policy.d.ts +0 -97
  183. package/lib/types/shot-language.d.ts +0 -46
  184. package/lib/types/story-beat-language.d.ts +0 -35
  185. package/lib/types/style-library.d.ts +0 -33
  186. package/skills/chapter-batch/SKILL.md +0 -81
  187. package/src/client/mount.tsx._new +0 -97
  188. package/src/client/mount.tsx._nf +0 -97
  189. package/src/client/mount.tsx._tmp +0 -97
  190. package/src/client/panel/BookshelfBar.tsx +0 -170
  191. package/src/client/panel/FlowGuide.tsx +0 -84
  192. package/src/client/panel/MangaRoleLibrary.tsx +0 -1002
  193. package/src/client/panel/MangaWorkspace.tsx +0 -715
  194. package/src/client/panel/ProgressHomeView.tsx +0 -87
  195. package/src/client/panel/PropLibrary.tsx +0 -175
  196. package/src/client/panel/SceneLibrary.tsx +0 -453
  197. package/src/client/panel/StoryboardTab.tsx +0 -472
  198. package/src/client/panel/StyleCard.tsx +0 -90
  199. package/src/client/panel/StyleGallery.tsx +0 -58
  200. package/src/comic-presets.ts +0 -67
  201. package/src/manga-genre-rules.ts +0 -87
  202. package/src/prompt-utils.ts +0 -73
  203. package/src/review-policy.ts +0 -161
  204. package/src/shot-language.ts +0 -181
  205. package/src/story-beat-language.ts +0 -130
  206. package/src/style-library.ts +0 -84
@@ -0,0 +1,215 @@
1
+ /**
2
+ * 模型参数能力兼容层。
3
+ *
4
+ * 设计原则:**界面上保存的温度/思考档位是用户偏好,不是最终请求值。** 构造请求前
5
+ * 必须经过本层收敛到厂商允许的范围 —— 否则换模型、走自定义中转、或厂商改了约束,
6
+ * 就会出现「换个 provider 就报参数错误」这类故障。
7
+ *
8
+ * 两条硬要求:
9
+ * 1. **按模型身份判断,不按 provider 判断**。同一个模型经由自定义中转调用时,
10
+ * provider 名可能完全自定义,但参数约束属于模型本身;把判断写成
11
+ * `provider === '某个厂商' && ...` 会让走中转的调用绕过约束。
12
+ * 2. **约束要有出处**。每条规则的来源写在规则上,不靠猜。下列规则来自厂商官方
13
+ * 《模型参数参考》(https://platform.kimi.com/docs/api/models-overview.md):
14
+ * · kimi-k3 : temperature 固定 1.0;支持顶层 reasoning_effort
15
+ * · kimi-k2.7-code : temperature 固定 1.0;不支持 reasoning_effort(用 thinking,且不可禁用)
16
+ * · kimi-k2.6 : thinking 固定 1.0 / 非 thinking 固定 0.6;不支持 reasoning_effort
17
+ * 官方同时建议:这类模型**不要显式传入 temperature**。本层因此优先「不传」,
18
+ * 仅在调用方无法省略该参数时才钳到允许值。
19
+ */
20
+
21
+ /** 一次请求的参数约束。 */
22
+ export interface ModelCapability {
23
+ /** 该模型只接受这一个温度值(如 Kimi 全系),缺省表示不约束。 */
24
+ fixedTemperature?: number
25
+ /** 温度允许的下界(默认 0)。 */
26
+ minTemperature?: number
27
+ /** 温度允许的上界(默认 2,主流 OpenAI 兼容区间)。 */
28
+ maxTemperature?: number
29
+ /**
30
+ * 是否支持 OpenAI 兼容的 `reasoning_effort`。
31
+ * false 表示**不得下发**该参数(如 Kimi K2.x 用的是 `thinking`),下发会被厂商拒绝。
32
+ */
33
+ supportsReasoning?: boolean
34
+ /**
35
+ * 推理控制方式:`reasoning_effort`(OpenAI 兼容顶层参数)或 `thinking`(Kimi K2.x 专属)。
36
+ * 运行时若适配层支持,应按此选择参数名;仅为诊断与后续适配保留。
37
+ */
38
+ reasoningControl?: 'reasoning-effort' | 'thinking' | 'none'
39
+ /** 严格结构化输出必须关闭思考(覆盖用户偏好)。 */
40
+ reasoningForcedOff?: boolean
41
+ /** 命中的规则名,用于日志与测试断言。 */
42
+ rule: string
43
+ /** 约束出处(文档 URL 或说明),便于复核与更新。 */
44
+ source: string
45
+ }
46
+
47
+ /** 一道匹配规则:先命中先生效。 */
48
+ interface CapabilityRule {
49
+ /** 规则名。 */
50
+ rule: string
51
+ /** 约束出处。 */
52
+ source: string
53
+ /** 模型 id 归一化后是否命中。 */
54
+ matches: (canonical: string) => boolean
55
+ capability: Omit<ModelCapability, 'rule' | 'source'>
56
+ }
57
+
58
+ const KIMI_SOURCE = 'https://platform.kimi.com/docs/api/models-overview.md'
59
+
60
+ /**
61
+ * 把模型 id 归一化为「模型身份」。
62
+ *
63
+ * 处理:去空白与首尾斜杠、小写、剥掉供应商前缀(`kimi/kimi-k3` → `kimi-k3`)。
64
+ * @param model - 原始模型 id。
65
+ * @returns 归一化后的身份(小写、无前缀)。
66
+ */
67
+ export function canonicalModelId(model: string | undefined): string {
68
+ if (typeof model !== 'string') return ''
69
+ const trimmed = model.trim().toLowerCase().replace(/^\/+|\/+$/g, '')
70
+ if (trimmed === '') return ''
71
+ const segments = trimmed.split('/')
72
+ return segments[segments.length - 1] ?? ''
73
+ }
74
+
75
+ const RULES: CapabilityRule[] = [
76
+ {
77
+ rule: 'kimi-k3-fixed-temperature',
78
+ source: KIMI_SOURCE,
79
+ // 只命中 k3 本身;k2.6 / k2.7 另立规则(约束不同)。
80
+ matches: (m) => /^kimi[-_.]?k-?3(?:[-_.]|$)/.test(m),
81
+ capability: { fixedTemperature: 1, supportsReasoning: true, reasoningControl: 'reasoning-effort' },
82
+ },
83
+ {
84
+ rule: 'kimi-k2.7-code-fixed-temperature',
85
+ source: KIMI_SOURCE,
86
+ matches: (m) => /^kimi[-_.]?k-?2[-_.]?7(?:[-_.]|$)/.test(m),
87
+ capability: {
88
+ fixedTemperature: 1,
89
+ // 不支持 reasoning_effort;思考由 thinking 控制且不可禁用。
90
+ supportsReasoning: false,
91
+ reasoningControl: 'thinking',
92
+ reasoningForcedOff: true,
93
+ },
94
+ },
95
+ {
96
+ rule: 'kimi-k2.6-temperature-by-thinking',
97
+ source: KIMI_SOURCE,
98
+ matches: (m) => /^kimi[-_.]?k-?2[-_.]?6(?:[-_.]|$)/.test(m),
99
+ capability: {
100
+ // 思考模式 1.0 / 非思考 0.6;本插件的结构化任务默认关闭思考,故取 0.6 不安全,
101
+ // 统一收敛到 1.0(思考档),避免"关思考却给 1.0"这类组合出错。
102
+ fixedTemperature: 1,
103
+ supportsReasoning: false,
104
+ reasoningControl: 'thinking',
105
+ },
106
+ },
107
+ {
108
+ rule: 'deepseek-reasoner-fixed-temperature',
109
+ source: 'OpenAI 兼容约定:DeepSeek R1/reasoner 不接受自定义 temperature',
110
+ matches: (m) => /^deepseek[-_.]?(r1|reasoner)(?:[-_.]|$)/.test(m),
111
+ capability: { fixedTemperature: 1, supportsReasoning: true, reasoningControl: 'reasoning-effort' },
112
+ },
113
+ ]
114
+
115
+ /**
116
+ * 解析一条模型的能力约束。
117
+ * @param model - 模型 id(可能带供应商前缀)。
118
+ * @returns 命中的能力;无约束时返回 undefined。
119
+ */
120
+ export function resolveModelCapability(model: string | undefined): ModelCapability | undefined {
121
+ const canonical = canonicalModelId(model)
122
+ if (canonical === '') return undefined
123
+ for (const rule of RULES) {
124
+ if (rule.matches(canonical)) return { ...rule.capability, rule: rule.rule, source: rule.source }
125
+ }
126
+ return undefined
127
+ }
128
+
129
+ /** 一次待收敛的请求参数。 */
130
+ export interface RequestParams {
131
+ temperature: number
132
+ /** 请求方(含用户偏好)希望使用的思考档位;undefined 表示不涉及。 */
133
+ reasoningEffort?: 'off' | 'low' | 'high' | 'max'
134
+ }
135
+
136
+ /** 收敛结果:最终请求值 + 发生了哪些调整(便于日志与诊断)。 */
137
+ export interface ConvergedParams {
138
+ /**
139
+ * 最终要下发的温度;`undefined` 表示**应当省略该参数**。
140
+ * 厂商建议这类模型不要显式传 temperature 时,本层返回 undefined。
141
+ */
142
+ temperature: number | undefined
143
+ reasoningEffort?: 'off' | 'low' | 'high' | 'max'
144
+ /** 被本层改掉的项,形如 `temperature: 0.3 -> 省略`。 */
145
+ adjustments: string[]
146
+ /** 命中的规则名。 */
147
+ rule?: string
148
+ /** 约束出处。 */
149
+ source?: string
150
+ }
151
+
152
+ /**
153
+ * 把请求参数收敛到模型允许的范围。
154
+ *
155
+ * @param params - 调用方希望使用的参数。
156
+ * @param model - 实际要调用的模型 id(应传**实际模型**;换备用模型后需重算)。
157
+ * @param options - `structured: true` 表示这是严格结构化输出任务;
158
+ * `omitFixedTemperature: true` 表示调用方可以不传温度(推荐,厂商建议如此),
159
+ * 此时固定温度会收敛为 undefined 而不是钳到固定值。
160
+ * @returns 最终请求值与被调整项。
161
+ */
162
+ export function convergeRequestParams(
163
+ params: RequestParams,
164
+ model: string | undefined,
165
+ options: { structured?: boolean; omitFixedTemperature?: boolean } = {},
166
+ ): ConvergedParams {
167
+ const capability = resolveModelCapability(model)
168
+ const adjustments: string[] = []
169
+ let temperature: number | undefined = params.temperature
170
+ let reasoningEffort = params.reasoningEffort
171
+
172
+ if (capability?.fixedTemperature !== undefined) {
173
+ const fixed = capability.fixedTemperature
174
+ if (options.omitFixedTemperature === true) {
175
+ if (temperature !== undefined) {
176
+ adjustments.push(`temperature: ${temperature} -> 省略(${capability.rule} 固定 ${fixed},厂商建议不要显式传入)`)
177
+ }
178
+ temperature = undefined
179
+ } else if (temperature !== fixed) {
180
+ adjustments.push(`temperature: ${temperature} -> ${fixed}(${capability.rule} 固定值)`)
181
+ temperature = fixed
182
+ }
183
+ } else if (capability !== undefined) {
184
+ const min = capability.minTemperature ?? 0
185
+ const max = capability.maxTemperature ?? 2
186
+ const clamped = Math.min(max, Math.max(min, temperature ?? min))
187
+ if (clamped !== temperature) {
188
+ adjustments.push(`temperature: ${temperature} -> ${clamped}(${capability.rule} 取值范围)`)
189
+ temperature = clamped
190
+ }
191
+ }
192
+
193
+ // 不支持 reasoning_effort 的模型:不得下发该参数,否则厂商直接报错。
194
+ if (capability?.supportsReasoning === false && reasoningEffort !== undefined) {
195
+ if (reasoningEffort !== 'off') {
196
+ adjustments.push(`reasoningEffort: ${reasoningEffort} -> 省略(${capability.rule} 不支持该参数)`)
197
+ }
198
+ reasoningEffort = undefined
199
+ }
200
+
201
+ // 严格结构化任务:能力档案要求关闭思考时,覆盖用户偏好(输出稳定性优先)。
202
+ if (options.structured === true && capability?.reasoningForcedOff === true && reasoningEffort !== undefined) {
203
+ adjustments.push(`reasoningEffort: ${reasoningEffort} -> off(结构化任务强制关闭思考)`)
204
+ reasoningEffort = 'off'
205
+ // 该模型通过 thinking 控制且不可禁用:等价于不传任何推理参数。
206
+ if (capability.reasoningControl === 'thinking') reasoningEffort = undefined
207
+ }
208
+
209
+ return {
210
+ temperature,
211
+ reasoningEffort,
212
+ adjustments,
213
+ ...(capability === undefined ? {} : { rule: capability.rule, source: capability.source }),
214
+ }
215
+ }