@cloud411716/fancy-webnovel 4.30.23 → 4.30.24

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.23",
3
+ "version": "4.30.24",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -153,6 +153,26 @@ function service(ctx, name) {
153
153
  }
154
154
  }
155
155
 
156
+ /** Read the child's terminal error from its durable session when available. */
157
+ async function subagentFailureDetail(ctx, childId) {
158
+ if (!childId) return '';
159
+ const query = service(ctx, 'sessionQuery');
160
+ if (!query || typeof query.readSession !== 'function') return '';
161
+ try {
162
+ const snapshot = await query.readSession(childId);
163
+ const events = Array.isArray(snapshot && snapshot.events) ? snapshot.events : [];
164
+ for (let index = events.length - 1; index >= 0; index -= 1) {
165
+ const event = events[index];
166
+ if (!event || event.type !== 'turn/end') continue;
167
+ const reason = event.data && event.data.reason;
168
+ if (!reason || reason.kind !== 'error') continue;
169
+ const message = reason.error && reason.error.message;
170
+ if (message) return String(message);
171
+ }
172
+ } catch { /* diagnostics only */ }
173
+ return '';
174
+ }
175
+
156
176
  function retargetPrompt(prompt, from, to) {
157
177
  return String(prompt || '').split(`目标文件(**绝对路径**):\`${from}\``).join(`目标文件(**绝对路径**):\`${to}\``);
158
178
  }
@@ -281,7 +301,7 @@ function textFromBlocks(blocks) {
281
301
  .join('');
282
302
  }
283
303
 
284
- async function callSubagent({ subagents, parent, prompt, route, label, schema, signal }) {
304
+ async function callSubagent({ ctx, subagents, parent, prompt, route, label, schema, signal }) {
285
305
  let activation;
286
306
  try {
287
307
  activation = await subagents.startActivation({
@@ -307,7 +327,11 @@ async function callSubagent({ subagents, parent, prompt, route, label, schema, s
307
327
  }),
308
328
  ]);
309
329
  if (!result || result.stopReason !== 'completed') {
310
- return { ok: false, error: (result && (result.diagnostic || result.stopReason)) || '子 agent 未完成' };
330
+ const detail = (result && result.diagnostic)
331
+ || await subagentFailureDetail(ctx, activation.childId)
332
+ || (result && result.stopReason)
333
+ || '子 agent 未完成';
334
+ return { ok: false, error: detail, childId: activation.childId };
311
335
  }
312
336
  if (schema) {
313
337
  if (result.structured === undefined) return { ok: false, error: '子 agent 没有返回结构化结果' };
@@ -319,6 +343,7 @@ async function callSubagent({ subagents, parent, prompt, route, label, schema, s
319
343
  ok: false,
320
344
  error: err && err.message ? err.message : String(err),
321
345
  stack: err && err.stack ? String(err.stack) : '',
346
+ childId: activation && activation.childId,
322
347
  };
323
348
  } finally {
324
349
  if (timer) clearTimeout(timer);
@@ -432,7 +457,7 @@ export async function runTeamBatch({
432
457
  const call = async (promptText, route, label, schema) => {
433
458
  if (calls >= maxCalls) return { ok: false, error: 'team workflow reached maxTotalCalls' };
434
459
  calls += 1;
435
- return callSubagent({ subagents, parent, prompt: promptText, route, label, schema, signal: parentSignal });
460
+ return callSubagent({ ctx, subagents, parent, prompt: promptText, route, label, schema, signal: parentSignal });
436
461
  };
437
462
 
438
463
  const [genA, genB] = await Promise.all([