@ynhcj/xiaoyi 1.8.0 → 1.9.1
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/channel.js +9 -1
- package/dist/runtime.d.ts +9 -12
- package/dist/runtime.js +14 -46
- package/package.json +1 -1
package/dist/channel.js
CHANGED
|
@@ -187,6 +187,8 @@ exports.xiaoyiPlugin = {
|
|
|
187
187
|
startAccount: async (ctx) => {
|
|
188
188
|
const runtime = (0, runtime_1.getXiaoYiRuntime)();
|
|
189
189
|
const resolvedAccount = ctx.account;
|
|
190
|
+
// Save handleInboundMessage callback to runtime for later use
|
|
191
|
+
runtime.setHandleInboundMessage(ctx.handleInboundMessage);
|
|
190
192
|
// Start WebSocket connection (single account mode)
|
|
191
193
|
await runtime.start(resolvedAccount.config);
|
|
192
194
|
// Setup message handler
|
|
@@ -195,8 +197,14 @@ exports.xiaoyiPlugin = {
|
|
|
195
197
|
connection.on("message", async (message) => {
|
|
196
198
|
// Store sessionId -> taskId mapping in runtime
|
|
197
199
|
runtime.setTaskIdForSession(message.sessionId, message.id);
|
|
200
|
+
// Get handleInboundMessage from runtime
|
|
201
|
+
const handleInboundMessage = runtime.getHandleInboundMessage();
|
|
202
|
+
if (!handleInboundMessage) {
|
|
203
|
+
console.error("handleInboundMessage not available");
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
198
206
|
// Convert A2A message to OpenClaw inbound message format
|
|
199
|
-
await
|
|
207
|
+
await handleInboundMessage({
|
|
200
208
|
channel: "xiaoyi",
|
|
201
209
|
accountId: resolvedAccount.accountId,
|
|
202
210
|
from: message.sender.id,
|
package/dist/runtime.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare class XiaoYiRuntime {
|
|
|
9
9
|
private runtime;
|
|
10
10
|
private config;
|
|
11
11
|
private sessionToTaskIdMap;
|
|
12
|
+
private handleInboundMessage;
|
|
12
13
|
/**
|
|
13
14
|
* Set OpenClaw runtime
|
|
14
15
|
*/
|
|
@@ -17,6 +18,14 @@ export declare class XiaoYiRuntime {
|
|
|
17
18
|
* Get OpenClaw runtime
|
|
18
19
|
*/
|
|
19
20
|
getRuntime(): any;
|
|
21
|
+
/**
|
|
22
|
+
* Set handleInboundMessage callback
|
|
23
|
+
*/
|
|
24
|
+
setHandleInboundMessage(handler: (message: any) => Promise<void>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get handleInboundMessage callback
|
|
27
|
+
*/
|
|
28
|
+
getHandleInboundMessage(): ((message: any) => Promise<void>) | null;
|
|
20
29
|
/**
|
|
21
30
|
* Start connection (single account mode)
|
|
22
31
|
*/
|
|
@@ -49,18 +58,6 @@ export declare class XiaoYiRuntime {
|
|
|
49
58
|
* Clear taskId for a session
|
|
50
59
|
*/
|
|
51
60
|
clearTaskIdForSession(sessionId: string): void;
|
|
52
|
-
/**
|
|
53
|
-
* Handle incoming A2A message
|
|
54
|
-
*/
|
|
55
|
-
private handleIncomingMessage;
|
|
56
|
-
/**
|
|
57
|
-
* Handle clear event
|
|
58
|
-
*/
|
|
59
|
-
private handleClearEvent;
|
|
60
|
-
/**
|
|
61
|
-
* Handle cancel event
|
|
62
|
-
*/
|
|
63
|
-
private handleCancelEvent;
|
|
64
61
|
}
|
|
65
62
|
export declare function getXiaoYiRuntime(): XiaoYiRuntime;
|
|
66
63
|
export declare function setXiaoYiRuntime(runtime: any): void;
|
package/dist/runtime.js
CHANGED
|
@@ -14,6 +14,7 @@ class XiaoYiRuntime {
|
|
|
14
14
|
this.runtime = null;
|
|
15
15
|
this.config = null;
|
|
16
16
|
this.sessionToTaskIdMap = new Map(); // Map sessionId to taskId
|
|
17
|
+
this.handleInboundMessage = null; // Store handleInboundMessage callback
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* Set OpenClaw runtime
|
|
@@ -27,6 +28,18 @@ class XiaoYiRuntime {
|
|
|
27
28
|
getRuntime() {
|
|
28
29
|
return this.runtime;
|
|
29
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Set handleInboundMessage callback
|
|
33
|
+
*/
|
|
34
|
+
setHandleInboundMessage(handler) {
|
|
35
|
+
this.handleInboundMessage = handler;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get handleInboundMessage callback
|
|
39
|
+
*/
|
|
40
|
+
getHandleInboundMessage() {
|
|
41
|
+
return this.handleInboundMessage;
|
|
42
|
+
}
|
|
30
43
|
/**
|
|
31
44
|
* Start connection (single account mode)
|
|
32
45
|
*/
|
|
@@ -37,10 +50,7 @@ class XiaoYiRuntime {
|
|
|
37
50
|
}
|
|
38
51
|
this.config = config;
|
|
39
52
|
const manager = new websocket_1.XiaoYiWebSocketManager(config);
|
|
40
|
-
// Setup event handlers
|
|
41
|
-
manager.on("message", (message) => {
|
|
42
|
-
this.handleIncomingMessage(message);
|
|
43
|
-
});
|
|
53
|
+
// Setup basic event handlers (message handling is done in channel.ts)
|
|
44
54
|
manager.on("error", (error) => {
|
|
45
55
|
console.error("XiaoYi channel error:", error);
|
|
46
56
|
});
|
|
@@ -50,12 +60,6 @@ class XiaoYiRuntime {
|
|
|
50
60
|
manager.on("authenticated", () => {
|
|
51
61
|
console.log("XiaoYi channel authenticated");
|
|
52
62
|
});
|
|
53
|
-
manager.on("clear", (data) => {
|
|
54
|
-
this.handleClearEvent(data);
|
|
55
|
-
});
|
|
56
|
-
manager.on("cancel", (data) => {
|
|
57
|
-
this.handleCancelEvent(data);
|
|
58
|
-
});
|
|
59
63
|
manager.on("maxReconnectAttemptsReached", () => {
|
|
60
64
|
console.error("XiaoYi channel max reconnect attempts reached");
|
|
61
65
|
this.stop();
|
|
@@ -113,42 +117,6 @@ class XiaoYiRuntime {
|
|
|
113
117
|
clearTaskIdForSession(sessionId) {
|
|
114
118
|
this.sessionToTaskIdMap.delete(sessionId);
|
|
115
119
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Handle incoming A2A message
|
|
118
|
-
*/
|
|
119
|
-
handleIncomingMessage(message) {
|
|
120
|
-
if (!this.runtime) {
|
|
121
|
-
console.error("Runtime not set, cannot handle message");
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
// Dispatch message to OpenClaw's message handling system
|
|
125
|
-
// This will be called by the channel plugin's gateway adapter
|
|
126
|
-
this.runtime.emit("xiaoyi:message", {
|
|
127
|
-
message,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Handle clear event
|
|
132
|
-
*/
|
|
133
|
-
handleClearEvent(data) {
|
|
134
|
-
if (!this.runtime) {
|
|
135
|
-
console.error("Runtime not set, cannot handle clear event");
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
// Emit clear event for OpenClaw to handle
|
|
139
|
-
this.runtime.emit("xiaoyi:clear", data);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Handle cancel event
|
|
143
|
-
*/
|
|
144
|
-
handleCancelEvent(data) {
|
|
145
|
-
if (!this.runtime) {
|
|
146
|
-
console.error("Runtime not set, cannot handle cancel event");
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
// Emit cancel event for OpenClaw to handle
|
|
150
|
-
this.runtime.emit("xiaoyi:cancel", data);
|
|
151
|
-
}
|
|
152
120
|
}
|
|
153
121
|
exports.XiaoYiRuntime = XiaoYiRuntime;
|
|
154
122
|
// Global runtime instance
|