@ynhcj/xiaoyi 2.0.2 → 2.0.4
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 +57 -31
- package/package.json +1 -1
package/dist/channel.js
CHANGED
|
@@ -197,6 +197,7 @@ exports.xiaoyiPlugin = {
|
|
|
197
197
|
console.log("XiaoYi: startAccount() called - START");
|
|
198
198
|
const runtime = (0, runtime_1.getXiaoYiRuntime)();
|
|
199
199
|
const resolvedAccount = ctx.account;
|
|
200
|
+
const config = ctx.cfg;
|
|
200
201
|
// Start WebSocket connection (single account mode)
|
|
201
202
|
await runtime.start(resolvedAccount.config);
|
|
202
203
|
// Setup message handler IMMEDIATELY after connection is established
|
|
@@ -214,39 +215,64 @@ exports.xiaoyiPlugin = {
|
|
|
214
215
|
runtime.setTaskIdForSession(message.sessionId, message.id);
|
|
215
216
|
// Get PluginRuntime from our runtime wrapper
|
|
216
217
|
const pluginRuntime = runtime.getPluginRuntime();
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
console.log(`XiaoYi: PluginRuntime.channel.reply type: ${typeof pluginRuntime?.channel?.reply}`);
|
|
220
|
-
console.log(`XiaoYi: PluginRuntime.channel.reply.handleInboundMessage type: ${typeof pluginRuntime?.channel?.reply?.handleInboundMessage}`);
|
|
221
|
-
if (!pluginRuntime || !pluginRuntime.channel?.reply?.handleInboundMessage) {
|
|
222
|
-
console.error("handleInboundMessage not available in PluginRuntime");
|
|
223
|
-
console.error(`PluginRuntime exists: ${!!pluginRuntime}`);
|
|
224
|
-
console.error(`PluginRuntime.channel exists: ${!!pluginRuntime?.channel}`);
|
|
225
|
-
console.error(`PluginRuntime.channel.reply exists: ${!!pluginRuntime?.channel?.reply}`);
|
|
226
|
-
console.error(`PluginRuntime.channel.reply.handleInboundMessage exists: ${!!pluginRuntime?.channel?.reply?.handleInboundMessage}`);
|
|
227
|
-
// Log the actual structure
|
|
228
|
-
if (pluginRuntime?.channel?.reply) {
|
|
229
|
-
console.error(`PluginRuntime.channel.reply keys: ${Object.keys(pluginRuntime.channel.reply).join(', ')}`);
|
|
230
|
-
}
|
|
218
|
+
if (!pluginRuntime) {
|
|
219
|
+
console.error("PluginRuntime not available");
|
|
231
220
|
return;
|
|
232
221
|
}
|
|
233
|
-
//
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
222
|
+
// Build MsgContext for OpenClaw's message pipeline
|
|
223
|
+
const msgContext = {
|
|
224
|
+
Body: message.content.text || "",
|
|
225
|
+
From: message.sender.id,
|
|
226
|
+
To: message.sessionId,
|
|
227
|
+
SessionKey: `xiaoyi:${resolvedAccount.accountId}:${message.sessionId}`,
|
|
228
|
+
AccountId: resolvedAccount.accountId,
|
|
229
|
+
MessageSid: message.messageId,
|
|
230
|
+
Timestamp: message.timestamp,
|
|
231
|
+
Provider: "xiaoyi",
|
|
232
|
+
Surface: "xiaoyi",
|
|
233
|
+
ChatType: "direct",
|
|
234
|
+
SenderName: message.sender.name,
|
|
235
|
+
SenderId: message.sender.id,
|
|
236
|
+
OriginatingChannel: "xiaoyi",
|
|
237
|
+
};
|
|
238
|
+
// Use the correct API to dispatch the message
|
|
239
|
+
try {
|
|
240
|
+
await pluginRuntime.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
241
|
+
ctx: msgContext,
|
|
242
|
+
cfg: config,
|
|
243
|
+
dispatcherOptions: {
|
|
244
|
+
deliver: async (payload) => {
|
|
245
|
+
console.log("XiaoYi: Delivering response:", payload);
|
|
246
|
+
// Send response back through WebSocket
|
|
247
|
+
const taskId = runtime.getTaskIdForSession(message.sessionId) || `task_${Date.now()}`;
|
|
248
|
+
const response = {
|
|
249
|
+
sessionId: message.sessionId,
|
|
250
|
+
messageId: `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
251
|
+
timestamp: Date.now(),
|
|
252
|
+
agentId: resolvedAccount.config.agentId,
|
|
253
|
+
sender: {
|
|
254
|
+
id: resolvedAccount.config.agentId,
|
|
255
|
+
name: "OpenClaw Agent",
|
|
256
|
+
type: "agent",
|
|
257
|
+
},
|
|
258
|
+
content: {
|
|
259
|
+
type: "text",
|
|
260
|
+
text: payload.text || "",
|
|
261
|
+
},
|
|
262
|
+
status: "success",
|
|
263
|
+
};
|
|
264
|
+
const conn = runtime.getConnection();
|
|
265
|
+
if (conn) {
|
|
266
|
+
await conn.sendResponse(response, taskId, message.sessionId);
|
|
267
|
+
console.log("XiaoYi: Response sent successfully");
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
console.error("Error dispatching message:", error);
|
|
275
|
+
}
|
|
250
276
|
});
|
|
251
277
|
// Setup cancel handler
|
|
252
278
|
connection.on("cancel", async (data) => {
|