@ynhcj/xiaoyi-channel 0.0.32-beta → 0.0.32-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.d.ts +0 -2
- package/dist/index.js +42 -2
- package/dist/src/bot.js +60 -56
- package/dist/src/channel.js +24 -8
- package/dist/src/client.js +11 -33
- package/dist/src/config.js +2 -2
- package/dist/src/cspl/call-api.d.ts +3 -0
- package/dist/src/cspl/call-api.js +86 -0
- package/dist/src/cspl/config.d.ts +19 -0
- package/dist/src/cspl/config.js +50 -0
- package/dist/src/cspl/constants.d.ts +43 -0
- package/dist/src/cspl/constants.js +22 -0
- package/dist/src/cspl/utils.d.ts +10 -0
- package/dist/src/cspl/utils.js +57 -0
- package/dist/src/file-upload.d.ts +5 -0
- package/dist/src/file-upload.js +88 -6
- package/dist/src/formatter.d.ts +14 -0
- package/dist/src/formatter.js +49 -28
- package/dist/src/heartbeat.js +0 -4
- package/dist/src/monitor.js +16 -10
- package/dist/src/onboarding.d.ts +3 -4
- package/dist/src/onboarding.js +2 -2
- package/dist/src/outbound.d.ts +2 -1
- package/dist/src/outbound.js +119 -103
- package/dist/src/parser.d.ts +7 -0
- package/dist/src/parser.js +22 -0
- package/dist/src/push.d.ts +8 -1
- package/dist/src/push.js +27 -40
- package/dist/src/reply-dispatcher.js +39 -7
- package/dist/src/steer-injector.d.ts +16 -0
- package/dist/src/steer-injector.js +74 -0
- package/dist/src/thread-bindings.d.ts +54 -0
- package/dist/src/thread-bindings.js +214 -0
- package/dist/src/tools/calendar-tool.js +5 -38
- package/dist/src/tools/call-phone-tool.js +1 -42
- package/dist/src/tools/create-alarm-tool.js +8 -103
- package/dist/src/tools/delete-alarm-tool.js +5 -69
- package/dist/src/tools/image-reading-tool.d.ts +5 -0
- package/dist/src/tools/image-reading-tool.js +328 -0
- package/dist/src/tools/location-tool.js +6 -40
- package/dist/src/tools/modify-alarm-tool.js +8 -117
- package/dist/src/tools/modify-note-tool.js +3 -41
- package/dist/src/tools/note-tool.js +4 -16
- package/dist/src/tools/search-alarm-tool.js +14 -118
- package/dist/src/tools/search-calendar-tool.js +8 -82
- package/dist/src/tools/search-contact-tool.js +2 -55
- package/dist/src/tools/search-file-tool.js +4 -61
- package/dist/src/tools/search-message-tool.js +2 -59
- package/dist/src/tools/search-note-tool.js +4 -22
- package/dist/src/tools/search-photo-gallery-tool.js +38 -59
- package/dist/src/tools/send-file-to-user-tool.js +1 -39
- package/dist/src/tools/send-message-tool.js +5 -56
- package/dist/src/tools/session-manager.js +0 -45
- package/dist/src/tools/upload-file-tool.js +0 -49
- package/dist/src/tools/upload-photo-tool.js +0 -42
- package/dist/src/tools/view-push-result-tool.d.ts +5 -0
- package/dist/src/tools/view-push-result-tool.js +107 -0
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +5 -0
- package/dist/src/tools/xiaoyi-collection-tool.js +112 -0
- package/dist/src/tools/xiaoyi-gui-tool.js +0 -34
- package/dist/src/trigger-handler.d.ts +22 -0
- package/dist/src/trigger-handler.js +59 -0
- package/dist/src/types.d.ts +1 -8
- package/dist/src/types.js +4 -0
- package/dist/src/utils/pushdata-manager.d.ts +28 -0
- package/dist/src/utils/pushdata-manager.js +171 -0
- package/dist/src/utils/pushid-manager.d.ts +12 -0
- package/dist/src/utils/pushid-manager.js +105 -0
- package/dist/src/websocket.d.ts +25 -31
- package/dist/src/websocket.js +239 -271
- package/package.json +2 -2
- package/dist/src/tools/search-photo-tool.d.ts +0 -9
- package/dist/src/tools/search-photo-tool.js +0 -270
- package/dist/src/utils/session.d.ts +0 -34
- package/dist/src/utils/session.js +0 -50
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
3
|
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
|
-
import { logger } from "../utils/logger.js";
|
|
5
4
|
// Enum definitions for alarm parameters (same as create-alarm-tool)
|
|
6
5
|
const ALARM_SNOOZE_DURATION_VALUES = [5, 10, 15, 20, 25, 30];
|
|
7
6
|
const ALARM_SNOOZE_TOTAL_VALUES = [0, 1, 3, 5, 10];
|
|
@@ -35,10 +34,13 @@ export const modifyAlarmTool = {
|
|
|
35
34
|
- daysOfWeek: 自定义响铃星期,仅当daysOfWakeType=3(自定义时间)时必需且有效,其他情况不要传递此参数。数组或JSON字符串,枚举值:Mon,Tue,Wed,Thu,Fri,Sat,Sun。注意:仅支持长度为1的数组,如果需要一周中不同的几天,需要多次调用此工具
|
|
36
35
|
|
|
37
36
|
使用流程:
|
|
38
|
-
1. 先调用 search_alarm 工具查询闹钟,获取 entityId
|
|
37
|
+
1. 先调用 search_alarm 工具查询闹钟,获取 entityId,
|
|
39
38
|
2. 调用此工具修改闹钟,传入 entityId 和需要修改的参数
|
|
39
|
+
3. 其余不涉及需改的参数,如果search_alarm 或 create_alarm的结果中有相应的值,需要一并填上,需要与原有的保持一致,防止不填采用默认值
|
|
40
40
|
|
|
41
|
-
注意事项:操作超时时间为60
|
|
41
|
+
注意事项:操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。
|
|
42
|
+
|
|
43
|
+
回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。`,
|
|
42
44
|
parameters: {
|
|
43
45
|
type: "object",
|
|
44
46
|
properties: {
|
|
@@ -83,16 +85,10 @@ export const modifyAlarmTool = {
|
|
|
83
85
|
required: ["entityId"],
|
|
84
86
|
},
|
|
85
87
|
async execute(toolCallId, params) {
|
|
86
|
-
logger.log(`[MODIFY_ALARM_TOOL] 🚀 Starting execution`);
|
|
87
|
-
logger.log(`[MODIFY_ALARM_TOOL] - toolCallId: ${toolCallId}`);
|
|
88
|
-
logger.log(`[MODIFY_ALARM_TOOL] - params:`, JSON.stringify(params));
|
|
89
|
-
logger.log(`[MODIFY_ALARM_TOOL] - timestamp: ${new Date().toISOString()}`);
|
|
90
88
|
// ===== Validate required parameter: entityId =====
|
|
91
89
|
if (!params.entityId || typeof params.entityId !== "string") {
|
|
92
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Missing or invalid entityId`);
|
|
93
90
|
throw new Error("Missing required parameter: entityId must be a string obtained from search_alarm or create_alarm");
|
|
94
91
|
}
|
|
95
|
-
logger.log(`[MODIFY_ALARM_TOOL] - entityId: ${params.entityId}`);
|
|
96
92
|
// ===== Build intentParam with provided parameters =====
|
|
97
93
|
const intentParam = {
|
|
98
94
|
entityName: "Alarm",
|
|
@@ -101,98 +97,76 @@ export const modifyAlarmTool = {
|
|
|
101
97
|
// Parse and convert alarmTime if provided
|
|
102
98
|
if (params.alarmTime !== undefined && params.alarmTime !== null) {
|
|
103
99
|
if (typeof params.alarmTime !== "string") {
|
|
104
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmTime type`);
|
|
105
100
|
throw new Error("alarmTime must be a string in format YYYYMMDD hhmmss");
|
|
106
101
|
}
|
|
107
|
-
logger.log(`[MODIFY_ALARM_TOOL] 🕒 Parsing alarmTime: ${params.alarmTime}`);
|
|
108
102
|
const alarmTimeMs = parseAlarmTimeToTimestamp(params.alarmTime);
|
|
109
103
|
if (alarmTimeMs === null) {
|
|
110
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmTime format`);
|
|
111
104
|
throw new Error("Invalid alarmTime format. Required format: YYYYMMDD hhmmss (e.g., 20240315 143000)");
|
|
112
105
|
}
|
|
113
106
|
intentParam.alarmTime = alarmTimeMs;
|
|
114
|
-
logger.log(`[MODIFY_ALARM_TOOL] ✅ alarmTime converted to timestamp: ${alarmTimeMs}`);
|
|
115
107
|
}
|
|
116
108
|
// Add alarmTitle if provided
|
|
117
109
|
if (params.alarmTitle !== undefined && params.alarmTitle !== null) {
|
|
118
110
|
if (typeof params.alarmTitle !== "string") {
|
|
119
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmTitle type`);
|
|
120
111
|
throw new Error("alarmTitle must be a string");
|
|
121
112
|
}
|
|
122
113
|
intentParam.alarmTitle = params.alarmTitle;
|
|
123
|
-
logger.log(`[MODIFY_ALARM_TOOL] - alarmTitle: ${params.alarmTitle}`);
|
|
124
114
|
}
|
|
125
115
|
// Add alarmState if provided
|
|
126
116
|
if (params.alarmState !== undefined && params.alarmState !== null) {
|
|
127
117
|
if (typeof params.alarmState !== "number") {
|
|
128
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmState type`);
|
|
129
118
|
throw new Error("alarmState must be a number");
|
|
130
119
|
}
|
|
131
120
|
if (!ALARM_STATE_VALUES.includes(params.alarmState)) {
|
|
132
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmState value: ${params.alarmState}`);
|
|
133
121
|
throw new Error(`alarmState must be one of: ${ALARM_STATE_VALUES.join(", ")}`);
|
|
134
122
|
}
|
|
135
123
|
intentParam.alarmState = params.alarmState;
|
|
136
|
-
logger.log(`[MODIFY_ALARM_TOOL] - alarmState: ${params.alarmState}`);
|
|
137
124
|
}
|
|
138
125
|
// Add alarmSnoozeDuration if provided
|
|
139
126
|
if (params.alarmSnoozeDuration !== undefined && params.alarmSnoozeDuration !== null) {
|
|
140
127
|
if (typeof params.alarmSnoozeDuration !== "number") {
|
|
141
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmSnoozeDuration type`);
|
|
142
128
|
throw new Error("alarmSnoozeDuration must be a number");
|
|
143
129
|
}
|
|
144
130
|
if (!ALARM_SNOOZE_DURATION_VALUES.includes(params.alarmSnoozeDuration)) {
|
|
145
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmSnoozeDuration value: ${params.alarmSnoozeDuration}`);
|
|
146
131
|
throw new Error(`alarmSnoozeDuration must be one of: ${ALARM_SNOOZE_DURATION_VALUES.join(", ")}`);
|
|
147
132
|
}
|
|
148
133
|
intentParam.alarmSnoozeDuration = params.alarmSnoozeDuration;
|
|
149
|
-
logger.log(`[MODIFY_ALARM_TOOL] - alarmSnoozeDuration: ${params.alarmSnoozeDuration}`);
|
|
150
134
|
}
|
|
151
135
|
// Add alarmSnoozeTotal if provided
|
|
152
136
|
if (params.alarmSnoozeTotal !== undefined && params.alarmSnoozeTotal !== null) {
|
|
153
137
|
if (typeof params.alarmSnoozeTotal !== "number") {
|
|
154
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmSnoozeTotal type`);
|
|
155
138
|
throw new Error("alarmSnoozeTotal must be a number");
|
|
156
139
|
}
|
|
157
140
|
if (!ALARM_SNOOZE_TOTAL_VALUES.includes(params.alarmSnoozeTotal)) {
|
|
158
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmSnoozeTotal value: ${params.alarmSnoozeTotal}`);
|
|
159
141
|
throw new Error(`alarmSnoozeTotal must be one of: ${ALARM_SNOOZE_TOTAL_VALUES.join(", ")}`);
|
|
160
142
|
}
|
|
161
143
|
intentParam.alarmSnoozeTotal = params.alarmSnoozeTotal;
|
|
162
|
-
logger.log(`[MODIFY_ALARM_TOOL] - alarmSnoozeTotal: ${params.alarmSnoozeTotal}`);
|
|
163
144
|
}
|
|
164
145
|
// Add alarmRingDuration if provided
|
|
165
146
|
if (params.alarmRingDuration !== undefined && params.alarmRingDuration !== null) {
|
|
166
147
|
if (typeof params.alarmRingDuration !== "number") {
|
|
167
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmRingDuration type`);
|
|
168
148
|
throw new Error("alarmRingDuration must be a number");
|
|
169
149
|
}
|
|
170
150
|
if (!ALARM_RING_DURATION_VALUES.includes(params.alarmRingDuration)) {
|
|
171
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmRingDuration value: ${params.alarmRingDuration}`);
|
|
172
151
|
throw new Error(`alarmRingDuration must be one of: ${ALARM_RING_DURATION_VALUES.join(", ")}`);
|
|
173
152
|
}
|
|
174
153
|
intentParam.alarmRingDuration = params.alarmRingDuration;
|
|
175
|
-
logger.log(`[MODIFY_ALARM_TOOL] - alarmRingDuration: ${params.alarmRingDuration}`);
|
|
176
154
|
}
|
|
177
155
|
// Add daysOfWakeType if provided
|
|
178
156
|
if (params.daysOfWakeType !== undefined && params.daysOfWakeType !== null) {
|
|
179
157
|
if (typeof params.daysOfWakeType !== "number") {
|
|
180
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid daysOfWakeType type`);
|
|
181
158
|
throw new Error("daysOfWakeType must be a number");
|
|
182
159
|
}
|
|
183
160
|
if (!DAYS_OF_WAKE_TYPE_VALUES.includes(params.daysOfWakeType)) {
|
|
184
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid daysOfWakeType value: ${params.daysOfWakeType}`);
|
|
185
161
|
throw new Error(`daysOfWakeType must be one of: ${DAYS_OF_WAKE_TYPE_VALUES.join(", ")}`);
|
|
186
162
|
}
|
|
187
163
|
intentParam.daysOfWakeType = params.daysOfWakeType;
|
|
188
|
-
logger.log(`[MODIFY_ALARM_TOOL] - daysOfWakeType: ${params.daysOfWakeType}`);
|
|
189
164
|
}
|
|
190
165
|
// Add daysOfWeek if provided - only valid when daysOfWakeType is 3
|
|
191
166
|
if (params.daysOfWeek !== undefined && params.daysOfWeek !== null) {
|
|
192
167
|
// Check if daysOfWakeType is 3 or will be set to 3
|
|
193
168
|
const targetDaysOfWakeType = params.daysOfWakeType !== undefined ? params.daysOfWakeType : null;
|
|
194
169
|
if (targetDaysOfWakeType !== null && targetDaysOfWakeType !== 3) {
|
|
195
|
-
logger.warn(`[MODIFY_ALARM_TOOL] ⚠️ daysOfWeek parameter is ignored when daysOfWakeType is not 3 (current: ${targetDaysOfWakeType}). Please remove daysOfWeek parameter.`);
|
|
196
170
|
// Skip processing daysOfWeek when daysOfWakeType is not 3
|
|
197
171
|
}
|
|
198
172
|
else {
|
|
@@ -200,73 +174,53 @@ export const modifyAlarmTool = {
|
|
|
200
174
|
let normalizedDaysOfWeek = null;
|
|
201
175
|
// 情况1: 已经是数组
|
|
202
176
|
if (Array.isArray(params.daysOfWeek)) {
|
|
203
|
-
logger.log(`[MODIFY_ALARM_TOOL] ✅ daysOfWeek is already an array`);
|
|
204
177
|
normalizedDaysOfWeek = params.daysOfWeek;
|
|
205
178
|
}
|
|
206
179
|
// 情况2: 是字符串,尝试解析为 JSON 数组
|
|
207
180
|
else if (typeof params.daysOfWeek === 'string') {
|
|
208
|
-
logger.log(`[MODIFY_ALARM_TOOL] 🔄 daysOfWeek is a string, attempting to parse as JSON...`);
|
|
209
181
|
try {
|
|
210
182
|
const parsed = JSON.parse(params.daysOfWeek);
|
|
211
183
|
if (Array.isArray(parsed)) {
|
|
212
|
-
logger.log(`[MODIFY_ALARM_TOOL] ✅ Successfully parsed JSON string to array`);
|
|
213
184
|
normalizedDaysOfWeek = parsed;
|
|
214
185
|
}
|
|
215
186
|
else {
|
|
216
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Parsed JSON is not an array:`, typeof parsed);
|
|
217
187
|
throw new Error("daysOfWeek must be an array or a JSON string representing an array");
|
|
218
188
|
}
|
|
219
189
|
}
|
|
220
190
|
catch (parseError) {
|
|
221
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Failed to parse daysOfWeek as JSON:`, parseError);
|
|
222
191
|
throw new Error(`daysOfWeek must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
223
192
|
}
|
|
224
193
|
}
|
|
225
194
|
// 情况3: 其他类型,报错
|
|
226
195
|
else {
|
|
227
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid daysOfWeek type:`, typeof params.daysOfWeek);
|
|
228
196
|
throw new Error(`daysOfWeek must be an array or a JSON string, got ${typeof params.daysOfWeek}`);
|
|
229
197
|
}
|
|
230
198
|
// 验证数组非空
|
|
231
199
|
if (!normalizedDaysOfWeek || normalizedDaysOfWeek.length === 0) {
|
|
232
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ daysOfWeek array is empty`);
|
|
233
200
|
throw new Error("daysOfWeek array cannot be empty");
|
|
234
201
|
}
|
|
235
202
|
// 验证数组长度必须为1
|
|
236
203
|
if (normalizedDaysOfWeek.length !== 1) {
|
|
237
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ daysOfWeek array length must be 1, got ${normalizedDaysOfWeek.length}`);
|
|
238
204
|
throw new Error("daysOfWeek 仅支持长度为1的数组。如果需要一周中不同的几天,需要多次调用此工具");
|
|
239
205
|
}
|
|
240
206
|
// Validate each day
|
|
241
207
|
for (const day of normalizedDaysOfWeek) {
|
|
242
208
|
if (typeof day !== "string" || !DAYS_OF_WEEK_VALUES.includes(day)) {
|
|
243
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid day value: ${day}`);
|
|
244
209
|
throw new Error(`daysOfWeek must contain only: ${DAYS_OF_WEEK_VALUES.join(", ")}`);
|
|
245
210
|
}
|
|
246
211
|
}
|
|
247
212
|
intentParam.daysOfWeek = normalizedDaysOfWeek;
|
|
248
|
-
logger.log(`[MODIFY_ALARM_TOOL] - daysOfWeek: ${normalizedDaysOfWeek.join(", ")}`);
|
|
249
213
|
}
|
|
250
214
|
}
|
|
251
215
|
// Get session context
|
|
252
|
-
logger.log(`[MODIFY_ALARM_TOOL] 🔍 Attempting to get session context...`);
|
|
253
216
|
const sessionContext = getCurrentSessionContext();
|
|
254
217
|
if (!sessionContext) {
|
|
255
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ FAILED: No active session found!`);
|
|
256
|
-
logger.error(`[MODIFY_ALARM_TOOL] - toolCallId: ${toolCallId}`);
|
|
257
218
|
throw new Error("No active XY session found. Modify alarm tool can only be used during an active conversation.");
|
|
258
219
|
}
|
|
259
|
-
logger.log(`[MODIFY_ALARM_TOOL] ✅ Session context found`);
|
|
260
|
-
logger.log(`[MODIFY_ALARM_TOOL] - sessionId: ${sessionContext.sessionId}`);
|
|
261
|
-
logger.log(`[MODIFY_ALARM_TOOL] - taskId: ${sessionContext.taskId}`);
|
|
262
|
-
logger.log(`[MODIFY_ALARM_TOOL] - messageId: ${sessionContext.messageId}`);
|
|
263
220
|
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
264
221
|
// Get WebSocket manager
|
|
265
|
-
logger.log(`[MODIFY_ALARM_TOOL] 🔌 Getting WebSocket manager...`);
|
|
266
222
|
const wsManager = getXYWebSocketManager(config);
|
|
267
|
-
logger.log(`[MODIFY_ALARM_TOOL] ✅ WebSocket manager obtained`);
|
|
268
223
|
// Build ModifyAlarm command
|
|
269
|
-
logger.log(`[MODIFY_ALARM_TOOL] 📦 Building ModifyAlarm command...`);
|
|
270
224
|
const command = {
|
|
271
225
|
header: {
|
|
272
226
|
namespace: "Common",
|
|
@@ -282,15 +236,7 @@ export const modifyAlarmTool = {
|
|
|
282
236
|
actionResponse: true,
|
|
283
237
|
appType: "OHOS_APP",
|
|
284
238
|
timeOut: 5,
|
|
285
|
-
intentParam:
|
|
286
|
-
bundleName: "com.huawei.hmos.clock",
|
|
287
|
-
moduleName: "entry",
|
|
288
|
-
abilityName: "com.huawei.hmos.clock.phone",
|
|
289
|
-
intentName: "ModifyAlarm",
|
|
290
|
-
executeMode: "background",
|
|
291
|
-
intentRequestVersion: 100,
|
|
292
|
-
intentParam: intentParam,
|
|
293
|
-
},
|
|
239
|
+
intentParam: intentParam,
|
|
294
240
|
permissionId: [],
|
|
295
241
|
achieveType: "INTENT",
|
|
296
242
|
},
|
|
@@ -307,76 +253,35 @@ export const modifyAlarmTool = {
|
|
|
307
253
|
},
|
|
308
254
|
};
|
|
309
255
|
// Send command and wait for response (60 second timeout)
|
|
310
|
-
logger.log(`[MODIFY_ALARM_TOOL] ⏳ Setting up promise to wait for alarm modification response...`);
|
|
311
|
-
logger.log(`[MODIFY_ALARM_TOOL] - Timeout: 60 seconds`);
|
|
312
256
|
return new Promise((resolve, reject) => {
|
|
313
257
|
const timeout = setTimeout(() => {
|
|
314
|
-
logger.error(`[MODIFY_ALARM_TOOL] ⏰ Timeout: No response received within 60 seconds`);
|
|
315
258
|
wsManager.off("data-event", handler);
|
|
316
259
|
reject(new Error("修改闹钟超时(60秒)"));
|
|
317
260
|
}, 60000);
|
|
318
261
|
// Listen for data events from WebSocket
|
|
319
262
|
const handler = (event) => {
|
|
320
|
-
logger.log(`[MODIFY_ALARM_TOOL] 📨 Received data event:`, JSON.stringify(event));
|
|
321
263
|
if (event.intentName === "ModifyAlarm") {
|
|
322
|
-
logger.log(`[MODIFY_ALARM_TOOL] 🎯 ModifyAlarm event received`);
|
|
323
|
-
logger.log(`[MODIFY_ALARM_TOOL] - status: ${event.status}`);
|
|
324
264
|
clearTimeout(timeout);
|
|
325
265
|
wsManager.off("data-event", handler);
|
|
326
266
|
if (event.status === "success" && event.outputs) {
|
|
327
|
-
|
|
328
|
-
logger.log(`[MODIFY_ALARM_TOOL] - outputs:`, JSON.stringify(event.outputs));
|
|
329
|
-
// Check for error code in outputs
|
|
330
|
-
const code = event.outputs.code !== undefined ? event.outputs.code : null;
|
|
331
|
-
if (code !== null && code !== 0) {
|
|
332
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Device returned error`);
|
|
333
|
-
logger.error(`[MODIFY_ALARM_TOOL] - code: ${code}`);
|
|
334
|
-
const errorMsg = event.outputs.errorMsg || event.outputs.errMsg || "未知错误";
|
|
335
|
-
logger.error(`[MODIFY_ALARM_TOOL] - errorMsg: ${errorMsg}`);
|
|
336
|
-
reject(new Error(`修改闹钟失败: ${errorMsg} (错误代码: ${code})`));
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
// Extract result with safe navigation
|
|
340
|
-
const result = event.outputs.result || {};
|
|
341
|
-
logger.log(`[MODIFY_ALARM_TOOL] 📋 Alarm result:`, JSON.stringify(result));
|
|
342
|
-
// Build response with safe navigation
|
|
343
|
-
const response = {
|
|
344
|
-
success: true,
|
|
345
|
-
alarm: {
|
|
346
|
-
entityId: result.entityId || params.entityId,
|
|
347
|
-
entityType: result.entityType || result.entityName,
|
|
348
|
-
alarmTitle: result.alarmTitle,
|
|
349
|
-
alarmTime: result.alarmTime,
|
|
350
|
-
alarmState: result.alarmState,
|
|
351
|
-
alarmRingDuration: result.alarmRingDuration,
|
|
352
|
-
alarmSnoozeDuration: result.alarmSnoozeDuration,
|
|
353
|
-
alarmSnoozeTotal: result.alarmSnoozeTotal,
|
|
354
|
-
daysOfWakeType: result.daysOfWakeType,
|
|
355
|
-
},
|
|
356
|
-
code,
|
|
357
|
-
};
|
|
267
|
+
// 成功,直接返回完整的 event.outputs JSON 字符串
|
|
358
268
|
resolve({
|
|
359
269
|
content: [
|
|
360
270
|
{
|
|
361
271
|
type: "text",
|
|
362
|
-
text: JSON.stringify(
|
|
272
|
+
text: JSON.stringify(event.outputs),
|
|
363
273
|
},
|
|
364
274
|
],
|
|
365
275
|
});
|
|
366
276
|
}
|
|
367
277
|
else {
|
|
368
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Alarm modification failed`);
|
|
369
|
-
logger.error(`[MODIFY_ALARM_TOOL] - status: ${event.status}`);
|
|
370
|
-
logger.error(`[MODIFY_ALARM_TOOL] - outputs:`, JSON.stringify(event.outputs || {}));
|
|
371
278
|
reject(new Error(`修改闹钟失败: ${event.status}`));
|
|
372
279
|
}
|
|
373
280
|
}
|
|
374
281
|
};
|
|
375
282
|
// Register event handler
|
|
376
|
-
logger.log(`[MODIFY_ALARM_TOOL] 📡 Registering data-event handler on WebSocket manager`);
|
|
377
283
|
wsManager.on("data-event", handler);
|
|
378
284
|
// Send the command
|
|
379
|
-
logger.log(`[MODIFY_ALARM_TOOL] 📤 Sending ModifyAlarm command...`);
|
|
380
285
|
sendCommand({
|
|
381
286
|
config,
|
|
382
287
|
sessionId,
|
|
@@ -385,10 +290,8 @@ export const modifyAlarmTool = {
|
|
|
385
290
|
command,
|
|
386
291
|
})
|
|
387
292
|
.then(() => {
|
|
388
|
-
logger.log(`[MODIFY_ALARM_TOOL] ✅ Command sent successfully, waiting for response...`);
|
|
389
293
|
})
|
|
390
294
|
.catch((error) => {
|
|
391
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Failed to send command:`, error);
|
|
392
295
|
clearTimeout(timeout);
|
|
393
296
|
wsManager.off("data-event", handler);
|
|
394
297
|
reject(error);
|
|
@@ -410,17 +313,14 @@ function parseAlarmTimeToTimestamp(alarmTime) {
|
|
|
410
313
|
const trimmed = alarmTime.trim();
|
|
411
314
|
// Check basic format (should have at least 13 characters: YYYYMMDD hhmmss)
|
|
412
315
|
if (trimmed.length < 13) {
|
|
413
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ alarmTime too short: ${trimmed}`);
|
|
414
316
|
return null;
|
|
415
317
|
}
|
|
416
318
|
// Extract date and time parts
|
|
417
319
|
// Format: YYYYMMDD hhmmss
|
|
418
320
|
const datePart = trimmed.substring(0, 8); // YYYYMMDD
|
|
419
321
|
const timePart = trimmed.substring(8).trim(); // hhmmss (may have leading space)
|
|
420
|
-
logger.log(`[MODIFY_ALARM_TOOL] - datePart: ${datePart}, timePart: ${timePart}`);
|
|
421
322
|
// Validate lengths
|
|
422
323
|
if (datePart.length !== 8 || timePart.length !== 6) {
|
|
423
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid part lengths: datePart=${datePart.length}, timePart=${timePart.length}`);
|
|
424
324
|
return null;
|
|
425
325
|
}
|
|
426
326
|
// Parse components
|
|
@@ -430,45 +330,36 @@ function parseAlarmTimeToTimestamp(alarmTime) {
|
|
|
430
330
|
const hour = parseInt(timePart.substring(0, 2), 10);
|
|
431
331
|
const minute = parseInt(timePart.substring(2, 4), 10);
|
|
432
332
|
const second = parseInt(timePart.substring(4, 6), 10);
|
|
433
|
-
logger.log(`[MODIFY_ALARM_TOOL] - Parsed: ${year}-${month}-${day} ${hour}:${minute}:${second}`);
|
|
434
333
|
// Validate values
|
|
435
334
|
if (isNaN(year) || isNaN(month) || isNaN(day) ||
|
|
436
335
|
isNaN(hour) || isNaN(minute) || isNaN(second)) {
|
|
437
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ NaN detected in parsed values`);
|
|
438
336
|
return null;
|
|
439
337
|
}
|
|
440
338
|
// Validate ranges
|
|
441
339
|
if (month < 1 || month > 12) {
|
|
442
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid month: ${month}`);
|
|
443
340
|
return null;
|
|
444
341
|
}
|
|
445
342
|
if (day < 1 || day > 31) {
|
|
446
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid day: ${day}`);
|
|
447
343
|
return null;
|
|
448
344
|
}
|
|
449
345
|
if (hour < 0 || hour > 23) {
|
|
450
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid hour: ${hour}`);
|
|
451
346
|
return null;
|
|
452
347
|
}
|
|
453
348
|
if (minute < 0 || minute > 59) {
|
|
454
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid minute: ${minute}`);
|
|
455
349
|
return null;
|
|
456
350
|
}
|
|
457
351
|
if (second < 0 || second > 59) {
|
|
458
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid second: ${second}`);
|
|
459
352
|
return null;
|
|
460
353
|
}
|
|
461
354
|
// Create Date object and get timestamp
|
|
462
355
|
const date = new Date(year, month - 1, day, hour, minute, second);
|
|
463
356
|
const timestamp = date.getTime();
|
|
464
357
|
if (isNaN(timestamp)) {
|
|
465
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Generated timestamp is NaN`);
|
|
466
358
|
return null;
|
|
467
359
|
}
|
|
468
360
|
return timestamp;
|
|
469
361
|
}
|
|
470
362
|
catch (error) {
|
|
471
|
-
logger.error(`[MODIFY_ALARM_TOOL] ❌ Exception in parseAlarmTimeToTimestamp:`, error);
|
|
472
363
|
return null;
|
|
473
364
|
}
|
|
474
365
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
3
|
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
|
-
import { logger } from "../utils/logger.js";
|
|
5
4
|
/**
|
|
6
5
|
* XY modify note tool - appends content to an existing note on user's device.
|
|
7
6
|
* Requires entityId from search_notes tool as prerequisite.
|
|
@@ -13,7 +12,7 @@ import { logger } from "../utils/logger.js";
|
|
|
13
12
|
export const modifyNoteTool = {
|
|
14
13
|
name: "modify_note",
|
|
15
14
|
label: "Modify Note",
|
|
16
|
-
description: "在指定备忘录中追加新内容。使用前必须先调用 search_notes 工具获取备忘录的 entityId。参数说明:entityId 是备忘录的唯一标识符(从 search_notes 工具获取),text 是要追加的文本内容。注意:操作超时时间为60
|
|
15
|
+
description: "在指定备忘录中追加新内容。使用前必须先调用 search_notes 工具获取备忘录的 entityId。参数说明:entityId 是备忘录的唯一标识符(从 search_notes 工具获取),text 是要追加的文本内容。注意:操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。",
|
|
17
16
|
parameters: {
|
|
18
17
|
type: "object",
|
|
19
18
|
properties: {
|
|
@@ -29,34 +28,19 @@ export const modifyNoteTool = {
|
|
|
29
28
|
required: ["entityId", "text"],
|
|
30
29
|
},
|
|
31
30
|
async execute(toolCallId, params) {
|
|
32
|
-
logger.log(`[MODIFY_NOTE_TOOL] 🚀 Starting execution`);
|
|
33
|
-
logger.log(`[MODIFY_NOTE_TOOL] - toolCallId: ${toolCallId}`);
|
|
34
|
-
logger.log(`[MODIFY_NOTE_TOOL] - params:`, JSON.stringify(params));
|
|
35
|
-
logger.log(`[MODIFY_NOTE_TOOL] - timestamp: ${new Date().toISOString()}`);
|
|
36
31
|
// Validate parameters
|
|
37
32
|
if (!params.entityId || !params.text) {
|
|
38
|
-
logger.error(`[MODIFY_NOTE_TOOL] ❌ Missing required parameters`);
|
|
39
33
|
throw new Error("Missing required parameters: entityId and text are required");
|
|
40
34
|
}
|
|
41
35
|
// Get session context
|
|
42
|
-
logger.log(`[MODIFY_NOTE_TOOL] 🔍 Attempting to get session context...`);
|
|
43
36
|
const sessionContext = getCurrentSessionContext();
|
|
44
37
|
if (!sessionContext) {
|
|
45
|
-
logger.error(`[MODIFY_NOTE_TOOL] ❌ FAILED: No active session found!`);
|
|
46
|
-
logger.error(`[MODIFY_NOTE_TOOL] - toolCallId: ${toolCallId}`);
|
|
47
38
|
throw new Error("No active XY session found. Modify note tool can only be used during an active conversation.");
|
|
48
39
|
}
|
|
49
|
-
logger.log(`[MODIFY_NOTE_TOOL] ✅ Session context found`);
|
|
50
|
-
logger.log(`[MODIFY_NOTE_TOOL] - sessionId: ${sessionContext.sessionId}`);
|
|
51
|
-
logger.log(`[MODIFY_NOTE_TOOL] - taskId: ${sessionContext.taskId}`);
|
|
52
|
-
logger.log(`[MODIFY_NOTE_TOOL] - messageId: ${sessionContext.messageId}`);
|
|
53
40
|
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
54
41
|
// Get WebSocket manager
|
|
55
|
-
logger.log(`[MODIFY_NOTE_TOOL] 🔌 Getting WebSocket manager...`);
|
|
56
42
|
const wsManager = getXYWebSocketManager(config);
|
|
57
|
-
logger.log(`[MODIFY_NOTE_TOOL] ✅ WebSocket manager obtained`);
|
|
58
43
|
// Build ModifyNote command
|
|
59
|
-
logger.log(`[MODIFY_NOTE_TOOL] 📦 Building ModifyNote command...`);
|
|
60
44
|
const command = {
|
|
61
45
|
header: {
|
|
62
46
|
namespace: "Common",
|
|
@@ -92,56 +76,36 @@ export const modifyNoteTool = {
|
|
|
92
76
|
pageControlRelated: false,
|
|
93
77
|
},
|
|
94
78
|
};
|
|
95
|
-
logger.log(`[MODIFY_NOTE_TOOL] - entityId: ${params.entityId}`);
|
|
96
|
-
logger.log(`[MODIFY_NOTE_TOOL] - contentType: 1 (append mode)`);
|
|
97
|
-
logger.log(`[MODIFY_NOTE_TOOL] - text length: ${params.text.length} characters`);
|
|
98
79
|
// Send command and wait for response (60 second timeout)
|
|
99
|
-
logger.log(`[MODIFY_NOTE_TOOL] ⏳ Setting up promise to wait for note modification response...`);
|
|
100
|
-
logger.log(`[MODIFY_NOTE_TOOL] - Timeout: 60 seconds`);
|
|
101
80
|
return new Promise((resolve, reject) => {
|
|
102
81
|
const timeout = setTimeout(() => {
|
|
103
|
-
logger.error(`[MODIFY_NOTE_TOOL] ⏰ Timeout: No response received within 60 seconds`);
|
|
104
82
|
wsManager.off("data-event", handler);
|
|
105
83
|
reject(new Error("修改备忘录超时(60秒)"));
|
|
106
84
|
}, 60000);
|
|
107
85
|
// Listen for data events from WebSocket
|
|
108
86
|
const handler = (event) => {
|
|
109
|
-
logger.log(`[MODIFY_NOTE_TOOL] 📨 Received data event:`, JSON.stringify(event));
|
|
110
87
|
if (event.intentName === "ModifyNote") {
|
|
111
|
-
logger.log(`[MODIFY_NOTE_TOOL] 🎯 ModifyNote event received`);
|
|
112
|
-
logger.log(`[MODIFY_NOTE_TOOL] - status: ${event.status}`);
|
|
113
88
|
clearTimeout(timeout);
|
|
114
89
|
wsManager.off("data-event", handler);
|
|
115
90
|
if (event.status === "success" && event.outputs) {
|
|
116
|
-
|
|
117
|
-
logger.log(`[MODIFY_NOTE_TOOL] - outputs:`, JSON.stringify(event.outputs));
|
|
118
|
-
// Return the result directly as requested
|
|
119
|
-
const result = event.outputs.result;
|
|
120
|
-
logger.log(`[MODIFY_NOTE_TOOL] 📝 Note updated:`);
|
|
121
|
-
logger.log(`[MODIFY_NOTE_TOOL] - entityId: ${result?.entityId}`);
|
|
122
|
-
logger.log(`[MODIFY_NOTE_TOOL] - title: ${result?.title}`);
|
|
123
|
-
logger.log(`[MODIFY_NOTE_TOOL] - modifiedDate: ${result?.modifiedDate}`);
|
|
91
|
+
// 成功,直接返回完整的 event.outputs JSON 字符串
|
|
124
92
|
resolve({
|
|
125
93
|
content: [
|
|
126
94
|
{
|
|
127
95
|
type: "text",
|
|
128
|
-
text: JSON.stringify(
|
|
96
|
+
text: JSON.stringify(event.outputs),
|
|
129
97
|
},
|
|
130
98
|
],
|
|
131
99
|
});
|
|
132
100
|
}
|
|
133
101
|
else {
|
|
134
|
-
logger.error(`[MODIFY_NOTE_TOOL] ❌ Note modification failed`);
|
|
135
|
-
logger.error(`[MODIFY_NOTE_TOOL] - status: ${event.status}`);
|
|
136
102
|
reject(new Error(`修改备忘录失败: ${event.status}`));
|
|
137
103
|
}
|
|
138
104
|
}
|
|
139
105
|
};
|
|
140
106
|
// Register event handler
|
|
141
|
-
logger.log(`[MODIFY_NOTE_TOOL] 📡 Registering data-event handler on WebSocket manager`);
|
|
142
107
|
wsManager.on("data-event", handler);
|
|
143
108
|
// Send the command
|
|
144
|
-
logger.log(`[MODIFY_NOTE_TOOL] 📤 Sending ModifyNote command...`);
|
|
145
109
|
sendCommand({
|
|
146
110
|
config,
|
|
147
111
|
sessionId,
|
|
@@ -150,10 +114,8 @@ export const modifyNoteTool = {
|
|
|
150
114
|
command,
|
|
151
115
|
})
|
|
152
116
|
.then(() => {
|
|
153
|
-
logger.log(`[MODIFY_NOTE_TOOL] ✅ Command sent successfully, waiting for response...`);
|
|
154
117
|
})
|
|
155
118
|
.catch((error) => {
|
|
156
|
-
logger.error(`[MODIFY_NOTE_TOOL] ❌ Failed to send command:`, error);
|
|
157
119
|
clearTimeout(timeout);
|
|
158
120
|
wsManager.off("data-event", handler);
|
|
159
121
|
reject(error);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
3
|
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
|
-
import { logger } from "../utils/logger.js";
|
|
5
4
|
/**
|
|
6
5
|
* Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
|
|
7
6
|
* 抛出此错误会让 openclaw 返回 HTTP 400 而非 500,
|
|
@@ -26,6 +25,8 @@ export const noteTool = {
|
|
|
26
25
|
a. 操作超时时间为60秒,请勿重复调用此工具
|
|
27
26
|
b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
|
|
28
27
|
c. 调用工具前需认真检查调用参数是否满足工具要求
|
|
28
|
+
|
|
29
|
+
回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
|
|
29
30
|
`,
|
|
30
31
|
parameters: {
|
|
31
32
|
type: "object",
|
|
@@ -42,7 +43,6 @@ export const noteTool = {
|
|
|
42
43
|
required: ["title", "content"],
|
|
43
44
|
},
|
|
44
45
|
async execute(toolCallId, params) {
|
|
45
|
-
logger.debug("Executing note tool, toolCallId:", toolCallId);
|
|
46
46
|
// Validate parameters — 抛 ToolInputError 而非普通 Error,
|
|
47
47
|
// 让 openclaw 返回 400 而非 500,明确告知 LLM 这是参数错误,不应重试。
|
|
48
48
|
if (typeof params.title !== "string" || !params.title) {
|
|
@@ -101,28 +101,16 @@ export const noteTool = {
|
|
|
101
101
|
}, 60000);
|
|
102
102
|
// Listen for data events from WebSocket
|
|
103
103
|
const handler = (event) => {
|
|
104
|
-
logger.debug("Received data event:", event);
|
|
105
104
|
if (event.intentName === "CreateNote") {
|
|
106
105
|
clearTimeout(timeout);
|
|
107
106
|
wsManager.off("data-event", handler);
|
|
108
107
|
if (event.status === "success" && event.outputs) {
|
|
109
|
-
|
|
110
|
-
logger.log(`Note created: title=${result?.title}, id=${result?.entityId}`);
|
|
108
|
+
// 成功,直接返回完整的 event.outputs JSON 字符串
|
|
111
109
|
resolve({
|
|
112
110
|
content: [
|
|
113
111
|
{
|
|
114
112
|
type: "text",
|
|
115
|
-
text: JSON.stringify(
|
|
116
|
-
success: true,
|
|
117
|
-
note: {
|
|
118
|
-
entityId: result?.entityId,
|
|
119
|
-
title: result?.title,
|
|
120
|
-
content: result?.content,
|
|
121
|
-
entityName: result?.entityName,
|
|
122
|
-
modifiedDate: result?.modifiedDate,
|
|
123
|
-
},
|
|
124
|
-
code,
|
|
125
|
-
}),
|
|
113
|
+
text: JSON.stringify(event.outputs),
|
|
126
114
|
},
|
|
127
115
|
],
|
|
128
116
|
});
|