@ynhcj/xiaoyi-channel 0.0.87-beta → 0.0.87-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 (131) hide show
  1. package/dist/index.d.ts +6 -9
  2. package/dist/index.js +26 -21
  3. package/dist/src/bot.js +26 -3
  4. package/dist/src/channel.js +2 -30
  5. package/dist/src/client.js +7 -1
  6. package/dist/src/login-token-handler.d.ts +8 -0
  7. package/dist/src/login-token-handler.js +60 -0
  8. package/dist/src/message-queue.d.ts +17 -0
  9. package/dist/src/message-queue.js +51 -0
  10. package/dist/src/monitor.js +64 -4
  11. package/dist/src/provider.d.ts +2 -1
  12. package/dist/src/provider.js +440 -31
  13. package/dist/src/reply-dispatcher.js +6 -0
  14. package/dist/src/runtime.d.ts +3 -11
  15. package/dist/src/runtime.js +6 -18
  16. package/dist/src/self-evolution-handler.d.ts +7 -0
  17. package/dist/src/self-evolution-handler.js +140 -0
  18. package/dist/src/self-evolution-keyword.d.ts +9 -0
  19. package/dist/src/self-evolution-keyword.js +147 -0
  20. package/dist/src/self-evolution-tool-result-nudge.d.ts +3 -0
  21. package/dist/src/self-evolution-tool-result-nudge.js +96 -0
  22. package/dist/src/skill-retriever/config.d.ts +4 -0
  23. package/dist/src/skill-retriever/config.js +23 -0
  24. package/dist/src/skill-retriever/hooks.d.ts +22 -0
  25. package/dist/src/skill-retriever/hooks.js +82 -0
  26. package/dist/src/skill-retriever/tool-search.d.ts +16 -0
  27. package/dist/src/skill-retriever/tool-search.js +172 -0
  28. package/dist/src/skill-retriever/types.d.ts +36 -0
  29. package/dist/src/skill-retriever/types.js +1 -0
  30. package/dist/src/task-manager.d.ts +4 -0
  31. package/dist/src/task-manager.js +12 -1
  32. package/dist/src/tools/calendar-tool.d.ts +2 -1
  33. package/dist/src/tools/calendar-tool.js +112 -116
  34. package/dist/src/tools/call-device-tool.d.ts +6 -0
  35. package/dist/src/tools/call-device-tool.js +153 -0
  36. package/dist/src/tools/call-phone-tool.d.ts +2 -1
  37. package/dist/src/tools/call-phone-tool.js +109 -113
  38. package/dist/src/tools/create-alarm-tool.d.ts +2 -1
  39. package/dist/src/tools/create-alarm-tool.js +227 -231
  40. package/dist/src/tools/create-all-tools.d.ts +16 -0
  41. package/dist/src/tools/create-all-tools.js +50 -0
  42. package/dist/src/tools/delete-alarm-tool.d.ts +2 -1
  43. package/dist/src/tools/delete-alarm-tool.js +131 -135
  44. package/dist/src/tools/device-tool-map.js +2 -0
  45. package/dist/src/tools/get-alarm-tool-schema.d.ts +17 -0
  46. package/dist/src/tools/get-alarm-tool-schema.js +17 -0
  47. package/dist/src/tools/get-calendar-tool-schema.d.ts +17 -0
  48. package/dist/src/tools/get-calendar-tool-schema.js +13 -0
  49. package/dist/src/tools/get-collection-tool-schema.d.ts +17 -0
  50. package/dist/src/tools/get-collection-tool-schema.js +12 -0
  51. package/dist/src/tools/get-contact-tool-schema.d.ts +17 -0
  52. package/dist/src/tools/get-contact-tool-schema.js +17 -0
  53. package/dist/src/tools/get-device-file-tool-schema.d.ts +17 -0
  54. package/dist/src/tools/get-device-file-tool-schema.js +14 -0
  55. package/dist/src/tools/get-email-tool-schema.d.ts +17 -0
  56. package/dist/src/tools/get-email-tool-schema.js +12 -0
  57. package/dist/src/tools/get-note-tool-schema.d.ts +17 -0
  58. package/dist/src/tools/get-note-tool-schema.js +15 -0
  59. package/dist/src/tools/get-photo-tool-schema.d.ts +17 -0
  60. package/dist/src/tools/get-photo-tool-schema.js +13 -0
  61. package/dist/src/tools/image-reading-tool.d.ts +2 -1
  62. package/dist/src/tools/image-reading-tool.js +86 -90
  63. package/dist/src/tools/location-tool.d.ts +2 -1
  64. package/dist/src/tools/location-tool.js +87 -91
  65. package/dist/src/tools/login-token-tool.d.ts +6 -0
  66. package/dist/src/tools/login-token-tool.js +133 -0
  67. package/dist/src/tools/modify-alarm-tool.d.ts +2 -1
  68. package/dist/src/tools/modify-alarm-tool.js +232 -236
  69. package/dist/src/tools/modify-note-tool.d.ts +2 -1
  70. package/dist/src/tools/modify-note-tool.js +104 -108
  71. package/dist/src/tools/note-tool.d.ts +2 -1
  72. package/dist/src/tools/note-tool.js +103 -107
  73. package/dist/src/tools/query-app-message-tool.d.ts +5 -0
  74. package/dist/src/tools/query-app-message-tool.js +135 -0
  75. package/dist/src/tools/query-memory-data-tool.d.ts +5 -0
  76. package/dist/src/tools/query-memory-data-tool.js +151 -0
  77. package/dist/src/tools/query-todo-task-tool.d.ts +5 -0
  78. package/dist/src/tools/query-todo-task-tool.js +130 -0
  79. package/dist/src/tools/save-file-to-phone-tool.d.ts +2 -1
  80. package/dist/src/tools/save-file-to-phone-tool.js +127 -131
  81. package/dist/src/tools/save-media-to-gallery-tool.d.ts +2 -1
  82. package/dist/src/tools/save-media-to-gallery-tool.js +134 -138
  83. package/dist/src/tools/save-self-evolution-skill-tool.d.ts +2 -0
  84. package/dist/src/tools/save-self-evolution-skill-tool.js +410 -0
  85. package/dist/src/tools/schema-tool-factory.d.ts +27 -0
  86. package/dist/src/tools/schema-tool-factory.js +32 -0
  87. package/dist/src/tools/search-alarm-tool.d.ts +2 -1
  88. package/dist/src/tools/search-alarm-tool.js +171 -175
  89. package/dist/src/tools/search-calendar-tool.d.ts +2 -1
  90. package/dist/src/tools/search-calendar-tool.js +145 -149
  91. package/dist/src/tools/search-contact-tool.d.ts +2 -1
  92. package/dist/src/tools/search-contact-tool.js +98 -102
  93. package/dist/src/tools/search-email-tool.d.ts +2 -1
  94. package/dist/src/tools/search-email-tool.js +107 -111
  95. package/dist/src/tools/search-file-tool.d.ts +2 -1
  96. package/dist/src/tools/search-file-tool.js +99 -103
  97. package/dist/src/tools/search-message-tool.d.ts +2 -1
  98. package/dist/src/tools/search-message-tool.js +100 -104
  99. package/dist/src/tools/search-note-tool.d.ts +2 -1
  100. package/dist/src/tools/search-note-tool.js +95 -99
  101. package/dist/src/tools/search-photo-gallery-tool.d.ts +2 -1
  102. package/dist/src/tools/search-photo-gallery-tool.js +34 -38
  103. package/dist/src/tools/send-email-tool.d.ts +5 -0
  104. package/dist/src/tools/send-email-tool.js +131 -0
  105. package/dist/src/tools/send-file-to-user-tool.d.ts +2 -1
  106. package/dist/src/tools/send-file-to-user-tool.js +153 -155
  107. package/dist/src/tools/send-message-tool.d.ts +2 -1
  108. package/dist/src/tools/send-message-tool.js +119 -123
  109. package/dist/src/tools/session-manager.d.ts +21 -6
  110. package/dist/src/tools/session-manager.js +135 -18
  111. package/dist/src/tools/upload-file-tool.d.ts +2 -1
  112. package/dist/src/tools/upload-file-tool.js +79 -83
  113. package/dist/src/tools/upload-photo-tool.d.ts +2 -1
  114. package/dist/src/tools/upload-photo-tool.js +70 -74
  115. package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +2 -1
  116. package/dist/src/tools/xiaoyi-add-collection-tool.js +143 -147
  117. package/dist/src/tools/xiaoyi-collection-tool.d.ts +2 -1
  118. package/dist/src/tools/xiaoyi-collection-tool.js +112 -116
  119. package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +2 -1
  120. package/dist/src/tools/xiaoyi-delete-collection-tool.js +124 -128
  121. package/dist/src/tools/xiaoyi-gui-tool.d.ts +2 -1
  122. package/dist/src/tools/xiaoyi-gui-tool.js +84 -88
  123. package/dist/src/utils/runtime-manager.js +24 -2
  124. package/dist/src/utils/self-evolution-manager.d.ts +10 -0
  125. package/dist/src/utils/self-evolution-manager.js +68 -0
  126. package/dist/src/utils/tool-call-nudge-manager.d.ts +16 -0
  127. package/dist/src/utils/tool-call-nudge-manager.js +47 -0
  128. package/dist/src/websocket.d.ts +3 -0
  129. package/dist/src/websocket.js +94 -24
  130. package/openclaw.plugin.json +21 -0
  131. package/package.json +3 -3
@@ -1,6 +1,5 @@
1
1
  import { getXYWebSocketManager } from "../client.js";
2
2
  import { sendCommand } from "../formatter.js";
3
- import { getCurrentSessionContext } from "./session-manager.js";
4
3
  // Enum definitions for alarm parameters (same as create-alarm-tool)
5
4
  const ALARM_SNOOZE_DURATION_VALUES = [5, 10, 15, 20, 25, 30];
6
5
  const ALARM_SNOOZE_TOTAL_VALUES = [0, 1, 3, 5, 10];
@@ -15,10 +14,12 @@ const DAYS_OF_WEEK_VALUES = ["Mon", "Tues", "Wed", "Thur", "Fri", "Sat", "Sun"];
15
14
  * 1. Call search_alarm or create_alarm tool first to get entityId
16
15
  * 2. Use the entityId to identify which alarm to modify
17
16
  */
18
- export const modifyAlarmTool = {
19
- name: "modify_alarm",
20
- label: "Modify Alarm",
21
- description: `修改用户设备上已存在的闹钟。
17
+ export function createModifyAlarmTool(ctx) {
18
+ const { config, sessionId, taskId, messageId } = ctx;
19
+ return {
20
+ name: "modify_alarm",
21
+ label: "Modify Alarm",
22
+ description: `修改用户设备上已存在的闹钟。
22
23
 
23
24
  使用流程:
24
25
  1. 先调用 search_alarm 工具查询闹钟,获取 entityId,
@@ -28,260 +29,255 @@ export const modifyAlarmTool = {
28
29
  注意事项:操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。
29
30
 
30
31
  回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。`,
31
- parameters: {
32
- type: "object",
33
- properties: {
34
- entityId: {
35
- type: "string",
36
- description: "(必需)闹钟的唯一标识符,必须先通过 search_alarm 或 create_alarm 工具获取",
37
- },
38
- alarmTime: {
39
- type: "string",
40
- description: "(可选)闹钟时间,格式必须为:YYYYMMDD hhmmss(例如:20240315 143000)",
41
- },
42
- alarmTitle: {
43
- type: "string",
44
- description: "(可选)闹钟名称/标题",
45
- },
46
- alarmState: {
47
- type: "number",
48
- description: "(可选)闹钟开启状态,枚举值:0=关闭,1=开启",
49
- },
50
- alarmSnoozeDuration: {
51
- type: "number",
52
- description: "(可选)小睡间隔(分钟),枚举值:5,10,15,20,25,30",
53
- },
54
- alarmSnoozeTotal: {
55
- type: "number",
56
- description: "(可选)再响次数,枚举值:0,1,3,5,10",
57
- },
58
- alarmRingDuration: {
59
- type: "number",
60
- description: "(可选)响铃时长(分钟),枚举值:1,5,10,15,20,30",
61
- },
62
- daysOfWakeType: {
63
- type: "number",
64
- description: "(可选)闹钟响铃类型,枚举值:0=单次,1=法定节假日,2=每天,3=自定义,4=法定工作日",
65
- },
66
- daysOfWeek: {
67
- // 不指定 type,允许传入数组或 JSON 字符串
68
- // 具体的类型验证和转换在 execute 函数内部进行
69
- description: "(可选)自定义响铃星期,仅当daysOfWakeType=3(自定义时间)时必需且有效,其他情况不要传递此参数。数组或JSON字符串,枚举值:Mon,Tues,Wed,Thur,Fri,Sat,Sun",
32
+ parameters: {
33
+ type: "object",
34
+ properties: {
35
+ entityId: {
36
+ type: "string",
37
+ description: "(必需)闹钟的唯一标识符,必须先通过 search_alarm 或 create_alarm 工具获取",
38
+ },
39
+ alarmTime: {
40
+ type: "string",
41
+ description: "(可选)闹钟时间,格式必须为:YYYYMMDD hhmmss(例如:20240315 143000)",
42
+ },
43
+ alarmTitle: {
44
+ type: "string",
45
+ description: "(可选)闹钟名称/标题",
46
+ },
47
+ alarmState: {
48
+ type: "number",
49
+ description: "(可选)闹钟开启状态,枚举值:0=关闭,1=开启",
50
+ },
51
+ alarmSnoozeDuration: {
52
+ type: "number",
53
+ description: "(可选)小睡间隔(分钟),枚举值:5,10,15,20,25,30",
54
+ },
55
+ alarmSnoozeTotal: {
56
+ type: "number",
57
+ description: "(可选)再响次数,枚举值:0,1,3,5,10",
58
+ },
59
+ alarmRingDuration: {
60
+ type: "number",
61
+ description: "(可选)响铃时长(分钟),枚举值:1,5,10,15,20,30",
62
+ },
63
+ daysOfWakeType: {
64
+ type: "number",
65
+ description: "(可选)闹钟响铃类型,枚举值:0=单次,1=法定节假日,2=每天,3=自定义,4=法定工作日",
66
+ },
67
+ daysOfWeek: {
68
+ // 不指定 type,允许传入数组或 JSON 字符串
69
+ // 具体的类型验证和转换在 execute 函数内部进行
70
+ description: "(可选)自定义响铃星期,仅当daysOfWakeType=3(自定义时间)时必需且有效,其他情况不要传递此参数。数组或JSON字符串,枚举值:Mon,Tues,Wed,Thur,Fri,Sat,Sun",
71
+ },
70
72
  },
73
+ required: ["entityId"],
71
74
  },
72
- required: ["entityId"],
73
- },
74
- async execute(toolCallId, params) {
75
- // ===== Validate required parameter: entityId =====
76
- if (!params.entityId || typeof params.entityId !== "string") {
77
- throw new Error("Missing required parameter: entityId must be a string obtained from search_alarm or create_alarm");
78
- }
79
- // ===== Build intentParam with provided parameters =====
80
- const intentParam = {
81
- entityName: "Alarm",
82
- entityId: params.entityId,
83
- };
84
- // Parse and convert alarmTime if provided
85
- if (params.alarmTime !== undefined && params.alarmTime !== null) {
86
- if (typeof params.alarmTime !== "string") {
87
- throw new Error("alarmTime must be a string in format YYYYMMDD hhmmss");
88
- }
89
- const alarmTimeMs = parseAlarmTimeToTimestamp(params.alarmTime);
90
- if (alarmTimeMs === null) {
91
- throw new Error("Invalid alarmTime format. Required format: YYYYMMDD hhmmss (e.g., 20240315 143000)");
75
+ async execute(toolCallId, params) {
76
+ // ===== Validate required parameter: entityId =====
77
+ if (!params.entityId || typeof params.entityId !== "string") {
78
+ throw new Error("Missing required parameter: entityId must be a string obtained from search_alarm or create_alarm");
92
79
  }
93
- intentParam.alarmTime = alarmTimeMs;
94
- }
95
- // Add alarmTitle if provided
96
- if (params.alarmTitle !== undefined && params.alarmTitle !== null) {
97
- if (typeof params.alarmTitle !== "string") {
98
- throw new Error("alarmTitle must be a string");
99
- }
100
- intentParam.alarmTitle = params.alarmTitle;
101
- }
102
- // Add alarmState if provided
103
- if (params.alarmState !== undefined && params.alarmState !== null) {
104
- if (typeof params.alarmState !== "number") {
105
- throw new Error("alarmState must be a number");
106
- }
107
- if (!ALARM_STATE_VALUES.includes(params.alarmState)) {
108
- throw new Error(`alarmState must be one of: ${ALARM_STATE_VALUES.join(", ")}`);
109
- }
110
- intentParam.alarmState = params.alarmState;
111
- }
112
- // Add alarmSnoozeDuration if provided
113
- if (params.alarmSnoozeDuration !== undefined && params.alarmSnoozeDuration !== null) {
114
- if (typeof params.alarmSnoozeDuration !== "number") {
115
- throw new Error("alarmSnoozeDuration must be a number");
116
- }
117
- if (!ALARM_SNOOZE_DURATION_VALUES.includes(params.alarmSnoozeDuration)) {
118
- throw new Error(`alarmSnoozeDuration must be one of: ${ALARM_SNOOZE_DURATION_VALUES.join(", ")}`);
119
- }
120
- intentParam.alarmSnoozeDuration = params.alarmSnoozeDuration;
121
- }
122
- // Add alarmSnoozeTotal if provided
123
- if (params.alarmSnoozeTotal !== undefined && params.alarmSnoozeTotal !== null) {
124
- if (typeof params.alarmSnoozeTotal !== "number") {
125
- throw new Error("alarmSnoozeTotal must be a number");
80
+ // ===== Build intentParam with provided parameters =====
81
+ const intentParam = {
82
+ entityName: "Alarm",
83
+ entityId: params.entityId,
84
+ };
85
+ // Parse and convert alarmTime if provided
86
+ if (params.alarmTime !== undefined && params.alarmTime !== null) {
87
+ if (typeof params.alarmTime !== "string") {
88
+ throw new Error("alarmTime must be a string in format YYYYMMDD hhmmss");
89
+ }
90
+ const alarmTimeMs = parseAlarmTimeToTimestamp(params.alarmTime);
91
+ if (alarmTimeMs === null) {
92
+ throw new Error("Invalid alarmTime format. Required format: YYYYMMDD hhmmss (e.g., 20240315 143000)");
93
+ }
94
+ intentParam.alarmTime = alarmTimeMs;
126
95
  }
127
- if (!ALARM_SNOOZE_TOTAL_VALUES.includes(params.alarmSnoozeTotal)) {
128
- throw new Error(`alarmSnoozeTotal must be one of: ${ALARM_SNOOZE_TOTAL_VALUES.join(", ")}`);
96
+ // Add alarmTitle if provided
97
+ if (params.alarmTitle !== undefined && params.alarmTitle !== null) {
98
+ if (typeof params.alarmTitle !== "string") {
99
+ throw new Error("alarmTitle must be a string");
100
+ }
101
+ intentParam.alarmTitle = params.alarmTitle;
129
102
  }
130
- intentParam.alarmSnoozeTotal = params.alarmSnoozeTotal;
131
- }
132
- // Add alarmRingDuration if provided
133
- if (params.alarmRingDuration !== undefined && params.alarmRingDuration !== null) {
134
- if (typeof params.alarmRingDuration !== "number") {
135
- throw new Error("alarmRingDuration must be a number");
103
+ // Add alarmState if provided
104
+ if (params.alarmState !== undefined && params.alarmState !== null) {
105
+ if (typeof params.alarmState !== "number") {
106
+ throw new Error("alarmState must be a number");
107
+ }
108
+ if (!ALARM_STATE_VALUES.includes(params.alarmState)) {
109
+ throw new Error(`alarmState must be one of: ${ALARM_STATE_VALUES.join(", ")}`);
110
+ }
111
+ intentParam.alarmState = params.alarmState;
136
112
  }
137
- if (!ALARM_RING_DURATION_VALUES.includes(params.alarmRingDuration)) {
138
- throw new Error(`alarmRingDuration must be one of: ${ALARM_RING_DURATION_VALUES.join(", ")}`);
113
+ // Add alarmSnoozeDuration if provided
114
+ if (params.alarmSnoozeDuration !== undefined && params.alarmSnoozeDuration !== null) {
115
+ if (typeof params.alarmSnoozeDuration !== "number") {
116
+ throw new Error("alarmSnoozeDuration must be a number");
117
+ }
118
+ if (!ALARM_SNOOZE_DURATION_VALUES.includes(params.alarmSnoozeDuration)) {
119
+ throw new Error(`alarmSnoozeDuration must be one of: ${ALARM_SNOOZE_DURATION_VALUES.join(", ")}`);
120
+ }
121
+ intentParam.alarmSnoozeDuration = params.alarmSnoozeDuration;
139
122
  }
140
- intentParam.alarmRingDuration = params.alarmRingDuration;
141
- }
142
- // Add daysOfWakeType if provided
143
- if (params.daysOfWakeType !== undefined && params.daysOfWakeType !== null) {
144
- if (typeof params.daysOfWakeType !== "number") {
145
- throw new Error("daysOfWakeType must be a number");
123
+ // Add alarmSnoozeTotal if provided
124
+ if (params.alarmSnoozeTotal !== undefined && params.alarmSnoozeTotal !== null) {
125
+ if (typeof params.alarmSnoozeTotal !== "number") {
126
+ throw new Error("alarmSnoozeTotal must be a number");
127
+ }
128
+ if (!ALARM_SNOOZE_TOTAL_VALUES.includes(params.alarmSnoozeTotal)) {
129
+ throw new Error(`alarmSnoozeTotal must be one of: ${ALARM_SNOOZE_TOTAL_VALUES.join(", ")}`);
130
+ }
131
+ intentParam.alarmSnoozeTotal = params.alarmSnoozeTotal;
146
132
  }
147
- if (!DAYS_OF_WAKE_TYPE_VALUES.includes(params.daysOfWakeType)) {
148
- throw new Error(`daysOfWakeType must be one of: ${DAYS_OF_WAKE_TYPE_VALUES.join(", ")}`);
133
+ // Add alarmRingDuration if provided
134
+ if (params.alarmRingDuration !== undefined && params.alarmRingDuration !== null) {
135
+ if (typeof params.alarmRingDuration !== "number") {
136
+ throw new Error("alarmRingDuration must be a number");
137
+ }
138
+ if (!ALARM_RING_DURATION_VALUES.includes(params.alarmRingDuration)) {
139
+ throw new Error(`alarmRingDuration must be one of: ${ALARM_RING_DURATION_VALUES.join(", ")}`);
140
+ }
141
+ intentParam.alarmRingDuration = params.alarmRingDuration;
149
142
  }
150
- intentParam.daysOfWakeType = params.daysOfWakeType;
151
- }
152
- // Add daysOfWeek if provided - only valid when daysOfWakeType is 3
153
- if (params.daysOfWeek !== undefined && params.daysOfWeek !== null) {
154
- // Check if daysOfWakeType is 3 or will be set to 3
155
- const targetDaysOfWakeType = params.daysOfWakeType !== undefined ? params.daysOfWakeType : null;
156
- if (targetDaysOfWakeType !== null && targetDaysOfWakeType !== 3) {
157
- // Skip processing daysOfWeek when daysOfWakeType is not 3
143
+ // Add daysOfWakeType if provided
144
+ if (params.daysOfWakeType !== undefined && params.daysOfWakeType !== null) {
145
+ if (typeof params.daysOfWakeType !== "number") {
146
+ throw new Error("daysOfWakeType must be a number");
147
+ }
148
+ if (!DAYS_OF_WAKE_TYPE_VALUES.includes(params.daysOfWakeType)) {
149
+ throw new Error(`daysOfWakeType must be one of: ${DAYS_OF_WAKE_TYPE_VALUES.join(", ")}`);
150
+ }
151
+ intentParam.daysOfWakeType = params.daysOfWakeType;
158
152
  }
159
- else {
160
- // ===== 参数规范化:兼容数组和 JSON 字符串 =====
161
- let normalizedDaysOfWeek = null;
162
- // 情况1: 已经是数组
163
- if (Array.isArray(params.daysOfWeek)) {
164
- normalizedDaysOfWeek = params.daysOfWeek;
153
+ // Add daysOfWeek if provided - only valid when daysOfWakeType is 3
154
+ if (params.daysOfWeek !== undefined && params.daysOfWeek !== null) {
155
+ // Check if daysOfWakeType is 3 or will be set to 3
156
+ const targetDaysOfWakeType = params.daysOfWakeType !== undefined ? params.daysOfWakeType : null;
157
+ if (targetDaysOfWakeType !== null && targetDaysOfWakeType !== 3) {
158
+ // Skip processing daysOfWeek when daysOfWakeType is not 3
165
159
  }
166
- // 情况2: 是字符串,尝试解析为 JSON 数组
167
- else if (typeof params.daysOfWeek === 'string') {
168
- try {
169
- const parsed = JSON.parse(params.daysOfWeek);
170
- if (Array.isArray(parsed)) {
171
- normalizedDaysOfWeek = parsed;
160
+ else {
161
+ // ===== 参数规范化:兼容数组和 JSON 字符串 =====
162
+ let normalizedDaysOfWeek = null;
163
+ // 情况1: 已经是数组
164
+ if (Array.isArray(params.daysOfWeek)) {
165
+ normalizedDaysOfWeek = params.daysOfWeek;
166
+ }
167
+ // 情况2: 是字符串,尝试解析为 JSON 数组
168
+ else if (typeof params.daysOfWeek === 'string') {
169
+ try {
170
+ const parsed = JSON.parse(params.daysOfWeek);
171
+ if (Array.isArray(parsed)) {
172
+ normalizedDaysOfWeek = parsed;
173
+ }
174
+ else {
175
+ throw new Error("daysOfWeek must be an array or a JSON string representing an array");
176
+ }
172
177
  }
173
- else {
174
- throw new Error("daysOfWeek must be an array or a JSON string representing an array");
178
+ catch (parseError) {
179
+ throw new Error(`daysOfWeek must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
175
180
  }
176
181
  }
177
- catch (parseError) {
178
- throw new Error(`daysOfWeek must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
182
+ // 情况3: 其他类型,报错
183
+ else {
184
+ throw new Error(`daysOfWeek must be an array or a JSON string, got ${typeof params.daysOfWeek}`);
179
185
  }
180
- }
181
- // 情况3: 其他类型,报错
182
- else {
183
- throw new Error(`daysOfWeek must be an array or a JSON string, got ${typeof params.daysOfWeek}`);
184
- }
185
- // 验证数组非空
186
- if (!normalizedDaysOfWeek || normalizedDaysOfWeek.length === 0) {
187
- throw new Error("daysOfWeek array cannot be empty");
188
- }
189
- // Validate each day
190
- for (const day of normalizedDaysOfWeek) {
191
- if (typeof day !== "string" || !DAYS_OF_WEEK_VALUES.includes(day)) {
192
- throw new Error(`daysOfWeek must contain only: ${DAYS_OF_WEEK_VALUES.join(", ")}`);
186
+ // 验证数组非空
187
+ if (!normalizedDaysOfWeek || normalizedDaysOfWeek.length === 0) {
188
+ throw new Error("daysOfWeek array cannot be empty");
189
+ }
190
+ // Validate each day
191
+ for (const day of normalizedDaysOfWeek) {
192
+ if (typeof day !== "string" || !DAYS_OF_WEEK_VALUES.includes(day)) {
193
+ throw new Error(`daysOfWeek must contain only: ${DAYS_OF_WEEK_VALUES.join(", ")}`);
194
+ }
193
195
  }
196
+ intentParam.daysOfWeek = normalizedDaysOfWeek;
194
197
  }
195
- intentParam.daysOfWeek = normalizedDaysOfWeek;
196
198
  }
197
- }
198
- // Get session context
199
- const sessionContext = getCurrentSessionContext();
200
- if (!sessionContext) {
201
- throw new Error("No active XY session found. Modify alarm tool can only be used during an active conversation.");
202
- }
203
- const { config, sessionId, taskId, messageId } = sessionContext;
204
- // Get WebSocket manager
205
- const wsManager = getXYWebSocketManager(config);
206
- // Build ModifyAlarm command
207
- const command = {
208
- header: {
209
- namespace: "Common",
210
- name: "Action",
211
- },
212
- payload: {
213
- cardParam: {},
214
- executeParam: {
215
- executeMode: "background",
216
- intentName: "ModifyAlarm",
217
- bundleName: "com.huawei.hmos.clock",
218
- needUnlock: true,
219
- actionResponse: true,
220
- appType: "OHOS_APP",
221
- timeOut: 5,
222
- intentParam: intentParam,
223
- permissionId: [],
224
- achieveType: "INTENT",
199
+ // Get WebSocket manager
200
+ const wsManager = getXYWebSocketManager(config);
201
+ // Build ModifyAlarm command
202
+ const command = {
203
+ header: {
204
+ namespace: "Common",
205
+ name: "Action",
225
206
  },
226
- responses: [
227
- {
228
- resultCode: "",
229
- displayText: "",
230
- ttsText: "",
207
+ payload: {
208
+ cardParam: {},
209
+ executeParam: {
210
+ executeMode: "background",
211
+ intentName: "ModifyAlarm",
212
+ bundleName: "com.huawei.hmos.clock",
213
+ needUnlock: true,
214
+ actionResponse: true,
215
+ appType: "OHOS_APP",
216
+ timeOut: 5,
217
+ intentParam: intentParam,
218
+ permissionId: [],
219
+ achieveType: "INTENT",
231
220
  },
232
- ],
233
- needUploadResult: true,
234
- noHalfPage: false,
235
- pageControlRelated: false,
236
- },
237
- };
238
- // Send command and wait for response (60 second timeout)
239
- return new Promise((resolve, reject) => {
240
- const timeout = setTimeout(() => {
241
- wsManager.off("data-event", handler);
242
- reject(new Error("修改闹钟超时(60秒)"));
243
- }, 60000);
244
- // Listen for data events from WebSocket
245
- const handler = (event) => {
246
- if (event.intentName === "ModifyAlarm") {
247
- clearTimeout(timeout);
221
+ responses: [
222
+ {
223
+ resultCode: "",
224
+ displayText: "",
225
+ ttsText: "",
226
+ },
227
+ ],
228
+ needUploadResult: true,
229
+ noHalfPage: false,
230
+ pageControlRelated: false,
231
+ },
232
+ };
233
+ // Send command and wait for response (60 second timeout)
234
+ return new Promise((resolve, reject) => {
235
+ const timeout = setTimeout(() => {
248
236
  wsManager.off("data-event", handler);
249
- if (event.status === "success" && event.outputs) {
250
- // 成功,直接返回完整的 event.outputs JSON 字符串
251
- resolve({
252
- content: [
253
- {
254
- type: "text",
255
- text: JSON.stringify(event.outputs),
256
- },
257
- ],
258
- });
259
- }
260
- else {
261
- reject(new Error(`修改闹钟失败: ${event.status}`));
237
+ reject(new Error("修改闹钟超时(60秒)"));
238
+ }, 60000);
239
+ // Listen for data events from WebSocket
240
+ const handler = (event) => {
241
+ if (event.intentName === "ModifyAlarm") {
242
+ clearTimeout(timeout);
243
+ wsManager.off("data-event", handler);
244
+ if (event.status === "success" && event.outputs) {
245
+ // 成功,直接返回完整的 event.outputs JSON 字符串
246
+ resolve({
247
+ content: [
248
+ {
249
+ type: "text",
250
+ text: JSON.stringify(event.outputs),
251
+ },
252
+ ],
253
+ });
254
+ }
255
+ else {
256
+ reject(new Error(`修改闹钟失败: ${event.status}`));
257
+ }
262
258
  }
263
- }
264
- };
265
- // Register event handler
266
- wsManager.on("data-event", handler);
267
- // Send the command
268
- sendCommand({
269
- config,
270
- sessionId,
271
- taskId,
272
- messageId,
273
- command,
274
- })
275
- .then(() => {
276
- })
277
- .catch((error) => {
278
- clearTimeout(timeout);
279
- wsManager.off("data-event", handler);
280
- reject(error);
259
+ };
260
+ // Register event handler
261
+ wsManager.on("data-event", handler);
262
+ // Send the command
263
+ sendCommand({
264
+ config,
265
+ sessionId,
266
+ taskId,
267
+ messageId,
268
+ command,
269
+ })
270
+ .then(() => {
271
+ })
272
+ .catch((error) => {
273
+ clearTimeout(timeout);
274
+ wsManager.off("data-event", handler);
275
+ reject(error);
276
+ });
281
277
  });
282
- });
283
- },
284
- };
278
+ },
279
+ };
280
+ }
285
281
  // Enum for alarm state
286
282
  const ALARM_STATE_VALUES = [0, 1];
287
283
  /**
@@ -1,3 +1,4 @@
1
+ import type { SessionContext } from "./session-manager.js";
1
2
  /**
2
3
  * XY modify note tool - appends content to an existing note on user's device.
3
4
  * Requires entityId from search_notes tool as prerequisite.
@@ -6,4 +7,4 @@
6
7
  * 1. Call search_notes tool first to get the entityId of target note
7
8
  * 2. Use the entityId to append content to that note
8
9
  */
9
- export declare const modifyNoteTool: any;
10
+ export declare function createModifyNoteTool(ctx: SessionContext): any;