@ynhcj/xiaoyi-channel 0.0.79-next → 0.0.80-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.
@@ -4,10 +4,15 @@ import { AsyncLocalStorage } from "async_hooks";
4
4
  import { configManager } from "../utils/config-manager.js";
5
5
  import { toolCallNudgeManager } from "../utils/tool-call-nudge-manager.js";
6
6
  import { getCurrentTaskId, getCurrentMessageId } from "../task-manager.js";
7
- // Map of sessionKey -> SessionContextWithRef
8
- const activeSessions = new Map();
9
- activeSessions.__debugId = `map-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
10
- console.log(`[SESSION-MGR] activeSessions Map created: ${activeSessions.__debugId}`);
7
+ // Use globalThis to ensure a single Map instance across all module copies.
8
+ // The xy_channel plugin may be loaded by openclaw from different module resolution
9
+ // paths (plugin entry vs tool registration), causing session-manager.ts to be
10
+ // instantiated multiple times. globalThis guarantees all code shares the same Map.
11
+ const _g = globalThis;
12
+ if (!_g.__xyActiveSessions) {
13
+ _g.__xyActiveSessions = new Map();
14
+ }
15
+ const activeSessions = _g.__xyActiveSessions;
11
16
  // AsyncLocalStorage for thread-safe session context isolation
12
17
  const asyncLocalStorage = new AsyncLocalStorage();
13
18
  /**
@@ -15,7 +20,6 @@ const asyncLocalStorage = new AsyncLocalStorage();
15
20
  * Should be called when starting to process a message.
16
21
  */
17
22
  export function registerSession(sessionKey, context) {
18
- console.log(`[SESSION-MGR] registerSession: key=${sessionKey}, Map instance=${activeSessions.__debugId ?? "unknown"}, current size=${activeSessions.size}`);
19
23
  const existing = activeSessions.get(sessionKey);
20
24
  if (existing) {
21
25
  // 更新上下文,增加引用计数
@@ -36,17 +40,13 @@ export function registerSession(sessionKey, context) {
36
40
  * Should be called when message processing is complete.
37
41
  */
38
42
  export function unregisterSession(sessionKey) {
39
- console.log(`[SESSION-MGR] unregisterSession: key=${sessionKey}, Map instance=${activeSessions.__debugId ?? "unknown"}, current size=${activeSessions.size}`);
40
43
  const existing = activeSessions.get(sessionKey);
41
44
  if (!existing) {
42
- console.log(`[SESSION-MGR] unregisterSession: key=${sessionKey} NOT FOUND in map`);
43
45
  return;
44
46
  }
45
47
  existing.refCount--;
46
- console.log(`[SESSION-MGR] unregisterSession: key=${sessionKey}, refCount after decrement=${existing.refCount}`);
47
48
  if (existing.refCount <= 0) {
48
49
  activeSessions.delete(sessionKey);
49
- console.log(`[SESSION-MGR] unregisterSession: key=${sessionKey} DELETED from map, new size=${activeSessions.size}`);
50
50
  configManager.clearSession(existing.sessionId);
51
51
  toolCallNudgeManager.clearSession(sessionKey);
52
52
  }
@@ -102,7 +102,6 @@ export function getCurrentSessionContext() {
102
102
  }
103
103
  // 2. Fallback: look up from global activeSessions Map
104
104
  if (activeSessions.size === 0) {
105
- console.log(`[SESSION-MGR] ⚠️ getCurrentSessionContext: ALS lost, activeSessions.size=0 (Map instance=${activeSessions.__debugId ?? "unknown"})`);
106
105
  return null;
107
106
  }
108
107
  // 2a. Single active session — return it directly
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.79-next",
3
+ "version": "0.0.80-next",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",