@ynhcj/xiaoyi-channel 0.0.190-next → 0.0.191-next

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/dist/index.js CHANGED
@@ -184,23 +184,36 @@ function registerSubagentHooks(api) {
184
184
  // This is the PRIMARY delivery tracking mechanism. When all expected
185
185
  // subagents have ended and parent has settled, we finalize the A2A session.
186
186
  api.on("subagent_ended", async (event, ctx) => {
187
- const requesterSessionKey = ctx?.requesterSessionKey;
188
- if (!requesterSessionKey)
189
- return;
190
- const transition = markSubagentEnded(requesterSessionKey);
191
- console.log(`[XY-SUBAGENT] ended, sessionKey=${event?.targetSessionKey?.slice(0, 30)}, outcome=${event?.outcome}, complete=${transition?.isComplete ?? false}, shouldFinalize=${transition?.shouldFinalize ?? false}`);
192
- if (transition?.shouldFinalize) {
193
- // All subagents ended and parent already settled — finalize A2A session
194
- const { resolveXYConfig } = await import("./src/config.js");
195
- const { deliverSubagentFinalResult } = await import("./src/outbound.js");
196
- const { getXYRuntime } = await import("./src/runtime.js");
197
- const config = resolveXYConfig(getXYRuntime().config);
198
- await deliverSubagentFinalResult({
199
- config,
200
- state: transition.state,
201
- reason: "all-subagents-ended-after-parent-settled",
202
- });
203
- console.log(`[XY-SUBAGENT] Finalized A2A session after all subagents ended`);
187
+ try {
188
+ const requesterSessionKey = ctx?.requesterSessionKey;
189
+ if (!requesterSessionKey) {
190
+ console.log(`[XY-SUBAGENT-END] no requesterSessionKey in ctx`);
191
+ return;
192
+ }
193
+ const transition = markSubagentEnded(requesterSessionKey);
194
+ console.log(`[XY-SUBAGENT-END] ended, targetSessionKey=${event?.targetSessionKey?.slice(0, 30)}, outcome=${event?.outcome}, complete=${transition?.isComplete ?? false}, shouldFinalize=${transition?.shouldFinalize ?? false}, transition=${!!transition}`);
195
+ if (transition?.shouldFinalize) {
196
+ console.log(`[XY-SUBAGENT-END] Starting finalization...`);
197
+ const [{ resolveXYConfig }, { deliverSubagentFinalResult }, { getXYRuntime }] = await Promise.all([
198
+ import("./src/config.js"),
199
+ import("./src/outbound.js"),
200
+ import("./src/runtime.js"),
201
+ ]);
202
+ const rt = getXYRuntime();
203
+ console.log(`[XY-SUBAGENT-END] Runtime config type: ${typeof rt.config}, keys: ${rt.config ? Object.keys(rt.config).slice(0, 5).join(',') : 'null'}`);
204
+ const cfg = rt.config;
205
+ const config = resolveXYConfig(cfg);
206
+ console.log(`[XY-SUBAGENT-END] XY config resolved, wsUrl=${config.wsUrl?.slice(0, 20)}`);
207
+ await deliverSubagentFinalResult({
208
+ config,
209
+ state: transition.state,
210
+ reason: "all-subagents-ended-after-parent-settled",
211
+ });
212
+ console.log(`[XY-SUBAGENT-END] Finalized A2A session after all subagents ended`);
213
+ }
214
+ }
215
+ catch (err) {
216
+ console.error(`[XY-SUBAGENT-END] Error in subagent_ended hook:`, err instanceof Error ? `${err.name}: ${err.message}\n${err.stack}` : String(err));
204
217
  }
205
218
  });
206
219
  }
@@ -20,7 +20,7 @@ export async function deliverSubagentFinalResult(params) {
20
20
  const log = logger.withContext(state.sessionId, state.taskId);
21
21
  const finalText = state.completionTexts.length > 0
22
22
  ? state.completionTexts.join("\n\n")
23
- : (text ?? "");
23
+ : (text || undefined) ?? "子任务已完成";
24
24
  await sendStatusUpdate({
25
25
  config,
26
26
  sessionId: state.sessionId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.190-next",
3
+ "version": "0.0.191-next",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",