@ynhcj/xiaoyi 2.3.4 → 2.3.5
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 +19 -19
- package/dist/types.d.ts +1 -2
- package/dist/websocket.js +9 -11
- package/package.json +1 -1
package/dist/channel.js
CHANGED
|
@@ -215,7 +215,7 @@ exports.xiaoyiPlugin = {
|
|
|
215
215
|
const runtime = getXiaoYiRuntime();
|
|
216
216
|
console.log(`XiaoYi: [Message Handler] Using runtime instance: ${runtime.getInstanceId()}`);
|
|
217
217
|
// Store sessionId -> taskId mapping in runtime (use params.id as taskId)
|
|
218
|
-
runtime.setTaskIdForSession(message.sessionId, message.params.id);
|
|
218
|
+
runtime.setTaskIdForSession(message.params.sessionId, message.params.id);
|
|
219
219
|
// Get PluginRuntime from our runtime wrapper
|
|
220
220
|
const pluginRuntime = runtime.getPluginRuntime();
|
|
221
221
|
if (!pluginRuntime) {
|
|
@@ -291,8 +291,8 @@ exports.xiaoyiPlugin = {
|
|
|
291
291
|
const msgContext = {
|
|
292
292
|
Body: bodyText,
|
|
293
293
|
From: senderId,
|
|
294
|
-
To: message.sessionId,
|
|
295
|
-
SessionKey: `xiaoyi:${resolvedAccount.accountId}:${message.sessionId}`,
|
|
294
|
+
To: message.params.sessionId,
|
|
295
|
+
SessionKey: `xiaoyi:${resolvedAccount.accountId}:${message.params.sessionId}`,
|
|
296
296
|
AccountId: resolvedAccount.accountId,
|
|
297
297
|
MessageSid: message.id, // Use top-level id as message sequence number
|
|
298
298
|
Timestamp: Date.now(), // Generate timestamp since new format doesn't include it
|
|
@@ -307,30 +307,30 @@ exports.xiaoyiPlugin = {
|
|
|
307
307
|
try {
|
|
308
308
|
console.log("\n" + "=".repeat(60));
|
|
309
309
|
console.log(`XiaoYi: [MESSAGE] Processing user message`);
|
|
310
|
-
console.log(` Session: ${message.sessionId}`);
|
|
310
|
+
console.log(` Session: ${message.params.sessionId}`);
|
|
311
311
|
console.log(` Task ID: ${message.params.id}`);
|
|
312
312
|
console.log(` User input: ${bodyText.substring(0, 50)}${bodyText.length > 50 ? "..." : ""}`);
|
|
313
313
|
console.log(` Images: ${images.length}`);
|
|
314
314
|
console.log("=".repeat(60) + "\n");
|
|
315
|
-
const taskId = runtime.getTaskIdForSession(message.sessionId) || `task_${Date.now()}`;
|
|
315
|
+
const taskId = runtime.getTaskIdForSession(message.params.sessionId) || `task_${Date.now()}`;
|
|
316
316
|
const startTime = Date.now();
|
|
317
317
|
let accumulatedText = "";
|
|
318
318
|
// ==================== START TIMEOUT PROTECTION ====================
|
|
319
319
|
// Start 60-second timeout timer
|
|
320
320
|
const timeoutConfig = runtime.getTimeoutConfig();
|
|
321
|
-
console.log(`[TIMEOUT] Starting ${timeoutConfig.duration}ms timeout protection for session ${message.sessionId}`);
|
|
322
|
-
runtime.setTimeoutForSession(message.sessionId, async () => {
|
|
321
|
+
console.log(`[TIMEOUT] Starting ${timeoutConfig.duration}ms timeout protection for session ${message.params.sessionId}`);
|
|
322
|
+
runtime.setTimeoutForSession(message.params.sessionId, async () => {
|
|
323
323
|
// Timeout callback - send timeout message to user
|
|
324
324
|
const elapsed = Date.now() - startTime;
|
|
325
325
|
console.log("\n" + "=".repeat(60));
|
|
326
|
-
console.log(`[TIMEOUT] Timeout triggered for session ${message.sessionId}`);
|
|
326
|
+
console.log(`[TIMEOUT] Timeout triggered for session ${message.params.sessionId}`);
|
|
327
327
|
console.log(` Elapsed: ${elapsed}ms`);
|
|
328
328
|
console.log(` Task ID: ${taskId}`);
|
|
329
329
|
console.log("=".repeat(60) + "\n");
|
|
330
330
|
const conn = runtime.getConnection();
|
|
331
331
|
if (conn) {
|
|
332
332
|
const timeoutResponse = {
|
|
333
|
-
sessionId: message.sessionId,
|
|
333
|
+
sessionId: message.params.sessionId,
|
|
334
334
|
messageId: `timeout_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
335
335
|
timestamp: Date.now(),
|
|
336
336
|
agentId: resolvedAccount.config.agentId,
|
|
@@ -346,8 +346,8 @@ exports.xiaoyiPlugin = {
|
|
|
346
346
|
status: "success",
|
|
347
347
|
};
|
|
348
348
|
try {
|
|
349
|
-
await conn.sendResponse(timeoutResponse, taskId, message.sessionId, true, false);
|
|
350
|
-
console.log(`[TIMEOUT] Timeout message sent successfully to session ${message.sessionId}\n`);
|
|
349
|
+
await conn.sendResponse(timeoutResponse, taskId, message.params.sessionId, true, false);
|
|
350
|
+
console.log(`[TIMEOUT] Timeout message sent successfully to session ${message.params.sessionId}\n`);
|
|
351
351
|
}
|
|
352
352
|
catch (error) {
|
|
353
353
|
console.error(`[TIMEOUT] Failed to send timeout message:`, error);
|
|
@@ -368,10 +368,10 @@ exports.xiaoyiPlugin = {
|
|
|
368
368
|
accumulatedText = completeText;
|
|
369
369
|
// ==================== CHECK TIMEOUT ====================
|
|
370
370
|
// If timeout already sent, discard this response
|
|
371
|
-
if (runtime.isSessionTimeout(message.sessionId)) {
|
|
371
|
+
if (runtime.isSessionTimeout(message.params.sessionId)) {
|
|
372
372
|
console.log("\n" + "=".repeat(60));
|
|
373
373
|
console.log(`[TIMEOUT] Response received AFTER timeout`);
|
|
374
|
-
console.log(` Session: ${message.sessionId}`);
|
|
374
|
+
console.log(` Session: ${message.params.sessionId}`);
|
|
375
375
|
console.log(` Elapsed: ${elapsed}ms`);
|
|
376
376
|
console.log(` Action: DISCARDING (timeout message already sent)`);
|
|
377
377
|
console.log("=".repeat(60) + "\n");
|
|
@@ -382,7 +382,7 @@ exports.xiaoyiPlugin = {
|
|
|
382
382
|
if (!completeText || completeText.length === 0) {
|
|
383
383
|
console.log("\n" + "=".repeat(60));
|
|
384
384
|
console.log(`[TIMEOUT] Empty response detected`);
|
|
385
|
-
console.log(` Session: ${message.sessionId}`);
|
|
385
|
+
console.log(` Session: ${message.params.sessionId}`);
|
|
386
386
|
console.log(` Elapsed: ${elapsed}ms`);
|
|
387
387
|
console.log(` Action: KEEPING TIMEOUT (session conflict detected)`);
|
|
388
388
|
console.log("=".repeat(60) + "\n");
|
|
@@ -397,7 +397,7 @@ exports.xiaoyiPlugin = {
|
|
|
397
397
|
console.log("-".repeat(60) + "\n");
|
|
398
398
|
// Send final response to XiaoYi
|
|
399
399
|
const response = {
|
|
400
|
-
sessionId: message.sessionId,
|
|
400
|
+
sessionId: message.params.sessionId,
|
|
401
401
|
messageId: `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
402
402
|
timestamp: Date.now(),
|
|
403
403
|
agentId: resolvedAccount.config.agentId,
|
|
@@ -414,14 +414,14 @@ exports.xiaoyiPlugin = {
|
|
|
414
414
|
};
|
|
415
415
|
const conn = runtime.getConnection();
|
|
416
416
|
if (conn) {
|
|
417
|
-
await conn.sendResponse(response, taskId, message.sessionId, true, false);
|
|
417
|
+
await conn.sendResponse(response, taskId, message.params.sessionId, true, false);
|
|
418
418
|
console.log(`✓ XiaoYi: Response sent successfully\n`);
|
|
419
419
|
}
|
|
420
420
|
else {
|
|
421
421
|
console.error(`✗ XiaoYi: Connection not available\n`);
|
|
422
422
|
}
|
|
423
423
|
// Clear timeout as response was sent successfully
|
|
424
|
-
runtime.markSessionCompleted(message.sessionId);
|
|
424
|
+
runtime.markSessionCompleted(message.params.sessionId);
|
|
425
425
|
},
|
|
426
426
|
onIdle: async () => {
|
|
427
427
|
const elapsed = Date.now() - startTime;
|
|
@@ -432,7 +432,7 @@ exports.xiaoyiPlugin = {
|
|
|
432
432
|
// Only clear timeout if we have a valid response
|
|
433
433
|
// If empty, keep timeout running to handle session conflict
|
|
434
434
|
if (accumulatedText.length > 0) {
|
|
435
|
-
runtime.markSessionCompleted(message.sessionId);
|
|
435
|
+
runtime.markSessionCompleted(message.params.sessionId);
|
|
436
436
|
console.log(`[TIMEOUT] Timeout cleared (valid response)\n`);
|
|
437
437
|
}
|
|
438
438
|
else {
|
|
@@ -448,7 +448,7 @@ exports.xiaoyiPlugin = {
|
|
|
448
448
|
catch (error) {
|
|
449
449
|
console.error("XiaoYi: [ERROR] Error dispatching message:", error);
|
|
450
450
|
// Clear timeout on error
|
|
451
|
-
runtime.clearSessionTimeout(message.sessionId);
|
|
451
|
+
runtime.clearSessionTimeout(message.params.sessionId);
|
|
452
452
|
}
|
|
453
453
|
});
|
|
454
454
|
// Setup cancel handler
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
export interface A2ARequestMessage {
|
|
2
2
|
agentId: string;
|
|
3
|
-
sessionId: string;
|
|
4
3
|
jsonrpc: "2.0";
|
|
5
4
|
id: string;
|
|
6
5
|
method: "message/stream";
|
|
7
6
|
params: {
|
|
8
7
|
id: string;
|
|
9
|
-
sessionId
|
|
8
|
+
sessionId: string;
|
|
10
9
|
agentLoginSessionId?: string;
|
|
11
10
|
message: {
|
|
12
11
|
role: "user" | "agent";
|
package/dist/websocket.js
CHANGED
|
@@ -320,9 +320,9 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
320
320
|
return;
|
|
321
321
|
}
|
|
322
322
|
// Record session → server mapping
|
|
323
|
-
if (message.sessionId) {
|
|
324
|
-
this.sessionServerMap.set(message.sessionId, sourceServer);
|
|
325
|
-
console.log(`[MAP] Session ${message.sessionId} -> ${sourceServer}`);
|
|
323
|
+
if (message.params.sessionId) {
|
|
324
|
+
this.sessionServerMap.set(message.params.sessionId, sourceServer);
|
|
325
|
+
console.log(`[MAP] Session ${message.params.sessionId} -> ${sourceServer}`);
|
|
326
326
|
}
|
|
327
327
|
// Handle special messages (clearContext, tasks/cancel)
|
|
328
328
|
if (message.method === "clearContext") {
|
|
@@ -341,7 +341,7 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
341
341
|
if (this.isA2ARequestMessage(message)) {
|
|
342
342
|
// Store task for potential cancellation
|
|
343
343
|
this.activeTasks.set(message.id, {
|
|
344
|
-
sessionId: message.sessionId,
|
|
344
|
+
sessionId: message.params.sessionId,
|
|
345
345
|
timestamp: Date.now(),
|
|
346
346
|
});
|
|
347
347
|
// Emit with server info
|
|
@@ -476,16 +476,16 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
476
476
|
* Handle clearContext method
|
|
477
477
|
*/
|
|
478
478
|
handleClearContext(message, sourceServer) {
|
|
479
|
-
console.log(`[${sourceServer}] Received clearContext for session: ${message.sessionId}`);
|
|
480
|
-
this.sendClearContextResponse(message.id, message.sessionId, true, sourceServer)
|
|
479
|
+
console.log(`[${sourceServer}] Received clearContext for session: ${message.params.sessionId}`);
|
|
480
|
+
this.sendClearContextResponse(message.id, message.params.sessionId, true, sourceServer)
|
|
481
481
|
.catch(error => console.error(`[${sourceServer}] Failed to send clearContext response:`, error));
|
|
482
482
|
this.emit("clear", {
|
|
483
|
-
sessionId: message.sessionId,
|
|
483
|
+
sessionId: message.params.sessionId,
|
|
484
484
|
id: message.id,
|
|
485
485
|
serverId: sourceServer,
|
|
486
486
|
});
|
|
487
487
|
// Remove session mapping
|
|
488
|
-
this.sessionServerMap.delete(message.sessionId);
|
|
488
|
+
this.sessionServerMap.delete(message.params.sessionId);
|
|
489
489
|
}
|
|
490
490
|
/**
|
|
491
491
|
* Handle clear message (legacy format)
|
|
@@ -770,14 +770,12 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
770
770
|
isA2ARequestMessage(data) {
|
|
771
771
|
return data &&
|
|
772
772
|
typeof data.agentId === "string" &&
|
|
773
|
-
typeof data.sessionId === "string" &&
|
|
774
773
|
data.jsonrpc === "2.0" &&
|
|
775
774
|
typeof data.id === "string" &&
|
|
776
775
|
data.method === "message/stream" &&
|
|
777
776
|
data.params &&
|
|
778
777
|
typeof data.params.id === "string" &&
|
|
779
|
-
|
|
780
|
-
(data.params.sessionId === undefined || typeof data.params.sessionId === "string") &&
|
|
778
|
+
typeof data.params.sessionId === "string" &&
|
|
781
779
|
data.params.message &&
|
|
782
780
|
typeof data.params.message.role === "string" &&
|
|
783
781
|
Array.isArray(data.params.message.parts);
|