@ynhcj/xiaoyi 2.4.2 → 2.4.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 +44 -36
  2. package/package.json +1 -1
package/dist/channel.js CHANGED
@@ -330,44 +330,52 @@ 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
+ const timeoutResponse = {
345
+ sessionId: sessionId,
346
+ messageId: `timeout_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
347
+ timestamp: Date.now(),
348
+ agentId: resolvedAccount.config.agentId,
349
+ sender: {
350
+ id: resolvedAccount.config.agentId,
351
+ name: "OpenClaw Agent",
352
+ type: "agent",
353
+ },
354
+ content: {
355
+ type: "text",
356
+ text: timeoutConfig.message,
357
+ },
358
+ status: "success",
359
+ };
360
+ try {
361
+ // Send timeout message with isFinal=false (not final), append=false (replace)
362
+ await conn.sendResponse(timeoutResponse, taskId, sessionId, false, false);
363
+ console.log(`[TIMEOUT] Timeout message sent successfully to session ${sessionId}\n`);
364
+ // Restart the timeout timer - allow repeated timeout messages
365
+ console.log(`[TIMEOUT] Restarting timeout timer for session ${sessionId}...\n`);
366
+ runtime.setTimeoutForSession(sessionId, createTimeoutHandler());
367
+ }
368
+ catch (error) {
369
+ console.error(`[TIMEOUT] Failed to send timeout message:`, error);
370
+ }
362
371
  }
363
- catch (error) {
364
- console.error(`[TIMEOUT] Failed to send timeout message:`, error);
372
+ else {
373
+ console.error(`[TIMEOUT] Connection not available, cannot send timeout message\n`);
365
374
  }
366
- }
367
- else {
368
- console.error(`[TIMEOUT] Connection not available, cannot send timeout message\n`);
369
- }
370
- });
375
+ };
376
+ };
377
+ // Start initial timeout
378
+ runtime.setTimeoutForSession(sessionId, createTimeoutHandler());
371
379
  // ==================== END TIMEOUT PROTECTION ====================
372
380
  await pluginRuntime.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
373
381
  ctx: msgContext,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi",
3
- "version": "2.4.2",
3
+ "version": "2.4.3",
4
4
  "description": "XiaoYi channel plugin for OpenClaw",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",