@ynhcj/xiaoyi 2.0.1 → 2.0.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.
Files changed (2) hide show
  1. package/dist/channel.js +58 -22
  2. 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,30 +215,65 @@ 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
- if (!pluginRuntime || !pluginRuntime.channel?.reply?.handleInboundMessage) {
218
- console.error("handleInboundMessage not available in PluginRuntime");
219
- console.error(`PluginRuntime exists: ${!!pluginRuntime}`);
220
- console.error(`PluginRuntime.channel exists: ${!!pluginRuntime?.channel}`);
221
- console.error(`PluginRuntime.channel.reply exists: ${!!pluginRuntime?.channel?.reply}`);
218
+ if (!pluginRuntime) {
219
+ console.error("PluginRuntime not available");
222
220
  return;
223
221
  }
224
- // Convert A2A message to OpenClaw inbound message format
225
- await pluginRuntime.channel.reply.handleInboundMessage({
226
- channel: "xiaoyi",
227
- accountId: resolvedAccount.accountId,
228
- from: message.sender.id,
229
- text: message.content.text || "",
230
- messageId: message.messageId,
231
- timestamp: message.timestamp,
232
- peer: {
233
- kind: "dm",
234
- id: message.sessionId, // Use sessionId as peer id for routing responses
235
- },
236
- meta: {
237
- sessionId: message.sessionId,
238
- taskId: message.id,
239
- },
240
- });
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
+ send: async (text) => {
245
+ // Send response back through WebSocket
246
+ const taskId = runtime.getTaskIdForSession(message.sessionId) || `task_${Date.now()}`;
247
+ const response = {
248
+ sessionId: message.sessionId,
249
+ messageId: `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
250
+ timestamp: Date.now(),
251
+ agentId: resolvedAccount.config.agentId,
252
+ sender: {
253
+ id: resolvedAccount.config.agentId,
254
+ name: "OpenClaw Agent",
255
+ type: "agent",
256
+ },
257
+ content: {
258
+ type: "text",
259
+ text: text,
260
+ },
261
+ status: "success",
262
+ };
263
+ const conn = runtime.getConnection();
264
+ if (conn) {
265
+ await conn.sendResponse(response, taskId, message.sessionId);
266
+ }
267
+ },
268
+ sendTyping: async () => {
269
+ // XiaoYi A2A protocol doesn't have typing indicators
270
+ },
271
+ },
272
+ });
273
+ }
274
+ catch (error) {
275
+ console.error("Error dispatching message:", error);
276
+ }
241
277
  });
242
278
  // Setup cancel handler
243
279
  connection.on("cancel", async (data) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "XiaoYi channel plugin for OpenClaw",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",