@ynhcj/xiaoyi-channel 0.0.106-next → 0.0.107-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.
@@ -8,7 +8,7 @@
8
8
  // models.providers.xiaoyiprovider.api = "openai-completions"
9
9
  // models.providers.xiaoyiprovider.models = [...]
10
10
  import { createHash } from "crypto";
11
- import { getSession, getSessionByA2AId, xyAsyncLocalStorage } from "./xy-session-store.js";
11
+ import { getSession, getSessionByA2AId, getAllActiveSessions, xyAsyncLocalStorage } from "./xy-session-store.js";
12
12
  import { selfEvolutionManager } from "./utils/self-evolution-manager.js";
13
13
  // ── Retry config ──────────────────────────────────────────────
14
14
  const RETRY_DELAYS_MS = [10_000, 20_000, 40_000, 60_000, 60_000];
@@ -455,15 +455,27 @@ export const xiaoyiProvider = {
455
455
  : null;
456
456
  return async (model, context, options) => {
457
457
  const dynamicHeaders = {};
458
- // Priority: session store lookup (captured a2aSessionId) prepareExtraParams cache → uid fallback
459
- // We check capturedA2ASessionId FIRST because OpenClaw caches prepareExtraParams
460
- // by provider/modelId (not per-session). A previous call without ALS may have
461
- // populated the cache with FALLBACK_PREFIX_KEY, which would shadow the session
462
- // lookup if we checked it first.
458
+ // Resolve taskId via three-layer fallback (same pattern as requireSession):
459
+ // 1. capturedA2ASessionId store lookup (set at wrapStreamFn setup if ALS was active)
460
+ // 2. ALS store lookup (works at request time if async chain preserved context)
461
+ // 3. Store enumeration (safe when only one session is active)
463
462
  let resolvedTaskId = null;
464
463
  if (capturedA2ASessionId) {
465
464
  resolvedTaskId = getSessionByA2AId(capturedA2ASessionId)?.taskId ?? null;
466
465
  }
466
+ if (!resolvedTaskId) {
467
+ const alsContext = xyAsyncLocalStorage.getStore();
468
+ const alsKey = alsContext?.openclawSessionKey;
469
+ if (alsKey) {
470
+ resolvedTaskId = getSession(alsKey)?.taskId ?? null;
471
+ }
472
+ }
473
+ if (!resolvedTaskId) {
474
+ const allSessions = getAllActiveSessions();
475
+ if (allSessions.length === 1) {
476
+ resolvedTaskId = allSessions[0].session.taskId;
477
+ }
478
+ }
467
479
  if (resolvedTaskId) {
468
480
  // Session mode: use taskId from store (supports steer).
469
481
  const sessionId = resolvedTaskId.split("&")[0];
@@ -481,7 +493,7 @@ export const xiaoyiProvider = {
481
493
  }
482
494
  }
483
495
  else if (ctx.extraParams) {
484
- // No active session — try extraParams (may contain cached prepareExtraParams result).
496
+ // No active session — fall back to prepareExtraParams cache.
485
497
  const fallbackPrefix = ctx.extraParams[FALLBACK_PREFIX_KEY];
486
498
  if (typeof fallbackPrefix === "string") {
487
499
  // Fallback mode: generate fresh timestamp per request
@@ -531,9 +543,21 @@ export const xiaoyiProvider = {
531
543
  // not include session-specific data, so deviceType may be missing
532
544
  // from the cached extraParams even when a session is active.
533
545
  const extraParamsDeviceType = ctx.extraParams?.[DEVICE_TYPE_KEY] || undefined;
534
- const storeDeviceType = capturedA2ASessionId
535
- ? getSessionByA2AId(capturedA2ASessionId)?.deviceType
536
- : undefined;
546
+ let storeDeviceType;
547
+ if (capturedA2ASessionId) {
548
+ storeDeviceType = getSessionByA2AId(capturedA2ASessionId)?.deviceType;
549
+ }
550
+ if (!storeDeviceType) {
551
+ const alsCtx = xyAsyncLocalStorage.getStore();
552
+ const key = alsCtx?.openclawSessionKey;
553
+ if (key)
554
+ storeDeviceType = getSession(key)?.deviceType;
555
+ }
556
+ if (!storeDeviceType) {
557
+ const all = getAllActiveSessions();
558
+ if (all.length === 1)
559
+ storeDeviceType = all[0].session.deviceType;
560
+ }
537
561
  const deviceType = extraParamsDeviceType ?? storeDeviceType;
538
562
  // 在发送给模型前,优化 systemPrompt 结构
539
563
  if (context.systemPrompt) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.106-next",
3
+ "version": "0.0.107-next",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",