@ynhcj/xiaoyi-channel 0.0.95-beta β 0.0.97-beta
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/monitor.js
CHANGED
|
@@ -4,6 +4,7 @@ import { handleXYMessage } from "./bot.js";
|
|
|
4
4
|
import { parseA2AMessage } from "./parser.js";
|
|
5
5
|
import { hasActiveTask } from "./task-manager.js";
|
|
6
6
|
import { handleTriggerEvent } from "./trigger-handler.js";
|
|
7
|
+
import { handleSelfEvolutionEvent } from "./self-evolution-handler.js";
|
|
7
8
|
import { cleanupStaleTempFiles } from "./reply-dispatcher.js";
|
|
8
9
|
/**
|
|
9
10
|
* Per-session serial queue that ensures messages from the same session are processed
|
|
@@ -156,6 +157,10 @@ export async function monitorXYProvider(opts = {}) {
|
|
|
156
157
|
error(`[MONITOR] Failed to handle trigger-event:`, err);
|
|
157
158
|
});
|
|
158
159
|
};
|
|
160
|
+
const selfEvolutionHandler = (context) => {
|
|
161
|
+
log(`[MONITOR] Received self-evolution-event, dispatching to handler...`);
|
|
162
|
+
handleSelfEvolutionEvent(context, runtime);
|
|
163
|
+
};
|
|
159
164
|
const cleanup = () => {
|
|
160
165
|
log("XY gateway: cleaning up...");
|
|
161
166
|
// π Diagnose before cleanup
|
|
@@ -173,6 +178,7 @@ export async function monitorXYProvider(opts = {}) {
|
|
|
173
178
|
wsManager.off("disconnected", disconnectedHandler);
|
|
174
179
|
wsManager.off("error", errorHandler);
|
|
175
180
|
wsManager.off("trigger-event", triggerEventHandler);
|
|
181
|
+
wsManager.off("self-evolution-event", selfEvolutionHandler);
|
|
176
182
|
// β
Disconnect the wsManager to prevent connection leaks
|
|
177
183
|
// This is safe because each gateway lifecycle should have clean connections
|
|
178
184
|
wsManager.disconnect();
|
|
@@ -203,6 +209,7 @@ export async function monitorXYProvider(opts = {}) {
|
|
|
203
209
|
wsManager.on("disconnected", disconnectedHandler);
|
|
204
210
|
wsManager.on("error", errorHandler);
|
|
205
211
|
wsManager.on("trigger-event", triggerEventHandler);
|
|
212
|
+
wsManager.on("self-evolution-event", selfEvolutionHandler);
|
|
206
213
|
// Start periodic health check (every 6 hours)
|
|
207
214
|
console.log("π₯ Starting periodic health check (every 6 hours)...");
|
|
208
215
|
healthCheckInterval = setInterval(() => {
|
package/dist/src/provider.js
CHANGED
|
@@ -289,8 +289,10 @@ export const xiaoyiProvider = {
|
|
|
289
289
|
const traceId = ctx.extraParams[HEADER_TRACE_ID];
|
|
290
290
|
const sessionId = ctx.extraParams[HEADER_SESSION_ID];
|
|
291
291
|
const interactionId = ctx.extraParams[HEADER_INTERACTION_ID];
|
|
292
|
-
if (typeof traceId === "string")
|
|
293
|
-
|
|
292
|
+
if (typeof traceId === "string") {
|
|
293
|
+
const isCron = isCronTriggered(context.messages);
|
|
294
|
+
dynamicHeaders[HEADER_TRACE_ID] = isCron ? `cron_${traceId}` : traceId;
|
|
295
|
+
}
|
|
294
296
|
if (typeof sessionId === "string")
|
|
295
297
|
dynamicHeaders[HEADER_SESSION_ID] = sessionId;
|
|
296
298
|
if (typeof interactionId === "string")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function handleSelfEvolutionEvent(context: any, runtime: any): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
2
|
+
const XIAOYIENV_PATH = "/home/sandbox/.openclaw/.xiaoyienv";
|
|
3
|
+
export function handleSelfEvolutionEvent(context, runtime) {
|
|
4
|
+
const log = runtime?.log ?? console.log;
|
|
5
|
+
const error = runtime?.error ?? console.error;
|
|
6
|
+
try {
|
|
7
|
+
const state = context.event?.payload?.selfEvolutionState;
|
|
8
|
+
if (typeof state !== "string") {
|
|
9
|
+
error("[SELF_EVOLUTION] invalid payload: missing selfEvolutionState");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
log(`[SELF_EVOLUTION] received state: ${state}`);
|
|
13
|
+
let content;
|
|
14
|
+
try {
|
|
15
|
+
content = readFileSync(XIAOYIENV_PATH, "utf-8");
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// File doesn't exist yet β create it
|
|
19
|
+
log(`[SELF_EVOLUTION] ${XIAOYIENV_PATH} not found, creating new file`);
|
|
20
|
+
writeFileSync(XIAOYIENV_PATH, `selfEvolutionState=${state}\n`, "utf-8");
|
|
21
|
+
log(`[SELF_EVOLUTION] wrote selfEvolutionState=${state}`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const lines = content.split("\n");
|
|
25
|
+
const key = "selfEvolutionState";
|
|
26
|
+
let found = false;
|
|
27
|
+
const updated = lines.map((line) => {
|
|
28
|
+
if (line.startsWith(`${key}=`)) {
|
|
29
|
+
found = true;
|
|
30
|
+
return `${key}=${state}`;
|
|
31
|
+
}
|
|
32
|
+
return line;
|
|
33
|
+
});
|
|
34
|
+
if (!found) {
|
|
35
|
+
// Ensure trailing newline before appending
|
|
36
|
+
const trimmed = content.trimEnd();
|
|
37
|
+
writeFileSync(XIAOYIENV_PATH, `${trimmed}\n${key}=${state}\n`, "utf-8");
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
writeFileSync(XIAOYIENV_PATH, updated.join("\n"), "utf-8");
|
|
41
|
+
}
|
|
42
|
+
log(`[SELF_EVOLUTION] updated selfEvolutionState=${state} in ${XIAOYIENV_PATH}`);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
error("[SELF_EVOLUTION] failed to handle event:", err);
|
|
46
|
+
}
|
|
47
|
+
}
|
package/dist/src/websocket.js
CHANGED
|
@@ -394,6 +394,12 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
394
394
|
taskId: a2aRequest.params?.id, // ζ°η taskIdοΌηΉε»ζ¨ιζΆηζοΌ
|
|
395
395
|
});
|
|
396
396
|
}
|
|
397
|
+
else if (item.header?.namespace === "AgentEvent" && item.header?.name === "ClawSelfEvolutionState") {
|
|
398
|
+
console.log("[XY] ClawSelfEvolutionState event detected, emitting self-evolution-event");
|
|
399
|
+
this.emit("self-evolution-event", {
|
|
400
|
+
event: item,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
397
403
|
}
|
|
398
404
|
}
|
|
399
405
|
return;
|