@cloud411716/fancy-webnovel 4.30.42 → 4.30.44
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/package.json
CHANGED
|
@@ -938,6 +938,62 @@ function answerSingle(answer) {
|
|
|
938
938
|
return Array.isArray(answer.selected) ? String(answer.selected[0] || '').trim() : '';
|
|
939
939
|
}
|
|
940
940
|
|
|
941
|
+
function materialPreviewText(records) {
|
|
942
|
+
const lines = [
|
|
943
|
+
`## 待确认入库(${records.length} 条)`,
|
|
944
|
+
'',
|
|
945
|
+
'以下素材已经通过 Team 交叉审查和裁判,但**还没有写入数据库**。',
|
|
946
|
+
'',
|
|
947
|
+
];
|
|
948
|
+
records.forEach((record, index) => {
|
|
949
|
+
lines.push(`### ${index + 1}. ${record.name || '未命名'}`);
|
|
950
|
+
lines.push(`- note:${record.note || ''}`);
|
|
951
|
+
lines.push(`- derivation:${record.derivation || ''}`);
|
|
952
|
+
lines.push('');
|
|
953
|
+
});
|
|
954
|
+
return lines.join('\n');
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
async function confirmMaterialImport(ctx, invocation, session, records, previewFile = '') {
|
|
958
|
+
const preview = materialPreviewText(records) + (previewFile ? `\n\n预览文件:${previewFile}` : '');
|
|
959
|
+
await notify(session, 'success', preview);
|
|
960
|
+
const first = await askOne(ctx, invocation, {
|
|
961
|
+
id: 'material_import_confirm',
|
|
962
|
+
header: '素材入库',
|
|
963
|
+
question: `以上 ${records.length} 条素材要写入数据库吗?`,
|
|
964
|
+
options: [
|
|
965
|
+
{ label: '全部写入', description: '把全部素材写入数据库' },
|
|
966
|
+
{ label: '选择部分', description: '逐条选择要写入的素材' },
|
|
967
|
+
{ label: '全部不写入', description: '保留文件,不写数据库' },
|
|
968
|
+
],
|
|
969
|
+
});
|
|
970
|
+
if (!first.ok) return first;
|
|
971
|
+
const choice = answerSingle(first.answer);
|
|
972
|
+
if (choice === '全部写入') {
|
|
973
|
+
return { ok: true, selected: new Set(records.map((record) => record.name)) };
|
|
974
|
+
}
|
|
975
|
+
if (choice === '全部不写入') {
|
|
976
|
+
return { ok: true, selected: new Set() };
|
|
977
|
+
}
|
|
978
|
+
if (choice !== '选择部分') {
|
|
979
|
+
return { ok: false, message: '未识别的入库选择:' + (choice || '空') };
|
|
980
|
+
}
|
|
981
|
+
const second = await askOne(ctx, invocation, {
|
|
982
|
+
id: 'material_import_select',
|
|
983
|
+
header: '选择素材',
|
|
984
|
+
question: `选择要写入数据库的素材(可多选,共 ${records.length} 条)`,
|
|
985
|
+
multiple: true,
|
|
986
|
+
options: records.map((record) => ({
|
|
987
|
+
label: record.name || '未命名',
|
|
988
|
+
description: String(record.note || '').slice(0, 80),
|
|
989
|
+
})),
|
|
990
|
+
});
|
|
991
|
+
if (!second.ok) return second;
|
|
992
|
+
const known = new Set(records.map((record) => record.name));
|
|
993
|
+
const selected = new Set(answerList(second.answer).filter((name) => known.has(name)));
|
|
994
|
+
return { ok: true, selected };
|
|
995
|
+
}
|
|
996
|
+
|
|
941
997
|
function facetStateFromLabels(facetLabels) {
|
|
942
998
|
const facets = {};
|
|
943
999
|
for (const step of FACET_STEPS) {
|
|
@@ -1811,7 +1867,7 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
|
|
|
1811
1867
|
batchId,
|
|
1812
1868
|
batchNo,
|
|
1813
1869
|
keep: Math.min(next.requestCount, Math.max(0, item.target - item.generated)),
|
|
1814
|
-
poolSize: Math.max(30, Math.min(Number(nameStage.poolSize) || 80, Math.max(30, Math.min(next.requestCount, Math.max(0, item.target - item.generated)) *
|
|
1870
|
+
poolSize: Math.max(30, Math.min(Number(nameStage.poolSize) || 80, Math.max(30, Math.min(next.requestCount, Math.max(0, item.target - item.generated)) * 8))),
|
|
1815
1871
|
anchorNames: item.generated === 0 ? (Array.isArray(nameStage.anchorNames) ? nameStage.anchorNames : []) : [],
|
|
1816
1872
|
});
|
|
1817
1873
|
if (!nameOut.ok) {
|
|
@@ -2023,7 +2079,42 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
|
|
|
2023
2079
|
attemptDetail = checked.detail || attemptDetail;
|
|
2024
2080
|
continue;
|
|
2025
2081
|
}
|
|
2026
|
-
|
|
2082
|
+
let importFile = file;
|
|
2083
|
+
let reviewResult = null;
|
|
2084
|
+
if (useTeam && team.reviewBeforeImport) {
|
|
2085
|
+
const recordsForReview = readJsonlRecords(file);
|
|
2086
|
+
if (recordsForReview.length) {
|
|
2087
|
+
const previewFile = file.replace(/\.jsonl$/, '.review.md');
|
|
2088
|
+
fs.writeFileSync(previewFile, materialPreviewText(recordsForReview) + '\n', 'utf8');
|
|
2089
|
+
reviewResult = await confirmMaterialImport(ctx, invocation, session, recordsForReview, previewFile);
|
|
2090
|
+
if (!reviewResult.ok) {
|
|
2091
|
+
fatal = true;
|
|
2092
|
+
stopReason = reviewResult.message;
|
|
2093
|
+
lastReason = stopReason;
|
|
2094
|
+
await notify(session, 'error', reviewResult.message + '\n未写入数据库。文件:' + file);
|
|
2095
|
+
break;
|
|
2096
|
+
}
|
|
2097
|
+
if (!reviewResult.selected.size) {
|
|
2098
|
+
fatal = true;
|
|
2099
|
+
stopReason = '用户未选择入库素材';
|
|
2100
|
+
lastReason = stopReason;
|
|
2101
|
+
await notify(session, 'success', '未写入数据库。文件保留:' + file);
|
|
2102
|
+
break;
|
|
2103
|
+
}
|
|
2104
|
+
if (reviewResult.selected.size < recordsForReview.length) {
|
|
2105
|
+
const selectedFile = file.replace(/\.jsonl$/, '.selected.jsonl');
|
|
2106
|
+
const selectedRecords = recordsForReview.filter((record) => reviewResult.selected.has(record.name));
|
|
2107
|
+
fs.writeFileSync(selectedFile, selectedRecords.map((record) => JSON.stringify(record)).join('\n') + '\n', 'utf8');
|
|
2108
|
+
const selectedCheck = await validateBatch(selectedFile, item, groupId);
|
|
2109
|
+
if (!selectedCheck.ok) {
|
|
2110
|
+
attemptDetail = selectedCheck.detail || '用户选择的素材未通过校验';
|
|
2111
|
+
continue;
|
|
2112
|
+
}
|
|
2113
|
+
importFile = selectedFile;
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
const acceptedResult = await acceptBatch(importFile, item, groupId);
|
|
2027
2118
|
if (acceptedResult.fatal) {
|
|
2028
2119
|
fatal = true;
|
|
2029
2120
|
stopReason = '导入数据库失败:' + acceptedResult.detail;
|
|
@@ -2040,6 +2131,7 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
|
|
|
2040
2131
|
group_id: groupId || item.group_id || '',
|
|
2041
2132
|
batch: batchNo,
|
|
2042
2133
|
file,
|
|
2134
|
+
...(importFile !== file ? { selected_file: importFile } : {}),
|
|
2043
2135
|
request_count: next.requestCount,
|
|
2044
2136
|
imported: acceptedResult.imported,
|
|
2045
2137
|
generated: item.generated,
|
|
@@ -2047,6 +2139,9 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
|
|
|
2047
2139
|
attempts: attempt,
|
|
2048
2140
|
}) + '\n');
|
|
2049
2141
|
} catch { /* best effort */ }
|
|
2142
|
+
if (reviewResult && reviewResult.selected.size) {
|
|
2143
|
+
await notify(session, 'success', `✅ 已写入 ${acceptedResult.imported} 条素材(${item.label})。`);
|
|
2144
|
+
}
|
|
2050
2145
|
if (acceptedResult.imported === 0) {
|
|
2051
2146
|
stalled += 1;
|
|
2052
2147
|
attemptDetail = '本批没有新增素材(可能全是重复),必须写库中不存在的新素材';
|
|
@@ -2190,6 +2285,7 @@ function teamText(root, config) {
|
|
|
2190
2285
|
`最多审查轮次:${config.maxReviewRounds}`,
|
|
2191
2286
|
`最多 agent 调用:${config.maxTotalCalls}`,
|
|
2192
2287
|
`5 轮未通过交裁判:${config.judgeOnMaxRounds ? '是' : '否'}`,
|
|
2288
|
+
`入库前人工确认:${config.reviewBeforeImport ? '开启' : '关闭'}`,
|
|
2193
2289
|
`ability_name 名字阶段:${config.nameStage?.enabled ? '开启' : '关闭'}(池 ${config.nameStage?.poolSize || 80} / 留 ${config.nameStage?.keep || 20} / 裁判 ${config.nameStage?.judges || 3} / 达标 ${config.nameStage?.minScore || 4.5})`,
|
|
2194
2290
|
`锚点名字:${(config.nameStage?.anchorNames || []).join('、') || '(无)'}`,
|
|
2195
2291
|
'',
|
|
@@ -2249,7 +2345,7 @@ async function handleTeamCommand(ctx, session, tokens) {
|
|
|
2249
2345
|
const key = String(tokens[1] || '').toLowerCase();
|
|
2250
2346
|
const value = tokens.slice(2);
|
|
2251
2347
|
if (!key) {
|
|
2252
|
-
return notify(session, 'error', '用法:/fancy-material team set a|b|judge <provider> <model> [thinking] | rounds <n> | max-calls <n> | mode <cross|oneway> | judge-on-max <true|false> | name-stage on|off | anchors <名字...> | rejected <名字...> | name-pool <n> | name-keep <n> | name-judges <n>');
|
|
2348
|
+
return notify(session, 'error', '用法:/fancy-material team set a|b|judge <provider> <model> [thinking] | rounds <n> | max-calls <n> | mode <cross|oneway> | judge-on-max <true|false> | review-before-import on|off | name-stage on|off | anchors <名字...> | rejected <名字...> | name-pool <n> | name-keep <n> | name-judges <n>');
|
|
2253
2349
|
}
|
|
2254
2350
|
if (key === 'a' || key === 'b' || key === 'judge') {
|
|
2255
2351
|
if (value.length < 2) {
|
|
@@ -2310,6 +2406,13 @@ async function handleTeamCommand(ctx, session, tokens) {
|
|
|
2310
2406
|
writeTeamConfig(root, config);
|
|
2311
2407
|
return notify(session, 'success', `✅ 5 轮未通过交裁判:${config.judgeOnMaxRounds ? '是' : '否'}。`);
|
|
2312
2408
|
}
|
|
2409
|
+
if (key === 'review-before-import') {
|
|
2410
|
+
const on = String(value[0] || '').toLowerCase();
|
|
2411
|
+
if (on !== 'on' && on !== 'off') return notify(session, 'error', 'review-before-import 只能是 on 或 off。');
|
|
2412
|
+
config.reviewBeforeImport = on === 'on';
|
|
2413
|
+
writeTeamConfig(root, config);
|
|
2414
|
+
return notify(session, 'success', `✅ 入库前人工确认已${config.reviewBeforeImport ? '开启' : '关闭'}。`);
|
|
2415
|
+
}
|
|
2313
2416
|
if (key === 'name-stage') {
|
|
2314
2417
|
const on = String(value[0] || '').toLowerCase();
|
|
2315
2418
|
if (on !== 'on' && on !== 'off') return notify(session, 'error', 'name-stage 只能是 on 或 off。');
|
|
@@ -153,7 +153,9 @@ function buildNamePrompt({
|
|
|
153
153
|
lines.push('2. **主体 + 动作**:`工牌借脸`、`檐灰点眼`');
|
|
154
154
|
lines.push('3. **条件 + 后果**:`灯灭名断`');
|
|
155
155
|
lines.push('');
|
|
156
|
+
lines.push('4 字名优先 **2+2**:前两字是物象,后两字是结果/状态或强动作。');
|
|
156
157
|
lines.push('避免:**物象 + 动词 + 隐含对象**的三截压缩,例如 `灯烬点名`、`旧牌借脸`——读者要先补主语/宾语才知道发生了什么。');
|
|
158
|
+
lines.push('先在心里写一句普通句子,再压成 4 字;压完如果还要补主语或宾语,换一个名字。');
|
|
157
159
|
lines.push('名字单看就要有“这怎么可能/代价是什么”的张力;不读 note 也能在一眼里猜出能力方向。');
|
|
158
160
|
lines.push('读一遍要顺。不要为了凑四字把词压成不自然的缩写:`旧工牌` 不要压成 `旧牌`,`点眼` 不要写成 `点主`。');
|
|
159
161
|
lines.push('');
|
|
@@ -276,10 +278,14 @@ export async function runNameStage({
|
|
|
276
278
|
return { ok: false, error: 'name-stage 需要 generatorA / generatorB / judge 三条模型路由。' };
|
|
277
279
|
}
|
|
278
280
|
|
|
281
|
+
const nameWorldBlock = String(worldBlock || '')
|
|
282
|
+
.split(/\r?\n/)
|
|
283
|
+
.filter((line) => !line.includes('命名逻辑'))
|
|
284
|
+
.join('\n');
|
|
279
285
|
const promptA = buildNamePrompt({
|
|
280
286
|
role: 'A',
|
|
281
287
|
targetFile: aFile,
|
|
282
|
-
worldBlock,
|
|
288
|
+
worldBlock: nameWorldBlock,
|
|
283
289
|
styleSummary,
|
|
284
290
|
genres,
|
|
285
291
|
kind,
|
|
@@ -291,7 +297,7 @@ export async function runNameStage({
|
|
|
291
297
|
const promptB = buildNamePrompt({
|
|
292
298
|
role: 'B',
|
|
293
299
|
targetFile: bFile,
|
|
294
|
-
worldBlock,
|
|
300
|
+
worldBlock: nameWorldBlock,
|
|
295
301
|
styleSummary,
|
|
296
302
|
genres,
|
|
297
303
|
kind,
|
|
@@ -18,6 +18,7 @@ const DEFAULT_TEAM = Object.freeze({
|
|
|
18
18
|
maxReviewRounds: 5,
|
|
19
19
|
maxTotalCalls: 12,
|
|
20
20
|
judgeOnMaxRounds: true,
|
|
21
|
+
reviewBeforeImport: true,
|
|
21
22
|
generatorA: null,
|
|
22
23
|
generatorB: null,
|
|
23
24
|
judge: null,
|
|
@@ -56,6 +57,7 @@ export function readTeamConfig(root) {
|
|
|
56
57
|
out.maxReviewRounds = clampInt(out.maxReviewRounds, 1, 10, 5);
|
|
57
58
|
out.maxTotalCalls = clampInt(out.maxTotalCalls, 6, 40, 12);
|
|
58
59
|
out.judgeOnMaxRounds = out.judgeOnMaxRounds !== false;
|
|
60
|
+
out.reviewBeforeImport = out.reviewBeforeImport !== false;
|
|
59
61
|
const ns = raw && raw.nameStage && typeof raw.nameStage === 'object' ? raw.nameStage : {};
|
|
60
62
|
out.nameStage = {
|
|
61
63
|
enabled: ns.enabled !== false,
|