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