@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.
- package/dist/src/provider.js +34 -10
- package/package.json +1 -1
package/dist/src/provider.js
CHANGED
|
@@ -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
|
-
//
|
|
459
|
-
//
|
|
460
|
-
//
|
|
461
|
-
//
|
|
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 —
|
|
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
|
-
|
|
535
|
-
|
|
536
|
-
|
|
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) {
|