@ynhcj/xiaoyi-channel 0.0.26-beta → 0.0.27-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.
Files changed (33) hide show
  1. package/dist/src/bot.js +13 -3
  2. package/dist/src/channel.js +10 -1
  3. package/dist/src/tools/calendar-tool.js +2 -2
  4. package/dist/src/tools/call-phone-tool.d.ts +5 -0
  5. package/dist/src/tools/call-phone-tool.js +183 -0
  6. package/dist/src/tools/create-alarm-tool.d.ts +7 -0
  7. package/dist/src/tools/create-alarm-tool.js +395 -0
  8. package/dist/src/tools/delete-alarm-tool.d.ts +11 -0
  9. package/dist/src/tools/delete-alarm-tool.js +238 -0
  10. package/dist/src/tools/location-tool.js +2 -2
  11. package/dist/src/tools/modify-alarm-tool.d.ts +9 -0
  12. package/dist/src/tools/modify-alarm-tool.js +433 -0
  13. package/dist/src/tools/modify-note-tool.js +2 -2
  14. package/dist/src/tools/note-tool.js +2 -2
  15. package/dist/src/tools/search-alarm-tool.d.ts +8 -0
  16. package/dist/src/tools/search-alarm-tool.js +389 -0
  17. package/dist/src/tools/search-calendar-tool.js +2 -2
  18. package/dist/src/tools/search-contact-tool.js +2 -2
  19. package/dist/src/tools/search-file-tool.d.ts +5 -0
  20. package/dist/src/tools/search-file-tool.js +173 -0
  21. package/dist/src/tools/search-message-tool.d.ts +5 -0
  22. package/dist/src/tools/search-message-tool.js +173 -0
  23. package/dist/src/tools/search-note-tool.js +2 -2
  24. package/dist/src/tools/search-photo-gallery-tool.js +2 -2
  25. package/dist/src/tools/send-message-tool.d.ts +5 -0
  26. package/dist/src/tools/send-message-tool.js +189 -0
  27. package/dist/src/tools/session-manager.d.ts +12 -0
  28. package/dist/src/tools/session-manager.js +33 -0
  29. package/dist/src/tools/upload-file-tool.d.ts +13 -0
  30. package/dist/src/tools/upload-file-tool.js +265 -0
  31. package/dist/src/tools/upload-photo-tool.js +2 -2
  32. package/dist/src/tools/xiaoyi-gui-tool.js +2 -2
  33. package/package.json +1 -1
@@ -0,0 +1,433 @@
1
+ import { getXYWebSocketManager } from "../client.js";
2
+ import { sendCommand } from "../formatter.js";
3
+ import { getCurrentSessionContext } from "./session-manager.js";
4
+ import { logger } from "../utils/logger.js";
5
+ // Enum definitions for alarm parameters (same as create-alarm-tool)
6
+ const ALARM_SNOOZE_DURATION_VALUES = [5, 10, 15, 20, 25, 30];
7
+ const ALARM_SNOOZE_TOTAL_VALUES = [0, 1, 3, 5, 10];
8
+ const ALARM_RING_DURATION_VALUES = [1, 5, 10, 15, 20, 30];
9
+ const DAYS_OF_WAKE_TYPE_VALUES = [0, 1, 2, 3, 4];
10
+ const DAYS_OF_WEEK_VALUES = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
11
+ /**
12
+ * XY modify alarm tool - modifies an existing alarm on user's device.
13
+ * Requires entityId from search_alarm or create_alarm tool.
14
+ *
15
+ * Prerequisites:
16
+ * 1. Call search_alarm or create_alarm tool first to get entityId
17
+ * 2. Use the entityId to identify which alarm to modify
18
+ */
19
+ export const modifyAlarmTool = {
20
+ name: "modify_alarm",
21
+ label: "Modify Alarm",
22
+ description: `修改用户设备上已存在的闹钟。
23
+
24
+ 必需参数:
25
+ - entityId: 闹钟的唯一标识符,必须先通过 search_alarm 或 create_alarm 工具获取
26
+
27
+ 可选参数(与创建闹钟的参数完全一致):
28
+ - alarmTime: 闹钟时间,格式必须为:YYYYMMDD hhmmss(例如:20240315 143000)
29
+ - alarmTitle: 闹钟名称/标题
30
+ - alarmState: 闹钟开启状态,0=关闭,1=开启
31
+ - alarmSnoozeDuration: 小睡间隔(分钟),枚举值:5,10,15,20,25,30
32
+ - alarmSnoozeTotal: 再响次数,枚举值:0,1,3,5,10
33
+ - alarmRingDuration: 响铃时长(分钟),枚举值:1,5,10,15,20,30
34
+ - daysOfWakeType: 闹钟响铃类型,枚举值:0=单次,1=法定节假日,2=每天,3=自定义,4=法定工作日
35
+ - daysOfWeek: 自定义响铃星期(当daysOfWakeType=3时需要),数组,枚举值:Mon,Tue,Wed,Thu,Fri,Sat,Sun
36
+
37
+ 使用流程:
38
+ 1. 先调用 search_alarm 工具查询闹钟,获取 entityId
39
+ 2. 调用此工具修改闹钟,传入 entityId 和需要修改的参数
40
+
41
+ 注意事项:操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。`,
42
+ parameters: {
43
+ type: "object",
44
+ properties: {
45
+ entityId: {
46
+ type: "string",
47
+ description: "闹钟的唯一标识符,必须先通过 search_alarm 或 create_alarm 工具获取",
48
+ },
49
+ alarmTime: {
50
+ type: "string",
51
+ description: "闹钟时间,格式必须为:YYYYMMDD hhmmss(例如:20240315 143000)",
52
+ },
53
+ alarmTitle: {
54
+ type: "string",
55
+ description: "闹钟名称/标题",
56
+ },
57
+ alarmState: {
58
+ type: "number",
59
+ description: "闹钟开启状态:0=关闭,1=开启",
60
+ },
61
+ alarmSnoozeDuration: {
62
+ type: "number",
63
+ description: "小睡间隔(分钟),枚举值:5,10,15,20,25,30",
64
+ },
65
+ alarmSnoozeTotal: {
66
+ type: "number",
67
+ description: "再响次数,枚举值:0,1,3,5,10",
68
+ },
69
+ alarmRingDuration: {
70
+ type: "number",
71
+ description: "响铃时长(分钟),枚举值:1,5,10,15,20,30",
72
+ },
73
+ daysOfWakeType: {
74
+ type: "number",
75
+ description: "闹钟响铃类型:0=单次,1=法定节假日,2=每天,3=自定义,4=法定工作日",
76
+ },
77
+ daysOfWeek: {
78
+ type: "array",
79
+ items: {
80
+ type: "string",
81
+ },
82
+ description: "自定义响铃星期(当daysOfWakeType=3时需要),枚举值:Mon,Tue,Wed,Thu,Fri,Sat,Sun",
83
+ },
84
+ },
85
+ required: ["entityId"],
86
+ },
87
+ async execute(toolCallId, params) {
88
+ logger.log(`[MODIFY_ALARM_TOOL] 🚀 Starting execution`);
89
+ logger.log(`[MODIFY_ALARM_TOOL] - toolCallId: ${toolCallId}`);
90
+ logger.log(`[MODIFY_ALARM_TOOL] - params:`, JSON.stringify(params));
91
+ logger.log(`[MODIFY_ALARM_TOOL] - timestamp: ${new Date().toISOString()}`);
92
+ // ===== Validate required parameter: entityId =====
93
+ if (!params.entityId || typeof params.entityId !== "string") {
94
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Missing or invalid entityId`);
95
+ throw new Error("Missing required parameter: entityId must be a string obtained from search_alarm or create_alarm");
96
+ }
97
+ logger.log(`[MODIFY_ALARM_TOOL] - entityId: ${params.entityId}`);
98
+ // ===== Build intentParam with provided parameters =====
99
+ const intentParam = {
100
+ entityName: "Alarm",
101
+ entityId: params.entityId,
102
+ };
103
+ // Parse and convert alarmTime if provided
104
+ if (params.alarmTime !== undefined && params.alarmTime !== null) {
105
+ if (typeof params.alarmTime !== "string") {
106
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmTime type`);
107
+ throw new Error("alarmTime must be a string in format YYYYMMDD hhmmss");
108
+ }
109
+ logger.log(`[MODIFY_ALARM_TOOL] 🕒 Parsing alarmTime: ${params.alarmTime}`);
110
+ const alarmTimeMs = parseAlarmTimeToTimestamp(params.alarmTime);
111
+ if (alarmTimeMs === null) {
112
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmTime format`);
113
+ throw new Error("Invalid alarmTime format. Required format: YYYYMMDD hhmmss (e.g., 20240315 143000)");
114
+ }
115
+ intentParam.alarmTime = alarmTimeMs;
116
+ logger.log(`[MODIFY_ALARM_TOOL] ✅ alarmTime converted to timestamp: ${alarmTimeMs}`);
117
+ }
118
+ // Add alarmTitle if provided
119
+ if (params.alarmTitle !== undefined && params.alarmTitle !== null) {
120
+ if (typeof params.alarmTitle !== "string") {
121
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmTitle type`);
122
+ throw new Error("alarmTitle must be a string");
123
+ }
124
+ intentParam.alarmTitle = params.alarmTitle;
125
+ logger.log(`[MODIFY_ALARM_TOOL] - alarmTitle: ${params.alarmTitle}`);
126
+ }
127
+ // Add alarmState if provided
128
+ if (params.alarmState !== undefined && params.alarmState !== null) {
129
+ if (typeof params.alarmState !== "number") {
130
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmState type`);
131
+ throw new Error("alarmState must be a number");
132
+ }
133
+ if (!ALARM_STATE_VALUES.includes(params.alarmState)) {
134
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmState value: ${params.alarmState}`);
135
+ throw new Error(`alarmState must be one of: ${ALARM_STATE_VALUES.join(", ")}`);
136
+ }
137
+ intentParam.alarmState = params.alarmState;
138
+ logger.log(`[MODIFY_ALARM_TOOL] - alarmState: ${params.alarmState}`);
139
+ }
140
+ // Add alarmSnoozeDuration if provided
141
+ if (params.alarmSnoozeDuration !== undefined && params.alarmSnoozeDuration !== null) {
142
+ if (typeof params.alarmSnoozeDuration !== "number") {
143
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmSnoozeDuration type`);
144
+ throw new Error("alarmSnoozeDuration must be a number");
145
+ }
146
+ if (!ALARM_SNOOZE_DURATION_VALUES.includes(params.alarmSnoozeDuration)) {
147
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmSnoozeDuration value: ${params.alarmSnoozeDuration}`);
148
+ throw new Error(`alarmSnoozeDuration must be one of: ${ALARM_SNOOZE_DURATION_VALUES.join(", ")}`);
149
+ }
150
+ intentParam.alarmSnoozeDuration = params.alarmSnoozeDuration;
151
+ logger.log(`[MODIFY_ALARM_TOOL] - alarmSnoozeDuration: ${params.alarmSnoozeDuration}`);
152
+ }
153
+ // Add alarmSnoozeTotal if provided
154
+ if (params.alarmSnoozeTotal !== undefined && params.alarmSnoozeTotal !== null) {
155
+ if (typeof params.alarmSnoozeTotal !== "number") {
156
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmSnoozeTotal type`);
157
+ throw new Error("alarmSnoozeTotal must be a number");
158
+ }
159
+ if (!ALARM_SNOOZE_TOTAL_VALUES.includes(params.alarmSnoozeTotal)) {
160
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmSnoozeTotal value: ${params.alarmSnoozeTotal}`);
161
+ throw new Error(`alarmSnoozeTotal must be one of: ${ALARM_SNOOZE_TOTAL_VALUES.join(", ")}`);
162
+ }
163
+ intentParam.alarmSnoozeTotal = params.alarmSnoozeTotal;
164
+ logger.log(`[MODIFY_ALARM_TOOL] - alarmSnoozeTotal: ${params.alarmSnoozeTotal}`);
165
+ }
166
+ // Add alarmRingDuration if provided
167
+ if (params.alarmRingDuration !== undefined && params.alarmRingDuration !== null) {
168
+ if (typeof params.alarmRingDuration !== "number") {
169
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmRingDuration type`);
170
+ throw new Error("alarmRingDuration must be a number");
171
+ }
172
+ if (!ALARM_RING_DURATION_VALUES.includes(params.alarmRingDuration)) {
173
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid alarmRingDuration value: ${params.alarmRingDuration}`);
174
+ throw new Error(`alarmRingDuration must be one of: ${ALARM_RING_DURATION_VALUES.join(", ")}`);
175
+ }
176
+ intentParam.alarmRingDuration = params.alarmRingDuration;
177
+ logger.log(`[MODIFY_ALARM_TOOL] - alarmRingDuration: ${params.alarmRingDuration}`);
178
+ }
179
+ // Add daysOfWakeType if provided
180
+ let currentDaysOfWakeType = null;
181
+ if (params.daysOfWakeType !== undefined && params.daysOfWakeType !== null) {
182
+ if (typeof params.daysOfWakeType !== "number") {
183
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid daysOfWakeType type`);
184
+ throw new Error("daysOfWakeType must be a number");
185
+ }
186
+ if (!DAYS_OF_WAKE_TYPE_VALUES.includes(params.daysOfWakeType)) {
187
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid daysOfWakeType value: ${params.daysOfWakeType}`);
188
+ throw new Error(`daysOfWakeType must be one of: ${DAYS_OF_WAKE_TYPE_VALUES.join(", ")}`);
189
+ }
190
+ intentParam.daysOfWakeType = params.daysOfWakeType;
191
+ currentDaysOfWakeType = params.daysOfWakeType;
192
+ logger.log(`[MODIFY_ALARM_TOOL] - daysOfWakeType: ${params.daysOfWakeType}`);
193
+ }
194
+ // Add daysOfWeek if provided
195
+ if (params.daysOfWeek !== undefined && params.daysOfWeek !== null) {
196
+ if (!Array.isArray(params.daysOfWeek)) {
197
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid daysOfWeek type`);
198
+ throw new Error("daysOfWeek must be an array");
199
+ }
200
+ // Validate each day
201
+ for (const day of params.daysOfWeek) {
202
+ if (typeof day !== "string" || !DAYS_OF_WEEK_VALUES.includes(day)) {
203
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid day value: ${day}`);
204
+ throw new Error(`daysOfWeek must contain only: ${DAYS_OF_WEEK_VALUES.join(", ")}`);
205
+ }
206
+ }
207
+ intentParam.daysOfWeek = params.daysOfWeek;
208
+ logger.log(`[MODIFY_ALARM_TOOL] - daysOfWeek: ${params.daysOfWeek.join(", ")}`);
209
+ }
210
+ // Get session context
211
+ logger.log(`[MODIFY_ALARM_TOOL] 🔍 Attempting to get session context...`);
212
+ const sessionContext = getCurrentSessionContext();
213
+ if (!sessionContext) {
214
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ FAILED: No active session found!`);
215
+ logger.error(`[MODIFY_ALARM_TOOL] - toolCallId: ${toolCallId}`);
216
+ throw new Error("No active XY session found. Modify alarm tool can only be used during an active conversation.");
217
+ }
218
+ logger.log(`[MODIFY_ALARM_TOOL] ✅ Session context found`);
219
+ logger.log(`[MODIFY_ALARM_TOOL] - sessionId: ${sessionContext.sessionId}`);
220
+ logger.log(`[MODIFY_ALARM_TOOL] - taskId: ${sessionContext.taskId}`);
221
+ logger.log(`[MODIFY_ALARM_TOOL] - messageId: ${sessionContext.messageId}`);
222
+ const { config, sessionId, taskId, messageId } = sessionContext;
223
+ // Get WebSocket manager
224
+ logger.log(`[MODIFY_ALARM_TOOL] 🔌 Getting WebSocket manager...`);
225
+ const wsManager = getXYWebSocketManager(config);
226
+ logger.log(`[MODIFY_ALARM_TOOL] ✅ WebSocket manager obtained`);
227
+ // Build ModifyAlarm command
228
+ logger.log(`[MODIFY_ALARM_TOOL] 📦 Building ModifyAlarm command...`);
229
+ const command = {
230
+ header: {
231
+ namespace: "Common",
232
+ name: "Action",
233
+ },
234
+ payload: {
235
+ cardParam: {},
236
+ executeParam: {
237
+ executeMode: "background",
238
+ intentName: "ModifyAlarm",
239
+ bundleName: "com.huawei.hmos.clock",
240
+ needUnlock: true,
241
+ actionResponse: true,
242
+ appType: "OHOS_APP",
243
+ timeOut: 5,
244
+ intentParam: {
245
+ bundleName: "com.huawei.hmos.clock",
246
+ moduleName: "entry",
247
+ abilityName: "com.huawei.hmos.clock.phone",
248
+ intentName: "ModifyAlarm",
249
+ executeMode: "background",
250
+ intentRequestVersion: 100,
251
+ intentParam: intentParam,
252
+ },
253
+ permissionId: [],
254
+ achieveType: "INTENT",
255
+ },
256
+ responses: [
257
+ {
258
+ resultCode: "",
259
+ displayText: "",
260
+ ttsText: "",
261
+ },
262
+ ],
263
+ needUploadResult: true,
264
+ noHalfPage: false,
265
+ pageControlRelated: false,
266
+ },
267
+ };
268
+ // Send command and wait for response (60 second timeout)
269
+ logger.log(`[MODIFY_ALARM_TOOL] ⏳ Setting up promise to wait for alarm modification response...`);
270
+ logger.log(`[MODIFY_ALARM_TOOL] - Timeout: 60 seconds`);
271
+ return new Promise((resolve, reject) => {
272
+ const timeout = setTimeout(() => {
273
+ logger.error(`[MODIFY_ALARM_TOOL] ⏰ Timeout: No response received within 60 seconds`);
274
+ wsManager.off("data-event", handler);
275
+ reject(new Error("修改闹钟超时(60秒)"));
276
+ }, 60000);
277
+ // Listen for data events from WebSocket
278
+ const handler = (event) => {
279
+ logger.log(`[MODIFY_ALARM_TOOL] 📨 Received data event:`, JSON.stringify(event));
280
+ if (event.intentName === "ModifyAlarm") {
281
+ logger.log(`[MODIFY_ALARM_TOOL] 🎯 ModifyAlarm event received`);
282
+ logger.log(`[MODIFY_ALARM_TOOL] - status: ${event.status}`);
283
+ clearTimeout(timeout);
284
+ wsManager.off("data-event", handler);
285
+ if (event.status === "success" && event.outputs) {
286
+ logger.log(`[MODIFY_ALARM_TOOL] ✅ Alarm modification completed successfully`);
287
+ logger.log(`[MODIFY_ALARM_TOOL] - outputs:`, JSON.stringify(event.outputs));
288
+ // Check for error code in outputs
289
+ const code = event.outputs.code !== undefined ? event.outputs.code : null;
290
+ if (code !== null && code !== 0) {
291
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Device returned error`);
292
+ logger.error(`[MODIFY_ALARM_TOOL] - code: ${code}`);
293
+ const errorMsg = event.outputs.errorMsg || event.outputs.errMsg || "未知错误";
294
+ logger.error(`[MODIFY_ALARM_TOOL] - errorMsg: ${errorMsg}`);
295
+ reject(new Error(`修改闹钟失败: ${errorMsg} (错误代码: ${code})`));
296
+ return;
297
+ }
298
+ // Extract result with safe navigation
299
+ const result = event.outputs.result || {};
300
+ logger.log(`[MODIFY_ALARM_TOOL] 📋 Alarm result:`, JSON.stringify(result));
301
+ // Build response with safe navigation
302
+ const response = {
303
+ success: true,
304
+ alarm: {
305
+ entityId: result.entityId || params.entityId,
306
+ entityType: result.entityType || result.entityName,
307
+ alarmTitle: result.alarmTitle,
308
+ alarmTime: result.alarmTime,
309
+ alarmState: result.alarmState,
310
+ alarmRingDuration: result.alarmRingDuration,
311
+ alarmSnoozeDuration: result.alarmSnoozeDuration,
312
+ alarmSnoozeTotal: result.alarmSnoozeTotal,
313
+ daysOfWakeType: result.daysOfWakeType,
314
+ },
315
+ code,
316
+ };
317
+ resolve({
318
+ content: [
319
+ {
320
+ type: "text",
321
+ text: JSON.stringify(response),
322
+ },
323
+ ],
324
+ });
325
+ }
326
+ else {
327
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Alarm modification failed`);
328
+ logger.error(`[MODIFY_ALARM_TOOL] - status: ${event.status}`);
329
+ logger.error(`[MODIFY_ALARM_TOOL] - outputs:`, JSON.stringify(event.outputs || {}));
330
+ reject(new Error(`修改闹钟失败: ${event.status}`));
331
+ }
332
+ }
333
+ };
334
+ // Register event handler
335
+ logger.log(`[MODIFY_ALARM_TOOL] 📡 Registering data-event handler on WebSocket manager`);
336
+ wsManager.on("data-event", handler);
337
+ // Send the command
338
+ logger.log(`[MODIFY_ALARM_TOOL] 📤 Sending ModifyAlarm command...`);
339
+ sendCommand({
340
+ config,
341
+ sessionId,
342
+ taskId,
343
+ messageId,
344
+ command,
345
+ })
346
+ .then(() => {
347
+ logger.log(`[MODIFY_ALARM_TOOL] ✅ Command sent successfully, waiting for response...`);
348
+ })
349
+ .catch((error) => {
350
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Failed to send command:`, error);
351
+ clearTimeout(timeout);
352
+ wsManager.off("data-event", handler);
353
+ reject(error);
354
+ });
355
+ });
356
+ },
357
+ };
358
+ // Enum for alarm state
359
+ const ALARM_STATE_VALUES = [0, 1];
360
+ /**
361
+ * Parse alarmTime string (YYYYMMDD hhmmss) to timestamp in milliseconds
362
+ * @param alarmTime - Time string in format "YYYYMMDD hhmmss" (e.g., "20240315 143000")
363
+ * @returns Timestamp in milliseconds, or null if parsing fails
364
+ */
365
+ function parseAlarmTimeToTimestamp(alarmTime) {
366
+ try {
367
+ // Expected format: YYYYMMDD hhmmss
368
+ // Example: 20240315 143000
369
+ const trimmed = alarmTime.trim();
370
+ // Check basic format (should have at least 13 characters: YYYYMMDD hhmmss)
371
+ if (trimmed.length < 13) {
372
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ alarmTime too short: ${trimmed}`);
373
+ return null;
374
+ }
375
+ // Extract date and time parts
376
+ // Format: YYYYMMDD hhmmss
377
+ const datePart = trimmed.substring(0, 8); // YYYYMMDD
378
+ const timePart = trimmed.substring(8).trim(); // hhmmss (may have leading space)
379
+ logger.log(`[MODIFY_ALARM_TOOL] - datePart: ${datePart}, timePart: ${timePart}`);
380
+ // Validate lengths
381
+ if (datePart.length !== 8 || timePart.length !== 6) {
382
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid part lengths: datePart=${datePart.length}, timePart=${timePart.length}`);
383
+ return null;
384
+ }
385
+ // Parse components
386
+ const year = parseInt(datePart.substring(0, 4), 10);
387
+ const month = parseInt(datePart.substring(4, 6), 10);
388
+ const day = parseInt(datePart.substring(6, 8), 10);
389
+ const hour = parseInt(timePart.substring(0, 2), 10);
390
+ const minute = parseInt(timePart.substring(2, 4), 10);
391
+ const second = parseInt(timePart.substring(4, 6), 10);
392
+ logger.log(`[MODIFY_ALARM_TOOL] - Parsed: ${year}-${month}-${day} ${hour}:${minute}:${second}`);
393
+ // Validate values
394
+ if (isNaN(year) || isNaN(month) || isNaN(day) ||
395
+ isNaN(hour) || isNaN(minute) || isNaN(second)) {
396
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ NaN detected in parsed values`);
397
+ return null;
398
+ }
399
+ // Validate ranges
400
+ if (month < 1 || month > 12) {
401
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid month: ${month}`);
402
+ return null;
403
+ }
404
+ if (day < 1 || day > 31) {
405
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid day: ${day}`);
406
+ return null;
407
+ }
408
+ if (hour < 0 || hour > 23) {
409
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid hour: ${hour}`);
410
+ return null;
411
+ }
412
+ if (minute < 0 || minute > 59) {
413
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid minute: ${minute}`);
414
+ return null;
415
+ }
416
+ if (second < 0 || second > 59) {
417
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Invalid second: ${second}`);
418
+ return null;
419
+ }
420
+ // Create Date object and get timestamp
421
+ const date = new Date(year, month - 1, day, hour, minute, second);
422
+ const timestamp = date.getTime();
423
+ if (isNaN(timestamp)) {
424
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Generated timestamp is NaN`);
425
+ return null;
426
+ }
427
+ return timestamp;
428
+ }
429
+ catch (error) {
430
+ logger.error(`[MODIFY_ALARM_TOOL] ❌ Exception in parseAlarmTimeToTimestamp:`, error);
431
+ return null;
432
+ }
433
+ }
@@ -1,6 +1,6 @@
1
1
  import { getXYWebSocketManager } from "../client.js";
2
2
  import { sendCommand } from "../formatter.js";
3
- import { getLatestSessionContext } from "./session-manager.js";
3
+ import { getCurrentSessionContext } from "./session-manager.js";
4
4
  import { logger } from "../utils/logger.js";
5
5
  /**
6
6
  * XY modify note tool - appends content to an existing note on user's device.
@@ -40,7 +40,7 @@ export const modifyNoteTool = {
40
40
  }
41
41
  // Get session context
42
42
  logger.log(`[MODIFY_NOTE_TOOL] 🔍 Attempting to get session context...`);
43
- const sessionContext = getLatestSessionContext();
43
+ const sessionContext = getCurrentSessionContext();
44
44
  if (!sessionContext) {
45
45
  logger.error(`[MODIFY_NOTE_TOOL] ❌ FAILED: No active session found!`);
46
46
  logger.error(`[MODIFY_NOTE_TOOL] - toolCallId: ${toolCallId}`);
@@ -1,6 +1,6 @@
1
1
  import { getXYWebSocketManager } from "../client.js";
2
2
  import { sendCommand } from "../formatter.js";
3
- import { getLatestSessionContext } from "./session-manager.js";
3
+ import { getCurrentSessionContext } from "./session-manager.js";
4
4
  import { logger } from "../utils/logger.js";
5
5
  /**
6
6
  * XY note tool - creates a note on user's device.
@@ -31,7 +31,7 @@ export const noteTool = {
31
31
  throw new Error("Missing required parameters: title and content are required");
32
32
  }
33
33
  // Get session context
34
- const sessionContext = getLatestSessionContext();
34
+ const sessionContext = getCurrentSessionContext();
35
35
  if (!sessionContext) {
36
36
  throw new Error("No active XY session found. Note tool can only be used during an active conversation.");
37
37
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * XY search alarm tool - searches alarms on user's device.
3
+ * Returns matching alarms based on various filter criteria.
4
+ *
5
+ * At least one search criterion must be provided.
6
+ * Multiple criteria can be combined.
7
+ */
8
+ export declare const searchAlarmTool: any;