@ynhcj/xiaoyi-channel 0.0.108-next → 0.0.109-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
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 { getCurrentSessionContext } from "./tools/session-manager.js";
|
|
11
|
+
import { activeSessions, asyncLocalStorage, getCurrentSessionContext } from "./tools/session-manager.js";
|
|
12
12
|
import { getCurrentTaskId } from "./task-manager.js";
|
|
13
13
|
import { selfEvolutionManager } from "./utils/self-evolution-manager.js";
|
|
14
14
|
// ── Retry config ──────────────────────────────────────────────
|
|
@@ -450,7 +450,13 @@ export const xiaoyiProvider = {
|
|
|
450
450
|
// session (lastRegisteredKey fallback). The captured sessionId lets us
|
|
451
451
|
// bypass that fallback and look up the correct taskId directly from
|
|
452
452
|
// task-manager.
|
|
453
|
-
const
|
|
453
|
+
const alsStore = asyncLocalStorage.getStore();
|
|
454
|
+
const sessionCtx = getCurrentSessionContext();
|
|
455
|
+
const capturedA2ASessionId = sessionCtx?.sessionId ?? null;
|
|
456
|
+
console.log(`[xiaoyiprovider] wrapStreamFn — ALS: ${alsStore ? "HIT" : "MISS"}, ` +
|
|
457
|
+
`capturedSessionId=${capturedA2ASessionId ?? "null"}, ` +
|
|
458
|
+
`taskId=${sessionCtx?.taskId ?? "null"}, ` +
|
|
459
|
+
`activeSessionsCount=${activeSessions.size}`);
|
|
454
460
|
return async (model, context, options) => {
|
|
455
461
|
// 每次请求时从 ctx.extraParams 动态读取 header
|
|
456
462
|
const dynamicHeaders = {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
1
2
|
import type { XYChannelConfig } from "../types.js";
|
|
2
3
|
export interface SessionContext {
|
|
3
4
|
config: XYChannelConfig;
|
|
@@ -7,6 +8,12 @@ export interface SessionContext {
|
|
|
7
8
|
agentId: string;
|
|
8
9
|
deviceType?: string;
|
|
9
10
|
}
|
|
11
|
+
interface SessionContextWithRef extends SessionContext {
|
|
12
|
+
refCount: number;
|
|
13
|
+
createdAt: number;
|
|
14
|
+
}
|
|
15
|
+
export declare const activeSessions: Map<string, SessionContextWithRef>;
|
|
16
|
+
export declare const asyncLocalStorage: AsyncLocalStorage<SessionContext>;
|
|
10
17
|
/**
|
|
11
18
|
* Register a session context for tool access.
|
|
12
19
|
* Should be called when starting to process a message.
|
|
@@ -58,3 +65,4 @@ export declare function cleanupStaleSessions(): number;
|
|
|
58
65
|
* Get the current number of active sessions (for diagnostics).
|
|
59
66
|
*/
|
|
60
67
|
export declare function getActiveSessionCount(): number;
|
|
68
|
+
export {};
|
|
@@ -18,7 +18,7 @@ const _g = globalThis;
|
|
|
18
18
|
if (!_g.__xyActiveSessions) {
|
|
19
19
|
_g.__xyActiveSessions = new Map();
|
|
20
20
|
}
|
|
21
|
-
const activeSessions = _g.__xyActiveSessions;
|
|
21
|
+
export const activeSessions = _g.__xyActiveSessions;
|
|
22
22
|
// Track the most recently registered sessionKey for reliable fallback
|
|
23
23
|
// when AsyncLocalStorage context is lost across openclaw's embedded runner boundary.
|
|
24
24
|
if (!_g.__xyLastRegisteredSessionKey) {
|
|
@@ -27,7 +27,7 @@ if (!_g.__xyLastRegisteredSessionKey) {
|
|
|
27
27
|
const getLastRegisteredKey = () => _g.__xyLastRegisteredSessionKey;
|
|
28
28
|
const setLastRegisteredKey = (key) => { _g.__xyLastRegisteredSessionKey = key; };
|
|
29
29
|
// AsyncLocalStorage for thread-safe session context isolation
|
|
30
|
-
const asyncLocalStorage = new AsyncLocalStorage();
|
|
30
|
+
export const asyncLocalStorage = new AsyncLocalStorage();
|
|
31
31
|
/**
|
|
32
32
|
* Register a session context for tool access.
|
|
33
33
|
* Should be called when starting to process a message.
|