@ynhcj/xiaoyi 2.1.8 → 2.1.9
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 +24 -82
- package/dist/websocket.d.ts +4 -0
- package/dist/websocket.js +15 -3
- package/package.json +1 -1
package/dist/channel.js
CHANGED
|
@@ -364,102 +364,44 @@ exports.xiaoyiPlugin = {
|
|
|
364
364
|
}
|
|
365
365
|
});
|
|
366
366
|
// Setup cancel handler
|
|
367
|
+
// Note: The response is already sent in websocket.ts, this is just for additional handling
|
|
367
368
|
connection.on("cancel", async (data) => {
|
|
368
369
|
console.log("\n" + "=".repeat(60));
|
|
369
|
-
console.log(`XiaoYi: [CANCEL]
|
|
370
|
+
console.log(`XiaoYi: [CANCEL] Cancel event received (response already sent)`);
|
|
370
371
|
console.log(` Session: ${data.sessionId}`);
|
|
371
372
|
console.log(` Task ID: ${data.taskId || "N/A"}`);
|
|
372
373
|
console.log("=".repeat(60) + "\n");
|
|
373
|
-
//
|
|
374
|
-
|
|
375
|
-
const runtime = getXiaoYiRuntime();
|
|
376
|
-
// Build SessionKey to match the format used in message handler
|
|
377
|
-
const sessionKey = `xiaoyi:${resolvedAccount.accountId}:${data.sessionId}`;
|
|
378
|
-
// Try to abort the running agent using OpenClaw's internal API
|
|
374
|
+
// Try to abort the running agent by clearing session queues
|
|
375
|
+
// This prevents new messages from being queued and may interrupt streaming
|
|
379
376
|
try {
|
|
380
|
-
|
|
381
|
-
//
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
catch {
|
|
390
|
-
return null;
|
|
391
|
-
}
|
|
392
|
-
})();
|
|
393
|
-
if (!abortEmbeddedPiRun) {
|
|
394
|
-
console.warn(`XiaoYi: [CANCEL] abortEmbeddedPiRun not available, falling back to event emission`);
|
|
395
|
-
throw new Error("abortEmbeddedPiRun not available");
|
|
396
|
-
}
|
|
397
|
-
// Try to load session store functions
|
|
398
|
-
const loadSessionStore = globalThis["__openclaw_loadSessionStore"] ||
|
|
399
|
-
(() => {
|
|
400
|
-
try {
|
|
401
|
-
const openclawPath = require.resolve("openclaw");
|
|
402
|
-
const sessionModule = require(`${openclawPath}/dist/config/sessions.js`);
|
|
403
|
-
return sessionModule.loadSessionStore;
|
|
404
|
-
}
|
|
405
|
-
catch {
|
|
406
|
-
return null;
|
|
407
|
-
}
|
|
408
|
-
})();
|
|
409
|
-
const resolveStorePath = globalThis["__openclaw_resolveStorePath"] ||
|
|
410
|
-
(() => {
|
|
411
|
-
try {
|
|
412
|
-
const openclawPath = require.resolve("openclaw");
|
|
413
|
-
const sessionModule = require(`${openclawPath}/dist/config/sessions.js`);
|
|
414
|
-
return sessionModule.resolveStorePath;
|
|
415
|
-
}
|
|
416
|
-
catch {
|
|
417
|
-
return null;
|
|
418
|
-
}
|
|
419
|
-
})();
|
|
420
|
-
if (!loadSessionStore || !resolveStorePath) {
|
|
421
|
-
console.warn(`XiaoYi: [CANCEL] Session store functions not available`);
|
|
422
|
-
throw new Error("Session store functions not available");
|
|
423
|
-
}
|
|
424
|
-
// Load session store and find the internal sessionId
|
|
425
|
-
const agentId = resolvedAccount.config.agentId || "default";
|
|
426
|
-
const storePath = resolveStorePath(config.session?.store, { agentId });
|
|
427
|
-
const store = loadSessionStore(storePath);
|
|
428
|
-
const sessionEntry = store[sessionKey];
|
|
429
|
-
if (sessionEntry && sessionEntry.sessionId) {
|
|
430
|
-
console.log(`XiaoYi: [CANCEL] Found session entry with internal sessionId: ${sessionEntry.sessionId}`);
|
|
431
|
-
// Abort the running agent
|
|
432
|
-
const aborted = abortEmbeddedPiRun(sessionEntry.sessionId);
|
|
433
|
-
if (aborted) {
|
|
434
|
-
console.log(`XiaoYi: [CANCEL] ✓ Successfully aborted agent run for session: ${data.sessionId}\n`);
|
|
377
|
+
const sessionKey = `xiaoyi:${resolvedAccount.accountId}:${data.sessionId}`;
|
|
378
|
+
// Try to load and use clearSessionQueues from OpenClaw at runtime
|
|
379
|
+
// Use require() instead of import to avoid TypeScript compilation errors
|
|
380
|
+
const clearSessionQueues = (() => {
|
|
381
|
+
try {
|
|
382
|
+
// Try direct require first (works when openclaw is installed as dependency)
|
|
383
|
+
const queueModule = require("openclaw/dist/auto-reply/reply/queue.js");
|
|
384
|
+
return queueModule.clearSessionQueues;
|
|
435
385
|
}
|
|
436
|
-
|
|
437
|
-
|
|
386
|
+
catch {
|
|
387
|
+
return null;
|
|
438
388
|
}
|
|
389
|
+
})();
|
|
390
|
+
if (clearSessionQueues) {
|
|
391
|
+
const cleared = clearSessionQueues([sessionKey]);
|
|
392
|
+
console.log(`XiaoYi: [CANCEL] Cleared session queues:`, cleared);
|
|
439
393
|
}
|
|
440
394
|
else {
|
|
441
|
-
console.
|
|
395
|
+
console.log(`XiaoYi: [CANCEL] clearSessionQueues not available, skipping queue cleanup`);
|
|
442
396
|
}
|
|
443
397
|
}
|
|
444
398
|
catch (error) {
|
|
445
|
-
console.
|
|
446
|
-
// Fallback: emit cancel event for any listeners
|
|
447
|
-
const pluginRuntime = runtime.getPluginRuntime();
|
|
448
|
-
if (pluginRuntime) {
|
|
449
|
-
pluginRuntime.emit("task:cancel", {
|
|
450
|
-
channel: "xiaoyi",
|
|
451
|
-
accountId: resolvedAccount.accountId,
|
|
452
|
-
taskId: data.taskId,
|
|
453
|
-
sessionId: data.sessionId,
|
|
454
|
-
});
|
|
455
|
-
console.log(`XiaoYi: [CANCEL] Emitted task:cancel event as fallback\n`);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
// Send success response
|
|
459
|
-
const connection = runtime.getConnection();
|
|
460
|
-
if (connection) {
|
|
461
|
-
await connection.sendCancelSuccessResponse(data.sessionId, data.taskId, data.id);
|
|
399
|
+
console.log(`XiaoYi: [CANCEL] Could not clear session queues:`, error);
|
|
462
400
|
}
|
|
401
|
+
// NOTE: True cancellation of the in-progress agent run requires OpenClaw's internal
|
|
402
|
+
// abortEmbeddedPiRun function, which needs the internal sessionId from session store.
|
|
403
|
+
// This channel plugin acknowledges the cancel request, but actual agent interruption
|
|
404
|
+
// depends on OpenClaw's internal mechanisms.
|
|
463
405
|
});
|
|
464
406
|
console.log("XiaoYi: Event handlers registered");
|
|
465
407
|
console.log("XiaoYi: startAccount() completed - END");
|
package/dist/websocket.d.ts
CHANGED
|
@@ -78,6 +78,10 @@ export declare class XiaoYiWebSocketManager extends EventEmitter {
|
|
|
78
78
|
/**
|
|
79
79
|
* Handle A2A tasks/cancel message
|
|
80
80
|
* Reference: https://developer.huawei.com/consumer/cn/doc/service/tasks-cancel-0000002537561193
|
|
81
|
+
*
|
|
82
|
+
* Simplified implementation similar to clearContext:
|
|
83
|
+
* 1. Send success response immediately
|
|
84
|
+
* 2. Emit cancel event for application to handle
|
|
81
85
|
*/
|
|
82
86
|
private handleTasksCancelMessage;
|
|
83
87
|
/**
|
package/dist/websocket.js
CHANGED
|
@@ -379,21 +379,33 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
379
379
|
/**
|
|
380
380
|
* Handle A2A tasks/cancel message
|
|
381
381
|
* Reference: https://developer.huawei.com/consumer/cn/doc/service/tasks-cancel-0000002537561193
|
|
382
|
+
*
|
|
383
|
+
* Simplified implementation similar to clearContext:
|
|
384
|
+
* 1. Send success response immediately
|
|
385
|
+
* 2. Emit cancel event for application to handle
|
|
382
386
|
*/
|
|
383
387
|
handleTasksCancelMessage(message) {
|
|
384
388
|
// Use taskId if available, otherwise use id as the task identifier
|
|
385
389
|
const effectiveTaskId = message.taskId || message.id;
|
|
386
|
-
console.log(
|
|
390
|
+
console.log(`\n============================================================`);
|
|
391
|
+
console.log(`XiaoYi: [CANCEL] Received cancel request`);
|
|
387
392
|
console.log(` Session: ${message.sessionId}`);
|
|
393
|
+
console.log(` Task ID: ${effectiveTaskId}`);
|
|
388
394
|
console.log(` Message ID: ${message.id}`);
|
|
395
|
+
console.log(`===========================================================\n`);
|
|
396
|
+
// Send success response immediately (similar to clearContext)
|
|
397
|
+
this.sendTasksCancelResponse(message.id, message.sessionId, true).catch(error => {
|
|
398
|
+
console.error("Failed to send tasks/cancel response:", error);
|
|
399
|
+
});
|
|
389
400
|
// Emit cancel event for application to handle
|
|
401
|
+
// The application can decide how to handle the cancellation
|
|
390
402
|
this.emit("cancel", {
|
|
391
403
|
sessionId: message.sessionId,
|
|
392
404
|
taskId: effectiveTaskId,
|
|
393
405
|
id: message.id,
|
|
394
406
|
});
|
|
395
|
-
//
|
|
396
|
-
|
|
407
|
+
// Remove from active tasks
|
|
408
|
+
this.activeTasks.delete(effectiveTaskId);
|
|
397
409
|
}
|
|
398
410
|
/**
|
|
399
411
|
* Send tasks/cancel success response
|