@ynhcj/xiaoyi-channel 0.0.203-beta → 0.0.205-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/index.js +3 -3
- package/dist/src/bot.js +52 -34
- package/dist/src/channel.js +68 -64
- package/dist/src/client.d.ts +5 -0
- package/dist/src/client.js +10 -0
- package/dist/src/cspl/call_api.js +2 -0
- package/dist/src/cspl/sentinel_hook.js +9 -8
- package/dist/src/formatter.js +21 -31
- package/dist/src/monitor.js +20 -9
- package/dist/src/outbound.js +5 -0
- package/dist/src/provider.js +49 -14
- package/dist/src/reply-dispatcher.d.ts +3 -0
- package/dist/src/reply-dispatcher.js +152 -159
- package/dist/src/self-evolution-handler.js +2 -1
- package/dist/src/task-manager.d.ts +5 -6
- package/dist/src/task-manager.js +5 -9
- package/dist/src/tools/agent-as-skill-tool.d.ts +41 -2
- package/dist/src/tools/agent-as-skill-tool.js +144 -146
- package/dist/src/tools/calendar-tool.d.ts +24 -2
- package/dist/src/tools/calendar-tool.js +115 -117
- package/dist/src/tools/call-device-tool.d.ts +20 -6
- package/dist/src/tools/call-device-tool.js +116 -138
- package/dist/src/tools/call-phone-tool.d.ts +21 -2
- package/dist/src/tools/call-phone-tool.js +112 -114
- package/dist/src/tools/check-plugin-privilege-tool.d.ts +16 -2
- package/dist/src/tools/check-plugin-privilege-tool.js +141 -143
- package/dist/src/tools/create-alarm-tool.d.ts +39 -2
- package/dist/src/tools/create-alarm-tool.js +229 -231
- package/dist/src/tools/delete-alarm-tool.d.ts +15 -2
- package/dist/src/tools/delete-alarm-tool.js +134 -136
- package/dist/src/tools/device-tool-map.js +3 -1
- package/dist/src/tools/discover-cross-devices-tool.d.ts +16 -2
- package/dist/src/tools/discover-cross-devices-tool.js +121 -124
- package/dist/src/tools/display-a2ui-card-bypath-tool.d.ts +21 -2
- package/dist/src/tools/display-a2ui-card-bypath-tool.js +53 -56
- package/dist/src/tools/get-alarm-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-alarm-tool-schema.js +10 -16
- package/dist/src/tools/get-calendar-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-calendar-tool-schema.js +8 -12
- package/dist/src/tools/get-collection-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-collection-tool-schema.js +9 -11
- package/dist/src/tools/get-contact-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-contact-tool-schema.js +10 -16
- package/dist/src/tools/get-device-file-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-device-file-tool-schema.js +9 -13
- package/dist/src/tools/get-email-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-email-tool-schema.js +8 -11
- package/dist/src/tools/get-note-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-note-tool-schema.js +9 -14
- package/dist/src/tools/get-photo-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-photo-tool-schema.js +9 -12
- package/dist/src/tools/image-reading-tool.d.ts +28 -2
- package/dist/src/tools/image-reading-tool.js +76 -76
- package/dist/src/tools/location-tool.d.ts +11 -2
- package/dist/src/tools/location-tool.js +93 -92
- package/dist/src/tools/login-token-tool.d.ts +20 -2
- package/dist/src/tools/login-token-tool.js +123 -125
- package/dist/src/tools/modify-alarm-tool.d.ts +47 -2
- package/dist/src/tools/modify-alarm-tool.js +250 -252
- package/dist/src/tools/modify-note-tool.d.ts +20 -2
- package/dist/src/tools/modify-note-tool.js +107 -109
- package/dist/src/tools/note-tool.d.ts +20 -2
- package/dist/src/tools/note-tool.js +106 -108
- package/dist/src/tools/query-app-message-tool.d.ts +28 -2
- package/dist/src/tools/query-app-message-tool.js +111 -113
- package/dist/src/tools/query-memory-data-tool.d.ts +28 -2
- package/dist/src/tools/query-memory-data-tool.js +112 -114
- package/dist/src/tools/query-todo-task-tool.d.ts +24 -2
- package/dist/src/tools/query-todo-task-tool.js +106 -108
- package/dist/src/tools/save-file-to-phone-tool.d.ts +24 -2
- package/dist/src/tools/save-file-to-phone-tool.js +130 -132
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +24 -2
- package/dist/src/tools/save-media-to-gallery-tool.js +137 -139
- package/dist/src/tools/save-self-evolution-skill-tool.d.ts +54 -2
- package/dist/src/tools/save-self-evolution-skill-tool.js +194 -194
- package/dist/src/tools/search-alarm-tool.d.ts +34 -2
- package/dist/src/tools/search-alarm-tool.js +174 -176
- package/dist/src/tools/search-calendar-tool.d.ts +24 -2
- package/dist/src/tools/search-calendar-tool.js +148 -150
- package/dist/src/tools/search-contact-tool.d.ts +16 -2
- package/dist/src/tools/search-contact-tool.js +101 -103
- package/dist/src/tools/search-email-tool.d.ts +21 -2
- package/dist/src/tools/search-email-tool.js +110 -112
- package/dist/src/tools/search-file-tool.d.ts +16 -2
- package/dist/src/tools/search-file-tool.js +104 -106
- package/dist/src/tools/search-message-tool.d.ts +16 -2
- package/dist/src/tools/search-message-tool.js +103 -105
- package/dist/src/tools/search-note-tool.d.ts +16 -2
- package/dist/src/tools/search-note-tool.js +98 -100
- package/dist/src/tools/search-photo-gallery-tool.d.ts +21 -2
- package/dist/src/tools/search-photo-gallery-tool.js +35 -37
- package/dist/src/tools/send-cross-device-task-tool.d.ts +35 -2
- package/dist/src/tools/send-cross-device-task-tool.js +140 -143
- package/dist/src/tools/send-email-tool.d.ts +24 -2
- package/dist/src/tools/send-email-tool.js +108 -110
- package/dist/src/tools/send-file-to-user-tool.d.ts +20 -2
- package/dist/src/tools/send-file-to-user-tool.js +174 -176
- package/dist/src/tools/send-html-card-tool.d.ts +20 -2
- package/dist/src/tools/send-html-card-tool.js +85 -87
- package/dist/src/tools/send-message-tool.d.ts +20 -2
- package/dist/src/tools/send-message-tool.js +122 -124
- package/dist/src/tools/session-manager.d.ts +7 -50
- package/dist/src/tools/session-manager.js +40 -231
- package/dist/src/tools/upload-file-tool.d.ts +20 -2
- package/dist/src/tools/upload-file-tool.js +80 -82
- package/dist/src/tools/upload-photo-tool.d.ts +20 -2
- package/dist/src/tools/upload-photo-tool.js +68 -70
- package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +32 -2
- package/dist/src/tools/xiaoyi-add-collection-tool.js +146 -148
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +20 -2
- package/dist/src/tools/xiaoyi-collection-tool.js +114 -116
- package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +15 -2
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +127 -129
- package/dist/src/tools/xiaoyi-gui-tool.d.ts +16 -2
- package/dist/src/tools/xiaoyi-gui-tool.js +92 -95
- package/dist/src/utils/logger.js +3 -14
- package/dist/src/websocket.d.ts +1 -1
- package/package.json +2 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { getXYRuntime } from "./runtime.js";
|
|
2
2
|
import { sendA2AResponse, sendStatusUpdate, sendReasoningTextUpdate, sendCommand } from "./formatter.js";
|
|
3
3
|
import { resolveXYConfig } from "./config.js";
|
|
4
|
-
import { getCurrentTaskId, getCurrentMessageId } from "./task-manager.js";
|
|
5
4
|
import { clearRunCrossTaskSentFiles, getCurrentSessionContext } from "./tools/session-manager.js";
|
|
6
5
|
import fs from "fs/promises";
|
|
7
6
|
import path from "path";
|
|
8
7
|
import { logger } from "./utils/logger.js";
|
|
8
|
+
import { getCurrentTaskId, getCurrentMessageId } from "./task-manager.js";
|
|
9
9
|
const TEMP_FILE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
10
10
|
const RUN_CROSS_TASK_LOG_TAG = "[RunCrossTask]";
|
|
11
11
|
function buildDistributionStatusCommand(context) {
|
|
@@ -96,15 +96,23 @@ export async function cleanupStaleTempFiles(tempDir = "/tmp/xy_channel") {
|
|
|
96
96
|
* Runtime is expected to be validated before calling this function.
|
|
97
97
|
*/
|
|
98
98
|
export function createXYReplyDispatcher(params) {
|
|
99
|
-
const { cfg, runtime, sessionId, taskId, messageId, accountId, steerState } = params;
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
const { cfg, runtime, sessionId, taskId, messageId, accountId, steerState, onIdleComplete } = params;
|
|
100
|
+
// fallback taskId/messageId(当 task-manager 返回 null 时使用)
|
|
101
|
+
// steer 触发时会通过 updateFallbackTaskId() 更新为最新的 taskId
|
|
102
|
+
let currentFallbackTaskId = taskId;
|
|
103
|
+
let currentFallbackMessageId = messageId;
|
|
104
|
+
// 跨链读取:steer 消息通过 registerTaskId 更新 Map,这里读取最新 taskId
|
|
103
105
|
const getActiveTaskId = () => {
|
|
104
|
-
return getCurrentTaskId(sessionId) ??
|
|
106
|
+
return getCurrentTaskId(sessionId) ?? currentFallbackTaskId;
|
|
105
107
|
};
|
|
106
108
|
const getActiveMessageId = () => {
|
|
107
|
-
return getCurrentMessageId(sessionId) ??
|
|
109
|
+
return getCurrentMessageId(sessionId) ?? currentFallbackMessageId;
|
|
110
|
+
};
|
|
111
|
+
/** steer 触发时调用,同步 fallback taskId/messageId 到最新值 */
|
|
112
|
+
const updateFallbackTaskId = (newTaskId, newMessageId) => {
|
|
113
|
+
currentFallbackTaskId = newTaskId;
|
|
114
|
+
currentFallbackMessageId = newMessageId;
|
|
115
|
+
logger.log(`[DISPATCHER-UPDATE] Updated fallback taskId: ${newTaskId}`);
|
|
108
116
|
};
|
|
109
117
|
// Create a scoped logger that always uses this session's sessionId
|
|
110
118
|
// and dynamically resolves the latest taskId
|
|
@@ -135,13 +143,12 @@ export function createXYReplyDispatcher(params) {
|
|
|
135
143
|
statusUpdateInterval = setInterval(() => {
|
|
136
144
|
// 🔑 使用动态taskId
|
|
137
145
|
const currentTaskId = getActiveTaskId();
|
|
138
|
-
const currentMessageId = getActiveMessageId();
|
|
139
146
|
scopedLog().log(`[STATUS-INTERVAL] Triggering status update, taskId=${currentTaskId}`);
|
|
140
147
|
void sendStatusUpdate({
|
|
141
148
|
config,
|
|
142
149
|
sessionId,
|
|
143
|
-
taskId: currentTaskId,
|
|
144
|
-
messageId:
|
|
150
|
+
taskId: currentTaskId,
|
|
151
|
+
messageId: getActiveMessageId(),
|
|
145
152
|
text: "任务正在处理中,请稍候~",
|
|
146
153
|
state: "working",
|
|
147
154
|
}).catch((err) => {
|
|
@@ -161,18 +168,10 @@ export function createXYReplyDispatcher(params) {
|
|
|
161
168
|
responsePrefixContextProvider: prefixContext.responsePrefixContextProvider,
|
|
162
169
|
humanDelay: core.channel.reply.resolveHumanDelayConfig(cfg, accountId),
|
|
163
170
|
onReplyStart: () => {
|
|
164
|
-
|
|
165
|
-
scopedLog().log(`[REPLY-START] Reply started, taskId=${currentTaskId}, steered=${steerState.steered}`);
|
|
171
|
+
scopedLog().log(`[REPLY-START] Reply started, taskId=${taskId}, steered=${steerState.steered}`);
|
|
166
172
|
},
|
|
167
173
|
deliver: async (payload, info) => {
|
|
168
|
-
// 🔑 steered dispatch不发送内容(让主dispatcher处理)
|
|
169
|
-
if (steerState.steered) {
|
|
170
|
-
scopedLog().log(`[DELIVER] Steered dispatch, skipping, kind=${info?.kind}`);
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
174
|
const text = payload.text ?? "";
|
|
174
|
-
const currentTaskId = getActiveTaskId();
|
|
175
|
-
const currentMessageId = getActiveMessageId();
|
|
176
175
|
scopedLog().log(`[DELIVER] kind=${info?.kind}, text.length=${text.length}`);
|
|
177
176
|
try {
|
|
178
177
|
if (!text.trim()) {
|
|
@@ -194,8 +193,8 @@ export function createXYReplyDispatcher(params) {
|
|
|
194
193
|
await sendA2AResponse({
|
|
195
194
|
config,
|
|
196
195
|
sessionId,
|
|
197
|
-
taskId:
|
|
198
|
-
messageId:
|
|
196
|
+
taskId: getActiveTaskId(),
|
|
197
|
+
messageId: getActiveMessageId(),
|
|
199
198
|
text,
|
|
200
199
|
append: true,
|
|
201
200
|
final: false,
|
|
@@ -208,20 +207,13 @@ export function createXYReplyDispatcher(params) {
|
|
|
208
207
|
onError: async (err, info) => {
|
|
209
208
|
runtime.error?.(`xy: ${info.kind} reply failed: ${String(err)}`);
|
|
210
209
|
stopStatusInterval();
|
|
211
|
-
// 🔑 steered dispatcher不发送错误状态(让主dispatcher处理)
|
|
212
|
-
if (steerState.steered) {
|
|
213
|
-
scopedLog().log(`[ON-ERROR] Steered dispatch, skipping error response`);
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
210
|
if (!hasSentResponse) {
|
|
217
|
-
const currentTaskId = getActiveTaskId();
|
|
218
|
-
const currentMessageId = getActiveMessageId();
|
|
219
211
|
try {
|
|
220
212
|
await sendStatusUpdate({
|
|
221
213
|
config,
|
|
222
214
|
sessionId,
|
|
223
|
-
taskId:
|
|
224
|
-
messageId:
|
|
215
|
+
taskId: getActiveTaskId(),
|
|
216
|
+
messageId: getActiveMessageId(),
|
|
225
217
|
text: "处理失败,请稍后重试",
|
|
226
218
|
state: "failed",
|
|
227
219
|
});
|
|
@@ -232,109 +224,119 @@ export function createXYReplyDispatcher(params) {
|
|
|
232
224
|
}
|
|
233
225
|
},
|
|
234
226
|
onIdle: async () => {
|
|
235
|
-
const currentTaskId = getActiveTaskId();
|
|
236
|
-
const currentMessageId = getActiveMessageId();
|
|
237
227
|
scopedLog().log(`[ON-IDLE] Reply idle, steered=${steerState.steered}, hasSentResponse=${hasSentResponse}, finalSent=${finalSent}`);
|
|
238
|
-
// 🔑 steered dispatch
|
|
239
|
-
|
|
240
|
-
|
|
228
|
+
// 🔑 steered dispatch without response — steer was injected into active run,
|
|
229
|
+
// no reply generated. Skip final response without sending error.
|
|
230
|
+
if (steerState.steered && !hasSentResponse) {
|
|
231
|
+
scopedLog().log(`[ON-IDLE] Steered dispatch, no response generated, skipping`);
|
|
241
232
|
stopStatusInterval();
|
|
242
|
-
return;
|
|
233
|
+
return;
|
|
243
234
|
}
|
|
244
|
-
//
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
235
|
+
// 🔑 用 try/finally 确保 cleanup 在 onIdle 的 async 工作全部完成后才执行。
|
|
236
|
+
// openclaw 的 waitForIdle() 以 void options.onIdle?.() 调用 onIdle,
|
|
237
|
+
// 不会 await 返回的 Promise,因此 onSettled 可能在 onIdle 中途触发。
|
|
238
|
+
// 所有清理逻辑必须放在 finally 块中,不要依赖 onSettled。
|
|
239
|
+
try {
|
|
240
|
+
// 正常模式(或未被steer的dispatch)
|
|
241
|
+
if (hasSentResponse && !finalSent) {
|
|
242
|
+
const trimmedFinalReplyText = finalReplyText.trim();
|
|
243
|
+
const trimmedAccumulatedText = accumulatedText.trim();
|
|
244
|
+
const crossTaskResultMessage = trimmedFinalReplyText || trimmedAccumulatedText;
|
|
245
|
+
const crossTaskResultSource = trimmedFinalReplyText ? "final" : "accumulated";
|
|
246
|
+
scopedLog().log(`[ON-IDLE] [SendCrossResult]Sending cross-task result, source=${crossTaskResultSource}, resultMessage.length=${crossTaskResultMessage.length}`);
|
|
247
|
+
try {
|
|
248
|
+
const runCrossTaskContext = getRunCrossTaskContext();
|
|
249
|
+
if (runCrossTaskContext) {
|
|
250
|
+
await sendRunCrossTaskResult({
|
|
251
|
+
config,
|
|
252
|
+
sessionId,
|
|
253
|
+
taskId: getActiveTaskId(),
|
|
254
|
+
messageId: getActiveMessageId(),
|
|
255
|
+
context: runCrossTaskContext,
|
|
256
|
+
resultCode: "0",
|
|
257
|
+
resultMessage: crossTaskResultMessage,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
// 🔑 使用动态taskId发送完成状态
|
|
261
|
+
await sendStatusUpdate({
|
|
255
262
|
config,
|
|
256
263
|
sessionId,
|
|
257
|
-
taskId:
|
|
258
|
-
messageId:
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
resultMessage: crossTaskResultMessage,
|
|
264
|
+
taskId: getActiveTaskId(),
|
|
265
|
+
messageId: getActiveMessageId(),
|
|
266
|
+
text: "任务处理已完成~",
|
|
267
|
+
state: "completed",
|
|
262
268
|
});
|
|
269
|
+
scopedLog().log(`[ON-IDLE] Sent completion status update`);
|
|
270
|
+
// 🔑 使用动态taskId发送最终响应(空字符串表示流结束)
|
|
271
|
+
await sendA2AResponse({
|
|
272
|
+
config,
|
|
273
|
+
sessionId,
|
|
274
|
+
taskId: getActiveTaskId(),
|
|
275
|
+
messageId: getActiveMessageId(),
|
|
276
|
+
text: "",
|
|
277
|
+
append: true,
|
|
278
|
+
final: true,
|
|
279
|
+
});
|
|
280
|
+
finalSent = true;
|
|
281
|
+
scopedLog().log(`[ON-IDLE] Sent final response (empty, stream end)`);
|
|
282
|
+
}
|
|
283
|
+
catch (err) {
|
|
284
|
+
scopedLog().error(`[ON-IDLE] Failed to send final response:`, err);
|
|
263
285
|
}
|
|
264
|
-
// 🔑 使用动态taskId发送完成状态
|
|
265
|
-
await sendStatusUpdate({
|
|
266
|
-
config,
|
|
267
|
-
sessionId,
|
|
268
|
-
taskId: currentTaskId,
|
|
269
|
-
messageId: currentMessageId,
|
|
270
|
-
text: "任务处理已完成~",
|
|
271
|
-
state: "completed",
|
|
272
|
-
});
|
|
273
|
-
scopedLog().log(`[ON-IDLE] Sent completion status update`);
|
|
274
|
-
// 🔑 使用动态taskId发送最终响应(空字符串表示流结束)
|
|
275
|
-
await sendA2AResponse({
|
|
276
|
-
config,
|
|
277
|
-
sessionId,
|
|
278
|
-
taskId: currentTaskId,
|
|
279
|
-
messageId: currentMessageId,
|
|
280
|
-
text: "",
|
|
281
|
-
append: true,
|
|
282
|
-
final: true,
|
|
283
|
-
});
|
|
284
|
-
finalSent = true;
|
|
285
|
-
scopedLog().log(`[ON-IDLE] Sent final response (empty, stream end)`);
|
|
286
|
-
}
|
|
287
|
-
catch (err) {
|
|
288
|
-
scopedLog().error(`[ON-IDLE] Failed to send final response:`, err);
|
|
289
286
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
287
|
+
else {
|
|
288
|
+
// 正常失败场景(非steered)
|
|
289
|
+
scopedLog().log(`[ON-IDLE] Skipping final message: hasSentResponse=${hasSentResponse}, finalSent=${finalSent}`);
|
|
290
|
+
try {
|
|
291
|
+
const runCrossTaskContext = getRunCrossTaskContext();
|
|
292
|
+
if (runCrossTaskContext) {
|
|
293
|
+
await sendRunCrossTaskResult({
|
|
294
|
+
config,
|
|
295
|
+
sessionId,
|
|
296
|
+
taskId: getActiveTaskId(),
|
|
297
|
+
messageId: getActiveMessageId(),
|
|
298
|
+
context: runCrossTaskContext,
|
|
299
|
+
resultCode: "1",
|
|
300
|
+
resultMessage: "任务执行异常,请重试",
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
await sendStatusUpdate({
|
|
304
|
+
config,
|
|
305
|
+
sessionId,
|
|
306
|
+
taskId: getActiveTaskId(),
|
|
307
|
+
messageId: getActiveMessageId(),
|
|
308
|
+
text: "任务处理中断了~",
|
|
309
|
+
state: "failed",
|
|
310
|
+
});
|
|
311
|
+
scopedLog().log(`[ON-IDLE] Sent failure status update`);
|
|
312
|
+
await sendA2AResponse({
|
|
298
313
|
config,
|
|
299
314
|
sessionId,
|
|
300
|
-
taskId:
|
|
301
|
-
messageId:
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
315
|
+
taskId: getActiveTaskId(),
|
|
316
|
+
messageId: getActiveMessageId(),
|
|
317
|
+
text: "任务执行异常,请重试~",
|
|
318
|
+
append: true,
|
|
319
|
+
final: true,
|
|
320
|
+
errorCode: 99921111,
|
|
321
|
+
errorMessage: "任务执行异常,请重试",
|
|
305
322
|
});
|
|
323
|
+
finalSent = true;
|
|
324
|
+
scopedLog().log(`[ON-IDLE] Sent error response, code=99921111`);
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
scopedLog().error(`[ON-IDLE] Failed to send error response:`, err);
|
|
306
328
|
}
|
|
307
|
-
await sendStatusUpdate({
|
|
308
|
-
config,
|
|
309
|
-
sessionId,
|
|
310
|
-
taskId: currentTaskId,
|
|
311
|
-
messageId: currentMessageId,
|
|
312
|
-
text: "任务处理中断了~",
|
|
313
|
-
state: "failed",
|
|
314
|
-
});
|
|
315
|
-
scopedLog().log(`[ON-IDLE] Sent failure status update`);
|
|
316
|
-
await sendA2AResponse({
|
|
317
|
-
config,
|
|
318
|
-
sessionId,
|
|
319
|
-
taskId: currentTaskId,
|
|
320
|
-
messageId: currentMessageId,
|
|
321
|
-
text: "任务执行异常,请重试~",
|
|
322
|
-
append: true,
|
|
323
|
-
final: true,
|
|
324
|
-
errorCode: 99921111,
|
|
325
|
-
errorMessage: "任务执行异常,请重试",
|
|
326
|
-
});
|
|
327
|
-
finalSent = true;
|
|
328
|
-
scopedLog().log(`[ON-IDLE] Sent error response, code=99921111`);
|
|
329
|
-
}
|
|
330
|
-
catch (err) {
|
|
331
|
-
scopedLog().error(`[ON-IDLE] Failed to send error response:`, err);
|
|
332
329
|
}
|
|
333
330
|
}
|
|
334
|
-
|
|
331
|
+
finally {
|
|
332
|
+
stopStatusInterval();
|
|
333
|
+
// 🔑 清理必须在 onIdle 内部完成,因为 openclaw 的 waitForIdle() 不会
|
|
334
|
+
// await onIdle 返回的 Promise(源码中为 void options.onIdle?.()),
|
|
335
|
+
// 导致 onSettled 在 onIdle 的 async 工作完成之前就执行。
|
|
336
|
+
await onIdleComplete?.();
|
|
337
|
+
}
|
|
335
338
|
},
|
|
336
339
|
onCleanup: () => {
|
|
337
|
-
const currentTaskId = getActiveTaskId();
|
|
338
340
|
scopedLog().log(`[ON-CLEANUP] Reply cleanup, steered=${steerState.steered}`);
|
|
339
341
|
},
|
|
340
342
|
});
|
|
@@ -345,12 +347,6 @@ export function createXYReplyDispatcher(params) {
|
|
|
345
347
|
suppressToolErrorWarnings: true,
|
|
346
348
|
onModelSelected: prefixContext.onModelSelected,
|
|
347
349
|
onToolStart: async ({ name, phase }) => {
|
|
348
|
-
// 🔑 steered dispatch不发送tool状态(让主dispatcher处理)
|
|
349
|
-
if (steerState.steered) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const currentTaskId = getActiveTaskId();
|
|
353
|
-
const currentMessageId = getActiveMessageId();
|
|
354
350
|
scopedLog().log(`[TOOL-START] Tool: ${name}, phase: ${phase}`);
|
|
355
351
|
if (phase === "start") {
|
|
356
352
|
const toolName = name || "unknown";
|
|
@@ -364,8 +360,8 @@ export function createXYReplyDispatcher(params) {
|
|
|
364
360
|
await sendStatusUpdate({
|
|
365
361
|
config,
|
|
366
362
|
sessionId,
|
|
367
|
-
taskId:
|
|
368
|
-
messageId:
|
|
363
|
+
taskId: getActiveTaskId(),
|
|
364
|
+
messageId: getActiveMessageId(),
|
|
369
365
|
text: `正在使用工具: ${toolName}...`,
|
|
370
366
|
state: "working",
|
|
371
367
|
});
|
|
@@ -377,12 +373,6 @@ export function createXYReplyDispatcher(params) {
|
|
|
377
373
|
}
|
|
378
374
|
},
|
|
379
375
|
onToolResult: async (payload) => {
|
|
380
|
-
// 🔑 steered dispatch不发送tool结果(让主dispatcher处理)
|
|
381
|
-
if (steerState.steered) {
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
const currentTaskId = getActiveTaskId();
|
|
385
|
-
const currentMessageId = getActiveMessageId();
|
|
386
376
|
const text = payload.text ?? "";
|
|
387
377
|
const hasMedia = Boolean(payload.mediaUrl || (payload.mediaUrls?.length ?? 0) > 0);
|
|
388
378
|
scopedLog().log(`[TOOL-RESULT] Tool result, text.length: ${text.length}`);
|
|
@@ -392,8 +382,8 @@ export function createXYReplyDispatcher(params) {
|
|
|
392
382
|
await sendStatusUpdate({
|
|
393
383
|
config,
|
|
394
384
|
sessionId,
|
|
395
|
-
taskId:
|
|
396
|
-
messageId:
|
|
385
|
+
taskId: getActiveTaskId(),
|
|
386
|
+
messageId: getActiveMessageId(),
|
|
397
387
|
text: resultText,
|
|
398
388
|
state: "working",
|
|
399
389
|
});
|
|
@@ -405,12 +395,6 @@ export function createXYReplyDispatcher(params) {
|
|
|
405
395
|
}
|
|
406
396
|
},
|
|
407
397
|
onReasoningStream: async (payload) => {
|
|
408
|
-
// 🔑 steered dispatch不发送reasoning stream
|
|
409
|
-
if (steerState.steered) {
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
const currentTaskId = getActiveTaskId();
|
|
413
|
-
const currentMessageId = getActiveMessageId();
|
|
414
398
|
let text = payload.text ?? "";
|
|
415
399
|
// Strip "Reasoning:" prefix that some reasoning models add to their thinking output
|
|
416
400
|
const lines = text.split(/\r?\n/);
|
|
@@ -422,8 +406,8 @@ export function createXYReplyDispatcher(params) {
|
|
|
422
406
|
await sendReasoningTextUpdate({
|
|
423
407
|
config,
|
|
424
408
|
sessionId,
|
|
425
|
-
taskId:
|
|
426
|
-
messageId:
|
|
409
|
+
taskId: getActiveTaskId(),
|
|
410
|
+
messageId: getActiveMessageId(),
|
|
427
411
|
text,
|
|
428
412
|
append: false,
|
|
429
413
|
});
|
|
@@ -434,27 +418,35 @@ export function createXYReplyDispatcher(params) {
|
|
|
434
418
|
}
|
|
435
419
|
},
|
|
436
420
|
onPartialReply: async (payload) => {
|
|
437
|
-
|
|
438
|
-
if (steerState.steered) {
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
const currentTaskId = getActiveTaskId();
|
|
442
|
-
const currentMessageId = getActiveMessageId();
|
|
443
|
-
const text = payload.text ?? "";
|
|
421
|
+
let text = payload.text ?? "";
|
|
444
422
|
try {
|
|
445
423
|
if (text.length > 0) {
|
|
446
|
-
|
|
424
|
+
// 模型可能返回完整文本(非纯增量),如果新文本以已累积内容开头,
|
|
425
|
+
// 则只取新增的后缀部分,避免 append 模式下重复拼接。
|
|
426
|
+
let sendText = text;
|
|
427
|
+
const dedupApplied = accumulatedText.length > 0 && text.startsWith(accumulatedText);
|
|
428
|
+
if (dedupApplied) {
|
|
429
|
+
sendText = text.slice(accumulatedText.length);
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
// 新文本不以已累积内容为前缀(如工具调用后模型重新开始生成),
|
|
433
|
+
// 更新 accumulatedText 为当前文本,后续基于此新前缀做去重
|
|
434
|
+
accumulatedText = "";
|
|
435
|
+
}
|
|
436
|
+
accumulatedText += sendText;
|
|
447
437
|
hasSentResponse = true;
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
438
|
+
if (sendText.length > 0) {
|
|
439
|
+
await sendA2AResponse({
|
|
440
|
+
config,
|
|
441
|
+
sessionId,
|
|
442
|
+
taskId: getActiveTaskId(),
|
|
443
|
+
messageId: getActiveMessageId(),
|
|
444
|
+
text: sendText,
|
|
445
|
+
append: true,
|
|
446
|
+
final: false,
|
|
447
|
+
log: false,
|
|
448
|
+
});
|
|
449
|
+
}
|
|
458
450
|
}
|
|
459
451
|
}
|
|
460
452
|
catch (err) {
|
|
@@ -465,5 +457,6 @@ export function createXYReplyDispatcher(params) {
|
|
|
465
457
|
markDispatchIdle,
|
|
466
458
|
startStatusInterval,
|
|
467
459
|
stopStatusInterval,
|
|
460
|
+
updateFallbackTaskId,
|
|
468
461
|
};
|
|
469
462
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import os from "os";
|
|
1
2
|
import { readFileSync, writeFileSync } from "fs";
|
|
2
3
|
import { v4 as uuidv4 } from "uuid";
|
|
3
4
|
import { resolveXYConfig } from "./config.js";
|
|
@@ -136,7 +137,7 @@ export async function handleSelfEvolutionStateGetEvent(context, cfg, runtime, ws
|
|
|
136
137
|
agentId: cfg.agentId,
|
|
137
138
|
sessionId,
|
|
138
139
|
taskId,
|
|
139
|
-
msgDetail: JSON.stringify(jsonRpcResponse),
|
|
140
|
+
msgDetail: JSON.stringify({ ...jsonRpcResponse, hostname: os.hostname() }),
|
|
140
141
|
};
|
|
141
142
|
logger.log(`[A2A_COMMAND] Sending A2A command, taskId: ${taskId}`);
|
|
142
143
|
await wsManager.sendMessage(sessionId, outboundMessage);
|
|
@@ -14,11 +14,14 @@ export declare function registerTaskId(sessionId: string, taskId: string, messag
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function decrementTaskIdRef(sessionId: string): void;
|
|
16
16
|
/**
|
|
17
|
-
* 获取session的当前活跃taskId
|
|
17
|
+
* 获取session的当前活跃taskId。
|
|
18
|
+
* 仅供 reply-dispatcher 跨链读取 steer 更新后的 taskId。
|
|
19
|
+
* 工具和 sendCommand 应使用 ALS SessionContext.taskId。
|
|
18
20
|
*/
|
|
19
21
|
export declare function getCurrentTaskId(sessionId: string): string | null;
|
|
20
22
|
/**
|
|
21
|
-
* 获取session的当前活跃messageId
|
|
23
|
+
* 获取session的当前活跃messageId。
|
|
24
|
+
* 仅供 reply-dispatcher 跨链读取 steer 更新后的 messageId。
|
|
22
25
|
*/
|
|
23
26
|
export declare function getCurrentMessageId(sessionId: string): string | null;
|
|
24
27
|
/**
|
|
@@ -29,8 +32,4 @@ export declare function hasActiveTask(sessionId: string): boolean;
|
|
|
29
32
|
* 获取所有活跃的 task bindings(用于 gateway_stop 通知等场景)
|
|
30
33
|
*/
|
|
31
34
|
export declare function getAllActiveTaskBindings(): TaskIdBinding[];
|
|
32
|
-
/**
|
|
33
|
-
* 强制清理(错误恢复用)
|
|
34
|
-
*/
|
|
35
|
-
export declare function forceCleanTaskId(sessionId: string): void;
|
|
36
35
|
export {};
|
package/dist/src/task-manager.js
CHANGED
|
@@ -44,14 +44,17 @@ export function decrementTaskIdRef(sessionId) {
|
|
|
44
44
|
activeTaskIds.delete(sessionId);
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
* 获取session的当前活跃taskId
|
|
47
|
+
* 获取session的当前活跃taskId。
|
|
48
|
+
* 仅供 reply-dispatcher 跨链读取 steer 更新后的 taskId。
|
|
49
|
+
* 工具和 sendCommand 应使用 ALS SessionContext.taskId。
|
|
48
50
|
*/
|
|
49
51
|
export function getCurrentTaskId(sessionId) {
|
|
50
52
|
const binding = activeTaskIds.get(sessionId);
|
|
51
53
|
return binding?.currentTaskId ?? null;
|
|
52
54
|
}
|
|
53
55
|
/**
|
|
54
|
-
* 获取session的当前活跃messageId
|
|
56
|
+
* 获取session的当前活跃messageId。
|
|
57
|
+
* 仅供 reply-dispatcher 跨链读取 steer 更新后的 messageId。
|
|
55
58
|
*/
|
|
56
59
|
export function getCurrentMessageId(sessionId) {
|
|
57
60
|
const binding = activeTaskIds.get(sessionId);
|
|
@@ -69,10 +72,3 @@ export function hasActiveTask(sessionId) {
|
|
|
69
72
|
export function getAllActiveTaskBindings() {
|
|
70
73
|
return Array.from(activeTaskIds.values());
|
|
71
74
|
}
|
|
72
|
-
/**
|
|
73
|
-
* 强制清理(错误恢复用)
|
|
74
|
-
*/
|
|
75
|
-
export function forceCleanTaskId(sessionId) {
|
|
76
|
-
logger.log(`[TASK_MANAGER] Force clearing taskId`);
|
|
77
|
-
activeTaskIds.delete(sessionId);
|
|
78
|
-
}
|
|
@@ -1,7 +1,46 @@
|
|
|
1
|
-
import type { SessionContext } from "./session-manager.js";
|
|
2
1
|
/**
|
|
3
2
|
* Agent-as-skill tool - invokes a registered agent by agentId as a skill.
|
|
4
3
|
* The tool receives the agentId, query, and optional file attachments,
|
|
5
4
|
* forwards the request to the target agent via WebSocket, and returns the result.
|
|
6
5
|
*/
|
|
7
|
-
export declare
|
|
6
|
+
export declare const agentAsSkillTool: {
|
|
7
|
+
name: string;
|
|
8
|
+
label: string;
|
|
9
|
+
description: string;
|
|
10
|
+
parameters: {
|
|
11
|
+
type: string;
|
|
12
|
+
properties: {
|
|
13
|
+
agentId: {
|
|
14
|
+
type: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
query: {
|
|
18
|
+
type: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
filesInfo: {
|
|
22
|
+
description: string;
|
|
23
|
+
items: {
|
|
24
|
+
type: string;
|
|
25
|
+
properties: {
|
|
26
|
+
fileType: {
|
|
27
|
+
type: string;
|
|
28
|
+
description: string;
|
|
29
|
+
enum: string[];
|
|
30
|
+
};
|
|
31
|
+
fileId: {
|
|
32
|
+
type: string;
|
|
33
|
+
description: string;
|
|
34
|
+
};
|
|
35
|
+
fileUrl: {
|
|
36
|
+
type: string;
|
|
37
|
+
description: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
required: string[];
|
|
44
|
+
};
|
|
45
|
+
execute(toolCallId: string, params: any): Promise<unknown>;
|
|
46
|
+
};
|