@ynhcj/xiaoyi-channel 0.0.58-beta → 0.0.60-beta
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/src/bot.js
CHANGED
|
@@ -9,6 +9,7 @@ import { registerSession, unregisterSession, runWithSessionContext } from "./too
|
|
|
9
9
|
import { configManager } from "./utils/config-manager.js";
|
|
10
10
|
import { addPushId } from "./utils/pushid-manager.js";
|
|
11
11
|
import { getPushDataById } from "./utils/pushdata-manager.js";
|
|
12
|
+
import { saveRuntimeInfo } from "./utils/runtime-manager.js";
|
|
12
13
|
import { registerTaskId, decrementTaskIdRef, lockTaskId, unlockTaskId, hasActiveTask, } from "./task-manager.js";
|
|
13
14
|
/**
|
|
14
15
|
* Handle an incoming A2A message.
|
|
@@ -125,6 +126,10 @@ export async function handleXYMessage(params) {
|
|
|
125
126
|
else {
|
|
126
127
|
log(`[BOT] ℹ️ No push_id found in message, will use config default`);
|
|
127
128
|
}
|
|
129
|
+
// 保存 runtime 信息到 .xiaoyiruntime 文件(异步,不阻塞主流程)
|
|
130
|
+
saveRuntimeInfo(parsed.sessionId, parsed.taskId).catch((err) => {
|
|
131
|
+
error(`[BOT] Failed to save runtime info:`, err);
|
|
132
|
+
});
|
|
128
133
|
// Resolve configuration (needed for status updates)
|
|
129
134
|
const config = resolveXYConfig(cfg);
|
|
130
135
|
// ✅ Resolve agent route (following feishu pattern)
|
package/dist/src/formatter.d.ts
CHANGED
package/dist/src/formatter.js
CHANGED
|
@@ -6,10 +6,10 @@ import { getXYRuntime } from "./runtime.js";
|
|
|
6
6
|
* Send an A2A artifact update response.
|
|
7
7
|
*/
|
|
8
8
|
export async function sendA2AResponse(params) {
|
|
9
|
-
const { config, sessionId, taskId, messageId, text, append, final, files } = params;
|
|
9
|
+
const { config, sessionId, taskId, messageId, text, append, final, files, errorCode, errorMessage } = params;
|
|
10
10
|
const runtime = getXYRuntime();
|
|
11
11
|
const log = runtime?.log ?? console.log;
|
|
12
|
-
const
|
|
12
|
+
const errorFn = runtime?.error ?? console.error;
|
|
13
13
|
// Build artifact update event
|
|
14
14
|
const artifact = {
|
|
15
15
|
taskId,
|
|
@@ -42,6 +42,14 @@ export async function sendA2AResponse(params) {
|
|
|
42
42
|
id: messageId,
|
|
43
43
|
result: artifact,
|
|
44
44
|
};
|
|
45
|
+
// 🔑 添加 error 字段(仅当提供 errorCode 时)
|
|
46
|
+
if (errorCode !== undefined) {
|
|
47
|
+
jsonRpcResponse.error = {
|
|
48
|
+
code: errorCode,
|
|
49
|
+
message: errorMessage ?? "任务执行异常,请重试",
|
|
50
|
+
};
|
|
51
|
+
log(`[A2A_RESPONSE] ⚠️ Including error code: ${errorCode}`);
|
|
52
|
+
}
|
|
45
53
|
// Send via WebSocket
|
|
46
54
|
const wsManager = getXYWebSocketManager(config);
|
|
47
55
|
const outboundMessage = {
|
|
@@ -235,9 +235,11 @@ export function createXYReplyDispatcher(params) {
|
|
|
235
235
|
text: "任务执行异常,请重试~",
|
|
236
236
|
append: false,
|
|
237
237
|
final: true,
|
|
238
|
+
errorCode: 99921111,
|
|
239
|
+
errorMessage: "任务执行异常,请重试",
|
|
238
240
|
});
|
|
239
241
|
finalSent = true;
|
|
240
|
-
log(`[ON_IDLE] ✅ Sent error response`);
|
|
242
|
+
log(`[ON_IDLE] ✅ Sent error response with code: 99921111`);
|
|
241
243
|
}
|
|
242
244
|
catch (err) {
|
|
243
245
|
error(`[ON_IDLE] Failed to send error response:`, err);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// xiaoyi runtime 持久化管理器
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { logger } from "./logger.js";
|
|
5
|
+
const RUNTIME_FILE = "/home/sandbox/.openclaw/.xiaoyiruntime";
|
|
6
|
+
/**
|
|
7
|
+
* 确保目录存在
|
|
8
|
+
*/
|
|
9
|
+
async function ensureDirectoryExists(filePath) {
|
|
10
|
+
const dir = path.dirname(filePath);
|
|
11
|
+
try {
|
|
12
|
+
await fs.mkdir(dir, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
logger.error(`[RuntimeManager] Failed to create directory ${dir}:`, error);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 保存 runtime 信息到 .xiaoyiruntime 文件
|
|
20
|
+
* @param sessionId - 会话 ID
|
|
21
|
+
* @param taskId - 任务 ID (param.id)
|
|
22
|
+
*/
|
|
23
|
+
export async function saveRuntimeInfo(sessionId, taskId) {
|
|
24
|
+
if (!sessionId || !taskId) {
|
|
25
|
+
logger.warn(`[RuntimeManager] Invalid sessionId or taskId: sessionId=${sessionId}, taskId=${taskId}`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
await ensureDirectoryExists(RUNTIME_FILE);
|
|
30
|
+
const content = `SESSION_ID=${sessionId}\nTASK_ID=${taskId}\n`;
|
|
31
|
+
await fs.writeFile(RUNTIME_FILE, content, "utf-8");
|
|
32
|
+
logger.log(`[RuntimeManager] ✅ Saved runtime info to .xiaoyiruntime`);
|
|
33
|
+
logger.log(`[RuntimeManager] - SESSION_ID: ${sessionId}`);
|
|
34
|
+
logger.log(`[RuntimeManager] - TASK_ID: ${taskId}`);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
logger.error(`[RuntimeManager] Failed to save runtime info:`, error);
|
|
38
|
+
// 不抛出异常,避免影响主流程
|
|
39
|
+
}
|
|
40
|
+
}
|