@cloud411716/fancy-webnovel 4.30.42 → 4.30.43

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "4.30.42",
3
+ "version": "4.30.43",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -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) {
@@ -2023,7 +2079,42 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
2023
2079
  attemptDetail = checked.detail || attemptDetail;
2024
2080
  continue;
2025
2081
  }
2026
- const acceptedResult = await acceptBatch(file, item, groupId);
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。');
@@ -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,