@ynhcj/xiaoyi 2.1.1 → 2.1.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.d.ts CHANGED
@@ -37,13 +37,7 @@ export declare const xiaoyiPlugin: {
37
37
  listAccountIds: (cfg: OpenClawConfig) => string[];
38
38
  resolveAccount: (cfg: OpenClawConfig, accountId?: string | null) => {
39
39
  accountId: string;
40
- config: {
41
- enabled: boolean;
42
- wsUrl: string;
43
- ak: string;
44
- sk: string;
45
- agentId: string;
46
- };
40
+ config: XiaoYiChannelConfig;
47
41
  enabled: boolean;
48
42
  };
49
43
  defaultAccountId: (cfg: OpenClawConfig) => "default" | undefined;
package/dist/channel.js CHANGED
@@ -247,11 +247,13 @@ exports.xiaoyiPlugin = {
247
247
  };
248
248
  // Use the correct API to dispatch the message (streaming mode enabled)
249
249
  try {
250
+ const streamingEnabled = resolvedAccount.config.enableStreaming === true;
250
251
  console.log("\n" + "=".repeat(60));
251
252
  console.log(`XiaoYi: [STREAMING] Starting message processing`);
252
253
  console.log(` Session: ${message.sessionId}`);
253
254
  console.log(` Task ID: ${message.params.id}`);
254
255
  console.log(` User input: ${bodyText.substring(0, 50)}${bodyText.length > 50 ? "..." : ""}`);
256
+ console.log(` Streaming: ${streamingEnabled ? "ENABLED" : "DISABLED (enableStreaming=false)"}`);
255
257
  console.log("=".repeat(60) + "\n");
256
258
  // Track response state for streaming
257
259
  let accumulatedText = "";
@@ -310,8 +312,9 @@ exports.xiaoyiPlugin = {
310
312
  console.log("=".repeat(60) + "\n");
311
313
  },
312
314
  },
313
- replyOptions: {
315
+ replyOptions: streamingEnabled ? {
314
316
  // Enable streaming responses through onPartialReply callback
317
+ disableBlockStreaming: false, // CRITICAL: Enable block streaming
315
318
  onPartialReply: async (payload) => {
316
319
  const elapsed = Date.now() - startTime;
317
320
  const newText = payload.text || "";
@@ -353,7 +356,7 @@ exports.xiaoyiPlugin = {
353
356
  console.log(` ✓ SENT (isFinal=false, append=true)\n`);
354
357
  }
355
358
  },
356
- },
359
+ } : undefined, // No replyOptions when streaming is disabled
357
360
  });
358
361
  }
359
362
  catch (error) {
@@ -18,11 +18,14 @@ export declare const XiaoYiConfigSchema: z.ZodObject<{
18
18
  agentId: z.ZodOptional<z.ZodString>;
19
19
  /** Enable debug logging */
20
20
  debug: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
21
+ /** Enable streaming responses (default: false) */
22
+ enableStreaming: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
21
23
  /** Multi-account configuration */
22
24
  accounts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
23
25
  }, "strip", z.ZodTypeAny, {
24
26
  enabled: boolean;
25
27
  debug: boolean;
28
+ enableStreaming: boolean;
26
29
  name?: string | undefined;
27
30
  wsUrl?: string | undefined;
28
31
  ak?: string | undefined;
@@ -37,6 +40,7 @@ export declare const XiaoYiConfigSchema: z.ZodObject<{
37
40
  sk?: string | undefined;
38
41
  agentId?: string | undefined;
39
42
  debug?: boolean | undefined;
43
+ enableStreaming?: boolean | undefined;
40
44
  accounts?: Record<string, unknown> | undefined;
41
45
  }>;
42
46
  export type XiaoYiConfig = z.infer<typeof XiaoYiConfigSchema>;
@@ -21,6 +21,8 @@ exports.XiaoYiConfigSchema = zod_1.z.object({
21
21
  agentId: zod_1.z.string().optional(),
22
22
  /** Enable debug logging */
23
23
  debug: zod_1.z.boolean().optional().default(false),
24
+ /** Enable streaming responses (default: false) */
25
+ enableStreaming: zod_1.z.boolean().optional().default(false),
24
26
  /** Multi-account configuration */
25
27
  accounts: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
26
28
  });
package/dist/types.d.ts CHANGED
@@ -141,6 +141,7 @@ export interface XiaoYiChannelConfig {
141
141
  ak: string;
142
142
  sk: string;
143
143
  agentId: string;
144
+ enableStreaming?: boolean;
144
145
  }
145
146
  export interface AuthCredentials {
146
147
  ak: string;
package/dist/websocket.js CHANGED
@@ -295,7 +295,22 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
295
295
  console.warn(`Received message with mismatched agentId: ${message.agentId}, expected: ${this.config.agentId}. Discarding.`);
296
296
  return;
297
297
  }
298
- // Check if it's a clear message
298
+ // Handle JSON-RPC 2.0 clearContext method (直接响应,不走 OpenClaw)
299
+ // Reference: https://developer.huawei.com/consumer/cn/doc/service/clear-context-0000002537681163
300
+ if (message.method === "clearContext") {
301
+ console.log(`[CLEAR] Received clearContext for session: ${message.sessionId}`);
302
+ // 直接返回成功响应
303
+ this.sendClearContextResponse(message.id, message.sessionId, true).catch(error => {
304
+ console.error("Failed to send clearContext response:", error);
305
+ });
306
+ // 可选:通知应用清除会话上下文
307
+ this.emit("clear", {
308
+ sessionId: message.sessionId,
309
+ id: message.id,
310
+ });
311
+ return;
312
+ }
313
+ // Check if it's a clear message (兼容旧格式)
299
314
  if (message.action === "clear") {
300
315
  this.handleClearMessage(message);
301
316
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "XiaoYi channel plugin for OpenClaw",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",