@ynhcj/xiaoyi 1.9.6 → 1.9.8

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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ChannelOutboundContext, OutboundDeliveryResult, ChannelGatewayStartAccountContext, ChannelGatewayStopAccountContext, ChannelGatewayProbeAccountContext, ChannelMessagingNormalizeTargetContext, ChannelStatusGetAccountStatusContext } from "openclaw";
1
+ import type { ChannelOutboundContext, OutboundDeliveryResult, ChannelGatewayContext, ChannelMessagingNormalizeTargetContext, ChannelStatusGetAccountStatusContext, OpenClawConfig } from "openclaw";
2
2
  import { XiaoYiChannelConfig } from "./types";
3
3
  /**
4
4
  * Resolved XiaoYi account configuration (single account mode)
@@ -34,8 +34,8 @@ export declare const xiaoyiPlugin: {
34
34
  * Config adapter - single account mode
35
35
  */
36
36
  config: {
37
- listAccountIds: (cfg: any) => string[];
38
- resolveAccount: (cfg: any, accountId?: string | null) => {
37
+ listAccountIds: (cfg: OpenClawConfig) => string[];
38
+ resolveAccount: (cfg: OpenClawConfig, accountId?: string | null) => {
39
39
  accountId: string;
40
40
  config: {
41
41
  enabled: boolean;
@@ -46,9 +46,12 @@ export declare const xiaoyiPlugin: {
46
46
  };
47
47
  enabled: boolean;
48
48
  };
49
- defaultAccountId: (cfg: any) => "default" | undefined;
50
- isConfigured: (account: any) => boolean;
51
- describeAccount: (account: any) => {
49
+ defaultAccountId: (cfg: OpenClawConfig) => "default" | undefined;
50
+ isConfigured: (account: any, cfg: OpenClawConfig) => boolean;
51
+ isEnabled: (account: any, cfg: OpenClawConfig) => boolean;
52
+ disabledReason: (account: any, cfg: OpenClawConfig) => string;
53
+ unconfiguredReason: (account: any, cfg: OpenClawConfig) => string;
54
+ describeAccount: (account: any, cfg: OpenClawConfig) => {
52
55
  accountId: any;
53
56
  name: string;
54
57
  enabled: any;
@@ -68,12 +71,8 @@ export declare const xiaoyiPlugin: {
68
71
  * Gateway adapter - manage connections
69
72
  */
70
73
  gateway: {
71
- startAccount: (ctx: ChannelGatewayStartAccountContext) => Promise<void>;
72
- stopAccount: (ctx: ChannelGatewayStopAccountContext) => Promise<void>;
73
- probeAccount: (ctx: ChannelGatewayProbeAccountContext) => Promise<{
74
- status: string;
75
- message: string;
76
- }>;
74
+ startAccount: (ctx: ChannelGatewayContext<ResolvedXiaoYiAccount>) => Promise<void>;
75
+ stopAccount: (ctx: ChannelGatewayContext<ResolvedXiaoYiAccount>) => Promise<void>;
77
76
  };
78
77
  /**
79
78
  * Messaging adapter - normalize targets
package/dist/channel.js CHANGED
@@ -70,7 +70,7 @@ exports.xiaoyiPlugin = {
70
70
  // Single account mode: always return "default"
71
71
  return "default";
72
72
  },
73
- isConfigured: (account) => {
73
+ isConfigured: (account, cfg) => {
74
74
  // Safely check if all required fields are present and non-empty
75
75
  if (!account || !account.config) {
76
76
  return false;
@@ -83,7 +83,16 @@ exports.xiaoyiPlugin = {
83
83
  const hasAgentId = typeof config.agentId === 'string' && config.agentId.trim().length > 0;
84
84
  return hasWsUrl && hasAk && hasSk && hasAgentId;
85
85
  },
86
- describeAccount: (account) => ({
86
+ isEnabled: (account, cfg) => {
87
+ return account?.enabled !== false;
88
+ },
89
+ disabledReason: (account, cfg) => {
90
+ return "Channel is disabled in configuration";
91
+ },
92
+ unconfiguredReason: (account, cfg) => {
93
+ return "Missing required configuration: wsUrl, ak, sk, or agentId";
94
+ },
95
+ describeAccount: (account, cfg) => ({
87
96
  accountId: account.accountId,
88
97
  name: 'XiaoYi',
89
98
  enabled: account.enabled,
@@ -188,8 +197,8 @@ exports.xiaoyiPlugin = {
188
197
  console.log("XiaoYi: startAccount() called - START");
189
198
  const runtime = (0, runtime_1.getXiaoYiRuntime)();
190
199
  const resolvedAccount = ctx.account;
191
- // Save handleInboundMessage callback to runtime for later use
192
- runtime.setHandleInboundMessage(ctx.handleInboundMessage);
200
+ // Store the runtime environment for accessing handleInboundMessage
201
+ runtime.setRuntime(ctx.runtime);
193
202
  // Start WebSocket connection (single account mode)
194
203
  await runtime.start(resolvedAccount.config);
195
204
  // Setup message handler IMMEDIATELY after connection is established
@@ -199,16 +208,18 @@ exports.xiaoyiPlugin = {
199
208
  }
200
209
  // Setup message handler
201
210
  connection.on("message", async (message) => {
211
+ // Get runtime dynamically to handle module reloads
212
+ const runtime = (0, runtime_1.getXiaoYiRuntime)();
202
213
  // Store sessionId -> taskId mapping in runtime
203
214
  runtime.setTaskIdForSession(message.sessionId, message.id);
204
- // Get handleInboundMessage from runtime
205
- const handleInboundMessage = runtime.getHandleInboundMessage();
206
- if (!handleInboundMessage) {
207
- console.error("handleInboundMessage not available");
215
+ // Get handleInboundMessage from runtime environment
216
+ const runtimeEnv = runtime.getRuntime();
217
+ if (!runtimeEnv || !runtimeEnv.channel?.reply?.handleInboundMessage) {
218
+ console.error("handleInboundMessage not available in runtime");
208
219
  return;
209
220
  }
210
221
  // Convert A2A message to OpenClaw inbound message format
211
- await handleInboundMessage({
222
+ await runtimeEnv.channel.reply.handleInboundMessage({
212
223
  channel: "xiaoyi",
213
224
  accountId: resolvedAccount.accountId,
214
225
  from: message.sender.id,
@@ -229,8 +240,9 @@ exports.xiaoyiPlugin = {
229
240
  connection.on("cancel", async (data) => {
230
241
  console.log(`Handling cancel request for task: ${data.taskId}`);
231
242
  // Emit cancel event to OpenClaw runtime
232
- if (runtime.getRuntime()) {
233
- runtime.getRuntime().emit("task:cancel", {
243
+ const runtimeEnv = runtime.getRuntime();
244
+ if (runtimeEnv) {
245
+ runtimeEnv.emit("task:cancel", {
234
246
  channel: "xiaoyi",
235
247
  accountId: resolvedAccount.accountId,
236
248
  taskId: data.taskId,
@@ -247,14 +259,6 @@ exports.xiaoyiPlugin = {
247
259
  const runtime = (0, runtime_1.getXiaoYiRuntime)();
248
260
  runtime.stop();
249
261
  },
250
- probeAccount: async (ctx) => {
251
- const runtime = (0, runtime_1.getXiaoYiRuntime)();
252
- const isConnected = runtime.isConnected();
253
- return {
254
- status: isConnected ? "healthy" : "unhealthy",
255
- message: isConnected ? "Connected" : "Disconnected",
256
- };
257
- },
258
262
  },
259
263
  /**
260
264
  * Messaging adapter - normalize targets
package/dist/runtime.d.ts CHANGED
@@ -9,7 +9,6 @@ export declare class XiaoYiRuntime {
9
9
  private runtime;
10
10
  private config;
11
11
  private sessionToTaskIdMap;
12
- private handleInboundMessage;
13
12
  private instanceId;
14
13
  constructor();
15
14
  getInstanceId(): string;
@@ -21,14 +20,6 @@ export declare class XiaoYiRuntime {
21
20
  * Get OpenClaw runtime
22
21
  */
23
22
  getRuntime(): any;
24
- /**
25
- * Set handleInboundMessage callback
26
- */
27
- setHandleInboundMessage(handler: (message: any) => Promise<void>): void;
28
- /**
29
- * Get handleInboundMessage callback
30
- */
31
- getHandleInboundMessage(): ((message: any) => Promise<void>) | null;
32
23
  /**
33
24
  * Start connection (single account mode)
34
25
  */
package/dist/runtime.js CHANGED
@@ -14,7 +14,6 @@ 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
18
17
  this.instanceId = `runtime_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
19
18
  console.log(`XiaoYi: Created new runtime instance: ${this.instanceId}`);
20
19
  }
@@ -33,20 +32,6 @@ class XiaoYiRuntime {
33
32
  getRuntime() {
34
33
  return this.runtime;
35
34
  }
36
- /**
37
- * Set handleInboundMessage callback
38
- */
39
- setHandleInboundMessage(handler) {
40
- console.log(`XiaoYi: [${this.instanceId}] Setting handleInboundMessage callback`);
41
- this.handleInboundMessage = handler;
42
- }
43
- /**
44
- * Get handleInboundMessage callback
45
- */
46
- getHandleInboundMessage() {
47
- console.log(`XiaoYi: [${this.instanceId}] Getting handleInboundMessage callback, available:`, !!this.handleInboundMessage);
48
- return this.handleInboundMessage;
49
- }
50
35
  /**
51
36
  * Start connection (single account mode)
52
37
  */
@@ -85,9 +70,8 @@ class XiaoYiRuntime {
85
70
  this.connection = null;
86
71
  console.log("XiaoYi channel stopped");
87
72
  }
88
- // Clear session mappings and handlers
73
+ // Clear session mappings
89
74
  this.sessionToTaskIdMap.clear();
90
- this.handleInboundMessage = null;
91
75
  }
92
76
  /**
93
77
  * Get WebSocket manager
@@ -132,8 +116,12 @@ const GLOBAL_KEY = Symbol.for('__xiaoyi_runtime_instance__');
132
116
  function getXiaoYiRuntime() {
133
117
  const g = global;
134
118
  if (!g[GLOBAL_KEY]) {
119
+ console.log("XiaoYi: Creating NEW runtime instance (global storage)");
135
120
  g[GLOBAL_KEY] = new XiaoYiRuntime();
136
121
  }
122
+ else {
123
+ console.log(`XiaoYi: Reusing EXISTING runtime instance: ${g[GLOBAL_KEY].getInstanceId()}`);
124
+ }
137
125
  return g[GLOBAL_KEY];
138
126
  }
139
127
  function setXiaoYiRuntime(runtime) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi",
3
- "version": "1.9.6",
3
+ "version": "1.9.8",
4
4
  "description": "XiaoYi channel plugin for OpenClaw",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",