@ynhcj/xiaoyi-channel 0.0.76-next → 0.0.77-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.
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// Session manager for XY tool context
|
|
2
2
|
// Stores active session contexts that tools can access
|
|
3
3
|
import { AsyncLocalStorage } from "async_hooks";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
4
5
|
import { configManager } from "../utils/config-manager.js";
|
|
5
6
|
import { toolCallNudgeManager } from "../utils/tool-call-nudge-manager.js";
|
|
6
7
|
import { getCurrentTaskId, getCurrentMessageId } from "../task-manager.js";
|
|
7
8
|
// Map of sessionKey -> SessionContextWithRef
|
|
8
9
|
const activeSessions = new Map();
|
|
10
|
+
activeSessions.__debugId = `map-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
11
|
+
logger.log(`[SESSION-MGR] activeSessions Map created: ${activeSessions.__debugId}`);
|
|
9
12
|
// AsyncLocalStorage for thread-safe session context isolation
|
|
10
13
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
11
14
|
/**
|
|
@@ -13,6 +16,7 @@ const asyncLocalStorage = new AsyncLocalStorage();
|
|
|
13
16
|
* Should be called when starting to process a message.
|
|
14
17
|
*/
|
|
15
18
|
export function registerSession(sessionKey, context) {
|
|
19
|
+
logger.log(`[SESSION-MGR] registerSession: key=${sessionKey}, Map instance=${activeSessions.__debugId ?? "unknown"}, current size=${activeSessions.size}`);
|
|
16
20
|
const existing = activeSessions.get(sessionKey);
|
|
17
21
|
if (existing) {
|
|
18
22
|
// 更新上下文,增加引用计数
|
|
@@ -95,6 +99,7 @@ export function getCurrentSessionContext() {
|
|
|
95
99
|
}
|
|
96
100
|
// 2. Fallback: look up from global activeSessions Map
|
|
97
101
|
if (activeSessions.size === 0) {
|
|
102
|
+
logger.log(`[SESSION-MGR] ⚠️ getCurrentSessionContext: ALS lost, activeSessions.size=0 (Map instance=${activeSessions.__debugId ?? "unknown"})`);
|
|
98
103
|
return null;
|
|
99
104
|
}
|
|
100
105
|
// 2a. Single active session — return it directly
|