@ynhcj/xiaoyi-channel 0.0.85-beta → 0.0.85-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/index.d.ts +6 -9
- package/dist/index.js +26 -21
- package/dist/src/bot.js +26 -3
- package/dist/src/channel.js +2 -29
- package/dist/src/client.js +7 -1
- package/dist/src/login-token-handler.d.ts +8 -0
- package/dist/src/login-token-handler.js +60 -0
- package/dist/src/message-queue.d.ts +17 -0
- package/dist/src/message-queue.js +51 -0
- package/dist/src/monitor.js +64 -4
- package/dist/src/provider.d.ts +2 -1
- package/dist/src/provider.js +442 -25
- package/dist/src/reply-dispatcher.js +6 -0
- package/dist/src/runtime.d.ts +3 -11
- package/dist/src/runtime.js +6 -18
- package/dist/src/self-evolution-handler.d.ts +7 -0
- package/dist/src/self-evolution-handler.js +140 -0
- package/dist/src/self-evolution-keyword.d.ts +9 -0
- package/dist/src/self-evolution-keyword.js +147 -0
- package/dist/src/self-evolution-tool-result-nudge.d.ts +3 -0
- package/dist/src/self-evolution-tool-result-nudge.js +96 -0
- package/dist/src/skill-retriever/config.d.ts +4 -0
- package/dist/src/skill-retriever/config.js +23 -0
- package/dist/src/skill-retriever/hooks.d.ts +22 -0
- package/dist/src/skill-retriever/hooks.js +82 -0
- package/dist/src/skill-retriever/tool-search.d.ts +16 -0
- package/dist/src/skill-retriever/tool-search.js +172 -0
- package/dist/src/skill-retriever/types.d.ts +36 -0
- package/dist/src/skill-retriever/types.js +1 -0
- package/dist/src/task-manager.d.ts +4 -0
- package/dist/src/task-manager.js +12 -1
- package/dist/src/tools/calendar-tool.d.ts +2 -1
- package/dist/src/tools/calendar-tool.js +112 -116
- package/dist/src/tools/call-device-tool.d.ts +6 -0
- package/dist/src/tools/call-device-tool.js +153 -0
- package/dist/src/tools/call-phone-tool.d.ts +2 -1
- package/dist/src/tools/call-phone-tool.js +109 -113
- package/dist/src/tools/create-alarm-tool.d.ts +2 -1
- package/dist/src/tools/create-alarm-tool.js +226 -241
- package/dist/src/tools/create-all-tools.d.ts +16 -0
- package/dist/src/tools/create-all-tools.js +50 -0
- package/dist/src/tools/delete-alarm-tool.d.ts +2 -1
- package/dist/src/tools/delete-alarm-tool.js +131 -138
- package/dist/src/tools/device-tool-map.js +5 -3
- package/dist/src/tools/get-alarm-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-alarm-tool-schema.js +17 -0
- package/dist/src/tools/get-calendar-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-calendar-tool-schema.js +13 -0
- package/dist/src/tools/get-collection-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-collection-tool-schema.js +12 -0
- package/dist/src/tools/get-contact-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-contact-tool-schema.js +17 -0
- package/dist/src/tools/get-device-file-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-device-file-tool-schema.js +14 -0
- package/dist/src/tools/get-email-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-email-tool-schema.js +12 -0
- package/dist/src/tools/get-note-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-note-tool-schema.js +15 -0
- package/dist/src/tools/get-photo-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-photo-tool-schema.js +13 -0
- package/dist/src/tools/image-reading-tool.d.ts +2 -1
- package/dist/src/tools/image-reading-tool.js +87 -94
- package/dist/src/tools/location-tool.d.ts +2 -1
- package/dist/src/tools/location-tool.js +87 -91
- package/dist/src/tools/login-token-tool.d.ts +6 -0
- package/dist/src/tools/login-token-tool.js +133 -0
- package/dist/src/tools/modify-alarm-tool.d.ts +2 -1
- package/dist/src/tools/modify-alarm-tool.js +233 -250
- package/dist/src/tools/modify-note-tool.d.ts +2 -1
- package/dist/src/tools/modify-note-tool.js +104 -108
- package/dist/src/tools/note-tool.d.ts +2 -1
- package/dist/src/tools/note-tool.js +103 -107
- package/dist/src/tools/query-app-message-tool.d.ts +5 -0
- package/dist/src/tools/query-app-message-tool.js +135 -0
- package/dist/src/tools/query-memory-data-tool.d.ts +5 -0
- package/dist/src/tools/query-memory-data-tool.js +151 -0
- package/dist/src/tools/query-todo-task-tool.d.ts +5 -0
- package/dist/src/tools/query-todo-task-tool.js +130 -0
- package/dist/src/tools/save-file-to-phone-tool.d.ts +2 -1
- package/dist/src/tools/save-file-to-phone-tool.js +127 -135
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +2 -1
- package/dist/src/tools/save-media-to-gallery-tool.js +134 -142
- package/dist/src/tools/save-self-evolution-skill-tool.d.ts +2 -0
- package/dist/src/tools/save-self-evolution-skill-tool.js +410 -0
- package/dist/src/tools/schema-tool-factory.d.ts +27 -0
- package/dist/src/tools/schema-tool-factory.js +32 -0
- package/dist/src/tools/search-alarm-tool.d.ts +2 -1
- package/dist/src/tools/search-alarm-tool.js +171 -182
- package/dist/src/tools/search-calendar-tool.d.ts +2 -1
- package/dist/src/tools/search-calendar-tool.js +145 -149
- package/dist/src/tools/search-contact-tool.d.ts +2 -1
- package/dist/src/tools/search-contact-tool.js +98 -102
- package/dist/src/tools/search-email-tool.d.ts +6 -0
- package/dist/src/tools/search-email-tool.js +133 -0
- package/dist/src/tools/search-file-tool.d.ts +2 -1
- package/dist/src/tools/search-file-tool.js +102 -106
- package/dist/src/tools/search-message-tool.d.ts +2 -1
- package/dist/src/tools/search-message-tool.js +100 -104
- package/dist/src/tools/search-note-tool.d.ts +2 -1
- package/dist/src/tools/search-note-tool.js +95 -99
- package/dist/src/tools/search-photo-gallery-tool.d.ts +2 -1
- package/dist/src/tools/search-photo-gallery-tool.js +35 -39
- package/dist/src/tools/send-email-tool.d.ts +5 -0
- package/dist/src/tools/send-email-tool.js +131 -0
- package/dist/src/tools/send-file-to-user-tool.d.ts +2 -1
- package/dist/src/tools/send-file-to-user-tool.js +154 -158
- package/dist/src/tools/send-message-tool.d.ts +2 -1
- package/dist/src/tools/send-message-tool.js +119 -123
- package/dist/src/tools/session-manager.d.ts +21 -6
- package/dist/src/tools/session-manager.js +134 -18
- package/dist/src/tools/upload-file-tool.d.ts +2 -1
- package/dist/src/tools/upload-file-tool.js +80 -84
- package/dist/src/tools/upload-photo-tool.d.ts +2 -1
- package/dist/src/tools/upload-photo-tool.js +70 -74
- package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-add-collection-tool.js +143 -147
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-collection-tool.js +112 -116
- package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +124 -128
- package/dist/src/tools/xiaoyi-gui-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-gui-tool.js +84 -88
- package/dist/src/utils/runtime-manager.js +24 -2
- package/dist/src/utils/self-evolution-manager.d.ts +10 -0
- package/dist/src/utils/self-evolution-manager.js +68 -0
- package/dist/src/utils/tool-call-nudge-manager.d.ts +16 -0
- package/dist/src/utils/tool-call-nudge-manager.js +47 -0
- package/dist/src/websocket.d.ts +3 -0
- package/dist/src/websocket.js +94 -24
- package/openclaw.plugin.json +21 -0
- package/package.json +3 -3
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const DEFAULT_TOOL_CALL_NUDGE_THRESHOLD = 6;
|
|
2
|
+
class ToolCallNudgeManager {
|
|
3
|
+
threshold;
|
|
4
|
+
sessions = new Map();
|
|
5
|
+
constructor(threshold = DEFAULT_TOOL_CALL_NUDGE_THRESHOLD) {
|
|
6
|
+
this.threshold = threshold;
|
|
7
|
+
}
|
|
8
|
+
getSessionState(sessionKey) {
|
|
9
|
+
let state = this.sessions.get(sessionKey);
|
|
10
|
+
if (!state) {
|
|
11
|
+
state = {
|
|
12
|
+
count: 0,
|
|
13
|
+
nudged: false,
|
|
14
|
+
};
|
|
15
|
+
this.sessions.set(sessionKey, state);
|
|
16
|
+
}
|
|
17
|
+
return state;
|
|
18
|
+
}
|
|
19
|
+
recordToolCall(sessionKey) {
|
|
20
|
+
const state = this.getSessionState(sessionKey);
|
|
21
|
+
state.count += 1;
|
|
22
|
+
if (!state.nudged && state.count >= this.threshold) {
|
|
23
|
+
state.nudged = true;
|
|
24
|
+
return {
|
|
25
|
+
count: state.count,
|
|
26
|
+
shouldNudge: true,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
count: state.count,
|
|
31
|
+
shouldNudge: false,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
tryMarkKeywordNudge(sessionKey) {
|
|
35
|
+
const state = this.getSessionState(sessionKey);
|
|
36
|
+
if (state.nudged) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
state.nudged = true;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
clearSession(sessionKey) {
|
|
43
|
+
this.sessions.delete(sessionKey);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export const TOOL_CALL_NUDGE_THRESHOLD = DEFAULT_TOOL_CALL_NUDGE_THRESHOLD;
|
|
47
|
+
export const toolCallNudgeManager = new ToolCallNudgeManager();
|
package/dist/src/websocket.d.ts
CHANGED
|
@@ -46,6 +46,9 @@ export declare class XYWebSocketManager extends EventEmitter {
|
|
|
46
46
|
private heartbeat;
|
|
47
47
|
private reconnectTimer;
|
|
48
48
|
private isShuttingDown;
|
|
49
|
+
private messageQueue;
|
|
50
|
+
private isBuffering;
|
|
51
|
+
private reconnectBufferTimer;
|
|
49
52
|
private log;
|
|
50
53
|
private error;
|
|
51
54
|
private onHealthEvent?;
|
package/dist/src/websocket.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import WebSocket from "ws";
|
|
3
3
|
import { EventEmitter } from "events";
|
|
4
4
|
import { HeartbeatManager } from "./heartbeat.js";
|
|
5
|
+
import { MessageQueue } from "./message-queue.js";
|
|
5
6
|
/**
|
|
6
7
|
* Manages single WebSocket connection to XY server.
|
|
7
8
|
*
|
|
@@ -28,6 +29,10 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
28
29
|
heartbeat = null;
|
|
29
30
|
reconnectTimer = null;
|
|
30
31
|
isShuttingDown = false;
|
|
32
|
+
// Message queue for buffering during disconnection/reconnection
|
|
33
|
+
messageQueue;
|
|
34
|
+
isBuffering = false;
|
|
35
|
+
reconnectBufferTimer = null;
|
|
31
36
|
// Logging functions
|
|
32
37
|
log;
|
|
33
38
|
error;
|
|
@@ -39,6 +44,7 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
39
44
|
this.runtime = runtime;
|
|
40
45
|
this.log = runtime?.log ?? console.log;
|
|
41
46
|
this.error = runtime?.error ?? console.error;
|
|
47
|
+
this.messageQueue = new MessageQueue(this.log);
|
|
42
48
|
}
|
|
43
49
|
/**
|
|
44
50
|
* Set health event callback to report activity to OpenClaw framework.
|
|
@@ -85,6 +91,13 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
85
91
|
clearTimeout(this.reconnectTimer);
|
|
86
92
|
this.reconnectTimer = null;
|
|
87
93
|
}
|
|
94
|
+
// Clear message queue on explicit disconnect (not during reconnection)
|
|
95
|
+
if (this.reconnectBufferTimer) {
|
|
96
|
+
clearTimeout(this.reconnectBufferTimer);
|
|
97
|
+
this.reconnectBufferTimer = null;
|
|
98
|
+
}
|
|
99
|
+
this.messageQueue.clear();
|
|
100
|
+
this.isBuffering = false;
|
|
88
101
|
this.cleanupConnection();
|
|
89
102
|
this.log("Disconnected from XY WebSocket server");
|
|
90
103
|
}
|
|
@@ -92,10 +105,15 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
92
105
|
* Send a message to the server.
|
|
93
106
|
*/
|
|
94
107
|
async sendMessage(sessionId, message) {
|
|
108
|
+
if (this.isBuffering) {
|
|
109
|
+
this.messageQueue.enqueue(message);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
95
112
|
if (!this.ws || !this.state.ready || this.ws.readyState !== WebSocket.OPEN) {
|
|
96
113
|
throw new Error("WebSocket not ready");
|
|
97
114
|
}
|
|
98
115
|
const messageStr = JSON.stringify(message);
|
|
116
|
+
this.log(`[WS-SEND] sessionId=${sessionId} taskId=${message.taskId} msgType=${message.msgType} len=${messageStr.length}`);
|
|
99
117
|
this.ws.send(messageStr);
|
|
100
118
|
}
|
|
101
119
|
/**
|
|
@@ -185,6 +203,11 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
185
203
|
clearTimeout(this.reconnectTimer);
|
|
186
204
|
this.reconnectTimer = null;
|
|
187
205
|
}
|
|
206
|
+
// Clear reconnect buffer timer (but keep message queue for reconnection)
|
|
207
|
+
if (this.reconnectBufferTimer) {
|
|
208
|
+
clearTimeout(this.reconnectBufferTimer);
|
|
209
|
+
this.reconnectBufferTimer = null;
|
|
210
|
+
}
|
|
188
211
|
// Clean up WebSocket
|
|
189
212
|
if (this.ws) {
|
|
190
213
|
// Remove all event listeners
|
|
@@ -276,12 +299,30 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
276
299
|
msgDetail: JSON.stringify({ agentId: this.config.agentId }),
|
|
277
300
|
};
|
|
278
301
|
const initMessageStr = JSON.stringify(initMessage);
|
|
279
|
-
|
|
302
|
+
this.log("[WS-SEND] Sending init message frame:", JSON.stringify(initMessage, null, 2));
|
|
280
303
|
this.ws.send(initMessageStr);
|
|
281
|
-
|
|
304
|
+
this.log(`[WS-SEND] Init message sent successfully, size: ${initMessageStr.length} bytes`);
|
|
282
305
|
// Mark as ready after init
|
|
283
306
|
this.state.ready = true;
|
|
284
307
|
this.emit("ready");
|
|
308
|
+
// Start 10-second buffer period after reconnection
|
|
309
|
+
if (this.isBuffering) {
|
|
310
|
+
this.log("[MessageQueue] Reconnected, starting 10s buffer period before flushing queue");
|
|
311
|
+
// Clear any existing buffer timer
|
|
312
|
+
if (this.reconnectBufferTimer) {
|
|
313
|
+
clearTimeout(this.reconnectBufferTimer);
|
|
314
|
+
}
|
|
315
|
+
this.reconnectBufferTimer = setTimeout(() => {
|
|
316
|
+
this.reconnectBufferTimer = null;
|
|
317
|
+
this.messageQueue.flush((msg) => {
|
|
318
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
319
|
+
this.ws.send(JSON.stringify(msg));
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
this.isBuffering = false;
|
|
323
|
+
this.log("[MessageQueue] Buffer period ended, resumed direct sending");
|
|
324
|
+
}, 10000);
|
|
325
|
+
}
|
|
285
326
|
// Start heartbeat
|
|
286
327
|
this.startHeartbeat();
|
|
287
328
|
}
|
|
@@ -320,7 +361,7 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
320
361
|
handleMessage(data) {
|
|
321
362
|
try {
|
|
322
363
|
const messageStr = data.toString();
|
|
323
|
-
|
|
364
|
+
this.log(`[WS-RECV] Raw message frame, size: ${messageStr.length} characters`);
|
|
324
365
|
const parsed = JSON.parse(messageStr);
|
|
325
366
|
// 提取并打印消息内容(只显示 text,data 只打印提示)
|
|
326
367
|
const parts = parsed.params?.message?.parts;
|
|
@@ -346,7 +387,7 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
346
387
|
// 如果长度 > 8,显示前5个 + *** + 后5个
|
|
347
388
|
maskedText = `${textContents.slice(0, 5)}***${textContents.slice(-5)}`;
|
|
348
389
|
}
|
|
349
|
-
|
|
390
|
+
this.log("[WS-RECV] Text:", maskedText);
|
|
350
391
|
}
|
|
351
392
|
}
|
|
352
393
|
}
|
|
@@ -356,7 +397,7 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
356
397
|
// Extract sessionId from params
|
|
357
398
|
const sessionId = a2aRequest.params?.sessionId;
|
|
358
399
|
if (!sessionId) {
|
|
359
|
-
|
|
400
|
+
this.error("[XY] Message missing sessionId");
|
|
360
401
|
return;
|
|
361
402
|
}
|
|
362
403
|
// Check if message contains only data parts (tool results)
|
|
@@ -367,10 +408,10 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
367
408
|
for (const dataPart of dataParts) {
|
|
368
409
|
const events = dataPart.data?.events;
|
|
369
410
|
if (!Array.isArray(events)) {
|
|
370
|
-
|
|
411
|
+
this.log("[XY] dataPart.data.events is not an array, skipping");
|
|
371
412
|
continue;
|
|
372
413
|
}
|
|
373
|
-
|
|
414
|
+
this.log(`[XY] Processing ${events.length} events from data.events`);
|
|
374
415
|
for (const item of events) {
|
|
375
416
|
if (item.header?.name === "UploadExeResult" && item.payload?.intentName) {
|
|
376
417
|
const dataEvent = {
|
|
@@ -378,15 +419,15 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
378
419
|
outputs: item.payload.outputs || {},
|
|
379
420
|
status: "success",
|
|
380
421
|
};
|
|
381
|
-
|
|
422
|
+
this.log(`[XY] Emitting data-event, intentName: ${item.payload.intentName}, size: ${JSON.stringify(dataEvent).length} bytes`);
|
|
382
423
|
this.emit("data-event", dataEvent);
|
|
383
424
|
}
|
|
384
425
|
else if (item.header?.namespace === "ClawAgent" && item.header?.name === "InvokeJarvisGUIAgentResponse") {
|
|
385
|
-
|
|
426
|
+
this.log(`[XY] Emitting gui-agent-response, size: ${JSON.stringify(item).length} bytes`);
|
|
386
427
|
this.emit("gui-agent-response", item);
|
|
387
428
|
}
|
|
388
429
|
else if (item.header?.namespace === "Common" && item.header?.name === "Trigger") {
|
|
389
|
-
|
|
430
|
+
this.log("[XY] Trigger event detected, emitting trigger-event with context");
|
|
390
431
|
// 传递完整上下文:event、sessionId、taskId
|
|
391
432
|
this.emit("trigger-event", {
|
|
392
433
|
event: item,
|
|
@@ -394,6 +435,27 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
394
435
|
taskId: a2aRequest.params?.id, // 新的 taskId(点击推送时生成)
|
|
395
436
|
});
|
|
396
437
|
}
|
|
438
|
+
else if (item.header?.namespace === "AgentEvent" && item.header?.name === "ClawSelfEvolutionState") {
|
|
439
|
+
this.log("[XY] ClawSelfEvolutionState event detected, emitting self-evolution-event");
|
|
440
|
+
this.emit("self-evolution-event", {
|
|
441
|
+
event: item,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
else if (item.header?.namespace === "AgentEvent" && item.header?.name === "ClawSelfEvolutionStateGet") {
|
|
445
|
+
this.log("[XY] ClawSelfEvolutionStateGet event detected, emitting self-evolution-state-get-event");
|
|
446
|
+
this.emit("self-evolution-state-get-event", {
|
|
447
|
+
event: item,
|
|
448
|
+
sessionId: sessionId,
|
|
449
|
+
taskId: a2aRequest.params?.id,
|
|
450
|
+
messageId: a2aRequest.id,
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
else if (item.header?.namespace === "LoginTokenEvent" && item.header?.name === "ClawAutoLogin") {
|
|
454
|
+
this.log("[XY] LoginTokenEvent.ClawAutoLogin detected, emitting login-token-event");
|
|
455
|
+
this.emit("login-token-event", {
|
|
456
|
+
event: item,
|
|
457
|
+
});
|
|
458
|
+
}
|
|
397
459
|
}
|
|
398
460
|
}
|
|
399
461
|
return;
|
|
@@ -404,16 +466,16 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
404
466
|
}
|
|
405
467
|
// Wrapped format (InboundWebSocketMessage)
|
|
406
468
|
const inboundMsg = parsed;
|
|
407
|
-
|
|
469
|
+
this.log(`[XY] Message type: Wrapped, msgType: ${inboundMsg.msgType}`);
|
|
408
470
|
// Handle heartbeat responses
|
|
409
471
|
if (inboundMsg.msgType === "heartbeat") {
|
|
410
|
-
|
|
472
|
+
this.log("[XY] Received heartbeat response");
|
|
411
473
|
this.onHealthEvent?.();
|
|
412
474
|
return;
|
|
413
475
|
}
|
|
414
476
|
// Handle data messages
|
|
415
477
|
if (inboundMsg.msgType === "data") {
|
|
416
|
-
|
|
478
|
+
this.log("[XY] Processing data message");
|
|
417
479
|
try {
|
|
418
480
|
const a2aRequest = JSON.parse(inboundMsg.msgDetail);
|
|
419
481
|
const dataParts = a2aRequest.params?.message?.parts?.filter((p) => p.kind === "data");
|
|
@@ -421,10 +483,10 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
421
483
|
for (const dataPart of dataParts) {
|
|
422
484
|
const events = dataPart.data?.events;
|
|
423
485
|
if (!Array.isArray(events)) {
|
|
424
|
-
|
|
486
|
+
this.log("[XY] dataPart.data.events is not an array, skipping");
|
|
425
487
|
continue;
|
|
426
488
|
}
|
|
427
|
-
|
|
489
|
+
this.log(`[XY] Processing ${events.length} events from data.events`);
|
|
428
490
|
for (const item of events) {
|
|
429
491
|
if (item.header?.name === "UploadExeResult" && item.payload?.intentName) {
|
|
430
492
|
const dataEvent = {
|
|
@@ -432,15 +494,15 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
432
494
|
outputs: item.payload.outputs || {},
|
|
433
495
|
status: "success",
|
|
434
496
|
};
|
|
435
|
-
|
|
497
|
+
this.log(`[XY] Emitting data-event, intentName: ${item.payload.intentName}, size: ${JSON.stringify(dataEvent).length} bytes`);
|
|
436
498
|
this.emit("data-event", dataEvent);
|
|
437
499
|
}
|
|
438
500
|
else if (item.header?.namespace === "ClawAgent" && item.header?.name === "InvokeJarvisGUIAgentResponse") {
|
|
439
|
-
|
|
501
|
+
this.log(`[XY] Emitting gui-agent-response, size: ${JSON.stringify(item).length} bytes`);
|
|
440
502
|
this.emit("gui-agent-response", item);
|
|
441
503
|
}
|
|
442
504
|
else if (item.header?.namespace === "Common" && item.header?.name === "Trigger") {
|
|
443
|
-
|
|
505
|
+
this.log("[XY] Trigger event detected (wrapped format), emitting trigger-event with context");
|
|
444
506
|
// 传递完整上下文:event、sessionId、taskId
|
|
445
507
|
this.emit("trigger-event", {
|
|
446
508
|
event: item,
|
|
@@ -448,33 +510,39 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
448
510
|
taskId: inboundMsg.taskId || a2aRequest.params?.id,
|
|
449
511
|
});
|
|
450
512
|
}
|
|
513
|
+
else if (item.header?.namespace === "LoginTokenEvent" && item.header?.name === "ClawAutoLogin") {
|
|
514
|
+
this.log("[XY] LoginTokenEvent.ClawAutoLogin detected (wrapped format), emitting login-token-event");
|
|
515
|
+
this.emit("login-token-event", {
|
|
516
|
+
event: item,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
451
519
|
}
|
|
452
520
|
}
|
|
453
521
|
}
|
|
454
522
|
}
|
|
455
523
|
catch (error) {
|
|
456
|
-
|
|
524
|
+
this.error("[XY] Failed to process data message:", error);
|
|
457
525
|
}
|
|
458
526
|
return;
|
|
459
527
|
}
|
|
460
528
|
// Parse msgDetail as A2AJsonRpcRequest
|
|
461
529
|
const a2aRequest = JSON.parse(inboundMsg.msgDetail);
|
|
462
|
-
|
|
530
|
+
this.log(`[XY] Parsed A2A request, method: ${a2aRequest.method}`);
|
|
463
531
|
const sessionId = inboundMsg.sessionId;
|
|
464
|
-
|
|
532
|
+
this.log(`[XY] Session ID: ${sessionId}`);
|
|
465
533
|
// Emit message event
|
|
466
|
-
|
|
534
|
+
this.log("[XY] *** EMITTING message event (Wrapped path) ***");
|
|
467
535
|
this.emit("message", a2aRequest, sessionId);
|
|
468
536
|
}
|
|
469
537
|
catch (error) {
|
|
470
|
-
|
|
538
|
+
this.error("[XY] Failed to parse message:", error);
|
|
471
539
|
}
|
|
472
540
|
}
|
|
473
541
|
/**
|
|
474
542
|
* Handle connection close.
|
|
475
543
|
*/
|
|
476
544
|
handleClose(code, reason) {
|
|
477
|
-
|
|
545
|
+
this.log(`WebSocket disconnected: code=${code}, reason=${reason}`);
|
|
478
546
|
// Only process if this is the current connection
|
|
479
547
|
if (!this.ws) {
|
|
480
548
|
this.log("Ignoring close event for already cleaned connection");
|
|
@@ -482,6 +550,8 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
482
550
|
}
|
|
483
551
|
this.state.connected = false;
|
|
484
552
|
this.state.ready = false;
|
|
553
|
+
// Start buffering messages during disconnection
|
|
554
|
+
this.isBuffering = true;
|
|
485
555
|
this.emit("disconnected");
|
|
486
556
|
// Clean up
|
|
487
557
|
if (this.heartbeat) {
|
package/openclaw.plugin.json
CHANGED
|
@@ -7,5 +7,26 @@
|
|
|
7
7
|
"type": "object",
|
|
8
8
|
"additionalProperties": false,
|
|
9
9
|
"properties": {}
|
|
10
|
+
},
|
|
11
|
+
"channelConfigs": {
|
|
12
|
+
"xiaoyi-channel": {
|
|
13
|
+
"schema": {
|
|
14
|
+
"type": "object",
|
|
15
|
+
"properties": {
|
|
16
|
+
"enabled": { "type": "boolean", "description": "Enable/disable the XY channel", "default": false },
|
|
17
|
+
"wsUrl1": { "type": "string", "description": "Primary WebSocket URL" },
|
|
18
|
+
"wsUrl2": { "type": "string", "description": "Secondary WebSocket URL" },
|
|
19
|
+
"apiKey": { "type": "string", "description": "API key for authentication" },
|
|
20
|
+
"uid": { "type": "string", "description": "User ID for file upload" },
|
|
21
|
+
"agentId": { "type": "string", "description": "Agent ID for this bot instance" },
|
|
22
|
+
"apiId": { "type": "string", "description": "API ID for push messages" },
|
|
23
|
+
"fileUploadUrl": { "type": "string", "description": "Base URL for file upload service" },
|
|
24
|
+
"pushUrl": { "type": "string", "description": "URL for push message service" }
|
|
25
|
+
},
|
|
26
|
+
"required": []
|
|
27
|
+
},
|
|
28
|
+
"label": "Xiaoyi Channel",
|
|
29
|
+
"description": "Xiaoyi A2A protocol integration"
|
|
30
|
+
}
|
|
10
31
|
}
|
|
11
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ynhcj/xiaoyi-channel",
|
|
3
|
-
"version": "0.0.85-
|
|
3
|
+
"version": "0.0.85-next",
|
|
4
4
|
"description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"openclaw.plugin.json"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "tsc"
|
|
19
|
+
"build": "node ./node_modules/typescript/bin/tsc"
|
|
20
20
|
},
|
|
21
21
|
"keywords": [
|
|
22
22
|
"openclaw",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"openclaw": ">=2026.
|
|
52
|
+
"openclaw": ">=2026.5.6"
|
|
53
53
|
},
|
|
54
54
|
"peerDependenciesMeta": {
|
|
55
55
|
"openclaw": {
|