@ynhcj/xiaoyi-channel 0.0.129-beta → 0.0.129-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.
Files changed (76) hide show
  1. package/dist/index.js +36 -7
  2. package/dist/src/bot.d.ts +8 -0
  3. package/dist/src/bot.js +151 -139
  4. package/dist/src/client.d.ts +1 -5
  5. package/dist/src/client.js +25 -39
  6. package/dist/src/cspl/call-api.d.ts +6 -0
  7. package/dist/src/cspl/call-api.js +33 -13
  8. package/dist/src/cspl/config.d.ts +11 -1
  9. package/dist/src/cspl/config.js +30 -0
  10. package/dist/src/cspl/middleware.d.ts +8 -0
  11. package/dist/src/cspl/middleware.js +90 -0
  12. package/dist/src/cspl/steer-context.d.ts +21 -0
  13. package/dist/src/cspl/steer-context.js +78 -0
  14. package/dist/src/file-download.js +3 -3
  15. package/dist/src/formatter.d.ts +0 -2
  16. package/dist/src/formatter.js +12 -14
  17. package/dist/src/heartbeat.js +3 -2
  18. package/dist/src/login-token-handler.js +13 -10
  19. package/dist/src/message-queue.js +2 -1
  20. package/dist/src/monitor.js +82 -48
  21. package/dist/src/outbound.js +3 -0
  22. package/dist/src/provider.js +82 -34
  23. package/dist/src/push.js +9 -9
  24. package/dist/src/reply-dispatcher.d.ts +3 -1
  25. package/dist/src/reply-dispatcher.js +61 -68
  26. package/dist/src/self-evolution-handler.js +11 -14
  27. package/dist/src/skill-retriever/hooks.js +0 -1
  28. package/dist/src/skill-retriever/tool-search.js +7 -12
  29. package/dist/src/task-manager.d.ts +4 -27
  30. package/dist/src/task-manager.js +13 -78
  31. package/dist/src/tools/calendar-tool.js +5 -1
  32. package/dist/src/tools/call-phone-tool.js +5 -1
  33. package/dist/src/tools/create-alarm-tool.js +5 -1
  34. package/dist/src/tools/delete-alarm-tool.js +5 -1
  35. package/dist/src/tools/image-reading-tool.d.ts +1 -1
  36. package/dist/src/tools/image-reading-tool.js +38 -114
  37. package/dist/src/tools/location-tool.js +5 -1
  38. package/dist/src/tools/login-token-tool.js +13 -2
  39. package/dist/src/tools/modify-alarm-tool.js +5 -1
  40. package/dist/src/tools/modify-note-tool.js +5 -1
  41. package/dist/src/tools/note-tool.js +5 -1
  42. package/dist/src/tools/query-app-message-tool.js +5 -1
  43. package/dist/src/tools/query-memory-data-tool.js +5 -1
  44. package/dist/src/tools/query-todo-task-tool.js +5 -1
  45. package/dist/src/tools/save-file-to-phone-tool.js +5 -1
  46. package/dist/src/tools/save-media-to-gallery-tool.js +5 -1
  47. package/dist/src/tools/search-alarm-tool.js +5 -1
  48. package/dist/src/tools/search-calendar-tool.js +5 -1
  49. package/dist/src/tools/search-contact-tool.js +5 -1
  50. package/dist/src/tools/search-email-tool.js +5 -1
  51. package/dist/src/tools/search-file-tool.js +5 -1
  52. package/dist/src/tools/search-message-tool.js +5 -1
  53. package/dist/src/tools/search-note-tool.js +5 -1
  54. package/dist/src/tools/search-photo-gallery-tool.js +5 -1
  55. package/dist/src/tools/send-email-tool.js +5 -1
  56. package/dist/src/tools/send-file-to-user-tool.js +0 -1
  57. package/dist/src/tools/send-message-tool.js +5 -1
  58. package/dist/src/tools/session-helper.d.ts +24 -0
  59. package/dist/src/tools/session-helper.js +45 -0
  60. package/dist/src/tools/session-manager.d.ts +8 -0
  61. package/dist/src/tools/session-manager.js +3 -15
  62. package/dist/src/tools/upload-file-tool.js +5 -1
  63. package/dist/src/tools/upload-photo-tool.js +5 -1
  64. package/dist/src/tools/xiaoyi-add-collection-tool.js +5 -1
  65. package/dist/src/tools/xiaoyi-collection-tool.js +5 -1
  66. package/dist/src/tools/xiaoyi-delete-collection-tool.js +5 -1
  67. package/dist/src/tools/xiaoyi-gui-tool.js +3 -1
  68. package/dist/src/trigger-handler.js +8 -9
  69. package/dist/src/utils/logger.js +106 -22
  70. package/dist/src/utils/throw.d.ts +5 -0
  71. package/dist/src/utils/throw.js +10 -0
  72. package/dist/src/websocket.js +4 -2
  73. package/dist/src/xy-session-store.d.ts +79 -0
  74. package/dist/src/xy-session-store.js +153 -0
  75. package/openclaw.plugin.json +3 -0
  76. package/package.json +6 -5
package/dist/src/push.js CHANGED
@@ -85,8 +85,8 @@ export class XYPushService {
85
85
  logger.log(`[PUSH] - HTTP Status: ${response.status} ${response.statusText}`);
86
86
  if (!response.ok) {
87
87
  const errorText = await response.text();
88
- logger.log(`[PUSH] ❌ Push request failed`);
89
- logger.log(`[PUSH] - HTTP Status: ${response.status}`);
88
+ logger.error(`[PUSH] ❌ Push request failed`);
89
+ logger.error(`[PUSH] - HTTP Status: ${response.status}`);
90
90
  throw new Error(`Push failed: HTTP ${response.status} - ${errorText}`);
91
91
  }
92
92
  // Try to parse JSON response with detailed error handling
@@ -94,7 +94,7 @@ export class XYPushService {
94
94
  try {
95
95
  const responseText = await response.text();
96
96
  if (!responseText || responseText.trim() === '') {
97
- logger.log(`[PUSH] ⚠️ Received empty response body`);
97
+ logger.error(`[PUSH] ⚠️ Received empty response body`);
98
98
  result = {};
99
99
  }
100
100
  else {
@@ -102,21 +102,21 @@ export class XYPushService {
102
102
  }
103
103
  }
104
104
  catch (parseError) {
105
- logger.log(`[PUSH] ❌ Failed to parse JSON response`);
106
- logger.log(`[PUSH] - Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
105
+ logger.error(`[PUSH] ❌ Failed to parse JSON response`);
106
+ logger.error(`[PUSH] - Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
107
107
  throw new Error(`Invalid JSON response from push service: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
108
108
  }
109
109
  logger.log(`[PUSH] ✅ Push message sent successfully`);
110
110
  logger.log(`[PUSH] - Trace ID: ${traceId}`);
111
111
  }
112
112
  catch (error) {
113
- logger.log(`[PUSH] ❌ Failed to send push message`);
113
+ logger.error(`[PUSH] ❌ Failed to send push message`);
114
114
  if (error instanceof Error) {
115
- logger.log(`[PUSH] - Error name: ${error.name}`);
116
- logger.log(`[PUSH] - Error message: ${error.message}`);
115
+ logger.error(`[PUSH] - Error name: ${error.name}`);
116
+ logger.error(`[PUSH] - Error message: ${error.message}`);
117
117
  }
118
118
  else {
119
- logger.log(`[PUSH] - Error:`, error);
119
+ logger.error(`[PUSH] - Error:`, error);
120
120
  }
121
121
  throw error;
122
122
  }
@@ -6,7 +6,9 @@ export interface CreateXYReplyDispatcherParams {
6
6
  taskId: string;
7
7
  messageId: string;
8
8
  accountId: string;
9
- isSteerFollower?: boolean;
9
+ steerState: {
10
+ steered: boolean;
11
+ };
10
12
  }
11
13
  /**
12
14
  * 清理 /tmp/xy_channel 目录中超过 24 小时的旧文件
@@ -45,12 +45,9 @@ export async function cleanupStaleTempFiles(tempDir = "/tmp/xy_channel") {
45
45
  * Runtime is expected to be validated before calling this function.
46
46
  */
47
47
  export function createXYReplyDispatcher(params) {
48
- const { cfg, runtime, sessionId, taskId, messageId, accountId, isSteerFollower } = params;
49
- const log = runtime?.log ?? console.log;
50
- const error = runtime?.error ?? console.error;
51
- log(`[DISPATCHER-CREATE] ******* Creating dispatcher *******`);
52
- log(`[DISPATCHER-CREATE] - taskId: ${taskId}`);
53
- log(`[DISPATCHER-CREATE] - isSteerFollower: ${isSteerFollower ?? false}`);
48
+ const { cfg, runtime, sessionId, taskId, messageId, accountId, steerState } = params;
49
+ logger.log(`[DISPATCHER-CREATE] ******* Creating dispatcher *******`);
50
+ logger.log(`[DISPATCHER-CREATE] - taskId: ${taskId}`);
54
51
  // 初始taskId和messageId(作为fallback)
55
52
  const initialTaskId = taskId;
56
53
  const initialMessageId = messageId;
@@ -80,14 +77,14 @@ export function createXYReplyDispatcher(params) {
80
77
  * Start the status update interval
81
78
  */
82
79
  const startStatusInterval = () => {
83
- log(`[STATUS INTERVAL] Starting interval for session ${sessionId}`);
80
+ logger.log(`[STATUS INTERVAL] Starting interval for session ${sessionId}`);
84
81
  statusUpdateInterval = setInterval(() => {
85
82
  // 🔑 使用动态taskId
86
83
  const currentTaskId = getActiveTaskId();
87
84
  const currentMessageId = getActiveMessageId();
88
- log(`[STATUS INTERVAL] Triggering status update`);
89
- log(`[STATUS INTERVAL] - sessionId: ${sessionId}`);
90
- log(`[STATUS INTERVAL] - currentTaskId: ${currentTaskId}`);
85
+ logger.log(`[STATUS INTERVAL] Triggering status update`);
86
+ logger.log(`[STATUS INTERVAL] - sessionId: ${sessionId}`);
87
+ logger.log(`[STATUS INTERVAL] - currentTaskId: ${currentTaskId}`);
91
88
  void sendStatusUpdate({
92
89
  config,
93
90
  sessionId,
@@ -95,15 +92,14 @@ export function createXYReplyDispatcher(params) {
95
92
  messageId: currentMessageId, // 🔑 动态messageId
96
93
  text: "任务正在处理中,请稍候~",
97
94
  state: "working",
98
- runtime,
99
95
  }).catch((err) => {
100
- error(`Failed to send status update:`, err);
96
+ logger.error(`Failed to send status update:`, err);
101
97
  });
102
98
  }, 30000); // 30 seconds
103
99
  };
104
100
  const stopStatusInterval = () => {
105
101
  if (statusUpdateInterval) {
106
- log(`[STATUS INTERVAL] Stopping interval for session ${sessionId}`);
102
+ logger.log(`[STATUS INTERVAL] Stopping interval for session ${sessionId}`);
107
103
  clearInterval(statusUpdateInterval);
108
104
  statusUpdateInterval = null;
109
105
  }
@@ -114,21 +110,26 @@ export function createXYReplyDispatcher(params) {
114
110
  humanDelay: core.channel.reply.resolveHumanDelayConfig(cfg, accountId),
115
111
  onReplyStart: () => {
116
112
  const currentTaskId = getActiveTaskId();
117
- log(`[REPLY START] Reply started for session ${sessionId}, taskId=${currentTaskId}, isSteerFollower=${isSteerFollower}`);
113
+ logger.log(`[REPLY START] Reply started for session ${sessionId}, taskId=${currentTaskId}, steered=${steerState.steered}`);
118
114
  },
119
115
  deliver: async (payload, info) => {
116
+ // 🔑 steered dispatch不发送内容(让主dispatcher处理)
117
+ if (steerState.steered) {
118
+ logger.log(`[DELIVER] Steered dispatch - skipping deliver, info.kind=${info?.kind}`);
119
+ return;
120
+ }
120
121
  const text = payload.text ?? "";
121
122
  const currentTaskId = getActiveTaskId();
122
123
  const currentMessageId = getActiveMessageId();
123
- log(`[DELIVER] sessionId=${sessionId}, taskId=${currentTaskId}, info.kind=${info?.kind}, text.length=${text.length}`);
124
+ logger.log(`[DELIVER] sessionId=${sessionId}, taskId=${currentTaskId}, info.kind=${info?.kind}, text.length=${text.length}`);
124
125
  try {
125
126
  if (!text.trim()) {
126
- log(`[DELIVER SKIP] Empty text, skipping`);
127
+ logger.log(`[DELIVER SKIP] Empty text, skipping`);
127
128
  return;
128
129
  }
129
130
  accumulatedText += text;
130
131
  hasSentResponse = true;
131
- log(`[DELIVER ACCUMULATE] Accumulated text, current length=${accumulatedText.length}`);
132
+ logger.log(`[DELIVER ACCUMULATE] Accumulated text, current length=${accumulatedText.length}`);
132
133
  // 🔑 使用动态taskId发送reasoningText更新
133
134
  await sendReasoningTextUpdate({
134
135
  config,
@@ -137,18 +138,18 @@ export function createXYReplyDispatcher(params) {
137
138
  messageId: currentMessageId,
138
139
  text,
139
140
  });
140
- log(`[DELIVER] ✅ Sent deliver text as reasoningText update`);
141
+ logger.log(`[DELIVER] ✅ Sent deliver text as reasoningText update`);
141
142
  }
142
143
  catch (deliverError) {
143
- error(`Failed to deliver message:`, deliverError);
144
+ logger.error(`Failed to deliver message:`, deliverError);
144
145
  }
145
146
  },
146
147
  onError: async (err, info) => {
147
148
  runtime.error?.(`xy: ${info.kind} reply failed: ${String(err)}`);
148
149
  stopStatusInterval();
149
- // 🔑 steer follower不发送错误状态(让主dispatcher处理)
150
- if (isSteerFollower) {
151
- log(`[ON_ERROR] Steer follower - skipping error response`);
150
+ // 🔑 steered dispatcher不发送错误状态(让主dispatcher处理)
151
+ if (steerState.steered) {
152
+ logger.log(`[ON_ERROR] Steered dispatch - skipping error response`);
152
153
  return;
153
154
  }
154
155
  if (!hasSentResponse) {
@@ -162,33 +163,31 @@ export function createXYReplyDispatcher(params) {
162
163
  messageId: currentMessageId,
163
164
  text: "处理失败,请稍后重试",
164
165
  state: "failed",
165
- runtime,
166
166
  });
167
167
  }
168
168
  catch (statusError) {
169
- error(`Failed to send error status:`, statusError);
169
+ logger.error(`Failed to send error status:`, statusError);
170
170
  }
171
171
  }
172
172
  },
173
173
  onIdle: async () => {
174
174
  const currentTaskId = getActiveTaskId();
175
175
  const currentMessageId = getActiveMessageId();
176
- log(`[ON_IDLE] Reply idle`);
177
- log(`[ON_IDLE] - sessionId: ${sessionId}`);
178
- log(`[ON_IDLE] - taskId: ${currentTaskId}`);
179
- log(`[ON_IDLE] - isSteerFollower: ${isSteerFollower}`);
180
- log(`[ON_IDLE] - hasSentResponse: ${hasSentResponse}`);
181
- log(`[ON_IDLE] - finalSent: ${finalSent}`);
182
- // 🔑 核心改动:steer follower不发送final响应
183
- if (isSteerFollower) {
184
- log(`[ON_IDLE] Steer follower - skipping final response`);
185
- log(`[ON_IDLE] - Message queued successfully, waiting for primary dispatcher`);
176
+ logger.log(`[ON_IDLE] Reply idle`);
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}`);
182
+ // 🔑 steered dispatch不发送final响应(核心已注入到活跃 Pi run)
183
+ if (steerState.steered) {
184
+ logger.log(`[ON_IDLE] Steered dispatch - skipping final response`);
186
185
  stopStatusInterval();
187
186
  return; // ← 直接返回,不发送任何东西!
188
187
  }
189
- // 正常模式(或steer的第一条消息)
188
+ // 正常模式(或未被steer的dispatch)
190
189
  if (hasSentResponse && !finalSent) {
191
- log(`[ON_IDLE] Sending accumulated text, length=${accumulatedText.length}`);
190
+ logger.log(`[ON_IDLE] Sending accumulated text, length=${accumulatedText.length}`);
192
191
  try {
193
192
  // 🔑 使用动态taskId发送完成状态
194
193
  await sendStatusUpdate({
@@ -198,9 +197,8 @@ export function createXYReplyDispatcher(params) {
198
197
  messageId: currentMessageId,
199
198
  text: "任务处理已完成~",
200
199
  state: "completed",
201
- runtime,
202
200
  });
203
- log(`[ON_IDLE] ✅ Sent completion status update`);
201
+ logger.log(`[ON_IDLE] ✅ Sent completion status update`);
204
202
  // 🔑 使用动态taskId发送最终响应
205
203
  await sendA2AResponse({
206
204
  config,
@@ -210,18 +208,17 @@ export function createXYReplyDispatcher(params) {
210
208
  text: accumulatedText,
211
209
  append: false,
212
210
  final: true,
213
- runtime,
214
211
  });
215
212
  finalSent = true;
216
- log(`[ON_IDLE] ✅ Sent final response with taskId=${currentTaskId}`);
213
+ logger.log(`[ON_IDLE] ✅ Sent final response with taskId=${currentTaskId}`);
217
214
  }
218
215
  catch (err) {
219
- error(`[ON_IDLE] Failed to send final response:`, err);
216
+ logger.error(`[ON_IDLE] Failed to send final response:`, err);
220
217
  }
221
218
  }
222
219
  else {
223
- // 正常失败场景(非steer follower)
224
- log(`[ON_IDLE] Skipping final message: hasSentResponse=${hasSentResponse}, finalSent=${finalSent}`);
220
+ // 正常失败场景(非steered)
221
+ logger.log(`[ON_IDLE] Skipping final message: hasSentResponse=${hasSentResponse}, finalSent=${finalSent}`);
225
222
  try {
226
223
  await sendStatusUpdate({
227
224
  config,
@@ -230,9 +227,8 @@ export function createXYReplyDispatcher(params) {
230
227
  messageId: currentMessageId,
231
228
  text: "任务处理中断了~",
232
229
  state: "failed",
233
- runtime,
234
230
  });
235
- log(`[ON_IDLE] ✅ Sent failure status update`);
231
+ logger.log(`[ON_IDLE] ✅ Sent failure status update`);
236
232
  await sendA2AResponse({
237
233
  config,
238
234
  sessionId,
@@ -243,20 +239,19 @@ export function createXYReplyDispatcher(params) {
243
239
  final: true,
244
240
  errorCode: 99921111,
245
241
  errorMessage: "任务执行异常,请重试",
246
- runtime,
247
242
  });
248
243
  finalSent = true;
249
- log(`[ON_IDLE] ✅ Sent error response with code: 99921111`);
244
+ logger.log(`[ON_IDLE] ✅ Sent error response with code: 99921111`);
250
245
  }
251
246
  catch (err) {
252
- error(`[ON_IDLE] Failed to send error response:`, err);
247
+ logger.error(`[ON_IDLE] Failed to send error response:`, err);
253
248
  }
254
249
  }
255
250
  stopStatusInterval();
256
251
  },
257
252
  onCleanup: () => {
258
253
  const currentTaskId = getActiveTaskId();
259
- log(`[ON_CLEANUP] Reply cleanup, taskId=${currentTaskId}, isSteerFollower=${isSteerFollower}`);
254
+ logger.log(`[ON_CLEANUP] Reply cleanup, taskId=${currentTaskId}, steered=${steerState.steered}`);
260
255
  },
261
256
  });
262
257
  return {
@@ -265,19 +260,19 @@ export function createXYReplyDispatcher(params) {
265
260
  ...replyOptions,
266
261
  onModelSelected: prefixContext.onModelSelected,
267
262
  onToolStart: async ({ name, phase }) => {
268
- // 🔑 steer follower不发送tool状态(让主dispatcher处理)
269
- if (isSteerFollower) {
263
+ // 🔑 steered dispatch不发送tool状态(让主dispatcher处理)
264
+ if (steerState.steered) {
270
265
  return;
271
266
  }
272
267
  const currentTaskId = getActiveTaskId();
273
268
  const currentMessageId = getActiveMessageId();
274
- log(`[TOOL START] Tool: ${name}, phase: ${phase}, taskId: ${currentTaskId}`);
269
+ logger.log(`[TOOL START] Tool: ${name}, phase: ${phase}, taskId: ${currentTaskId}`);
275
270
  if (phase === "start") {
276
271
  const toolName = name || "unknown";
277
272
  // call_device_tool 由自身 execute() 内部发送具体子工具名的状态更新
278
273
  // get_xxx_tool_schema 是给 LLM 查 schema 用的,无需向用户展示
279
274
  if (toolName === "call_device_tool" || toolName.endsWith("_tool_schema") || toolName === "huawei_id_tool") {
280
- log(`[TOOL START] Skipping generic status for ${toolName}`);
275
+ logger.log(`[TOOL START] Skipping generic status for ${toolName}`);
281
276
  return;
282
277
  }
283
278
  try {
@@ -288,25 +283,24 @@ export function createXYReplyDispatcher(params) {
288
283
  messageId: currentMessageId,
289
284
  text: `正在使用工具: ${toolName}...`,
290
285
  state: "working",
291
- runtime,
292
286
  });
293
- log(`[TOOL START] ✅ Sent status update for tool start: ${toolName}`);
287
+ logger.log(`[TOOL START] ✅ Sent status update for tool start: ${toolName}`);
294
288
  }
295
289
  catch (err) {
296
- error(`[TOOL START] ❌ Failed to send tool start status:`, err);
290
+ logger.error(`[TOOL START] ❌ Failed to send tool start status:`, err);
297
291
  }
298
292
  }
299
293
  },
300
294
  onToolResult: async (payload) => {
301
- // 🔑 steer follower不发送tool结果(让主dispatcher处理)
302
- if (isSteerFollower) {
295
+ // 🔑 steered dispatch不发送tool结果(让主dispatcher处理)
296
+ if (steerState.steered) {
303
297
  return;
304
298
  }
305
299
  const currentTaskId = getActiveTaskId();
306
300
  const currentMessageId = getActiveMessageId();
307
301
  const text = payload.text ?? "";
308
302
  const hasMedia = Boolean(payload.mediaUrl || (payload.mediaUrls?.length ?? 0) > 0);
309
- log(`[TOOL RESULT] Tool result, taskId: ${currentTaskId}, text.length: ${text.length}`);
303
+ logger.log(`[TOOL RESULT] Tool result, taskId: ${currentTaskId}, text.length: ${text.length}`);
310
304
  try {
311
305
  if (text.length > 0 || hasMedia) {
312
306
  const resultText = text.length > 0 ? text : "工具执行完成";
@@ -317,28 +311,27 @@ export function createXYReplyDispatcher(params) {
317
311
  messageId: currentMessageId,
318
312
  text: resultText,
319
313
  state: "working",
320
- runtime,
321
314
  });
322
- log(`[TOOL RESULT] ✅ Sent tool result as status update`);
315
+ logger.log(`[TOOL RESULT] ✅ Sent tool result as status update`);
323
316
  }
324
317
  }
325
318
  catch (err) {
326
- error(`[TOOL RESULT] ❌ Failed to send tool result status:`, err);
319
+ logger.error(`[TOOL RESULT] ❌ Failed to send tool result status:`, err);
327
320
  }
328
321
  },
329
322
  onReasoningStream: async (payload) => {
330
- // 🔑 steer follower不发送reasoning stream
331
- if (isSteerFollower) {
323
+ // 🔑 steered dispatch不发送reasoning stream
324
+ if (steerState.steered) {
332
325
  return;
333
326
  }
334
327
  const text = payload.text ?? "";
335
- log(`[REASONING STREAM] Reasoning chunk received, text.length: ${text.length}`);
328
+ logger.log(`[REASONING STREAM] Reasoning chunk received, text.length: ${text.length}`);
336
329
  // Reasoning stream 目前被注释掉
337
330
  // 如果需要可以启用
338
331
  },
339
332
  onPartialReply: async (payload) => {
340
- // 🔑 steer follower不发送partial reply(让主dispatcher处理)
341
- if (isSteerFollower) {
333
+ // 🔑 steered dispatch不发送partial reply(让主dispatcher处理)
334
+ if (steerState.steered) {
342
335
  return;
343
336
  }
344
337
  const currentTaskId = getActiveTaskId();
@@ -357,7 +350,7 @@ export function createXYReplyDispatcher(params) {
357
350
  }
358
351
  }
359
352
  catch (err) {
360
- error(`[PARTIAL REPLY] ❌ Failed to send partial reply:`, err);
353
+ logger.error(`[PARTIAL REPLY] ❌ Failed to send partial reply:`, err);
361
354
  }
362
355
  },
363
356
  },
@@ -1,25 +1,24 @@
1
1
  import { readFileSync, writeFileSync } from "fs";
2
2
  import { v4 as uuidv4 } from "uuid";
3
+ import { logger } from "./utils/logger.js";
3
4
  const XIAOYIRUNTIME_PATH = "/home/sandbox/.openclaw/.xiaoyiruntime";
4
5
  export function handleSelfEvolutionEvent(context, runtime) {
5
- const log = runtime?.log ?? console.log;
6
- const error = runtime?.error ?? console.error;
7
6
  try {
8
7
  const state = context.event?.payload?.selfEvolutionState;
9
8
  if (typeof state !== "string") {
10
- error("[SELF_EVOLUTION] invalid payload: missing selfEvolutionState");
9
+ logger.error("[SELF_EVOLUTION] invalid payload: missing selfEvolutionState");
11
10
  return;
12
11
  }
13
- log(`[SELF_EVOLUTION] received state: ${state}`);
12
+ logger.log(`[SELF_EVOLUTION] received state: ${state}`);
14
13
  let content;
15
14
  try {
16
15
  content = readFileSync(XIAOYIRUNTIME_PATH, "utf-8");
17
16
  }
18
17
  catch {
19
18
  // File doesn't exist yet — create it
20
- log(`[SELF_EVOLUTION] ${XIAOYIRUNTIME_PATH} not found, creating new file`);
19
+ logger.log(`[SELF_EVOLUTION] ${XIAOYIRUNTIME_PATH} not found, creating new file`);
21
20
  writeFileSync(XIAOYIRUNTIME_PATH, `selfEvolutionState=${state}\n`, "utf-8");
22
- log(`[SELF_EVOLUTION] wrote selfEvolutionState=${state}`);
21
+ logger.log(`[SELF_EVOLUTION] wrote selfEvolutionState=${state}`);
23
22
  return;
24
23
  }
25
24
  const lines = content.split("\n");
@@ -40,10 +39,10 @@ export function handleSelfEvolutionEvent(context, runtime) {
40
39
  else {
41
40
  writeFileSync(XIAOYIRUNTIME_PATH, updated.join("\n"), "utf-8");
42
41
  }
43
- log(`[SELF_EVOLUTION] updated selfEvolutionState=${state} in ${XIAOYIRUNTIME_PATH}`);
42
+ logger.log(`[SELF_EVOLUTION] updated selfEvolutionState=${state} in ${XIAOYIRUNTIME_PATH}`);
44
43
  }
45
44
  catch (err) {
46
- error("[SELF_EVOLUTION] failed to handle event:", err);
45
+ logger.error("[SELF_EVOLUTION] failed to handle event:", err);
47
46
  }
48
47
  }
49
48
  /**
@@ -51,8 +50,6 @@ export function handleSelfEvolutionEvent(context, runtime) {
51
50
  * 参考trigger实现:直接使用当前已连接的 wsManager 发送消息,避免 getXYWebSocketManager 返回未连接实例
52
51
  */
53
52
  export async function handleSelfEvolutionStateGetEvent(context, cfg, runtime, wsManager) {
54
- const log = runtime?.log ?? console.log;
55
- const error = runtime?.error ?? console.error;
56
53
  try {
57
54
  const { sessionId, taskId } = context;
58
55
  const messageId = context.messageId ?? uuidv4();
@@ -71,7 +68,7 @@ export async function handleSelfEvolutionStateGetEvent(context, cfg, runtime, ws
71
68
  catch {
72
69
  // 文件不存在,使用默认值 false
73
70
  }
74
- log(`[SELF_EVOLUTION_GET] read selfEvolutionState=${state}, sending command back`);
71
+ logger.log(`[SELF_EVOLUTION_GET] read selfEvolutionState=${state}, sending command back`);
75
72
  const command = {
76
73
  header: {
77
74
  namespace: "Common",
@@ -130,11 +127,11 @@ export async function handleSelfEvolutionStateGetEvent(context, cfg, runtime, ws
130
127
  taskId,
131
128
  msgDetail: JSON.stringify(jsonRpcResponse),
132
129
  };
133
- log(`[A2A_COMMAND] 📤 Sending A2A command: taskId: ${taskId}`);
130
+ logger.log(`[A2A_COMMAND] 📤 Sending A2A command: taskId: ${taskId}`);
134
131
  await wsManager.sendMessage(sessionId, outboundMessage);
135
- log(`[SELF_EVOLUTION_GET] command sent successfully`);
132
+ logger.log(`[SELF_EVOLUTION_GET] command sent successfully`);
136
133
  }
137
134
  catch (err) {
138
- error("[SELF_EVOLUTION_GET] failed to handle event:", err);
135
+ logger.error("[SELF_EVOLUTION_GET] failed to handle event:", err);
139
136
  }
140
137
  }
@@ -5,7 +5,6 @@ const TOOL_RETRIEVER_HEADER = `[系统消息,非用户发言]
5
5
  `;
6
6
  const TOOL_RETRIEVER_FOOTER = `
7
7
  以上是检索到的、与当前用户请求相关但用户尚未安装的skill,请按照TOOLS.md中find-skills中的[隐式推荐触发规则]来判断是否要给用户推荐。
8
- ---以下是用户原始请求---
9
8
  `;
10
9
  const PLUGIN_LOG_PREFIX = "[skill-retriever]";
11
10
  const SKIP_KEYWORDS = ["安装", "装一下", "下载", "查询", "查找", "install", "卸载", "删除", "重载", "定时任务", "重装", "进化"];
@@ -123,21 +123,16 @@ export async function searchTools(options) {
123
123
  const rawSkills = responseData.content.skills;
124
124
  const installedSkills = getInstalledSkills();
125
125
  const formattedData = formatSkillData(rawSkills, installedSkills);
126
- const topTools = formattedData.slice(0, 2);
127
- const allInstalled = topTools.every((tool) => tool.status === "已安装");
128
- if (allInstalled) {
129
- logger.log(`${PLUGIN_LOG_PREFIX} [DEBUG] All top 2 skills are installed, returning null`);
126
+ const candidateTools = formattedData.filter((tool) => (tool.rrfScore ?? 0) >= 0.016);
127
+ logger.log(`${PLUGIN_LOG_PREFIX} [DEBUG] Candidates with rrfScore >= 0.016: ${candidateTools.length}, details: ${candidateTools.map((t) => `${t.skillId}(rrfScore=${t.rrfScore}, status=${t.status})`).join(", ")}`);
128
+ const hasInstalledInCandidates = candidateTools.some((tool) => tool.status === "已安装");
129
+ if (hasInstalledInCandidates) {
130
+ logger.log(`${PLUGIN_LOG_PREFIX} [DEBUG] Candidates contain installed skill, returning null`);
130
131
  return null;
131
132
  }
132
- const hasInstalledWithHighScore = topTools.some((tool) => tool.status === "已安装" && (tool.rrfScore ?? 0) >= 0.016);
133
- if (hasInstalledWithHighScore) {
134
- logger.log(`${PLUGIN_LOG_PREFIX} [DEBUG] Top 2 has installed skill with rrfScore >= 0.016, returning null`);
135
- return null;
136
- }
137
- let filteredTools = topTools.filter((tool) => tool.status === "未安装" && (tool.rrfScore ?? 0) >= 0.016);
138
- logger.log(`${PLUGIN_LOG_PREFIX} [DEBUG] After filtering uninstalled with rrfScore >= 0.016: ${filteredTools.length}, details: ${filteredTools.map((t) => `${t.skillId}(rrfScore=${t.rrfScore})`).join(", ")}`);
133
+ const filteredTools = candidateTools.slice(0, 2);
139
134
  if (filteredTools.length === 0) {
140
- logger.log(`${PLUGIN_LOG_PREFIX} [DEBUG] No uninstalled skills with rrfScore >= 0.016, returning null`);
135
+ logger.log(`${PLUGIN_LOG_PREFIX} [DEBUG] No candidates with rrfScore >= 0.016, returning null`);
141
136
  return null;
142
137
  }
143
138
  return {
@@ -2,36 +2,17 @@ interface TaskIdBinding {
2
2
  sessionId: string;
3
3
  currentTaskId: string;
4
4
  currentMessageId: string;
5
- refCount: number;
6
5
  updatedAt: number;
7
- locked: boolean;
8
6
  }
9
7
  /**
10
- * 注册或更新session的活跃taskId
11
- * 返回是否是更新(用于判断是否是第二条消息)
8
+ * 注册或更新session的活跃taskId。
9
+ * Returns true if this was an update (session already had an active task).
12
10
  */
13
- export declare function registerTaskId(sessionId: string, taskId: string, messageId: string, options?: {
14
- incrementRef?: boolean;
15
- }): {
16
- isUpdate: boolean;
17
- refCount: number;
18
- };
11
+ export declare function registerTaskId(sessionId: string, taskId: string, messageId: string): boolean;
19
12
  /**
20
- * 增加引用计数(消息开始处理时调用)
21
- */
22
- export declare function incrementTaskIdRef(sessionId: string): void;
23
- /**
24
- * 减少引用计数,当refCount=0时才真正清理
13
+ * 移除session的活跃taskId(消息处理完成时调用)。
25
14
  */
26
15
  export declare function decrementTaskIdRef(sessionId: string): void;
27
- /**
28
- * 锁定taskId,防止被清理(第一个消息使用)
29
- */
30
- export declare function lockTaskId(sessionId: string): void;
31
- /**
32
- * 解锁taskId(第一个消息完成时使用)
33
- */
34
- export declare function unlockTaskId(sessionId: string): void;
35
16
  /**
36
17
  * 获取session的当前活跃taskId
37
18
  */
@@ -44,10 +25,6 @@ export declare function getCurrentMessageId(sessionId: string): string | null;
44
25
  * 检查session是否有活跃的taskId
45
26
  */
46
27
  export declare function hasActiveTask(sessionId: string): boolean;
47
- /**
48
- * 获取完整的binding信息(用于调试)
49
- */
50
- export declare function getTaskIdBinding(sessionId: string): TaskIdBinding | null;
51
28
  /**
52
29
  * 获取所有活跃的 task bindings(用于 gateway_stop 通知等场景)
53
30
  */