@cloud411716/fancy-webnovel 4.30.26 → 4.30.28

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.26",
3
+ "version": "4.30.28",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -2065,8 +2065,8 @@ function teamText(root, config) {
2065
2065
  '',
2066
2066
  '设置示例:',
2067
2067
  ' /fancy-material team set a opencode-go glm-5.3',
2068
- ' /fancy-material team set b opencode-go kimi-k3',
2069
- ' /fancy-material team set judge opencode-go deepseek-v4.1-flash',
2068
+ ' /fancy-material team set b opencode-go hy4-flash off',
2069
+ ' /fancy-material team set judge opencode-go mimo-v2.6-flash low',
2070
2070
  ' /fancy-material team set rounds 5',
2071
2071
  ' /fancy-material team on',
2072
2072
  ].join('\n');
@@ -2115,14 +2115,18 @@ async function handleTeamCommand(ctx, session, tokens) {
2115
2115
  const key = String(tokens[1] || '').toLowerCase();
2116
2116
  const value = tokens.slice(2);
2117
2117
  if (!key) {
2118
- return notify(session, 'error', '用法:/fancy-material team set a|b|judge <provider> <model> | rounds <n> | max-calls <n> | mode <cross|oneway> | judge-on-max <true|false>');
2118
+ 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>');
2119
2119
  }
2120
2120
  if (key === 'a' || key === 'b' || key === 'judge') {
2121
2121
  if (value.length < 2) {
2122
- return notify(session, 'error', `用法:/fancy-material team set ${key} <provider> <model>`);
2122
+ return notify(session, 'error', `用法:/fancy-material team set ${key} <provider> <model> [off|minimal|low|medium|high|xhigh|max]`);
2123
2123
  }
2124
2124
  const provider = value[0];
2125
2125
  const model = value[1];
2126
+ const reasoningEffort = String(value[2] || '').trim().toLowerCase();
2127
+ if (reasoningEffort && !['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'].includes(reasoningEffort)) {
2128
+ return notify(session, 'error', 'thinking 等级只能是 off / minimal / low / medium / high / xhigh / max。');
2129
+ }
2126
2130
  let models;
2127
2131
  try {
2128
2132
  models = await listTeamModels(ctx, provider);
@@ -2138,9 +2142,10 @@ async function handleTeamCommand(ctx, session, tokens) {
2138
2142
  if (clash) {
2139
2143
  return notify(session, 'error', `❌ ${provider}/${model} 已被 ${clash} 使用。A、B、裁判必须使用不同模型。`);
2140
2144
  }
2141
- config[field] = { provider, model };
2145
+ config[field] = { provider, model, ...(reasoningEffort ? { reasoningEffort } : {}) };
2142
2146
  writeTeamConfig(root, config);
2143
- return notify(session, 'success', `✅ ${field} 已设为 ${provider}/${model}。`
2147
+ return notify(session, 'success', `✅ ${field} 已设为 ${provider}/${model}`
2148
+ + (reasoningEffort ? `(thinking: ${reasoningEffort})` : '(thinking: 模型默认)') + '。'
2144
2149
  + (catalogMiss ? '\n⚠️ 该模型不在当前 provider 目录里,生成时以实际 API 为准。' : ''));
2145
2150
  }
2146
2151
  if (key === 'rounds') {
@@ -70,11 +70,13 @@ function normalizeRoute(value) {
70
70
  const provider = String(value.provider || '').trim();
71
71
  const model = String(value.model || '').trim();
72
72
  if (!provider || !model) return null;
73
- return { provider, model };
73
+ const reasoningEffort = String(value.reasoningEffort || '').trim();
74
+ return { provider, model, ...(reasoningEffort ? { reasoningEffort } : {}) };
74
75
  }
75
76
 
76
77
  export function teamRouteText(route) {
77
- return route ? `${route.provider}/${route.model}` : '(未设置)';
78
+ if (!route) return '(未设置)';
79
+ return `${route.provider}/${route.model}${route.reasoningEffort ? '(thinking: ' + route.reasoningEffort + ')' : ''}`;
78
80
  }
79
81
 
80
82
  export function teamConfigProblem(config) {
@@ -303,6 +305,82 @@ function textFromBlocks(blocks) {
303
305
  .join('');
304
306
  }
305
307
 
308
+ /** Find the first complete JSON object in a string, tolerating prose/fences. */
309
+ function extractJsonObject(text) {
310
+ const source = String(text || '');
311
+ for (let start = source.indexOf('{'); start >= 0; start = source.indexOf('{', start + 1)) {
312
+ let depth = 0;
313
+ let inString = false;
314
+ let escaped = false;
315
+ for (let index = start; index < source.length; index += 1) {
316
+ const char = source[index];
317
+ if (inString) {
318
+ if (escaped) escaped = false;
319
+ else if (char === '\\') escaped = true;
320
+ else if (char === '"') inString = false;
321
+ continue;
322
+ }
323
+ if (char === '"') { inString = true; continue; }
324
+ if (char === '{') depth += 1;
325
+ else if (char === '}') {
326
+ depth -= 1;
327
+ if (depth === 0) {
328
+ try { return JSON.parse(source.slice(start, index + 1)); } catch { break; }
329
+ }
330
+ }
331
+ }
332
+ }
333
+ return undefined;
334
+ }
335
+
336
+ /** Check the small JSON-Schema subset used by team structured outputs. */
337
+ function matchesSchema(value, schema) {
338
+ if (!schema || typeof schema !== 'object') return true;
339
+ if (schema.type === 'object') {
340
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
341
+ for (const key of schema.required || []) {
342
+ if (!(key in value)) return false;
343
+ }
344
+ if (schema.additionalProperties === false) {
345
+ const allowed = new Set(Object.keys(schema.properties || {}));
346
+ for (const key of Object.keys(value)) if (!allowed.has(key)) return false;
347
+ }
348
+ for (const [key, child] of Object.entries(schema.properties || {})) {
349
+ if (key in value && !matchesSchema(value[key], child)) return false;
350
+ }
351
+ return true;
352
+ }
353
+ if (schema.type === 'array') {
354
+ if (!Array.isArray(value)) return false;
355
+ return value.every((item) => matchesSchema(item, schema.items));
356
+ }
357
+ if (schema.type === 'string') {
358
+ if (typeof value !== 'string') return false;
359
+ return !Array.isArray(schema.enum) || schema.enum.includes(value);
360
+ }
361
+ if (schema.type === 'boolean') return typeof value === 'boolean';
362
+ if (schema.type === 'number' || schema.type === 'integer') return typeof value === 'number';
363
+ return true;
364
+ }
365
+
366
+ /** Recover a structured value when a model emits JSON in a text/tool-call block. */
367
+ function structuredFromBlocks(blocks, schema) {
368
+ const candidates = [];
369
+ for (const block of Array.isArray(blocks) ? blocks : []) {
370
+ if (!block) continue;
371
+ if (block.type === 'text') candidates.push(block.text);
372
+ if (block.type === 'tool-call') {
373
+ if (typeof block.arguments === 'string') candidates.push(block.arguments);
374
+ else if (block.arguments && typeof block.arguments === 'object') candidates.push(JSON.stringify(block.arguments));
375
+ }
376
+ }
377
+ for (const candidate of candidates) {
378
+ const parsed = extractJsonObject(candidate);
379
+ if (parsed !== undefined && matchesSchema(parsed, schema)) return parsed;
380
+ }
381
+ return undefined;
382
+ }
383
+
306
384
  async function callSubagent({ ctx, subagents, parent, prompt, route, label, schema, signal }) {
307
385
  let activation;
308
386
  try {
@@ -313,7 +391,11 @@ async function callSubagent({ ctx, subagents, parent, prompt, route, label, sche
313
391
  parent,
314
392
  signal,
315
393
  delivery: 'caller',
316
- agentOptions: { provider: route.provider, model: route.model },
394
+ agentOptions: {
395
+ provider: route.provider,
396
+ model: route.model,
397
+ ...(route.reasoningEffort ? { reasoningEffort: route.reasoningEffort } : {}),
398
+ },
317
399
  ...(schema ? { outputSchema: schema } : {}),
318
400
  });
319
401
  } catch (err) {
@@ -328,16 +410,24 @@ async function callSubagent({ ctx, subagents, parent, prompt, route, label, sche
328
410
  if (timer && typeof timer.unref === 'function') timer.unref();
329
411
  }),
330
412
  ]);
413
+ if (schema) {
414
+ const value = result && result.structured !== undefined
415
+ ? result.structured
416
+ : structuredFromBlocks(result && result.output, schema);
417
+ if (value !== undefined) return { ok: true, value };
418
+ }
331
419
  if (!result || result.stopReason !== 'completed') {
420
+ const preview = textFromBlocks(result && result.output).slice(0, 300);
332
421
  const detail = (result && result.diagnostic)
333
422
  || await subagentFailureDetail(ctx, activation.childId)
423
+ || (preview ? `子 agent 未按 schema 返回结果:${preview}` : '')
334
424
  || (result && result.stopReason)
335
425
  || '子 agent 未完成';
336
426
  return { ok: false, error: detail, childId: activation.childId };
337
427
  }
338
428
  if (schema) {
339
- if (result.structured === undefined) return { ok: false, error: '子 agent 没有返回结构化结果' };
340
- return { ok: true, value: result.structured };
429
+ const preview = textFromBlocks(result.output).slice(0, 300);
430
+ return { ok: false, error: '子 agent 没有返回结构化结果' + (preview ? ':' + preview : ''), childId: activation.childId };
341
431
  }
342
432
  return { ok: true, value: textFromBlocks(result.output) };
343
433
  } catch (err) {
@@ -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> [thinking] 设置模型和 thinking 等级(三者必须不同)
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 模式