@ynhcj/xiaoyi-channel 0.0.134-beta → 0.0.136-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 +6 -40
- package/dist/src/bot.js +27 -37
- package/dist/src/cspl/call-api.d.ts +6 -0
- package/dist/src/cspl/call-api.js +48 -0
- package/dist/src/cspl/config.d.ts +11 -1
- package/dist/src/cspl/config.js +30 -0
- package/dist/src/cspl/middleware.d.ts +8 -0
- package/dist/src/cspl/middleware.js +87 -0
- package/dist/src/login-token-handler.js +8 -4
- package/dist/src/reply-dispatcher.d.ts +3 -1
- package/dist/src/reply-dispatcher.js +25 -22
- package/dist/src/task-manager.d.ts +4 -27
- package/dist/src/task-manager.js +13 -78
- package/dist/src/tools/calendar-tool.js +5 -1
- package/dist/src/tools/call-phone-tool.js +5 -1
- package/dist/src/tools/create-alarm-tool.js +5 -1
- package/dist/src/tools/delete-alarm-tool.js +5 -1
- package/dist/src/tools/location-tool.js +5 -1
- package/dist/src/tools/login-token-tool.js +13 -2
- package/dist/src/tools/modify-alarm-tool.js +5 -1
- package/dist/src/tools/modify-note-tool.js +5 -1
- package/dist/src/tools/note-tool.js +5 -1
- package/dist/src/tools/query-app-message-tool.js +5 -1
- package/dist/src/tools/query-memory-data-tool.js +5 -1
- package/dist/src/tools/query-todo-task-tool.js +5 -1
- package/dist/src/tools/save-file-to-phone-tool.js +5 -1
- package/dist/src/tools/save-media-to-gallery-tool.js +5 -1
- package/dist/src/tools/search-alarm-tool.js +5 -1
- package/dist/src/tools/search-calendar-tool.js +5 -1
- package/dist/src/tools/search-contact-tool.js +5 -1
- package/dist/src/tools/search-email-tool.js +5 -1
- package/dist/src/tools/search-file-tool.js +5 -1
- package/dist/src/tools/search-message-tool.js +5 -1
- package/dist/src/tools/search-note-tool.js +5 -1
- package/dist/src/tools/search-photo-gallery-tool.js +5 -1
- package/dist/src/tools/send-email-tool.js +5 -1
- package/dist/src/tools/send-message-tool.js +5 -1
- package/dist/src/tools/upload-file-tool.js +5 -1
- package/dist/src/tools/upload-photo-tool.js +5 -1
- package/dist/src/tools/xiaoyi-add-collection-tool.js +5 -1
- package/dist/src/tools/xiaoyi-collection-tool.js +5 -1
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +5 -1
- package/dist/src/tools/xiaoyi-gui-tool.js +3 -1
- package/openclaw.plugin.json +3 -0
- package/package.json +1 -1
package/dist/src/task-manager.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// TaskId Manager - 管理session级别的活跃taskId
|
|
2
|
-
//
|
|
2
|
+
// 用于 monitor.ts 检测活跃任务(决定是否并发执行steer消息)
|
|
3
3
|
import { logger } from "./utils/logger.js";
|
|
4
4
|
/**
|
|
5
5
|
* Session到活跃TaskId的映射
|
|
6
|
-
* Key: sessionId
|
|
6
|
+
* Key: sessionId
|
|
7
7
|
* Value: TaskIdBinding
|
|
8
8
|
* Uses globalThis to ensure a single Map across all module copies.
|
|
9
9
|
*/
|
|
@@ -13,98 +13,39 @@ if (!_g.__xyActiveTaskIds) {
|
|
|
13
13
|
}
|
|
14
14
|
const activeTaskIds = _g.__xyActiveTaskIds;
|
|
15
15
|
/**
|
|
16
|
-
* 注册或更新session的活跃taskId
|
|
17
|
-
*
|
|
16
|
+
* 注册或更新session的活跃taskId。
|
|
17
|
+
* Returns true if this was an update (session already had an active task).
|
|
18
18
|
*/
|
|
19
|
-
export function registerTaskId(sessionId, taskId, messageId
|
|
19
|
+
export function registerTaskId(sessionId, taskId, messageId) {
|
|
20
20
|
logger.log(`[TASK_MANAGER] 📝 Registering/Updating taskId for session: ${sessionId}`);
|
|
21
|
-
logger.log(`[TASK_MANAGER] -
|
|
22
|
-
logger.log(`[TASK_MANAGER] - New messageId: ${messageId}`);
|
|
23
|
-
logger.log(`[TASK_MANAGER] - incrementRef: ${options?.incrementRef ?? false}`);
|
|
21
|
+
logger.log(`[TASK_MANAGER] - taskId: ${taskId}`);
|
|
24
22
|
const existing = activeTaskIds.get(sessionId);
|
|
25
23
|
if (existing) {
|
|
26
24
|
logger.log(`[TASK_MANAGER] - Previous taskId: ${existing.currentTaskId}`);
|
|
27
|
-
logger.log(`[TASK_MANAGER] -
|
|
28
|
-
logger.log(`[TASK_MANAGER] - 🔄 Switching taskId (steer mode detected)`);
|
|
29
|
-
// 更新taskId,但保持引用计数
|
|
25
|
+
logger.log(`[TASK_MANAGER] - 🔄 Updating taskId`);
|
|
30
26
|
existing.currentTaskId = taskId;
|
|
31
27
|
existing.currentMessageId = messageId;
|
|
32
28
|
existing.updatedAt = Date.now();
|
|
33
|
-
|
|
34
|
-
existing.refCount++;
|
|
35
|
-
logger.log(`[TASK_MANAGER] - Incremented refCount: ${existing.refCount}`);
|
|
36
|
-
}
|
|
37
|
-
logger.log(`[TASK_MANAGER] - ✅ TaskId updated, refCount=${existing.refCount}`);
|
|
38
|
-
return { isUpdate: true, refCount: existing.refCount };
|
|
29
|
+
return true; // isUpdate
|
|
39
30
|
}
|
|
40
31
|
else {
|
|
41
|
-
// 新注册
|
|
42
32
|
const binding = {
|
|
43
33
|
sessionId,
|
|
44
34
|
currentTaskId: taskId,
|
|
45
35
|
currentMessageId: messageId,
|
|
46
|
-
refCount: 1,
|
|
47
36
|
updatedAt: Date.now(),
|
|
48
|
-
locked: false,
|
|
49
37
|
};
|
|
50
38
|
activeTaskIds.set(sessionId, binding);
|
|
51
|
-
logger.log(`[TASK_MANAGER] - ✅ TaskId registered (new)
|
|
52
|
-
return
|
|
39
|
+
logger.log(`[TASK_MANAGER] - ✅ TaskId registered (new)`);
|
|
40
|
+
return false;
|
|
53
41
|
}
|
|
54
42
|
}
|
|
55
43
|
/**
|
|
56
|
-
*
|
|
57
|
-
*/
|
|
58
|
-
export function incrementTaskIdRef(sessionId) {
|
|
59
|
-
const binding = activeTaskIds.get(sessionId);
|
|
60
|
-
if (binding) {
|
|
61
|
-
binding.refCount++;
|
|
62
|
-
logger.log(`[TASK_MANAGER] ➕ Incremented refCount for ${sessionId}: ${binding.refCount}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* 减少引用计数,当refCount=0时才真正清理
|
|
44
|
+
* 移除session的活跃taskId(消息处理完成时调用)。
|
|
67
45
|
*/
|
|
68
46
|
export function decrementTaskIdRef(sessionId) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
logger.log(`[TASK_MANAGER] ⚠️ No binding found for ${sessionId}`);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
binding.refCount--;
|
|
75
|
-
logger.log(`[TASK_MANAGER] ➖ Decremented refCount for ${sessionId}: ${binding.refCount}`);
|
|
76
|
-
if (binding.refCount <= 0 && !binding.locked) {
|
|
77
|
-
logger.log(`[TASK_MANAGER] 🗑️ RefCount=0 and unlocked, clearing taskId`);
|
|
78
|
-
activeTaskIds.delete(sessionId);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
logger.log(`[TASK_MANAGER] - Keeping binding (refCount=${binding.refCount}, locked=${binding.locked})`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* 锁定taskId,防止被清理(第一个消息使用)
|
|
86
|
-
*/
|
|
87
|
-
export function lockTaskId(sessionId) {
|
|
88
|
-
const binding = activeTaskIds.get(sessionId);
|
|
89
|
-
if (binding) {
|
|
90
|
-
binding.locked = true;
|
|
91
|
-
logger.log(`[TASK_MANAGER] 🔒 Locked taskId for ${sessionId}`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* 解锁taskId(第一个消息完成时使用)
|
|
96
|
-
*/
|
|
97
|
-
export function unlockTaskId(sessionId) {
|
|
98
|
-
const binding = activeTaskIds.get(sessionId);
|
|
99
|
-
if (binding) {
|
|
100
|
-
binding.locked = false;
|
|
101
|
-
logger.log(`[TASK_MANAGER] 🔓 Unlocked taskId for ${sessionId}`);
|
|
102
|
-
// 解锁后,如果refCount=0,立即清理
|
|
103
|
-
if (binding.refCount <= 0) {
|
|
104
|
-
logger.log(`[TASK_MANAGER] 🗑️ Unlocked and refCount=0, clearing taskId`);
|
|
105
|
-
activeTaskIds.delete(sessionId);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
47
|
+
logger.log(`[TASK_MANAGER] 🗑️ Removing taskId for ${sessionId}`);
|
|
48
|
+
activeTaskIds.delete(sessionId);
|
|
108
49
|
}
|
|
109
50
|
/**
|
|
110
51
|
* 获取session的当前活跃taskId
|
|
@@ -126,12 +67,6 @@ export function getCurrentMessageId(sessionId) {
|
|
|
126
67
|
export function hasActiveTask(sessionId) {
|
|
127
68
|
return activeTaskIds.has(sessionId);
|
|
128
69
|
}
|
|
129
|
-
/**
|
|
130
|
-
* 获取完整的binding信息(用于调试)
|
|
131
|
-
*/
|
|
132
|
-
export function getTaskIdBinding(sessionId) {
|
|
133
|
-
return activeTaskIds.get(sessionId) ?? null;
|
|
134
|
-
}
|
|
135
70
|
/**
|
|
136
71
|
* 获取所有活跃的 task bindings(用于 gateway_stop 通知等场景)
|
|
137
72
|
*/
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
/**
|
|
4
6
|
* XY calendar event tool - creates a calendar event on user's device.
|
|
5
7
|
* Requires title, dtStart (start time), and dtEnd (end time) parameters.
|
|
@@ -85,6 +87,7 @@ export function createCalendarTool(ctx) {
|
|
|
85
87
|
return new Promise((resolve, reject) => {
|
|
86
88
|
const timeout = setTimeout(() => {
|
|
87
89
|
wsManager.off("data-event", handler);
|
|
90
|
+
logger.error("超时: 创建日程超时(60秒)", { sessionId, toolCallId });
|
|
88
91
|
reject(new Error("创建日程超时(60秒)"));
|
|
89
92
|
}, 60000);
|
|
90
93
|
// Listen for data events from WebSocket
|
|
@@ -110,10 +113,11 @@ export function createCalendarTool(ctx) {
|
|
|
110
113
|
// Register event handler
|
|
111
114
|
wsManager.on("data-event", handler);
|
|
112
115
|
// Send the command
|
|
116
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
113
117
|
sendCommand({
|
|
114
118
|
config,
|
|
115
119
|
sessionId,
|
|
116
|
-
taskId,
|
|
120
|
+
taskId: currentTaskId,
|
|
117
121
|
messageId,
|
|
118
122
|
command,
|
|
119
123
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
/**
|
|
4
6
|
* XY call phone tool - makes a phone call on user's device.
|
|
5
7
|
* Requires phoneNumber parameter and optional slotId (0 for primary SIM, 1 for secondary SIM).
|
|
@@ -77,6 +79,7 @@ export function createCallPhoneTool(ctx) {
|
|
|
77
79
|
return new Promise((resolve, reject) => {
|
|
78
80
|
const timeout = setTimeout(() => {
|
|
79
81
|
wsManager.off("data-event", handler);
|
|
82
|
+
logger.error("超时: 拨打电话超时(60秒)", { sessionId, toolCallId });
|
|
80
83
|
reject(new Error("拨打电话超时(60秒)"));
|
|
81
84
|
}, 60000);
|
|
82
85
|
// Listen for data events from WebSocket
|
|
@@ -102,10 +105,11 @@ export function createCallPhoneTool(ctx) {
|
|
|
102
105
|
// Register event handler
|
|
103
106
|
wsManager.on("data-event", handler);
|
|
104
107
|
// Send the command
|
|
108
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
105
109
|
sendCommand({
|
|
106
110
|
config,
|
|
107
111
|
sessionId,
|
|
108
|
-
taskId,
|
|
112
|
+
taskId: currentTaskId,
|
|
109
113
|
messageId,
|
|
110
114
|
command,
|
|
111
115
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
// Enum definitions for alarm parameters
|
|
4
6
|
const ALARM_SNOOZE_DURATION_VALUES = [5, 10, 15, 20, 25, 30];
|
|
5
7
|
const ALARM_SNOOZE_TOTAL_VALUES = [0, 1, 3, 5, 10];
|
|
@@ -222,6 +224,7 @@ b. 使用该工具之前需获取当前真实时间
|
|
|
222
224
|
return new Promise((resolve, reject) => {
|
|
223
225
|
const timeout = setTimeout(() => {
|
|
224
226
|
wsManager.off("data-event", handler);
|
|
227
|
+
logger.error("超时: 创建闹钟超时(60秒)", { sessionId, toolCallId });
|
|
225
228
|
reject(new Error("创建闹钟超时(60秒)"));
|
|
226
229
|
}, 60000);
|
|
227
230
|
// Listen for data events from WebSocket
|
|
@@ -248,10 +251,11 @@ b. 使用该工具之前需获取当前真实时间
|
|
|
248
251
|
// Register event handler
|
|
249
252
|
wsManager.on("data-event", handler);
|
|
250
253
|
// Send the command
|
|
254
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
251
255
|
sendCommand({
|
|
252
256
|
config,
|
|
253
257
|
sessionId,
|
|
254
|
-
taskId,
|
|
258
|
+
taskId: currentTaskId,
|
|
255
259
|
messageId,
|
|
256
260
|
command,
|
|
257
261
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
/**
|
|
4
6
|
* XY delete alarm tool - deletes existing alarms on user's device.
|
|
5
7
|
* Requires entityId(s) from search_alarm or create_alarm tool as prerequisite.
|
|
@@ -121,6 +123,7 @@ export function createDeleteAlarmTool(ctx) {
|
|
|
121
123
|
return new Promise((resolve, reject) => {
|
|
122
124
|
const timeout = setTimeout(() => {
|
|
123
125
|
wsManager.off("data-event", handler);
|
|
126
|
+
logger.error("超时: 删除闹钟超时(60秒)", { sessionId, toolCallId });
|
|
124
127
|
reject(new Error("删除闹钟超时(60秒)"));
|
|
125
128
|
}, 60000);
|
|
126
129
|
// Listen for data events from WebSocket
|
|
@@ -147,10 +150,11 @@ export function createDeleteAlarmTool(ctx) {
|
|
|
147
150
|
// Register event handler
|
|
148
151
|
wsManager.on("data-event", handler);
|
|
149
152
|
// Send the command
|
|
153
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
150
154
|
sendCommand({
|
|
151
155
|
config,
|
|
152
156
|
sessionId,
|
|
153
|
-
taskId,
|
|
157
|
+
taskId: currentTaskId,
|
|
154
158
|
messageId,
|
|
155
159
|
command,
|
|
156
160
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
/**
|
|
4
6
|
* XY location tool - gets user's current location.
|
|
5
7
|
* Returns WGS84 coordinates (latitude, longitude).
|
|
@@ -53,6 +55,7 @@ export function createLocationTool(ctx) {
|
|
|
53
55
|
return new Promise((resolve, reject) => {
|
|
54
56
|
const timeout = setTimeout(() => {
|
|
55
57
|
wsManager.off("data-event", handler);
|
|
58
|
+
logger.error("超时: 获取位置超时(60秒)", { sessionId, toolCallId });
|
|
56
59
|
reject(new Error("获取位置超时(60秒)"));
|
|
57
60
|
}, 60000);
|
|
58
61
|
// Listen for data events from WebSocket
|
|
@@ -80,10 +83,11 @@ export function createLocationTool(ctx) {
|
|
|
80
83
|
// Note: The WebSocket manager needs to emit 'data-event' when receiving data events
|
|
81
84
|
wsManager.on("data-event", handler);
|
|
82
85
|
// Send the command
|
|
86
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
83
87
|
sendCommand({
|
|
84
88
|
config,
|
|
85
89
|
sessionId,
|
|
86
|
-
taskId,
|
|
90
|
+
taskId: currentTaskId,
|
|
87
91
|
messageId,
|
|
88
92
|
command,
|
|
89
93
|
}).then(() => {
|
|
@@ -105,12 +105,23 @@ export function createLoginTokenTool(ctx) {
|
|
|
105
105
|
const diff = Date.now() - tokenTime;
|
|
106
106
|
if (diff <= TOKEN_VALIDITY_MS) {
|
|
107
107
|
// (3) Found valid token
|
|
108
|
-
|
|
108
|
+
const code = match.code ?? "";
|
|
109
|
+
let resultText;
|
|
110
|
+
if (code === "0" || code === "") {
|
|
111
|
+
resultText = "获取用户授权成功";
|
|
112
|
+
}
|
|
113
|
+
else if (code === "400") {
|
|
114
|
+
resultText = "小艺App版本较低,获取用户授权失败";
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
resultText = "获取用户授权失败";
|
|
118
|
+
}
|
|
119
|
+
logger.log(`[LOGIN_TOKEN] Got login token for clientId=${clientId}, code=${code}`);
|
|
109
120
|
resolve({
|
|
110
121
|
content: [
|
|
111
122
|
{
|
|
112
123
|
type: "text",
|
|
113
|
-
text:
|
|
124
|
+
text: resultText,
|
|
114
125
|
},
|
|
115
126
|
],
|
|
116
127
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
// Enum definitions for alarm parameters (same as create-alarm-tool)
|
|
4
6
|
const ALARM_SNOOZE_DURATION_VALUES = [5, 10, 15, 20, 25, 30];
|
|
5
7
|
const ALARM_SNOOZE_TOTAL_VALUES = [0, 1, 3, 5, 10];
|
|
@@ -234,6 +236,7 @@ export function createModifyAlarmTool(ctx) {
|
|
|
234
236
|
return new Promise((resolve, reject) => {
|
|
235
237
|
const timeout = setTimeout(() => {
|
|
236
238
|
wsManager.off("data-event", handler);
|
|
239
|
+
logger.error("超时: 修改闹钟超时(60秒)", { sessionId, toolCallId });
|
|
237
240
|
reject(new Error("修改闹钟超时(60秒)"));
|
|
238
241
|
}, 60000);
|
|
239
242
|
// Listen for data events from WebSocket
|
|
@@ -260,10 +263,11 @@ export function createModifyAlarmTool(ctx) {
|
|
|
260
263
|
// Register event handler
|
|
261
264
|
wsManager.on("data-event", handler);
|
|
262
265
|
// Send the command
|
|
266
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
263
267
|
sendCommand({
|
|
264
268
|
config,
|
|
265
269
|
sessionId,
|
|
266
|
-
taskId,
|
|
270
|
+
taskId: currentTaskId,
|
|
267
271
|
messageId,
|
|
268
272
|
command,
|
|
269
273
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
/**
|
|
4
6
|
* XY modify note tool - appends content to an existing note on user's device.
|
|
5
7
|
* Requires entityId from search_notes tool as prerequisite.
|
|
@@ -75,6 +77,7 @@ export function createModifyNoteTool(ctx) {
|
|
|
75
77
|
return new Promise((resolve, reject) => {
|
|
76
78
|
const timeout = setTimeout(() => {
|
|
77
79
|
wsManager.off("data-event", handler);
|
|
80
|
+
logger.error("超时: 修改备忘录超时(60秒)", { sessionId, toolCallId });
|
|
78
81
|
reject(new Error("修改备忘录超时(60秒)"));
|
|
79
82
|
}, 60000);
|
|
80
83
|
// Listen for data events from WebSocket
|
|
@@ -101,10 +104,11 @@ export function createModifyNoteTool(ctx) {
|
|
|
101
104
|
// Register event handler
|
|
102
105
|
wsManager.on("data-event", handler);
|
|
103
106
|
// Send the command
|
|
107
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
104
108
|
sendCommand({
|
|
105
109
|
config,
|
|
106
110
|
sessionId,
|
|
107
|
-
taskId,
|
|
111
|
+
taskId: currentTaskId,
|
|
108
112
|
messageId,
|
|
109
113
|
command,
|
|
110
114
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
/**
|
|
4
6
|
* Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
|
|
5
7
|
* 抛出此错误会让 openclaw 返回 HTTP 400 而非 500,
|
|
@@ -92,6 +94,7 @@ export function createNoteTool(ctx) {
|
|
|
92
94
|
return new Promise((resolve, reject) => {
|
|
93
95
|
const timeout = setTimeout(() => {
|
|
94
96
|
wsManager.off("data-event", handler);
|
|
97
|
+
logger.error("超时: 创建备忘录超时(60秒)", { sessionId, toolCallId });
|
|
95
98
|
reject(new Error("创建备忘录超时(60秒)"));
|
|
96
99
|
}, 60000);
|
|
97
100
|
// Listen for data events from WebSocket
|
|
@@ -118,10 +121,11 @@ export function createNoteTool(ctx) {
|
|
|
118
121
|
// Register event handler
|
|
119
122
|
wsManager.on("data-event", handler);
|
|
120
123
|
// Send the command
|
|
124
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
121
125
|
sendCommand({
|
|
122
126
|
config,
|
|
123
127
|
sessionId,
|
|
124
|
-
taskId,
|
|
128
|
+
taskId: currentTaskId,
|
|
125
129
|
messageId,
|
|
126
130
|
command,
|
|
127
131
|
}).catch((error) => {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// QueryAppMessage tool implementation
|
|
2
2
|
import { getXYWebSocketManager } from "../client.js";
|
|
3
3
|
import { sendCommand } from "../formatter.js";
|
|
4
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
5
|
+
import { logger } from "../utils/logger.js";
|
|
4
6
|
class ToolInputError extends Error {
|
|
5
7
|
status = 400;
|
|
6
8
|
constructor(message) {
|
|
@@ -94,6 +96,7 @@ c. 调用工具前需认真检查调用参数是否满足工具要求
|
|
|
94
96
|
return new Promise((resolve, reject) => {
|
|
95
97
|
const timeout = setTimeout(() => {
|
|
96
98
|
wsManager.off("data-event", handler);
|
|
99
|
+
logger.error("超时: 查询通知消息超时(60秒)", { sessionId, toolCallId: _toolCallId });
|
|
97
100
|
reject(new Error("查询通知消息超时(60秒)"));
|
|
98
101
|
}, 60000);
|
|
99
102
|
const handler = (event) => {
|
|
@@ -116,10 +119,11 @@ c. 调用工具前需认真检查调用参数是否满足工具要求
|
|
|
116
119
|
}
|
|
117
120
|
};
|
|
118
121
|
wsManager.on("data-event", handler);
|
|
122
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
119
123
|
sendCommand({
|
|
120
124
|
config,
|
|
121
125
|
sessionId,
|
|
122
|
-
taskId,
|
|
126
|
+
taskId: currentTaskId,
|
|
123
127
|
messageId,
|
|
124
128
|
command,
|
|
125
129
|
})
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// QueryMemoryData tool implementation
|
|
2
2
|
import { getXYWebSocketManager } from "../client.js";
|
|
3
3
|
import { sendCommand } from "../formatter.js";
|
|
4
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
5
|
+
import { logger } from "../utils/logger.js";
|
|
4
6
|
class ToolInputError extends Error {
|
|
5
7
|
status = 400;
|
|
6
8
|
constructor(message) {
|
|
@@ -110,6 +112,7 @@ c. 调用工具前需认真检查调用参数是否满足工具要求
|
|
|
110
112
|
return new Promise((resolve, reject) => {
|
|
111
113
|
const timeout = setTimeout(() => {
|
|
112
114
|
wsManager.off("data-event", handler);
|
|
115
|
+
logger.error("超时: 查询记忆数据超时(60秒)", { sessionId, toolCallId: _toolCallId });
|
|
113
116
|
reject(new Error("查询记忆数据超时(60秒)"));
|
|
114
117
|
}, 60000);
|
|
115
118
|
const handler = (event) => {
|
|
@@ -132,10 +135,11 @@ c. 调用工具前需认真检查调用参数是否满足工具要求
|
|
|
132
135
|
}
|
|
133
136
|
};
|
|
134
137
|
wsManager.on("data-event", handler);
|
|
138
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
135
139
|
sendCommand({
|
|
136
140
|
config,
|
|
137
141
|
sessionId,
|
|
138
|
-
taskId,
|
|
142
|
+
taskId: currentTaskId,
|
|
139
143
|
messageId,
|
|
140
144
|
command,
|
|
141
145
|
})
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// QueryTodoTask tool implementation
|
|
2
2
|
import { getXYWebSocketManager } from "../client.js";
|
|
3
3
|
import { sendCommand } from "../formatter.js";
|
|
4
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
5
|
+
import { logger } from "../utils/logger.js";
|
|
4
6
|
class ToolInputError extends Error {
|
|
5
7
|
status = 400;
|
|
6
8
|
constructor(message) {
|
|
@@ -89,6 +91,7 @@ d. 当只传入 startTime 时,返回该时间点之后的所有任务;当只
|
|
|
89
91
|
return new Promise((resolve, reject) => {
|
|
90
92
|
const timeout = setTimeout(() => {
|
|
91
93
|
wsManager.off("data-event", handler);
|
|
94
|
+
logger.error("超时: 查询待办任务超时(60秒)", { sessionId, toolCallId: _toolCallId });
|
|
92
95
|
reject(new Error("查询待办任务超时(60秒)"));
|
|
93
96
|
}, 60000);
|
|
94
97
|
const handler = (event) => {
|
|
@@ -111,10 +114,11 @@ d. 当只传入 startTime 时,返回该时间点之后的所有任务;当只
|
|
|
111
114
|
}
|
|
112
115
|
};
|
|
113
116
|
wsManager.on("data-event", handler);
|
|
117
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
114
118
|
sendCommand({
|
|
115
119
|
config,
|
|
116
120
|
sessionId,
|
|
117
|
-
taskId,
|
|
121
|
+
taskId: currentTaskId,
|
|
118
122
|
messageId,
|
|
119
123
|
command,
|
|
120
124
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
import { XYFileUploadService } from "../file-upload.js";
|
|
4
6
|
/**
|
|
5
7
|
* Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
|
|
@@ -117,6 +119,7 @@ export function createSaveFileToPhoneTool(ctx) {
|
|
|
117
119
|
return new Promise((resolve, reject) => {
|
|
118
120
|
const timeout = setTimeout(() => {
|
|
119
121
|
wsManager.off("data-event", handler);
|
|
122
|
+
logger.error("超时: 保存文件到手机超时(60秒)", { sessionId, toolCallId });
|
|
120
123
|
reject(new Error("保存文件到手机超时(60秒)"));
|
|
121
124
|
}, 60000);
|
|
122
125
|
// Listen for data events from WebSocket
|
|
@@ -142,10 +145,11 @@ export function createSaveFileToPhoneTool(ctx) {
|
|
|
142
145
|
// Register event handler
|
|
143
146
|
wsManager.on("data-event", handler);
|
|
144
147
|
// Send the command
|
|
148
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
145
149
|
sendCommand({
|
|
146
150
|
config,
|
|
147
151
|
sessionId,
|
|
148
|
-
taskId,
|
|
152
|
+
taskId: currentTaskId,
|
|
149
153
|
messageId,
|
|
150
154
|
command,
|
|
151
155
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
import { XYFileUploadService } from "../file-upload.js";
|
|
4
6
|
/**
|
|
5
7
|
* Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
|
|
@@ -125,6 +127,7 @@ export function createSaveMediaToGalleryTool(ctx) {
|
|
|
125
127
|
return new Promise((resolve, reject) => {
|
|
126
128
|
const timeout = setTimeout(() => {
|
|
127
129
|
wsManager.off("data-event", handler);
|
|
130
|
+
logger.error("超时: 保存媒体到图库超时(60秒)", { sessionId, toolCallId });
|
|
128
131
|
reject(new Error("保存媒体到图库超时(60秒)"));
|
|
129
132
|
}, 60000);
|
|
130
133
|
// Listen for data events from WebSocket
|
|
@@ -150,10 +153,11 @@ export function createSaveMediaToGalleryTool(ctx) {
|
|
|
150
153
|
// Register event handler
|
|
151
154
|
wsManager.on("data-event", handler);
|
|
152
155
|
// Send the command
|
|
156
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
153
157
|
sendCommand({
|
|
154
158
|
config,
|
|
155
159
|
sessionId,
|
|
156
|
-
taskId,
|
|
160
|
+
taskId: currentTaskId,
|
|
157
161
|
messageId,
|
|
158
162
|
command,
|
|
159
163
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
// Enum definitions for alarm search parameters
|
|
4
6
|
const RANGE_TYPE_VALUES = ["all", "next", "current"];
|
|
5
7
|
const ALARM_STATE_VALUES = [0, 1];
|
|
@@ -166,6 +168,7 @@ b. 使用该工具之前需获取当前真实时间
|
|
|
166
168
|
return new Promise((resolve, reject) => {
|
|
167
169
|
const timeout = setTimeout(() => {
|
|
168
170
|
wsManager.off("data-event", handler);
|
|
171
|
+
logger.error("超时: 检索闹钟超时(60秒)", { sessionId, toolCallId });
|
|
169
172
|
reject(new Error("检索闹钟超时(60秒)"));
|
|
170
173
|
}, 60000);
|
|
171
174
|
// Listen for data events from WebSocket
|
|
@@ -192,10 +195,11 @@ b. 使用该工具之前需获取当前真实时间
|
|
|
192
195
|
// Register event handler
|
|
193
196
|
wsManager.on("data-event", handler);
|
|
194
197
|
// Send the command
|
|
198
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
195
199
|
sendCommand({
|
|
196
200
|
config,
|
|
197
201
|
sessionId,
|
|
198
|
-
taskId,
|
|
202
|
+
taskId: currentTaskId,
|
|
199
203
|
messageId,
|
|
200
204
|
command,
|
|
201
205
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
/**
|
|
4
6
|
* XY search calendar event tool - searches calendar events on user's device.
|
|
5
7
|
* Returns matching events based on time range and optional title filter.
|
|
@@ -137,6 +139,7 @@ d. 如果查询结果返回-303,代表查询结果为空
|
|
|
137
139
|
return new Promise((resolve, reject) => {
|
|
138
140
|
const timeout = setTimeout(() => {
|
|
139
141
|
wsManager.off("data-event", handler);
|
|
142
|
+
logger.error("超时: 检索日程超时(60秒)", { sessionId, toolCallId });
|
|
140
143
|
reject(new Error("检索日程超时(60秒)"));
|
|
141
144
|
}, 60000);
|
|
142
145
|
// Listen for data events from WebSocket
|
|
@@ -163,10 +166,11 @@ d. 如果查询结果返回-303,代表查询结果为空
|
|
|
163
166
|
// Register event handler
|
|
164
167
|
wsManager.on("data-event", handler);
|
|
165
168
|
// Send the command
|
|
169
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
166
170
|
sendCommand({
|
|
167
171
|
config,
|
|
168
172
|
sessionId,
|
|
169
|
-
taskId,
|
|
173
|
+
taskId: currentTaskId,
|
|
170
174
|
messageId,
|
|
171
175
|
command,
|
|
172
176
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
3
5
|
/**
|
|
4
6
|
* XY search contact tool - searches contacts on user's device.
|
|
5
7
|
* Returns matching contact information based on name.
|
|
@@ -65,6 +67,7 @@ export function createSearchContactTool(ctx) {
|
|
|
65
67
|
return new Promise((resolve, reject) => {
|
|
66
68
|
const timeout = setTimeout(() => {
|
|
67
69
|
wsManager.off("data-event", handler);
|
|
70
|
+
logger.error("超时: 搜索联系人超时(60秒)", { sessionId, toolCallId });
|
|
68
71
|
reject(new Error("搜索联系人超时(60秒)"));
|
|
69
72
|
}, 60000);
|
|
70
73
|
// Listen for data events from WebSocket
|
|
@@ -91,10 +94,11 @@ export function createSearchContactTool(ctx) {
|
|
|
91
94
|
// Register event handler
|
|
92
95
|
wsManager.on("data-event", handler);
|
|
93
96
|
// Send the command
|
|
97
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
94
98
|
sendCommand({
|
|
95
99
|
config,
|
|
96
100
|
sessionId,
|
|
97
|
-
taskId,
|
|
101
|
+
taskId: currentTaskId,
|
|
98
102
|
messageId,
|
|
99
103
|
command,
|
|
100
104
|
})
|