@ynhcj/xiaoyi-channel 0.0.147-beta → 0.0.147-next
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 +26 -69
- package/dist/src/approval-bridge.d.ts +48 -0
- package/dist/src/approval-bridge.js +382 -0
- package/dist/src/bot.js +73 -69
- package/dist/src/channel.js +59 -5
- package/dist/src/client.js +13 -23
- package/dist/src/cron-command.d.ts +15 -0
- package/dist/src/cron-command.js +49 -0
- package/dist/src/cron-query-handler.d.ts +7 -0
- package/dist/src/cron-query-handler.js +188 -0
- package/dist/src/cspl/call_api.d.ts +2 -0
- package/dist/src/cspl/call_api.js +107 -0
- package/dist/src/cspl/config.d.ts +4 -17
- package/dist/src/cspl/config.js +100 -70
- package/dist/src/cspl/configs.json +10 -0
- package/dist/src/cspl/constants.d.ts +49 -24
- package/dist/src/cspl/constants.js +46 -16
- package/dist/src/cspl/sentinel_hook.d.ts +2 -0
- package/dist/src/cspl/sentinel_hook.js +98 -0
- package/dist/src/cspl/steer-context.js +1 -1
- package/dist/src/cspl/upload_file.d.ts +1 -0
- package/dist/src/cspl/upload_file.js +211 -0
- package/dist/src/cspl/utils.d.ts +11 -2
- package/dist/src/cspl/utils.js +265 -15
- package/dist/src/formatter.d.ts +13 -1
- package/dist/src/formatter.js +115 -40
- package/dist/src/monitor.js +31 -22
- package/dist/src/outbound.js +8 -9
- package/dist/src/parser.d.ts +2 -1
- package/dist/src/parser.js +55 -0
- package/dist/src/provider.js +19 -17
- package/dist/src/push.d.ts +11 -1
- package/dist/src/push.js +101 -17
- package/dist/src/reply-dispatcher.js +138 -55
- package/dist/src/self-evolution-handler.js +2 -2
- package/dist/src/sensitive-redactor.d.ts +4 -0
- package/dist/src/sensitive-redactor.js +364 -0
- package/dist/src/task-manager.js +6 -10
- package/dist/src/tools/agent-as-skill-tool.d.ts +7 -0
- package/dist/src/tools/agent-as-skill-tool.js +190 -0
- package/dist/src/tools/calendar-tool.js +3 -2
- package/dist/src/tools/call-phone-tool.js +3 -2
- package/dist/src/tools/create-alarm-tool.js +3 -2
- package/dist/src/tools/create-all-tools.js +11 -3
- package/dist/src/tools/delete-alarm-tool.js +3 -2
- package/dist/src/tools/device-tool-map.d.ts +1 -1
- package/dist/src/tools/device-tool-map.js +12 -5
- package/dist/src/tools/discover-cross-devices-tool.d.ts +2 -0
- package/dist/src/tools/discover-cross-devices-tool.js +235 -0
- package/dist/src/tools/display-a2ui-card-tool.d.ts +2 -0
- package/dist/src/tools/display-a2ui-card-tool.js +85 -0
- package/dist/src/tools/find-pc-devices-tool.d.ts +2 -1
- package/dist/src/tools/find-pc-devices-tool.js +85 -88
- package/dist/src/tools/get-collection-tool-schema.js +1 -1
- package/dist/src/tools/image-reading-tool.js +7 -6
- package/dist/src/tools/location-tool.js +3 -2
- package/dist/src/tools/modify-alarm-tool.js +3 -2
- package/dist/src/tools/modify-note-tool.js +3 -2
- package/dist/src/tools/note-tool.js +3 -2
- package/dist/src/tools/query-app-message-tool.js +4 -3
- package/dist/src/tools/query-memory-data-tool.js +4 -3
- package/dist/src/tools/query-todo-task-tool.js +4 -3
- package/dist/src/tools/save-file-to-phone-tool.js +3 -2
- package/dist/src/tools/save-media-to-gallery-tool.js +3 -2
- package/dist/src/tools/schema-tool-factory.js +1 -1
- package/dist/src/tools/search-alarm-tool.js +3 -2
- package/dist/src/tools/search-calendar-tool.js +3 -2
- package/dist/src/tools/search-contact-tool.js +3 -2
- package/dist/src/tools/search-email-tool.js +4 -3
- package/dist/src/tools/search-file-tool.js +8 -9
- package/dist/src/tools/search-message-tool.js +2 -1
- package/dist/src/tools/search-note-tool.js +3 -2
- package/dist/src/tools/search-photo-gallery-tool.js +5 -4
- package/dist/src/tools/send-cross-device-task-tool.d.ts +2 -0
- package/dist/src/tools/send-cross-device-task-tool.js +299 -0
- package/dist/src/tools/send-email-tool.js +4 -3
- package/dist/src/tools/send-file-to-user-tool.d.ts +1 -1
- package/dist/src/tools/send-file-to-user-tool.js +37 -8
- package/dist/src/tools/send-message-tool.js +2 -1
- package/dist/src/tools/session-manager.d.ts +14 -1
- package/dist/src/tools/session-manager.js +78 -0
- package/dist/src/tools/upload-file-tool.js +9 -7
- package/dist/src/tools/upload-photo-tool.js +5 -4
- package/dist/src/tools/xiaoyi-add-collection-tool.js +5 -3
- package/dist/src/tools/xiaoyi-collection-tool.js +4 -3
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +4 -3
- package/dist/src/tools/xiaoyi-gui-tool.js +7 -1
- package/dist/src/trigger-handler.js +4 -7
- package/dist/src/types.d.ts +22 -0
- package/dist/src/utils/config-manager.js +3 -6
- package/dist/src/utils/logger.d.ts +8 -0
- package/dist/src/utils/logger.js +69 -34
- package/dist/src/utils/pushdata-manager.js +1 -5
- package/dist/src/utils/pushid-manager.js +1 -2
- package/dist/src/utils/runtime-manager.js +1 -4
- package/dist/src/websocket.d.ts +3 -0
- package/dist/src/websocket.js +242 -38
- package/package.json +1 -1
|
@@ -1,11 +1,56 @@
|
|
|
1
1
|
import { getXYRuntime } from "./runtime.js";
|
|
2
|
-
import { sendA2AResponse, sendStatusUpdate, sendReasoningTextUpdate } from "./formatter.js";
|
|
2
|
+
import { sendA2AResponse, sendStatusUpdate, sendReasoningTextUpdate, sendCommand } from "./formatter.js";
|
|
3
3
|
import { resolveXYConfig } from "./config.js";
|
|
4
4
|
import { getCurrentTaskId, getCurrentMessageId } from "./task-manager.js";
|
|
5
|
+
import { clearRunCrossTaskSentFiles, getCurrentSessionContext } from "./tools/session-manager.js";
|
|
5
6
|
import fs from "fs/promises";
|
|
6
7
|
import path from "path";
|
|
7
8
|
import { logger } from "./utils/logger.js";
|
|
8
9
|
const TEMP_FILE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
10
|
+
const RUN_CROSS_TASK_LOG_TAG = "[RunCrossTask]";
|
|
11
|
+
function buildDistributionStatusCommand(context) {
|
|
12
|
+
return {
|
|
13
|
+
header: {
|
|
14
|
+
namespace: "DistributionInteraction",
|
|
15
|
+
name: "DistributionStatus",
|
|
16
|
+
},
|
|
17
|
+
payload: {
|
|
18
|
+
agentId: context.agentId,
|
|
19
|
+
isDistributed: true,
|
|
20
|
+
networkId: context.networkId,
|
|
21
|
+
distributionType: "softbus",
|
|
22
|
+
distributionExecutePolicy: "backgroundExecution",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function buildCrossTaskExecuteResultCommand(code, message, sentFiles = []) {
|
|
27
|
+
return {
|
|
28
|
+
header: {
|
|
29
|
+
namespace: "DistributionInteraction",
|
|
30
|
+
name: "CrossTaskExecuteResult",
|
|
31
|
+
},
|
|
32
|
+
payload: {
|
|
33
|
+
code,
|
|
34
|
+
message,
|
|
35
|
+
sentFiles,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async function sendRunCrossTaskResult(params) {
|
|
40
|
+
const { config, sessionId, taskId, messageId, context, resultCode, resultMessage } = params;
|
|
41
|
+
const sentFiles = Array.isArray(context.sentFiles) ? context.sentFiles : [];
|
|
42
|
+
const statusCommand = buildDistributionStatusCommand(context);
|
|
43
|
+
const resultCommand = buildCrossTaskExecuteResultCommand(resultCode, resultMessage, sentFiles);
|
|
44
|
+
await sendCommand({
|
|
45
|
+
config,
|
|
46
|
+
sessionId,
|
|
47
|
+
taskId,
|
|
48
|
+
messageId,
|
|
49
|
+
commands: [statusCommand, resultCommand],
|
|
50
|
+
});
|
|
51
|
+
clearRunCrossTaskSentFiles(context);
|
|
52
|
+
logger.log(`${RUN_CROSS_TASK_LOG_TAG} sent cross-task result, sessionId=${sessionId}, taskId=${taskId}, code=${resultCode}, sentFileCount=${sentFiles.length}, clearedSentFileCount=${sentFiles.length}, messageLength=${resultMessage.length}`);
|
|
53
|
+
}
|
|
9
54
|
/**
|
|
10
55
|
* 清理 /tmp/xy_channel 目录中超过 24 小时的旧文件
|
|
11
56
|
*/
|
|
@@ -32,11 +77,11 @@ export async function cleanupStaleTempFiles(tempDir = "/tmp/xy_channel") {
|
|
|
32
77
|
}
|
|
33
78
|
}
|
|
34
79
|
if (cleanedCount > 0) {
|
|
35
|
-
logger.log(`[CLEANUP]
|
|
80
|
+
logger.log(`[CLEANUP] Cleaned ${cleanedCount} stale files (>${TEMP_FILE_TTL_MS / 1000 / 3600}h) from ${tempDir}`);
|
|
36
81
|
}
|
|
37
82
|
}
|
|
38
83
|
catch (err) {
|
|
39
|
-
logger.error(`[CLEANUP]
|
|
84
|
+
logger.error(`[CLEANUP] Failed to cleanup temp dir:`, err);
|
|
40
85
|
}
|
|
41
86
|
}
|
|
42
87
|
/**
|
|
@@ -46,21 +91,19 @@ export async function cleanupStaleTempFiles(tempDir = "/tmp/xy_channel") {
|
|
|
46
91
|
*/
|
|
47
92
|
export function createXYReplyDispatcher(params) {
|
|
48
93
|
const { cfg, runtime, sessionId, taskId, messageId, accountId, steerState } = params;
|
|
49
|
-
logger.log(`[DISPATCHER-CREATE] ******* Creating dispatcher *******`);
|
|
50
|
-
logger.log(`[DISPATCHER-CREATE] - taskId: ${taskId}`);
|
|
51
94
|
// 初始taskId和messageId(作为fallback)
|
|
52
95
|
const initialTaskId = taskId;
|
|
53
96
|
const initialMessageId = messageId;
|
|
54
|
-
/**
|
|
55
|
-
* 🔑 核心改造:动态获取当前活跃的taskId和messageId
|
|
56
|
-
* 每次需要taskId时,都从TaskManager获取最新值
|
|
57
|
-
*/
|
|
58
97
|
const getActiveTaskId = () => {
|
|
59
98
|
return getCurrentTaskId(sessionId) ?? initialTaskId;
|
|
60
99
|
};
|
|
61
100
|
const getActiveMessageId = () => {
|
|
62
101
|
return getCurrentMessageId(sessionId) ?? initialMessageId;
|
|
63
102
|
};
|
|
103
|
+
// Create a scoped logger that always uses this session's sessionId
|
|
104
|
+
// and dynamically resolves the latest taskId
|
|
105
|
+
const scopedLog = () => logger.withContext(sessionId, getActiveTaskId());
|
|
106
|
+
scopedLog().log(`[DISPATCHER-CREATE] Creating dispatcher`);
|
|
64
107
|
const core = getXYRuntime();
|
|
65
108
|
const config = resolveXYConfig(cfg);
|
|
66
109
|
// Simplified prefix context for single-account Xiaoyi channel
|
|
@@ -73,18 +116,20 @@ export function createXYReplyDispatcher(params) {
|
|
|
73
116
|
let hasSentResponse = false;
|
|
74
117
|
let finalSent = false;
|
|
75
118
|
let accumulatedText = "";
|
|
119
|
+
const initialRunCrossTaskContext = getCurrentSessionContext()?.runCrossTaskContext;
|
|
120
|
+
const getRunCrossTaskContext = () => {
|
|
121
|
+
return getCurrentSessionContext()?.runCrossTaskContext ?? initialRunCrossTaskContext;
|
|
122
|
+
};
|
|
76
123
|
/**
|
|
77
124
|
* Start the status update interval
|
|
78
125
|
*/
|
|
79
126
|
const startStatusInterval = () => {
|
|
80
|
-
|
|
127
|
+
scopedLog().log(`[STATUS-INTERVAL] Starting interval`);
|
|
81
128
|
statusUpdateInterval = setInterval(() => {
|
|
82
129
|
// 🔑 使用动态taskId
|
|
83
130
|
const currentTaskId = getActiveTaskId();
|
|
84
131
|
const currentMessageId = getActiveMessageId();
|
|
85
|
-
|
|
86
|
-
logger.log(`[STATUS INTERVAL] - sessionId: ${sessionId}`);
|
|
87
|
-
logger.log(`[STATUS INTERVAL] - currentTaskId: ${currentTaskId}`);
|
|
132
|
+
scopedLog().log(`[STATUS-INTERVAL] Triggering status update, taskId=${currentTaskId}`);
|
|
88
133
|
void sendStatusUpdate({
|
|
89
134
|
config,
|
|
90
135
|
sessionId,
|
|
@@ -93,13 +138,13 @@ export function createXYReplyDispatcher(params) {
|
|
|
93
138
|
text: "任务正在处理中,请稍候~",
|
|
94
139
|
state: "working",
|
|
95
140
|
}).catch((err) => {
|
|
96
|
-
|
|
141
|
+
scopedLog().error(`Failed to send status update:`, err);
|
|
97
142
|
});
|
|
98
143
|
}, 30000); // 30 seconds
|
|
99
144
|
};
|
|
100
145
|
const stopStatusInterval = () => {
|
|
101
146
|
if (statusUpdateInterval) {
|
|
102
|
-
|
|
147
|
+
scopedLog().log(`[STATUS-INTERVAL] Stopping interval`);
|
|
103
148
|
clearInterval(statusUpdateInterval);
|
|
104
149
|
statusUpdateInterval = null;
|
|
105
150
|
}
|
|
@@ -110,38 +155,40 @@ export function createXYReplyDispatcher(params) {
|
|
|
110
155
|
humanDelay: core.channel.reply.resolveHumanDelayConfig(cfg, accountId),
|
|
111
156
|
onReplyStart: () => {
|
|
112
157
|
const currentTaskId = getActiveTaskId();
|
|
113
|
-
|
|
158
|
+
scopedLog().log(`[REPLY-START] Reply started, taskId=${currentTaskId}, steered=${steerState.steered}`);
|
|
114
159
|
},
|
|
115
160
|
deliver: async (payload, info) => {
|
|
116
161
|
// 🔑 steered dispatch不发送内容(让主dispatcher处理)
|
|
117
162
|
if (steerState.steered) {
|
|
118
|
-
|
|
163
|
+
scopedLog().log(`[DELIVER] Steered dispatch, skipping, kind=${info?.kind}`);
|
|
119
164
|
return;
|
|
120
165
|
}
|
|
121
166
|
const text = payload.text ?? "";
|
|
122
167
|
const currentTaskId = getActiveTaskId();
|
|
123
168
|
const currentMessageId = getActiveMessageId();
|
|
124
|
-
|
|
169
|
+
scopedLog().log(`[DELIVER] kind=${info?.kind}, text.length=${text.length}`);
|
|
125
170
|
try {
|
|
126
171
|
if (!text.trim()) {
|
|
127
|
-
|
|
172
|
+
scopedLog().log(`[DELIVER SKIP] Empty text, skipping`);
|
|
128
173
|
return;
|
|
129
174
|
}
|
|
130
175
|
accumulatedText += text;
|
|
131
176
|
hasSentResponse = true;
|
|
132
|
-
|
|
133
|
-
// 🔑 使用动态taskId发送
|
|
134
|
-
await
|
|
177
|
+
scopedLog().log(`[DELIVER] Sending text chunk via A2A response, length=${text.length}`);
|
|
178
|
+
// 🔑 使用动态taskId发送A2A响应(流式append)
|
|
179
|
+
await sendA2AResponse({
|
|
135
180
|
config,
|
|
136
181
|
sessionId,
|
|
137
182
|
taskId: currentTaskId,
|
|
138
183
|
messageId: currentMessageId,
|
|
139
184
|
text,
|
|
185
|
+
append: true,
|
|
186
|
+
final: false,
|
|
140
187
|
});
|
|
141
|
-
|
|
188
|
+
scopedLog().log(`[DELIVER] Sent deliver text as A2A response`);
|
|
142
189
|
}
|
|
143
190
|
catch (deliverError) {
|
|
144
|
-
|
|
191
|
+
scopedLog().error(`Failed to deliver message:`, deliverError);
|
|
145
192
|
}
|
|
146
193
|
},
|
|
147
194
|
onError: async (err, info) => {
|
|
@@ -149,7 +196,7 @@ export function createXYReplyDispatcher(params) {
|
|
|
149
196
|
stopStatusInterval();
|
|
150
197
|
// 🔑 steered dispatcher不发送错误状态(让主dispatcher处理)
|
|
151
198
|
if (steerState.steered) {
|
|
152
|
-
|
|
199
|
+
scopedLog().log(`[ON-ERROR] Steered dispatch, skipping error response`);
|
|
153
200
|
return;
|
|
154
201
|
}
|
|
155
202
|
if (!hasSentResponse) {
|
|
@@ -166,29 +213,36 @@ export function createXYReplyDispatcher(params) {
|
|
|
166
213
|
});
|
|
167
214
|
}
|
|
168
215
|
catch (statusError) {
|
|
169
|
-
|
|
216
|
+
scopedLog().error(`Failed to send error status:`, statusError);
|
|
170
217
|
}
|
|
171
218
|
}
|
|
172
219
|
},
|
|
173
220
|
onIdle: async () => {
|
|
174
221
|
const currentTaskId = getActiveTaskId();
|
|
175
222
|
const currentMessageId = getActiveMessageId();
|
|
176
|
-
|
|
177
|
-
logger.log(`[ON_IDLE] - sessionId: ${sessionId}`);
|
|
178
|
-
logger.log(`[ON_IDLE] - taskId: ${currentTaskId}`);
|
|
179
|
-
logger.log(`[ON_IDLE] - steered: ${steerState.steered}`);
|
|
180
|
-
logger.log(`[ON_IDLE] - hasSentResponse: ${hasSentResponse}`);
|
|
181
|
-
logger.log(`[ON_IDLE] - finalSent: ${finalSent}`);
|
|
223
|
+
scopedLog().log(`[ON-IDLE] Reply idle, steered=${steerState.steered}, hasSentResponse=${hasSentResponse}, finalSent=${finalSent}`);
|
|
182
224
|
// 🔑 steered dispatch不发送final响应(核心已注入到活跃 Pi run)
|
|
183
225
|
if (steerState.steered) {
|
|
184
|
-
|
|
226
|
+
scopedLog().log(`[ON-IDLE] Steered dispatch, skipping final response`);
|
|
185
227
|
stopStatusInterval();
|
|
186
228
|
return; // ← 直接返回,不发送任何东西!
|
|
187
229
|
}
|
|
188
230
|
// 正常模式(或未被steer的dispatch)
|
|
189
231
|
if (hasSentResponse && !finalSent) {
|
|
190
|
-
|
|
232
|
+
scopedLog().log(`[ON-IDLE] Sending accumulated text, length=${accumulatedText.length}`);
|
|
191
233
|
try {
|
|
234
|
+
const runCrossTaskContext = getRunCrossTaskContext();
|
|
235
|
+
if (runCrossTaskContext) {
|
|
236
|
+
await sendRunCrossTaskResult({
|
|
237
|
+
config,
|
|
238
|
+
sessionId,
|
|
239
|
+
taskId: currentTaskId,
|
|
240
|
+
messageId: currentMessageId,
|
|
241
|
+
context: runCrossTaskContext,
|
|
242
|
+
resultCode: "0",
|
|
243
|
+
resultMessage: accumulatedText,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
192
246
|
// 🔑 使用动态taskId发送完成状态
|
|
193
247
|
await sendStatusUpdate({
|
|
194
248
|
config,
|
|
@@ -198,28 +252,40 @@ export function createXYReplyDispatcher(params) {
|
|
|
198
252
|
text: "任务处理已完成~",
|
|
199
253
|
state: "completed",
|
|
200
254
|
});
|
|
201
|
-
|
|
202
|
-
// 🔑 使用动态taskId
|
|
255
|
+
scopedLog().log(`[ON-IDLE] Sent completion status update`);
|
|
256
|
+
// 🔑 使用动态taskId发送最终响应(空字符串表示流结束)
|
|
203
257
|
await sendA2AResponse({
|
|
204
258
|
config,
|
|
205
259
|
sessionId,
|
|
206
260
|
taskId: currentTaskId,
|
|
207
261
|
messageId: currentMessageId,
|
|
208
|
-
text:
|
|
262
|
+
text: "",
|
|
209
263
|
append: false,
|
|
210
264
|
final: true,
|
|
211
265
|
});
|
|
212
266
|
finalSent = true;
|
|
213
|
-
|
|
267
|
+
scopedLog().log(`[ON-IDLE] Sent final response (empty, stream end)`);
|
|
214
268
|
}
|
|
215
269
|
catch (err) {
|
|
216
|
-
|
|
270
|
+
scopedLog().error(`[ON-IDLE] Failed to send final response:`, err);
|
|
217
271
|
}
|
|
218
272
|
}
|
|
219
273
|
else {
|
|
220
274
|
// 正常失败场景(非steered)
|
|
221
|
-
|
|
275
|
+
scopedLog().log(`[ON-IDLE] Skipping final message: hasSentResponse=${hasSentResponse}, finalSent=${finalSent}`);
|
|
222
276
|
try {
|
|
277
|
+
const runCrossTaskContext = getRunCrossTaskContext();
|
|
278
|
+
if (runCrossTaskContext) {
|
|
279
|
+
await sendRunCrossTaskResult({
|
|
280
|
+
config,
|
|
281
|
+
sessionId,
|
|
282
|
+
taskId: currentTaskId,
|
|
283
|
+
messageId: currentMessageId,
|
|
284
|
+
context: runCrossTaskContext,
|
|
285
|
+
resultCode: "1",
|
|
286
|
+
resultMessage: "任务执行异常,请重试",
|
|
287
|
+
});
|
|
288
|
+
}
|
|
223
289
|
await sendStatusUpdate({
|
|
224
290
|
config,
|
|
225
291
|
sessionId,
|
|
@@ -228,7 +294,7 @@ export function createXYReplyDispatcher(params) {
|
|
|
228
294
|
text: "任务处理中断了~",
|
|
229
295
|
state: "failed",
|
|
230
296
|
});
|
|
231
|
-
|
|
297
|
+
scopedLog().log(`[ON-IDLE] Sent failure status update`);
|
|
232
298
|
await sendA2AResponse({
|
|
233
299
|
config,
|
|
234
300
|
sessionId,
|
|
@@ -241,23 +307,24 @@ export function createXYReplyDispatcher(params) {
|
|
|
241
307
|
errorMessage: "任务执行异常,请重试",
|
|
242
308
|
});
|
|
243
309
|
finalSent = true;
|
|
244
|
-
|
|
310
|
+
scopedLog().log(`[ON-IDLE] Sent error response, code=99921111`);
|
|
245
311
|
}
|
|
246
312
|
catch (err) {
|
|
247
|
-
|
|
313
|
+
scopedLog().error(`[ON-IDLE] Failed to send error response:`, err);
|
|
248
314
|
}
|
|
249
315
|
}
|
|
250
316
|
stopStatusInterval();
|
|
251
317
|
},
|
|
252
318
|
onCleanup: () => {
|
|
253
319
|
const currentTaskId = getActiveTaskId();
|
|
254
|
-
|
|
320
|
+
scopedLog().log(`[ON-CLEANUP] Reply cleanup, steered=${steerState.steered}`);
|
|
255
321
|
},
|
|
256
322
|
});
|
|
257
323
|
return {
|
|
258
324
|
dispatcher,
|
|
259
325
|
replyOptions: {
|
|
260
326
|
...replyOptions,
|
|
327
|
+
suppressToolErrorWarnings: true,
|
|
261
328
|
onModelSelected: prefixContext.onModelSelected,
|
|
262
329
|
onToolStart: async ({ name, phase }) => {
|
|
263
330
|
// 🔑 steered dispatch不发送tool状态(让主dispatcher处理)
|
|
@@ -266,13 +333,13 @@ export function createXYReplyDispatcher(params) {
|
|
|
266
333
|
}
|
|
267
334
|
const currentTaskId = getActiveTaskId();
|
|
268
335
|
const currentMessageId = getActiveMessageId();
|
|
269
|
-
|
|
336
|
+
scopedLog().log(`[TOOL-START] Tool: ${name}, phase: ${phase}`);
|
|
270
337
|
if (phase === "start") {
|
|
271
338
|
const toolName = name || "unknown";
|
|
272
339
|
// call_device_tool 由自身 execute() 内部发送具体子工具名的状态更新
|
|
273
340
|
// get_xxx_tool_schema 是给 LLM 查 schema 用的,无需向用户展示
|
|
274
341
|
if (toolName === "call_device_tool" || toolName.endsWith("_tool_schema") || toolName === "huawei_id_tool") {
|
|
275
|
-
|
|
342
|
+
scopedLog().log(`[TOOL-START] Skipping generic status for ${toolName}`);
|
|
276
343
|
return;
|
|
277
344
|
}
|
|
278
345
|
try {
|
|
@@ -284,10 +351,10 @@ export function createXYReplyDispatcher(params) {
|
|
|
284
351
|
text: `正在使用工具: ${toolName}...`,
|
|
285
352
|
state: "working",
|
|
286
353
|
});
|
|
287
|
-
|
|
354
|
+
scopedLog().log(`[TOOL-START] Sent status update for tool start: ${toolName}`);
|
|
288
355
|
}
|
|
289
356
|
catch (err) {
|
|
290
|
-
|
|
357
|
+
scopedLog().error(`[TOOL-START] Failed to send tool start status:`, err);
|
|
291
358
|
}
|
|
292
359
|
}
|
|
293
360
|
},
|
|
@@ -300,7 +367,7 @@ export function createXYReplyDispatcher(params) {
|
|
|
300
367
|
const currentMessageId = getActiveMessageId();
|
|
301
368
|
const text = payload.text ?? "";
|
|
302
369
|
const hasMedia = Boolean(payload.mediaUrl || (payload.mediaUrls?.length ?? 0) > 0);
|
|
303
|
-
|
|
370
|
+
scopedLog().log(`[TOOL-RESULT] Tool result, text.length: ${text.length}`);
|
|
304
371
|
try {
|
|
305
372
|
if (text.length > 0 || hasMedia) {
|
|
306
373
|
const resultText = text.length > 0 ? text : "工具执行完成";
|
|
@@ -312,11 +379,11 @@ export function createXYReplyDispatcher(params) {
|
|
|
312
379
|
text: resultText,
|
|
313
380
|
state: "working",
|
|
314
381
|
});
|
|
315
|
-
|
|
382
|
+
scopedLog().log(`[TOOL-RESULT] Sent tool result as status update`);
|
|
316
383
|
}
|
|
317
384
|
}
|
|
318
385
|
catch (err) {
|
|
319
|
-
|
|
386
|
+
scopedLog().error(`[TOOL-RESULT] Failed to send tool result status:`, err);
|
|
320
387
|
}
|
|
321
388
|
},
|
|
322
389
|
onReasoningStream: async (payload) => {
|
|
@@ -324,10 +391,26 @@ export function createXYReplyDispatcher(params) {
|
|
|
324
391
|
if (steerState.steered) {
|
|
325
392
|
return;
|
|
326
393
|
}
|
|
394
|
+
const currentTaskId = getActiveTaskId();
|
|
395
|
+
const currentMessageId = getActiveMessageId();
|
|
327
396
|
const text = payload.text ?? "";
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
397
|
+
scopedLog().log(`[REASONING-STREAM] Reasoning chunk received, text.length: ${text.length}`);
|
|
398
|
+
try {
|
|
399
|
+
if (text.length > 0) {
|
|
400
|
+
// 🔑 将模型真实的thinking/reasoning内容通过reasoningText转发
|
|
401
|
+
await sendReasoningTextUpdate({
|
|
402
|
+
config,
|
|
403
|
+
sessionId,
|
|
404
|
+
taskId: currentTaskId,
|
|
405
|
+
messageId: currentMessageId,
|
|
406
|
+
text,
|
|
407
|
+
append: true,
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
catch (err) {
|
|
412
|
+
scopedLog().error(`[REASONING-STREAM] Failed to send reasoning text:`, err);
|
|
413
|
+
}
|
|
331
414
|
},
|
|
332
415
|
onPartialReply: async (payload) => {
|
|
333
416
|
// 🔑 steered dispatch不发送partial reply(让主dispatcher处理)
|
|
@@ -350,7 +433,7 @@ export function createXYReplyDispatcher(params) {
|
|
|
350
433
|
}
|
|
351
434
|
}
|
|
352
435
|
catch (err) {
|
|
353
|
-
|
|
436
|
+
scopedLog().error(`[PARTIAL REPLY] Failed to send partial reply:`, err);
|
|
354
437
|
}
|
|
355
438
|
},
|
|
356
439
|
},
|
|
@@ -108,7 +108,7 @@ export async function handleSelfEvolutionStateGetEvent(context, cfg, runtime, ws
|
|
|
108
108
|
kind: "artifact-update",
|
|
109
109
|
append: false,
|
|
110
110
|
lastChunk: true,
|
|
111
|
-
final:
|
|
111
|
+
final: true,
|
|
112
112
|
artifact: {
|
|
113
113
|
artifactId: uuidv4(),
|
|
114
114
|
parts: [{
|
|
@@ -127,7 +127,7 @@ export async function handleSelfEvolutionStateGetEvent(context, cfg, runtime, ws
|
|
|
127
127
|
taskId,
|
|
128
128
|
msgDetail: JSON.stringify(jsonRpcResponse),
|
|
129
129
|
};
|
|
130
|
-
logger.log(`[A2A_COMMAND]
|
|
130
|
+
logger.log(`[A2A_COMMAND] Sending A2A command, taskId: ${taskId}`);
|
|
131
131
|
await wsManager.sendMessage(sessionId, outboundMessage);
|
|
132
132
|
logger.log(`[SELF_EVOLUTION_GET] command sent successfully`);
|
|
133
133
|
}
|