@ynhcj/xiaoyi 2.4.2 → 2.4.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 CHANGED
@@ -330,44 +330,36 @@ exports.xiaoyiPlugin = {
330
330
  // Start 60-second timeout timer
331
331
  const timeoutConfig = runtime.getTimeoutConfig();
332
332
  console.log(`[TIMEOUT] Starting ${timeoutConfig.duration}ms timeout protection for session ${sessionId}`);
333
- runtime.setTimeoutForSession(sessionId, async () => {
334
- // Timeout callback - send timeout message to user
335
- const elapsed = Date.now() - startTime;
336
- console.log("\n" + "=".repeat(60));
337
- console.log(`[TIMEOUT] Timeout triggered for session ${sessionId}`);
338
- console.log(` Elapsed: ${elapsed}ms`);
339
- console.log(` Task ID: ${taskId}`);
340
- console.log("=".repeat(60) + "\n");
341
- const conn = runtime.getConnection();
342
- if (conn) {
343
- const timeoutResponse = {
344
- sessionId: sessionId,
345
- messageId: `timeout_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
346
- timestamp: Date.now(),
347
- agentId: resolvedAccount.config.agentId,
348
- sender: {
349
- id: resolvedAccount.config.agentId,
350
- name: "OpenClaw Agent",
351
- type: "agent",
352
- },
353
- content: {
354
- type: "text",
355
- text: timeoutConfig.message,
356
- },
357
- status: "success",
358
- };
359
- try {
360
- await conn.sendResponse(timeoutResponse, taskId, sessionId, true, false);
361
- console.log(`[TIMEOUT] Timeout message sent successfully to session ${sessionId}\n`);
333
+ // Define recursive timeout handler
334
+ const createTimeoutHandler = () => {
335
+ return async () => {
336
+ const elapsed = Date.now() - startTime;
337
+ console.log("\n" + "=".repeat(60));
338
+ console.log(`[TIMEOUT] Timeout triggered for session ${sessionId}`);
339
+ console.log(` Elapsed: ${elapsed}ms`);
340
+ console.log(` Task ID: ${taskId}`);
341
+ console.log("=".repeat(60) + "\n");
342
+ const conn = runtime.getConnection();
343
+ if (conn) {
344
+ try {
345
+ // Send status update instead of artifact-update to keep conversation active
346
+ await conn.sendStatusUpdate(taskId, sessionId, timeoutConfig.message);
347
+ console.log(`[TIMEOUT] Status update sent successfully to session ${sessionId}\n`);
348
+ // Restart the timeout timer - allow repeated timeout messages
349
+ console.log(`[TIMEOUT] Restarting timeout timer for session ${sessionId}...\n`);
350
+ runtime.setTimeoutForSession(sessionId, createTimeoutHandler());
351
+ }
352
+ catch (error) {
353
+ console.error(`[TIMEOUT] Failed to send status update:`, error);
354
+ }
362
355
  }
363
- catch (error) {
364
- console.error(`[TIMEOUT] Failed to send timeout message:`, error);
356
+ else {
357
+ console.error(`[TIMEOUT] Connection not available, cannot send status update\n`);
365
358
  }
366
- }
367
- else {
368
- console.error(`[TIMEOUT] Connection not available, cannot send timeout message\n`);
369
- }
370
- });
359
+ };
360
+ };
361
+ // Start initial timeout
362
+ runtime.setTimeoutForSession(sessionId, createTimeoutHandler());
371
363
  // ==================== END TIMEOUT PROTECTION ====================
372
364
  await pluginRuntime.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
373
365
  ctx: msgContext,
@@ -70,6 +70,11 @@ export declare class XiaoYiWebSocketManager extends EventEmitter {
70
70
  * Send clear context response to specific server
71
71
  */
72
72
  sendClearContextResponse(requestId: string, sessionId: string, success?: boolean, targetServer?: ServerId): Promise<void>;
73
+ /**
74
+ * Send status update (for intermediate status messages, e.g., timeout warnings)
75
+ * This uses "status-update" event type which keeps the conversation active
76
+ */
77
+ sendStatusUpdate(taskId: string, sessionId: string, message: string, targetServer?: ServerId): Promise<void>;
73
78
  /**
74
79
  * Send tasks cancel response to specific server
75
80
  */
package/dist/websocket.js CHANGED
@@ -456,6 +456,64 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
456
456
  throw error;
457
457
  }
458
458
  }
459
+ /**
460
+ * Send status update (for intermediate status messages, e.g., timeout warnings)
461
+ * This uses "status-update" event type which keeps the conversation active
462
+ */
463
+ async sendStatusUpdate(taskId, sessionId, message, targetServer) {
464
+ const serverId = targetServer || this.sessionServerMap.get(sessionId);
465
+ if (!serverId) {
466
+ console.error(`[STATUS] Unknown server for session ${sessionId}`);
467
+ throw new Error(`Cannot send status update: unknown session ${sessionId}`);
468
+ }
469
+ const ws = serverId === 'server1' ? this.ws1 : this.ws2;
470
+ if (!ws || ws.readyState !== ws_1.default.OPEN) {
471
+ console.error(`[STATUS] ${serverId} not connected`);
472
+ throw new Error(`${serverId} is not available`);
473
+ }
474
+ // Create unique ID for this status update
475
+ const messageId = `status_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
476
+ const jsonRpcResponse = {
477
+ jsonrpc: "2.0",
478
+ id: messageId,
479
+ result: {
480
+ taskId: taskId,
481
+ kind: "status-update",
482
+ final: false, // IMPORTANT: Not final, keeps conversation active
483
+ status: {
484
+ message: {
485
+ role: "agent",
486
+ parts: [
487
+ {
488
+ kind: "text",
489
+ text: message,
490
+ },
491
+ ],
492
+ },
493
+ state: "working", // Indicates task is still being processed
494
+ },
495
+ },
496
+ };
497
+ const outboundMessage = {
498
+ msgType: "agent_response",
499
+ agentId: this.config.agentId,
500
+ sessionId: sessionId,
501
+ taskId: taskId,
502
+ msgDetail: JSON.stringify(jsonRpcResponse),
503
+ };
504
+ console.log(`[STATUS] Sending status update to ${serverId}:`);
505
+ console.log(` sessionId: ${sessionId}`);
506
+ console.log(` taskId: ${taskId}`);
507
+ console.log(` message: ${message}`);
508
+ console.log(` final: false, state: working\n`);
509
+ try {
510
+ ws.send(JSON.stringify(outboundMessage));
511
+ }
512
+ catch (error) {
513
+ console.error(`[STATUS] Failed to send to ${serverId}:`, error);
514
+ throw error;
515
+ }
516
+ }
459
517
  /**
460
518
  * Send tasks cancel response to specific server
461
519
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi",
3
- "version": "2.4.2",
3
+ "version": "2.4.4",
4
4
  "description": "XiaoYi channel plugin for OpenClaw",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,6 +29,11 @@
29
29
  "blurb": "小艺 A2A 协议支持,通过 WebSocket 连接。",
30
30
  "order": 80,
31
31
  "aliases": ["xy"]
32
+ },
33
+ "install": {
34
+ "npmSpec": "@ynhcj/xiaoyi",
35
+ "localPath": ".",
36
+ "defaultChoice": "npm"
32
37
  }
33
38
  },
34
39
  "peerDependencies": {