@ynhcj/xiaoyi-channel 0.0.126-next → 0.0.127-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,12 +1,33 @@
|
|
|
1
1
|
import { handleXYMessage } from "../bot.js";
|
|
2
2
|
import { logger } from "../utils/logger.js";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// Use globalThis to ensure a single cache across all module copies.
|
|
5
|
+
// The xy_channel plugin may be loaded by openclaw from different module
|
|
6
|
+
// resolution paths, causing steer-context.ts to be instantiated multiple
|
|
7
|
+
// times. globalThis guarantees all copies share the same cfg/runtime.
|
|
8
|
+
const _g = globalThis;
|
|
9
|
+
if (!_g.__xySteerCachedCfg) {
|
|
10
|
+
_g.__xySteerCachedCfg = null;
|
|
11
|
+
}
|
|
12
|
+
if (!_g.__xySteerCachedRuntime) {
|
|
13
|
+
_g.__xySteerCachedRuntime = null;
|
|
14
|
+
}
|
|
15
|
+
function getCachedCfg() {
|
|
16
|
+
return _g.__xySteerCachedCfg;
|
|
17
|
+
}
|
|
18
|
+
function setCachedCfg(cfg) {
|
|
19
|
+
_g.__xySteerCachedCfg = cfg;
|
|
20
|
+
}
|
|
21
|
+
function getCachedRuntime() {
|
|
22
|
+
return _g.__xySteerCachedRuntime;
|
|
23
|
+
}
|
|
24
|
+
function setCachedRuntime(runtime) {
|
|
25
|
+
_g.__xySteerCachedRuntime = runtime;
|
|
26
|
+
}
|
|
6
27
|
/** Called from handleXYMessage on every inbound A2A message to keep cfg/runtime fresh. */
|
|
7
28
|
export function setCsplSteerContext(cfg, runtime) {
|
|
8
|
-
|
|
9
|
-
|
|
29
|
+
setCachedCfg(cfg);
|
|
30
|
+
setCachedRuntime(runtime);
|
|
10
31
|
}
|
|
11
32
|
/**
|
|
12
33
|
* Inject a steer message into an active session by constructing a synthetic
|
|
@@ -19,7 +40,9 @@ export function setCsplSteerContext(cfg, runtime) {
|
|
|
19
40
|
*/
|
|
20
41
|
export async function tryInjectSteer(params) {
|
|
21
42
|
const { sessionId, taskId, message, source } = params;
|
|
22
|
-
|
|
43
|
+
const cfg = getCachedCfg();
|
|
44
|
+
const runtime = getCachedRuntime();
|
|
45
|
+
if (!cfg || !runtime) {
|
|
23
46
|
logger.error(`[STEER:${source}] No cached cfg/runtime, cannot inject steer`);
|
|
24
47
|
return false;
|
|
25
48
|
}
|
|
@@ -40,8 +63,8 @@ export async function tryInjectSteer(params) {
|
|
|
40
63
|
logger.log(`[STEER:${source}] Injecting steer for sessionId=${sessionId}, taskId=${taskId}`);
|
|
41
64
|
try {
|
|
42
65
|
await handleXYMessage({
|
|
43
|
-
cfg
|
|
44
|
-
runtime
|
|
66
|
+
cfg,
|
|
67
|
+
runtime,
|
|
45
68
|
message: syntheticMessage,
|
|
46
69
|
accountId: "default",
|
|
47
70
|
skipRegistration: true,
|