@ynhcj/xiaoyi 2.0.0 → 2.0.2

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 CHANGED
@@ -197,8 +197,6 @@ 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
- // Store the runtime environment for accessing handleInboundMessage
201
- runtime.setRuntime(ctx.runtime);
202
200
  // Start WebSocket connection (single account mode)
203
201
  await runtime.start(resolvedAccount.config);
204
202
  // Setup message handler IMMEDIATELY after connection is established
@@ -214,17 +212,26 @@ exports.xiaoyiPlugin = {
214
212
  console.log(`XiaoYi: [Message Handler] Using runtime instance: ${runtime.getInstanceId()}`);
215
213
  // Store sessionId -> taskId mapping in runtime
216
214
  runtime.setTaskIdForSession(message.sessionId, message.id);
217
- // Get handleInboundMessage from runtime environment
218
- const runtimeEnv = runtime.getRuntime();
219
- if (!runtimeEnv || !runtimeEnv.channel?.reply?.handleInboundMessage) {
220
- console.error("handleInboundMessage not available in runtime");
221
- console.error(`Runtime env exists: ${!!runtimeEnv}`);
222
- console.error(`Runtime env.channel exists: ${!!runtimeEnv?.channel}`);
223
- console.error(`Runtime env.channel.reply exists: ${!!runtimeEnv?.channel?.reply}`);
215
+ // Get PluginRuntime from our runtime wrapper
216
+ const pluginRuntime = runtime.getPluginRuntime();
217
+ console.log(`XiaoYi: PluginRuntime type: ${typeof pluginRuntime}`);
218
+ console.log(`XiaoYi: PluginRuntime.channel type: ${typeof pluginRuntime?.channel}`);
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
+ }
224
231
  return;
225
232
  }
226
233
  // Convert A2A message to OpenClaw inbound message format
227
- await runtimeEnv.channel.reply.handleInboundMessage({
234
+ await pluginRuntime.channel.reply.handleInboundMessage({
228
235
  channel: "xiaoyi",
229
236
  accountId: resolvedAccount.accountId,
230
237
  from: message.sender.id,
@@ -247,10 +254,10 @@ exports.xiaoyiPlugin = {
247
254
  // CRITICAL: Use dynamic require to get the latest runtime module after hot-reload
248
255
  const { getXiaoYiRuntime } = require("./runtime");
249
256
  const runtime = getXiaoYiRuntime();
250
- // Emit cancel event to OpenClaw runtime
251
- const runtimeEnv = runtime.getRuntime();
252
- if (runtimeEnv) {
253
- runtimeEnv.emit("task:cancel", {
257
+ // Get PluginRuntime and emit cancel event
258
+ const pluginRuntime = runtime.getPluginRuntime();
259
+ if (pluginRuntime) {
260
+ pluginRuntime.emit("task:cancel", {
254
261
  channel: "xiaoyi",
255
262
  accountId: resolvedAccount.accountId,
256
263
  taskId: data.taskId,
package/dist/runtime.d.ts CHANGED
@@ -6,20 +6,20 @@ import { XiaoYiChannelConfig } from "./types";
6
6
  */
7
7
  export declare class XiaoYiRuntime {
8
8
  private connection;
9
- private runtime;
9
+ private pluginRuntime;
10
10
  private config;
11
11
  private sessionToTaskIdMap;
12
12
  private instanceId;
13
13
  constructor();
14
14
  getInstanceId(): string;
15
15
  /**
16
- * Set OpenClaw runtime
16
+ * Set OpenClaw PluginRuntime (from api.runtime in register())
17
17
  */
18
- setRuntime(runtime: any): void;
18
+ setPluginRuntime(runtime: any): void;
19
19
  /**
20
- * Get OpenClaw runtime
20
+ * Get OpenClaw PluginRuntime
21
21
  */
22
- getRuntime(): any;
22
+ getPluginRuntime(): any;
23
23
  /**
24
24
  * Start connection (single account mode)
25
25
  */
package/dist/runtime.js CHANGED
@@ -11,7 +11,7 @@ const websocket_1 = require("./websocket");
11
11
  class XiaoYiRuntime {
12
12
  constructor() {
13
13
  this.connection = null;
14
- this.runtime = null;
14
+ this.pluginRuntime = null; // Store PluginRuntime from OpenClaw
15
15
  this.config = null;
16
16
  this.sessionToTaskIdMap = new Map(); // Map sessionId to taskId
17
17
  this.instanceId = `runtime_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
@@ -21,16 +21,17 @@ class XiaoYiRuntime {
21
21
  return this.instanceId;
22
22
  }
23
23
  /**
24
- * Set OpenClaw runtime
24
+ * Set OpenClaw PluginRuntime (from api.runtime in register())
25
25
  */
26
- setRuntime(runtime) {
27
- this.runtime = runtime;
26
+ setPluginRuntime(runtime) {
27
+ console.log(`XiaoYi: [${this.instanceId}] Setting PluginRuntime`);
28
+ this.pluginRuntime = runtime;
28
29
  }
29
30
  /**
30
- * Get OpenClaw runtime
31
+ * Get OpenClaw PluginRuntime
31
32
  */
32
- getRuntime() {
33
- return this.runtime;
33
+ getPluginRuntime() {
34
+ return this.pluginRuntime;
34
35
  }
35
36
  /**
36
37
  * Start connection (single account mode)
@@ -126,5 +127,5 @@ function getXiaoYiRuntime() {
126
127
  return g[GLOBAL_KEY];
127
128
  }
128
129
  function setXiaoYiRuntime(runtime) {
129
- getXiaoYiRuntime().setRuntime(runtime);
130
+ getXiaoYiRuntime().setPluginRuntime(runtime);
130
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "XiaoYi channel plugin for OpenClaw",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",