@ynhcj/xiaoyi 1.9.1 → 1.9.3
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 +45 -42
- package/dist/index.js +6 -0
- package/dist/runtime.js +4 -1
- package/package.json +1 -1
package/dist/channel.js
CHANGED
|
@@ -191,52 +191,55 @@ exports.xiaoyiPlugin = {
|
|
|
191
191
|
runtime.setHandleInboundMessage(ctx.handleInboundMessage);
|
|
192
192
|
// Start WebSocket connection (single account mode)
|
|
193
193
|
await runtime.start(resolvedAccount.config);
|
|
194
|
-
// Setup message handler
|
|
194
|
+
// Setup message handler IMMEDIATELY after connection is established
|
|
195
195
|
const connection = runtime.getConnection();
|
|
196
|
-
if (connection) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
196
|
+
if (!connection) {
|
|
197
|
+
throw new Error("Failed to get WebSocket connection after start");
|
|
198
|
+
}
|
|
199
|
+
// Setup message handler
|
|
200
|
+
connection.on("message", async (message) => {
|
|
201
|
+
// Store sessionId -> taskId mapping in runtime
|
|
202
|
+
runtime.setTaskIdForSession(message.sessionId, message.id);
|
|
203
|
+
// Get handleInboundMessage from runtime
|
|
204
|
+
const handleInboundMessage = runtime.getHandleInboundMessage();
|
|
205
|
+
if (!handleInboundMessage) {
|
|
206
|
+
console.error("handleInboundMessage not available");
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
// Convert A2A message to OpenClaw inbound message format
|
|
210
|
+
await handleInboundMessage({
|
|
211
|
+
channel: "xiaoyi",
|
|
212
|
+
accountId: resolvedAccount.accountId,
|
|
213
|
+
from: message.sender.id,
|
|
214
|
+
text: message.content.text || "",
|
|
215
|
+
messageId: message.messageId,
|
|
216
|
+
timestamp: message.timestamp,
|
|
217
|
+
peer: {
|
|
218
|
+
kind: "dm",
|
|
219
|
+
id: message.sessionId, // Use sessionId as peer id for routing responses
|
|
220
|
+
},
|
|
221
|
+
meta: {
|
|
222
|
+
sessionId: message.sessionId,
|
|
223
|
+
taskId: message.id,
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
// Setup cancel handler
|
|
228
|
+
connection.on("cancel", async (data) => {
|
|
229
|
+
console.log(`Handling cancel request for task: ${data.taskId}`);
|
|
230
|
+
// Emit cancel event to OpenClaw runtime
|
|
231
|
+
if (runtime.getRuntime()) {
|
|
232
|
+
runtime.getRuntime().emit("task:cancel", {
|
|
208
233
|
channel: "xiaoyi",
|
|
209
234
|
accountId: resolvedAccount.accountId,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
messageId: message.messageId,
|
|
213
|
-
timestamp: message.timestamp,
|
|
214
|
-
peer: {
|
|
215
|
-
kind: "dm",
|
|
216
|
-
id: message.sessionId, // Use sessionId as peer id for routing responses
|
|
217
|
-
},
|
|
218
|
-
meta: {
|
|
219
|
-
sessionId: message.sessionId,
|
|
220
|
-
taskId: message.id,
|
|
221
|
-
},
|
|
235
|
+
taskId: data.taskId,
|
|
236
|
+
sessionId: data.sessionId,
|
|
222
237
|
});
|
|
223
|
-
}
|
|
224
|
-
//
|
|
225
|
-
connection.
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (runtime.getRuntime()) {
|
|
229
|
-
runtime.getRuntime().emit("task:cancel", {
|
|
230
|
-
channel: "xiaoyi",
|
|
231
|
-
accountId: resolvedAccount.accountId,
|
|
232
|
-
taskId: data.taskId,
|
|
233
|
-
sessionId: data.sessionId,
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
// Send success response
|
|
237
|
-
await connection.sendCancelSuccessResponse(data.sessionId, data.taskId, data.id);
|
|
238
|
-
});
|
|
239
|
-
}
|
|
238
|
+
}
|
|
239
|
+
// Send success response
|
|
240
|
+
await connection.sendCancelSuccessResponse(data.sessionId, data.taskId, data.id);
|
|
241
|
+
});
|
|
242
|
+
console.log("XiaoYi: Event handlers registered");
|
|
240
243
|
},
|
|
241
244
|
stopAccount: async (ctx) => {
|
|
242
245
|
const runtime = (0, runtime_1.getXiaoYiRuntime)();
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,12 @@ const plugin = {
|
|
|
30
30
|
register(api) {
|
|
31
31
|
// Set runtime for managing WebSocket connections
|
|
32
32
|
(0, runtime_1.setXiaoYiRuntime)(api.runtime);
|
|
33
|
+
// Clean up any existing connections from previous plugin loads
|
|
34
|
+
const runtime = require("./runtime").getXiaoYiRuntime();
|
|
35
|
+
if (runtime.isConnected()) {
|
|
36
|
+
console.log("XiaoYi: Cleaning up existing connection from previous load");
|
|
37
|
+
runtime.stop();
|
|
38
|
+
}
|
|
33
39
|
// Register the channel plugin
|
|
34
40
|
api.registerChannel({ plugin: channel_1.xiaoyiPlugin });
|
|
35
41
|
console.log("XiaoYi channel plugin registered");
|
package/dist/runtime.js
CHANGED
|
@@ -32,12 +32,14 @@ class XiaoYiRuntime {
|
|
|
32
32
|
* Set handleInboundMessage callback
|
|
33
33
|
*/
|
|
34
34
|
setHandleInboundMessage(handler) {
|
|
35
|
+
console.log("XiaoYi: Setting handleInboundMessage callback");
|
|
35
36
|
this.handleInboundMessage = handler;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
39
|
* Get handleInboundMessage callback
|
|
39
40
|
*/
|
|
40
41
|
getHandleInboundMessage() {
|
|
42
|
+
console.log("XiaoYi: Getting handleInboundMessage callback, available:", !!this.handleInboundMessage);
|
|
41
43
|
return this.handleInboundMessage;
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
@@ -78,8 +80,9 @@ class XiaoYiRuntime {
|
|
|
78
80
|
this.connection = null;
|
|
79
81
|
console.log("XiaoYi channel stopped");
|
|
80
82
|
}
|
|
81
|
-
// Clear session mappings
|
|
83
|
+
// Clear session mappings and handlers
|
|
82
84
|
this.sessionToTaskIdMap.clear();
|
|
85
|
+
this.handleInboundMessage = null;
|
|
83
86
|
}
|
|
84
87
|
/**
|
|
85
88
|
* Get WebSocket manager
|