@cloud411716/fancy-webnovel 4.30.20 → 4.30.22
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
|
@@ -2059,6 +2059,8 @@ function teamText(root, config) {
|
|
|
2059
2059
|
'',
|
|
2060
2060
|
`配置文件:${teamConfigPath(root)}`,
|
|
2061
2061
|
'',
|
|
2062
|
+
'注意:A、B、裁判必须使用不同模型,否则双生成和交叉审查没有意义。',
|
|
2063
|
+
'',
|
|
2062
2064
|
'设置示例:',
|
|
2063
2065
|
' /fancy-material team set a opencode-go glm-5.3',
|
|
2064
2066
|
' /fancy-material team set b opencode-go kimi-k3',
|
|
@@ -2134,6 +2136,12 @@ async function handleTeamCommand(ctx, session, tokens) {
|
|
|
2134
2136
|
].filter(Boolean).join('\n'));
|
|
2135
2137
|
}
|
|
2136
2138
|
const field = key === 'a' ? 'generatorA' : key === 'b' ? 'generatorB' : 'judge';
|
|
2139
|
+
const clash = ['generatorA', 'generatorB', 'judge']
|
|
2140
|
+
.filter((name) => name !== field)
|
|
2141
|
+
.find((name) => config[name] && config[name].provider === provider && config[name].model === model);
|
|
2142
|
+
if (clash) {
|
|
2143
|
+
return notify(session, 'error', `❌ ${provider}/${model} 已被 ${clash} 使用。A、B、裁判必须使用不同模型。`);
|
|
2144
|
+
}
|
|
2137
2145
|
config[field] = { provider, model };
|
|
2138
2146
|
writeTeamConfig(root, config);
|
|
2139
2147
|
return notify(session, 'success', `✅ ${field} 已设为 ${provider}/${model}。`);
|
|
@@ -10,6 +10,7 @@ import fs from 'node:fs';
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
|
|
12
12
|
const TEAM_FILE = 'team.json';
|
|
13
|
+
const TEAM_CALL_TIMEOUT_MS = 20 * 60 * 1000;
|
|
13
14
|
const DEFAULT_TEAM = Object.freeze({
|
|
14
15
|
version: 1,
|
|
15
16
|
enabled: false,
|
|
@@ -83,6 +84,21 @@ export function teamConfigProblem(config) {
|
|
|
83
84
|
if (!config.generatorB) missing.push('generatorB');
|
|
84
85
|
if (!config.judge) missing.push('judge');
|
|
85
86
|
if (missing.length) return 'team 模式缺少模型:' + missing.join('、') + '。用 /fancy-material team set 设置。';
|
|
87
|
+
const seen = new Map();
|
|
88
|
+
const duplicates = [];
|
|
89
|
+
for (const [label, route] of [
|
|
90
|
+
['generatorA', config.generatorA],
|
|
91
|
+
['generatorB', config.generatorB],
|
|
92
|
+
['judge', config.judge],
|
|
93
|
+
]) {
|
|
94
|
+
const key = `${route.provider}/${route.model}`;
|
|
95
|
+
if (seen.has(key)) duplicates.push(`${seen.get(key)} 与 ${label} 都是 ${key}`);
|
|
96
|
+
else seen.set(key, label);
|
|
97
|
+
}
|
|
98
|
+
if (duplicates.length) {
|
|
99
|
+
return 'team 模式的三个角色必须使用不同模型:' + duplicates.join(';')
|
|
100
|
+
+ '。同模型会让双生成和交叉审查失去意义。';
|
|
101
|
+
}
|
|
86
102
|
return '';
|
|
87
103
|
}
|
|
88
104
|
|
|
@@ -260,8 +276,15 @@ async function callSubagent({ subagents, parent, prompt, route, label, schema, s
|
|
|
260
276
|
} catch (err) {
|
|
261
277
|
return { ok: false, error: err && err.message ? err.message : String(err) };
|
|
262
278
|
}
|
|
279
|
+
let timer = null;
|
|
263
280
|
try {
|
|
264
|
-
const result = await
|
|
281
|
+
const result = await Promise.race([
|
|
282
|
+
activation.result,
|
|
283
|
+
new Promise((_, reject) => {
|
|
284
|
+
timer = setTimeout(() => reject(new Error(`子 agent ${label} 超时`)), TEAM_CALL_TIMEOUT_MS);
|
|
285
|
+
if (timer && typeof timer.unref === 'function') timer.unref();
|
|
286
|
+
}),
|
|
287
|
+
]);
|
|
265
288
|
if (!result || result.stopReason !== 'completed') {
|
|
266
289
|
return { ok: false, error: (result && (result.diagnostic || result.stopReason)) || '子 agent 未完成' };
|
|
267
290
|
}
|
|
@@ -270,7 +293,14 @@ async function callSubagent({ subagents, parent, prompt, route, label, schema, s
|
|
|
270
293
|
return { ok: true, value: result.structured };
|
|
271
294
|
}
|
|
272
295
|
return { ok: true, value: textFromBlocks(result.output) };
|
|
296
|
+
} catch (err) {
|
|
297
|
+
return {
|
|
298
|
+
ok: false,
|
|
299
|
+
error: err && err.message ? err.message : String(err),
|
|
300
|
+
stack: err && err.stack ? String(err.stack) : '',
|
|
301
|
+
};
|
|
273
302
|
} finally {
|
|
303
|
+
if (timer) clearTimeout(timer);
|
|
274
304
|
try { await activation.dispose(); } catch { /* best effort */ }
|
|
275
305
|
}
|
|
276
306
|
}
|
|
@@ -334,6 +364,7 @@ export async function runTeamBatch({
|
|
|
334
364
|
}
|
|
335
365
|
const problem = teamConfigProblem(team);
|
|
336
366
|
if (problem) return { ok: false, error: problem };
|
|
367
|
+
const parentSignal = signal || new AbortController().signal;
|
|
337
368
|
|
|
338
369
|
const aFile = path.join(runDir, 'team-a.jsonl');
|
|
339
370
|
const bFile = path.join(runDir, 'team-b.jsonl');
|
|
@@ -348,46 +379,57 @@ export async function runTeamBatch({
|
|
|
348
379
|
writePromptFile(promptBFile, appendTeamRole(retargetPrompt(prompt, file, bFile), 'B', bFile, aFile));
|
|
349
380
|
writePromptFile(rubricFile, `${manualBlock || ''}\n\n${TEAM_RUBRIC}`);
|
|
350
381
|
|
|
382
|
+
const metaFile = path.join(runDir, 'team-meta.json');
|
|
383
|
+
const reviewFile = path.join(runDir, 'team-review.json');
|
|
384
|
+
const meta = {
|
|
385
|
+
batchId,
|
|
386
|
+
batchNo,
|
|
387
|
+
startedAt: new Date().toISOString(),
|
|
388
|
+
generatorA: team.generatorA,
|
|
389
|
+
generatorB: team.generatorB,
|
|
390
|
+
judge: team.judge,
|
|
391
|
+
reviewMode: team.reviewMode,
|
|
392
|
+
maxReviewRounds: team.maxReviewRounds,
|
|
393
|
+
maxTotalCalls: Math.max(6, Number(team.maxTotalCalls) || 12),
|
|
394
|
+
phase: 'generate',
|
|
395
|
+
};
|
|
396
|
+
writeJsonFile(metaFile, meta);
|
|
397
|
+
|
|
351
398
|
let calls = 0;
|
|
352
399
|
const maxCalls = Math.max(6, Number(team.maxTotalCalls) || 12);
|
|
353
400
|
const call = async (promptText, route, label, schema) => {
|
|
354
401
|
if (calls >= maxCalls) return { ok: false, error: 'team workflow reached maxTotalCalls' };
|
|
355
402
|
calls += 1;
|
|
356
|
-
return callSubagent({ subagents, parent, prompt: promptText, route, label, schema });
|
|
403
|
+
return callSubagent({ subagents, parent, prompt: promptText, route, label, schema, signal: parentSignal });
|
|
357
404
|
};
|
|
358
405
|
|
|
359
406
|
const [genA, genB] = await Promise.all([
|
|
360
407
|
call(genPrompt(promptAFile, aFile, bFile, 'A'), team.generatorA, 'gen-a'),
|
|
361
408
|
call(genPrompt(promptBFile, bFile, aFile, 'B'), team.generatorB, 'gen-b'),
|
|
362
409
|
]);
|
|
363
|
-
|
|
364
|
-
if (!
|
|
410
|
+
meta.calls = calls;
|
|
411
|
+
if (!genA.ok || !genB.ok) {
|
|
412
|
+
meta.error = !genA.ok ? '生成者 A 失败:' + genA.error : '生成者 B 失败:' + genB.error;
|
|
413
|
+
meta.genA = genA;
|
|
414
|
+
meta.genB = genB;
|
|
415
|
+
writeJsonFile(metaFile, meta);
|
|
416
|
+
return { ok: false, error: meta.error + (genA.stack ? '\n' + genA.stack : '') + (genB.stack ? '\n' + genB.stack : '') };
|
|
417
|
+
}
|
|
365
418
|
for (const [label, candidate] of [['A', aFile], ['B', bFile]]) {
|
|
366
419
|
if (!fs.existsSync(candidate) || fs.statSync(candidate).size === 0) {
|
|
367
|
-
|
|
420
|
+
meta.error = `生成者 ${label} 没有写出文件:${candidate}`;
|
|
421
|
+
writeJsonFile(metaFile, meta);
|
|
422
|
+
return { ok: false, error: meta.error };
|
|
368
423
|
}
|
|
369
424
|
}
|
|
370
425
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const parentSignal = signal || new AbortController().signal;
|
|
426
|
+
meta.phase = 'review';
|
|
427
|
+
writeJsonFile(metaFile, meta);
|
|
374
428
|
let aPassed = false;
|
|
375
429
|
let bPassed = false;
|
|
376
430
|
let round = 0;
|
|
377
431
|
let stopReason = '';
|
|
378
432
|
const history = [];
|
|
379
|
-
const meta = {
|
|
380
|
-
batchId,
|
|
381
|
-
batchNo,
|
|
382
|
-
startedAt: new Date().toISOString(),
|
|
383
|
-
generatorA: team.generatorA,
|
|
384
|
-
generatorB: team.generatorB,
|
|
385
|
-
judge: team.judge,
|
|
386
|
-
reviewMode: team.reviewMode,
|
|
387
|
-
maxReviewRounds: team.maxReviewRounds,
|
|
388
|
-
maxTotalCalls: maxCalls,
|
|
389
|
-
};
|
|
390
|
-
writeJsonFile(metaFile, meta);
|
|
391
433
|
|
|
392
434
|
// Keep one call in reserve for the judge. A full review-response-revision
|
|
393
435
|
// round costs up to six calls, so the budget check happens before each stage.
|
|
@@ -487,6 +529,8 @@ export async function runTeamBatch({
|
|
|
487
529
|
return { ok: false, error };
|
|
488
530
|
}
|
|
489
531
|
|
|
532
|
+
meta.phase = 'judge';
|
|
533
|
+
writeJsonFile(metaFile, meta);
|
|
490
534
|
const judge = await call(
|
|
491
535
|
judgePrompt(round, aPassed, bPassed, history, aFile, bFile, finalFile, rubricFile),
|
|
492
536
|
team.judge,
|
|
@@ -25,7 +25,7 @@ export function helpText() {
|
|
|
25
25
|
/fancy-material continue 沿用上次的世界母体、facet、风格和范围,继续追加素材
|
|
26
26
|
/fancy-material team show 查看双生成 + 交叉审查 + 裁判的配置
|
|
27
27
|
/fancy-material team models [provider] 查看当前可用模型(默认 opencode-go)
|
|
28
|
-
/fancy-material team set a|b|judge <provider> <model>
|
|
28
|
+
/fancy-material team set a|b|judge <provider> <model> 设置生成者/裁判模型(三者必须不同)
|
|
29
29
|
/fancy-material team set rounds <1-10> 设置最多交叉审查轮次(默认 5)
|
|
30
30
|
/fancy-material team set max-calls <6-40> 设置整个 workflow 最多 agent 调用
|
|
31
31
|
/fancy-material team on|off 开/关 Team 模式
|