@cloud411716/fancy-webnovel 4.27.3 → 4.28.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.
- package/docs/douyin-plugin.md +9 -1
- package/docs/material-library/README.md +3 -1
- package/docs/material-library/prompt.md +7 -4
- package/docs/material-library/schema.surql +40 -1
- package/lib/material-db.js +9 -2
- package/package.json +1 -1
- package/plugins/fancy-bootstrap/index.js +1 -1
- package/plugins/fancy-db/index.js +1 -1
- package/plugins/fancy-douyin/index.js +80 -1
- package/plugins/fancy-douyin/state.js +24 -1
- package/plugins/fancy-douyin/style-distill.js +197 -0
- package/plugins/fancy-douyin/templates.js +8 -1
- package/plugins/fancy-material/builtin-styles.js +448 -0
- package/plugins/fancy-material/index.js +92 -8
- package/plugins/fancy-material/styles.js +441 -0
- package/plugins/fancy-material/templates.js +12 -0
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 风格注册表:内置风格 + 数据库 douyin_style。
|
|
3
|
+
*
|
|
4
|
+
* 风格是跨 kind 的不变量;kind 只决定"写什么信息点"。
|
|
5
|
+
* 这里不处理具体生成,只负责加载、合并、按题材选择、渲染成提示词。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { RecordId } from 'surrealdb';
|
|
9
|
+
import { connectMaterial } from '#material-db';
|
|
10
|
+
import { BUILTIN_STYLES, SELECTABLE_STYLE_TYPES } from './builtin-styles.js';
|
|
11
|
+
|
|
12
|
+
export const STYLE_TABLE = 'douyin_style';
|
|
13
|
+
|
|
14
|
+
function asArray(value) {
|
|
15
|
+
return Array.isArray(value) ? value : [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function asObject(value) {
|
|
19
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function unique(values) {
|
|
23
|
+
return [...new Set(values.filter(Boolean))];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function mergeObject(base, patch) {
|
|
27
|
+
const out = { ...asObject(base) };
|
|
28
|
+
for (const [key, value] of Object.entries(asObject(patch))) {
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
out[key] = unique([...asArray(out[key]), ...value]);
|
|
31
|
+
} else if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
32
|
+
out[key] = mergeObject(out[key], value);
|
|
33
|
+
} else if (value !== undefined && value !== null && value !== '') {
|
|
34
|
+
out[key] = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function normalizeStyle(raw, origin = 'database') {
|
|
41
|
+
const style = raw && typeof raw === 'object' ? raw : {};
|
|
42
|
+
const profile = asObject(style.profile_json);
|
|
43
|
+
const merged = { ...profile, ...style };
|
|
44
|
+
return {
|
|
45
|
+
style_key: String(merged.style_key || '').trim(),
|
|
46
|
+
style_name: String(merged.style_name || merged.name || merged.style_key || '').trim(),
|
|
47
|
+
style_type: ['naming', 'structure', 'teaching', 'visual'].includes(String(merged.style_type || '').trim())
|
|
48
|
+
? String(merged.style_type).trim()
|
|
49
|
+
: 'naming',
|
|
50
|
+
account_names: unique([
|
|
51
|
+
...asArray(merged.account_names),
|
|
52
|
+
merged.account_name,
|
|
53
|
+
].map((v) => String(v || '').trim()).filter(Boolean)),
|
|
54
|
+
account_urls: unique([
|
|
55
|
+
...asArray(merged.account_urls),
|
|
56
|
+
merged.account_url,
|
|
57
|
+
].map((v) => String(v || '').trim()).filter(Boolean)),
|
|
58
|
+
genre_tags: unique(asArray(merged.genre_tags).map((v) => String(v || '').trim())),
|
|
59
|
+
dna: String(merged.dna || '').trim(),
|
|
60
|
+
naming_rules: asObject(merged.naming_rules),
|
|
61
|
+
lexicon: asObject(merged.lexicon),
|
|
62
|
+
cross_kind_examples: asObject(merged.cross_kind_examples),
|
|
63
|
+
anti_examples: unique(asArray(merged.anti_examples).map((v) => String(v || '').trim())),
|
|
64
|
+
compatibility: asObject(merged.compatibility),
|
|
65
|
+
confidence: Math.max(0, Math.min(1, Number(merged.confidence) || 0)),
|
|
66
|
+
source_works: Number(merged.source_works) || 0,
|
|
67
|
+
source_materials: Number(merged.source_materials) || 0,
|
|
68
|
+
version: Number(merged.version) || 1,
|
|
69
|
+
status: String(merged.status || 'active'),
|
|
70
|
+
origin: style.origin || origin,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function mergeStyle(base, patch) {
|
|
75
|
+
const a = normalizeStyle(base, base.origin || 'builtin');
|
|
76
|
+
const b = normalizeStyle(patch, patch.origin || 'database');
|
|
77
|
+
return {
|
|
78
|
+
...a,
|
|
79
|
+
...b,
|
|
80
|
+
style_key: b.style_key || a.style_key,
|
|
81
|
+
style_name: b.style_name || a.style_name,
|
|
82
|
+
style_type: b.style_type || a.style_type,
|
|
83
|
+
account_names: unique([...a.account_names, ...b.account_names]),
|
|
84
|
+
account_urls: unique([...a.account_urls, ...b.account_urls]),
|
|
85
|
+
genre_tags: unique([...a.genre_tags, ...b.genre_tags]),
|
|
86
|
+
dna: b.dna || a.dna,
|
|
87
|
+
naming_rules: mergeObject(a.naming_rules, b.naming_rules),
|
|
88
|
+
lexicon: mergeObject(a.lexicon, b.lexicon),
|
|
89
|
+
cross_kind_examples: mergeObject(a.cross_kind_examples, b.cross_kind_examples),
|
|
90
|
+
anti_examples: unique([...a.anti_examples, ...b.anti_examples]),
|
|
91
|
+
compatibility: { ...a.compatibility, ...b.compatibility },
|
|
92
|
+
confidence: Math.max(a.confidence, b.confidence),
|
|
93
|
+
source_works: Math.max(a.source_works, b.source_works),
|
|
94
|
+
source_materials: Math.max(a.source_materials, b.source_materials),
|
|
95
|
+
version: Math.max(a.version, b.version),
|
|
96
|
+
origin: b.origin === 'database' ? 'merged' : a.origin,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function databaseStyles(db) {
|
|
101
|
+
if (!db) return [];
|
|
102
|
+
try {
|
|
103
|
+
const result = await db.query(
|
|
104
|
+
"SELECT style_key, account_url, account_name, style_name, style_type, genre_tags, dna, naming_rules, lexicon, cross_kind_examples, anti_examples, compatibility, confidence, source_works, source_materials, version, status, profile_json FROM douyin_style WHERE status = 'active';",
|
|
105
|
+
);
|
|
106
|
+
const rows = Array.isArray(result) && Array.isArray(result[0]) ? result[0] : [];
|
|
107
|
+
return rows.map((row) => normalizeStyle({ ...row, origin: 'database' }, 'database'))
|
|
108
|
+
.filter((style) => style.style_key);
|
|
109
|
+
} catch {
|
|
110
|
+
// 旧库还没执行 schema v13 时不应阻断生成。
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function styleIdentity(style) {
|
|
116
|
+
return String(style.style_name || '').trim() + '\u0000' + String(style.dna || '').trim();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 同账号组可能产生多个 style_key(带账号前缀),按名称+DNA 去重。 */
|
|
120
|
+
function dedupeStyles(styles) {
|
|
121
|
+
const byIdentity = new Map();
|
|
122
|
+
for (const style of styles) {
|
|
123
|
+
const key = styleIdentity(style);
|
|
124
|
+
if (!key || key === '\u0000') {
|
|
125
|
+
byIdentity.set(style.style_key, style);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const existing = byIdentity.get(key);
|
|
129
|
+
if (!existing) {
|
|
130
|
+
byIdentity.set(key, style);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const merged = mergeStyle(existing, style);
|
|
134
|
+
merged.style_key = existing.style_key;
|
|
135
|
+
merged.origin = 'merged';
|
|
136
|
+
byIdentity.set(key, merged);
|
|
137
|
+
}
|
|
138
|
+
return [...byIdentity.values()];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 加载内置 + 数据库风格,同 style_key 合并;数据库字段优先。
|
|
143
|
+
*
|
|
144
|
+
* @param {string} root 工作区
|
|
145
|
+
* @param {{db?: object}} [options] 传入已有连接可避免重复连接
|
|
146
|
+
* @returns {Promise<{styles: object[], builtin: number, database: number}>}
|
|
147
|
+
*/
|
|
148
|
+
export async function loadStyleRegistry(root, { db = null } = {}) {
|
|
149
|
+
const byKey = new Map();
|
|
150
|
+
for (const style of BUILTIN_STYLES) {
|
|
151
|
+
const normalized = normalizeStyle(style, 'builtin');
|
|
152
|
+
if (normalized.style_key) byKey.set(normalized.style_key, normalized);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let ownedDb = null;
|
|
156
|
+
let useDb = db;
|
|
157
|
+
if (!useDb) {
|
|
158
|
+
try {
|
|
159
|
+
const connected = await connectMaterial(root);
|
|
160
|
+
ownedDb = connected.db;
|
|
161
|
+
useDb = connected.db;
|
|
162
|
+
} catch {
|
|
163
|
+
useDb = null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
let rows = [];
|
|
167
|
+
try {
|
|
168
|
+
rows = await databaseStyles(useDb);
|
|
169
|
+
} finally {
|
|
170
|
+
if (ownedDb) {
|
|
171
|
+
try { await ownedDb.close(); } catch { /* ignore */ }
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
for (const row of rows) {
|
|
176
|
+
if (!row.style_key) continue;
|
|
177
|
+
const existing = byKey.get(row.style_key);
|
|
178
|
+
byKey.set(row.style_key, existing ? mergeStyle(existing, row) : row);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
styles: dedupeStyles([...byKey.values()]),
|
|
183
|
+
builtin: BUILTIN_STYLES.length,
|
|
184
|
+
database: rows.length,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function compatibilityLevel(style, genres) {
|
|
189
|
+
let score = 0;
|
|
190
|
+
for (const raw of genres) {
|
|
191
|
+
const genre = String(raw || '').trim();
|
|
192
|
+
if (!genre) continue;
|
|
193
|
+
for (const [key, level] of Object.entries(style.compatibility || {})) {
|
|
194
|
+
if (!key) continue;
|
|
195
|
+
if (genre.includes(key) || key.includes(genre)) {
|
|
196
|
+
if (level === 'native') score += 6;
|
|
197
|
+
else if (level === 'adaptable') score += 3;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
for (const tag of style.genre_tags || []) {
|
|
201
|
+
if (tag && (genre.includes(tag) || tag.includes(genre))) score += 4;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return score;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function parseExplicit(explicit) {
|
|
208
|
+
if (Array.isArray(explicit)) return explicit.map((v) => String(v || '').trim()).filter(Boolean);
|
|
209
|
+
return String(explicit || '')
|
|
210
|
+
.split(/[,,、]/)
|
|
211
|
+
.map((v) => v.trim())
|
|
212
|
+
.filter(Boolean);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 选择本次风格。
|
|
217
|
+
*
|
|
218
|
+
* explicit:
|
|
219
|
+
* '' / 'auto' -> 自动按题材选 2-3 个
|
|
220
|
+
* 'none' -> 不使用账号风格
|
|
221
|
+
* 'suci,...' -> 手动指定 style_key
|
|
222
|
+
*/
|
|
223
|
+
export function selectStyles(styles, {
|
|
224
|
+
genres = [],
|
|
225
|
+
explicit = '',
|
|
226
|
+
limit = 3,
|
|
227
|
+
} = {}) {
|
|
228
|
+
const keys = parseExplicit(explicit);
|
|
229
|
+
const lower = keys.map((key) => key.toLowerCase());
|
|
230
|
+
if (lower.includes('none')) return [];
|
|
231
|
+
const all = Array.isArray(styles) ? styles : [];
|
|
232
|
+
const byKey = new Map(all.map((style) => [style.style_key.toLowerCase(), style]));
|
|
233
|
+
|
|
234
|
+
if (keys.length && !lower.includes('auto')) {
|
|
235
|
+
const selected = [];
|
|
236
|
+
const unknown = [];
|
|
237
|
+
for (const key of keys) {
|
|
238
|
+
const style = byKey.get(key.toLowerCase());
|
|
239
|
+
if (style) selected.push(style);
|
|
240
|
+
else unknown.push(key);
|
|
241
|
+
}
|
|
242
|
+
if (unknown.length) {
|
|
243
|
+
const available = all.map((style) => style.style_key).filter(Boolean).join('、');
|
|
244
|
+
throw new Error('未找到风格:' + unknown.join('、') + '\n可用风格:' + (available || '(暂无)'));
|
|
245
|
+
}
|
|
246
|
+
return selected.slice(0, Math.max(1, limit));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const ranked = all
|
|
250
|
+
.filter((style) => SELECTABLE_STYLE_TYPES.has(style.style_type))
|
|
251
|
+
.map((style) => ({ style, score: compatibilityLevel(style, genres) }))
|
|
252
|
+
.filter((item) => item.score > 0)
|
|
253
|
+
.sort((a, b) => (b.score - a.score) || (b.style.confidence - a.style.confidence));
|
|
254
|
+
return ranked.slice(0, Math.max(1, limit)).map((item) => item.style);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function stylesForAccount(styles, account) {
|
|
258
|
+
const name = String(account && (account.name || account.account_name) || '').trim();
|
|
259
|
+
const url = String(account && (account.url || account.account_url) || '').trim();
|
|
260
|
+
return (Array.isArray(styles) ? styles : []).filter((style) => {
|
|
261
|
+
if (url && (style.account_urls || []).includes(url)) return true;
|
|
262
|
+
if (name && (style.account_names || []).includes(name)) return true;
|
|
263
|
+
return false;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function styleExamples(style, limit = 3) {
|
|
268
|
+
const out = [];
|
|
269
|
+
for (const values of Object.values(style.cross_kind_examples || {})) {
|
|
270
|
+
for (const value of asArray(values)) {
|
|
271
|
+
if (value && !out.includes(value)) out.push(value);
|
|
272
|
+
if (out.length >= limit) return out;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return out;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function styleIndexLines(styles, { limit = 20 } = {}) {
|
|
279
|
+
return (Array.isArray(styles) ? styles : [])
|
|
280
|
+
.filter((style) => SELECTABLE_STYLE_TYPES.has(style.style_type))
|
|
281
|
+
.slice(0, limit)
|
|
282
|
+
.map((style) => `- \`${style.style_key}\`(${style.style_name})|${(style.genre_tags || []).join('、') || '通用'}|${style.dna}`);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* 生成注入 prompt 的风格块。
|
|
287
|
+
* 只展开本次选中的风格;其余只给索引,避免上下文爆炸。
|
|
288
|
+
*/
|
|
289
|
+
export function stylePromptBlock(styles, selected, { genres = [] } = {}) {
|
|
290
|
+
const all = Array.isArray(styles) ? styles : [];
|
|
291
|
+
const picked = Array.isArray(selected) ? selected : [];
|
|
292
|
+
const lines = [
|
|
293
|
+
'## 风格锁定(最高优先级)',
|
|
294
|
+
'',
|
|
295
|
+
'风格是跨 kind 的不变量:kind 决定“写什么信息点”,风格决定“用什么方式写”。',
|
|
296
|
+
'如果下面的风格规则与题材命名体例冲突,以风格规则为准;题材只负责换词汇和禁用项。',
|
|
297
|
+
'',
|
|
298
|
+
'### 可用风格索引',
|
|
299
|
+
...styleIndexLines(all),
|
|
300
|
+
'',
|
|
301
|
+
];
|
|
302
|
+
if (!picked.length) {
|
|
303
|
+
lines.push('本次未选择账号风格,按通用规则生成。');
|
|
304
|
+
return lines.join('\n');
|
|
305
|
+
}
|
|
306
|
+
lines.push('### 本次选中的风格');
|
|
307
|
+
for (const style of picked) {
|
|
308
|
+
lines.push('');
|
|
309
|
+
lines.push(`#### \`${style.style_key}\`(${style.style_name})`);
|
|
310
|
+
lines.push('- 风格类型:' + style.style_type);
|
|
311
|
+
lines.push('- 适用题材:' + (style.genre_tags || []).join('、'));
|
|
312
|
+
lines.push('- DNA:' + style.dna);
|
|
313
|
+
const rules = style.naming_rules || {};
|
|
314
|
+
if (rules.length) lines.push('- 长度:' + (Array.isArray(rules.length) ? rules.length.join('–') + ' 字' : rules.length));
|
|
315
|
+
if (rules.syntax) lines.push('- 句式:' + asArray(rules.syntax).join(';'));
|
|
316
|
+
if (rules.suffixes) lines.push('- 可用后缀:' + (asArray(rules.suffixes).join('、') || '无固定后缀'));
|
|
317
|
+
if (rules.forbidden) lines.push('- 禁用:' + asArray(rules.forbidden).join('、'));
|
|
318
|
+
if (rules.tone) lines.push('- 语气:' + rules.tone);
|
|
319
|
+
const preferred = asArray(style.lexicon && style.lexicon.preferred);
|
|
320
|
+
const forbidden = asArray(style.lexicon && style.lexicon.forbidden);
|
|
321
|
+
if (preferred.length) lines.push('- 偏好意象:' + preferred.join('、'));
|
|
322
|
+
if (forbidden.length) lines.push('- 禁用意象:' + forbidden.join('、'));
|
|
323
|
+
lines.push('- 跨 kind 正例:');
|
|
324
|
+
for (const [kind, values] of Object.entries(style.cross_kind_examples || {})) {
|
|
325
|
+
const list = asArray(values).slice(0, 6);
|
|
326
|
+
if (list.length) lines.push(` - \`${kind}\`:${list.join('、')}`);
|
|
327
|
+
}
|
|
328
|
+
if (style.anti_examples && style.anti_examples.length) {
|
|
329
|
+
lines.push('- 反例(出现即废弃):' + style.anti_examples.slice(0, 12).join('、'));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
lines.push('');
|
|
333
|
+
lines.push('本批题材:' + (genres.join('、') || '通用'));
|
|
334
|
+
lines.push('把选中风格的“核心语法”投射到本次题材和本批 kind 上;不要照抄正例,也不要退回通用仙气/古风形容词。');
|
|
335
|
+
return lines.join('\n');
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export function styleSummaryText(styles) {
|
|
339
|
+
return (Array.isArray(styles) ? styles : [])
|
|
340
|
+
.map((style) => `${style.style_key}(${style.style_name})`)
|
|
341
|
+
.join('、');
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export function styleBatchSummary(styles) {
|
|
345
|
+
return (Array.isArray(styles) ? styles : []).map((style) => {
|
|
346
|
+
const rules = style.naming_rules || {};
|
|
347
|
+
const bits = [
|
|
348
|
+
`- ${style.style_key}(${style.style_name}):${String(style.dna || '').replace(/[。;;]+$/u, '')}`,
|
|
349
|
+
];
|
|
350
|
+
if (rules.length) bits.push(`长度 ${Array.isArray(rules.length) ? rules.length.join('–') + ' 字' : rules.length}`);
|
|
351
|
+
if (rules.forbidden && rules.forbidden.length) bits.push('禁用 ' + rules.forbidden.join('、'));
|
|
352
|
+
return bits.join(';');
|
|
353
|
+
}).join('\n');
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* 把风格 patch 合并进数据库(同 style_key 做增量合并,不覆盖旧例子)。
|
|
358
|
+
* 只增/改 douyin_style,不碰 material、douyin_account、douyin_job。
|
|
359
|
+
*/
|
|
360
|
+
function accountKeyPrefix(account) {
|
|
361
|
+
const raw = String((account && (account.url || account.name)) || 'account')
|
|
362
|
+
.split('/')
|
|
363
|
+
.filter(Boolean)
|
|
364
|
+
.pop() || 'account';
|
|
365
|
+
return raw.replace(/[^A-Za-z0-9]/g, '').toLowerCase().slice(0, 24) || 'account';
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export async function upsertStyleProfiles(db, profiles, { account = null } = {}) {
|
|
369
|
+
if (!db || !Array.isArray(profiles)) return [];
|
|
370
|
+
const saved = [];
|
|
371
|
+
for (const raw of profiles) {
|
|
372
|
+
if (!raw || !raw.style_key) continue;
|
|
373
|
+
let key = String(raw.style_key).trim();
|
|
374
|
+
if (!/^[a-z][a-z0-9_-]*$/i.test(key)) continue;
|
|
375
|
+
let existing = null;
|
|
376
|
+
// 内置风格已经有归属账号;别的账号复用同一个 key 时自动加账号前缀。
|
|
377
|
+
const builtin = BUILTIN_STYLES.find((style) => style.style_key === key);
|
|
378
|
+
if (builtin && account && account.name && !(builtin.account_names || []).includes(account.name)) {
|
|
379
|
+
key = accountKeyPrefix(account) + '_' + key;
|
|
380
|
+
}
|
|
381
|
+
try {
|
|
382
|
+
const result = await db.query('SELECT * FROM douyin_style WHERE style_key = $key LIMIT 1;', { key });
|
|
383
|
+
existing = Array.isArray(result) && Array.isArray(result[0]) ? result[0][0] : null;
|
|
384
|
+
} catch { /* table may not exist yet */ }
|
|
385
|
+
// 同 key 已被另一个账号占用时,加上账号前缀,避免跨账号覆盖。
|
|
386
|
+
if (existing && account && existing.account_url && account.url && existing.account_url !== account.url) {
|
|
387
|
+
key = accountKeyPrefix(account) + '_' + key;
|
|
388
|
+
try {
|
|
389
|
+
const result = await db.query('SELECT * FROM douyin_style WHERE style_key = $key LIMIT 1;', { key });
|
|
390
|
+
existing = Array.isArray(result) && Array.isArray(result[0]) ? result[0][0] : null;
|
|
391
|
+
} catch { existing = null; }
|
|
392
|
+
}
|
|
393
|
+
const base = existing ? normalizeStyle({ ...existing, origin: 'database' }) : null;
|
|
394
|
+
const patch = normalizeStyle({
|
|
395
|
+
...raw,
|
|
396
|
+
style_key: key,
|
|
397
|
+
account_url: raw.account_url || (account && account.url) || '',
|
|
398
|
+
account_name: raw.account_name || (account && account.name) || '',
|
|
399
|
+
origin: 'database',
|
|
400
|
+
}, 'database');
|
|
401
|
+
const merged = base ? mergeStyle(base, patch) : patch;
|
|
402
|
+
merged.style_key = key;
|
|
403
|
+
merged.version = Math.max(1, Number(base?.version || 0) + 1);
|
|
404
|
+
merged.source_works = Math.max(Number(base?.source_works || 0), Number(patch.source_works || 0));
|
|
405
|
+
merged.source_materials = Math.max(Number(base?.source_materials || 0), Number(patch.source_materials || 0));
|
|
406
|
+
merged.status = 'active';
|
|
407
|
+
const content = {
|
|
408
|
+
style_key: merged.style_key,
|
|
409
|
+
account_url: (account && account.url) || merged.account_urls[0] || '',
|
|
410
|
+
account_name: (account && account.name) || merged.account_names[0] || '',
|
|
411
|
+
style_name: merged.style_name,
|
|
412
|
+
style_type: merged.style_type,
|
|
413
|
+
genre_tags: merged.genre_tags,
|
|
414
|
+
dna: merged.dna,
|
|
415
|
+
naming_rules: merged.naming_rules,
|
|
416
|
+
lexicon: merged.lexicon,
|
|
417
|
+
cross_kind_examples: merged.cross_kind_examples,
|
|
418
|
+
anti_examples: merged.anti_examples,
|
|
419
|
+
compatibility: merged.compatibility,
|
|
420
|
+
confidence: merged.confidence,
|
|
421
|
+
source_works: merged.source_works,
|
|
422
|
+
source_materials: merged.source_materials,
|
|
423
|
+
version: merged.version,
|
|
424
|
+
status: merged.status,
|
|
425
|
+
profile_json: {
|
|
426
|
+
account_names: merged.account_names,
|
|
427
|
+
account_urls: merged.account_urls,
|
|
428
|
+
naming_rules: merged.naming_rules,
|
|
429
|
+
lexicon: merged.lexicon,
|
|
430
|
+
cross_kind_examples: merged.cross_kind_examples,
|
|
431
|
+
anti_examples: merged.anti_examples,
|
|
432
|
+
compatibility: merged.compatibility,
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
const record = db.upsert(new RecordId(STYLE_TABLE, key));
|
|
436
|
+
if (existing) await record.merge(content);
|
|
437
|
+
else await record.content(content);
|
|
438
|
+
saved.push(merged);
|
|
439
|
+
}
|
|
440
|
+
return saved;
|
|
441
|
+
}
|
|
@@ -25,6 +25,8 @@ export function helpText() {
|
|
|
25
25
|
/fancy-material <素材类型> 只生成指定类型,例如:/fancy-material 地名
|
|
26
26
|
/fancy-material <题材> <素材类型> 自定义题材+素材类型,source=other,例如:/fancy-material 都市高武 地名
|
|
27
27
|
/fancy-material <题材> all 生成该题材下全部 58 个 kind,source=other,例如:/fancy-material 都市高武 all
|
|
28
|
+
/fancy-material --style <key> ... 手动指定账号风格;多个用逗号分隔,例如 --style suci,crazy-fish
|
|
29
|
+
不指定时按题材自动选 2-3 个兼容风格
|
|
28
30
|
/fancy-material load <文件.jsonl> 导入 JSONL;导入前先校验格式
|
|
29
31
|
/fancy-material init 创建/补齐素材库 schema、索引和查询/校验脚本
|
|
30
32
|
/fancy-material remove 删除整个素材库(会二次确认)
|
|
@@ -43,6 +45,8 @@ export function helpText() {
|
|
|
43
45
|
- 禁止用质量评价词做 tags:精品、高价值、文笔好、强力、神秘。
|
|
44
46
|
- tags 和 genres 都是数组:tags 3–8 个,genres 1–5 个;一个素材可以同时适配多个题材/标签。
|
|
45
47
|
- 每次运行:每个 kind 新增 50 条;每批最多 10 条,插件自动分批直到完成。
|
|
48
|
+
- 风格来源:内置风格库 + 数据库 douyin_style,按题材自动选 2-3 个;可用 --style 手动覆盖。
|
|
49
|
+
- 用 /fancy-douyin list 查看账号的 style_key、风格名和示例。
|
|
46
50
|
- 未指定类型:${MATERIAL_KINDS.length} 个 kind 全部排队。
|
|
47
51
|
- 题材来源:优先 _novel_topic.json,其次 _novel_topic_suggestion.json;都没有时弹框确认后使用内置全题材。
|
|
48
52
|
- 指定类型:只生成指定 kind,题材来源不变,source=builtin。
|
|
@@ -134,6 +138,7 @@ export function generationPrompt({
|
|
|
134
138
|
custom = null,
|
|
135
139
|
customKindPending = false,
|
|
136
140
|
sourceFixed = 'builtin',
|
|
141
|
+
styleSummary = '',
|
|
137
142
|
}) {
|
|
138
143
|
const lines = [];
|
|
139
144
|
if (includeBase && base) {
|
|
@@ -144,6 +149,9 @@ export function generationPrompt({
|
|
|
144
149
|
lines.push(...compactRules(genres, queryScript, workspace, sourceFixed), '');
|
|
145
150
|
}
|
|
146
151
|
|
|
152
|
+
if (styleSummary) {
|
|
153
|
+
lines.push('## 本批风格锁定(必须保持)', '', styleSummary, '');
|
|
154
|
+
}
|
|
147
155
|
lines.push('## 本次运行', '');
|
|
148
156
|
lines.push('- 工作区目录:' + workspace);
|
|
149
157
|
lines.push('- 目标文件(**绝对路径**):`' + target + '`');
|
|
@@ -253,6 +261,7 @@ export function generationRunText({
|
|
|
253
261
|
batches = 0,
|
|
254
262
|
total,
|
|
255
263
|
progressFile,
|
|
264
|
+
styles = [],
|
|
256
265
|
aborted = false,
|
|
257
266
|
stopReason = '',
|
|
258
267
|
}) {
|
|
@@ -279,6 +288,9 @@ export function generationRunText({
|
|
|
279
288
|
lines.push('本次新增:' + importedTotal + ' 条');
|
|
280
289
|
if (Number.isFinite(total)) lines.push('库中素材:' + total + ' 条');
|
|
281
290
|
if (batches) lines.push('已导入批次:' + batches + ' 批');
|
|
291
|
+
if (Array.isArray(styles) && styles.length) {
|
|
292
|
+
lines.push('本次风格:' + styles.map((style) => `${style.style_key}(${style.style_name})`).join('、'));
|
|
293
|
+
}
|
|
282
294
|
if (Number.isFinite(elapsedMs) && elapsedMs > 0) lines.push('耗时:' + formatDuration(elapsedMs));
|
|
283
295
|
if (stopReason) lines.push('停止原因:' + stopReason);
|
|
284
296
|
if (progressFile) lines.push('进度文件:' + progressFile);
|