@ynhcj/xiaoyi-channel 0.0.130-beta → 0.0.131-beta

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.
@@ -9,6 +9,7 @@
9
9
  // models.providers.xiaoyiprovider.models = [...]
10
10
  import { createHash } from "crypto";
11
11
  import { getCurrentSessionContext } from "./tools/session-manager.js";
12
+ import { getCurrentTaskId } from "./task-manager.js";
12
13
  import { selfEvolutionManager } from "./utils/self-evolution-manager.js";
13
14
  // ── Retry config ──────────────────────────────────────────────
14
15
  const RETRY_DELAYS_MS = [10_000, 20_000, 40_000, 60_000, 60_000];
@@ -442,6 +443,14 @@ export const xiaoyiProvider = {
442
443
  const underlying = ctx.streamFn;
443
444
  if (!underlying)
444
445
  return underlying;
446
+ // Capture A2A sessionId at agent setup time for multi-session isolation.
447
+ // openclaw calls wrapStreamFn per-agent (per session), so this runs inside
448
+ // the correct runWithSessionContext() ALS scope. When multiple sessions are
449
+ // active concurrently, getCurrentSessionContext() may later return the WRONG
450
+ // session (lastRegisteredKey fallback). The captured sessionId lets us
451
+ // bypass that fallback and look up the correct taskId directly from
452
+ // task-manager.
453
+ const capturedA2ASessionId = getCurrentSessionContext()?.sessionId ?? null;
445
454
  return async (model, context, options) => {
446
455
  // 每次请求时从 ctx.extraParams 动态读取 header
447
456
  const dynamicHeaders = {};
@@ -463,16 +472,26 @@ export const xiaoyiProvider = {
463
472
  }
464
473
  }
465
474
  else {
466
- // Session mode: get session context at request time via ALS.
467
- // OpenClaw caches prepareExtraParams by provider/modelId, so
468
- // ctx.extraParams holds the first session's values. We must
469
- // call getCurrentSessionContext() here to get the correct
470
- // sessionId/interactionId for the current concurrent request.
471
- const sessionCtx = getCurrentSessionContext();
472
- const traceId = ctx.extraParams[HEADER_TRACE_ID];
473
- const sessionId = sessionCtx?.taskId?.split("&")[0]
475
+ // Session mode: resolve taskId for the correct session.
476
+ //
477
+ // Priority:
478
+ // 1. capturedA2ASessionId → getCurrentTaskId() (most reliable,
479
+ // bypasses lastRegisteredKey fallback)
480
+ // 2. getCurrentSessionContext()?.taskId (works when ALS
481
+ // is intact)
482
+ // 3. ctx.extraParams cached values (last resort,
483
+ // may be stale / from wrong session)
484
+ let resolvedTaskId = null;
485
+ if (capturedA2ASessionId) {
486
+ resolvedTaskId = getCurrentTaskId(capturedA2ASessionId);
487
+ }
488
+ if (!resolvedTaskId) {
489
+ resolvedTaskId = getCurrentSessionContext()?.taskId ?? null;
490
+ }
491
+ const traceId = resolvedTaskId ?? ctx.extraParams[HEADER_TRACE_ID];
492
+ const sessionId = resolvedTaskId?.split("&")[0]
474
493
  ?? ctx.extraParams[HEADER_SESSION_ID];
475
- const interactionId = sessionCtx?.taskId?.split("&")[1]
494
+ const interactionId = resolvedTaskId?.split("&")[1]
476
495
  ?? ctx.extraParams[HEADER_INTERACTION_ID]
477
496
  ?? "";
478
497
  if (typeof traceId === "string") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.130-beta",
3
+ "version": "0.0.131-beta",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",