@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.
- package/dist/index.d.ts +6 -9
- package/dist/index.js +26 -21
- package/dist/src/bot.js +26 -3
- package/dist/src/channel.js +2 -29
- package/dist/src/client.js +7 -1
- package/dist/src/login-token-handler.d.ts +8 -0
- package/dist/src/login-token-handler.js +60 -0
- package/dist/src/message-queue.d.ts +17 -0
- package/dist/src/message-queue.js +51 -0
- package/dist/src/monitor.js +64 -4
- package/dist/src/provider.d.ts +2 -1
- package/dist/src/provider.js +442 -25
- package/dist/src/reply-dispatcher.js +6 -0
- package/dist/src/runtime.d.ts +3 -11
- package/dist/src/runtime.js +6 -18
- package/dist/src/self-evolution-handler.d.ts +7 -0
- package/dist/src/self-evolution-handler.js +140 -0
- package/dist/src/self-evolution-keyword.d.ts +9 -0
- package/dist/src/self-evolution-keyword.js +147 -0
- package/dist/src/self-evolution-tool-result-nudge.d.ts +3 -0
- package/dist/src/self-evolution-tool-result-nudge.js +96 -0
- package/dist/src/skill-retriever/config.d.ts +4 -0
- package/dist/src/skill-retriever/config.js +23 -0
- package/dist/src/skill-retriever/hooks.d.ts +22 -0
- package/dist/src/skill-retriever/hooks.js +82 -0
- package/dist/src/skill-retriever/tool-search.d.ts +16 -0
- package/dist/src/skill-retriever/tool-search.js +172 -0
- package/dist/src/skill-retriever/types.d.ts +36 -0
- package/dist/src/skill-retriever/types.js +1 -0
- package/dist/src/task-manager.d.ts +4 -0
- package/dist/src/task-manager.js +12 -1
- package/dist/src/tools/calendar-tool.d.ts +2 -1
- package/dist/src/tools/calendar-tool.js +112 -116
- package/dist/src/tools/call-device-tool.d.ts +6 -0
- package/dist/src/tools/call-device-tool.js +153 -0
- package/dist/src/tools/call-phone-tool.d.ts +2 -1
- package/dist/src/tools/call-phone-tool.js +109 -113
- package/dist/src/tools/create-alarm-tool.d.ts +2 -1
- package/dist/src/tools/create-alarm-tool.js +226 -241
- package/dist/src/tools/create-all-tools.d.ts +16 -0
- package/dist/src/tools/create-all-tools.js +50 -0
- package/dist/src/tools/delete-alarm-tool.d.ts +2 -1
- package/dist/src/tools/delete-alarm-tool.js +131 -138
- package/dist/src/tools/device-tool-map.js +5 -3
- package/dist/src/tools/get-alarm-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-alarm-tool-schema.js +17 -0
- package/dist/src/tools/get-calendar-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-calendar-tool-schema.js +13 -0
- package/dist/src/tools/get-collection-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-collection-tool-schema.js +12 -0
- package/dist/src/tools/get-contact-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-contact-tool-schema.js +17 -0
- package/dist/src/tools/get-device-file-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-device-file-tool-schema.js +14 -0
- package/dist/src/tools/get-email-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-email-tool-schema.js +12 -0
- package/dist/src/tools/get-note-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-note-tool-schema.js +15 -0
- package/dist/src/tools/get-photo-tool-schema.d.ts +17 -0
- package/dist/src/tools/get-photo-tool-schema.js +13 -0
- package/dist/src/tools/image-reading-tool.d.ts +2 -1
- package/dist/src/tools/image-reading-tool.js +87 -94
- package/dist/src/tools/location-tool.d.ts +2 -1
- package/dist/src/tools/location-tool.js +87 -91
- package/dist/src/tools/login-token-tool.d.ts +6 -0
- package/dist/src/tools/login-token-tool.js +133 -0
- package/dist/src/tools/modify-alarm-tool.d.ts +2 -1
- package/dist/src/tools/modify-alarm-tool.js +233 -250
- package/dist/src/tools/modify-note-tool.d.ts +2 -1
- package/dist/src/tools/modify-note-tool.js +104 -108
- package/dist/src/tools/note-tool.d.ts +2 -1
- package/dist/src/tools/note-tool.js +103 -107
- package/dist/src/tools/query-app-message-tool.d.ts +5 -0
- package/dist/src/tools/query-app-message-tool.js +135 -0
- package/dist/src/tools/query-memory-data-tool.d.ts +5 -0
- package/dist/src/tools/query-memory-data-tool.js +151 -0
- package/dist/src/tools/query-todo-task-tool.d.ts +5 -0
- package/dist/src/tools/query-todo-task-tool.js +130 -0
- package/dist/src/tools/save-file-to-phone-tool.d.ts +2 -1
- package/dist/src/tools/save-file-to-phone-tool.js +127 -135
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +2 -1
- package/dist/src/tools/save-media-to-gallery-tool.js +134 -142
- package/dist/src/tools/save-self-evolution-skill-tool.d.ts +2 -0
- package/dist/src/tools/save-self-evolution-skill-tool.js +410 -0
- package/dist/src/tools/schema-tool-factory.d.ts +27 -0
- package/dist/src/tools/schema-tool-factory.js +32 -0
- package/dist/src/tools/search-alarm-tool.d.ts +2 -1
- package/dist/src/tools/search-alarm-tool.js +171 -182
- package/dist/src/tools/search-calendar-tool.d.ts +2 -1
- package/dist/src/tools/search-calendar-tool.js +145 -149
- package/dist/src/tools/search-contact-tool.d.ts +2 -1
- package/dist/src/tools/search-contact-tool.js +98 -102
- package/dist/src/tools/search-email-tool.d.ts +6 -0
- package/dist/src/tools/search-email-tool.js +133 -0
- package/dist/src/tools/search-file-tool.d.ts +2 -1
- package/dist/src/tools/search-file-tool.js +102 -106
- package/dist/src/tools/search-message-tool.d.ts +2 -1
- package/dist/src/tools/search-message-tool.js +100 -104
- package/dist/src/tools/search-note-tool.d.ts +2 -1
- package/dist/src/tools/search-note-tool.js +95 -99
- package/dist/src/tools/search-photo-gallery-tool.d.ts +2 -1
- package/dist/src/tools/search-photo-gallery-tool.js +35 -39
- package/dist/src/tools/send-email-tool.d.ts +5 -0
- package/dist/src/tools/send-email-tool.js +131 -0
- package/dist/src/tools/send-file-to-user-tool.d.ts +2 -1
- package/dist/src/tools/send-file-to-user-tool.js +154 -158
- package/dist/src/tools/send-message-tool.d.ts +2 -1
- package/dist/src/tools/send-message-tool.js +119 -123
- package/dist/src/tools/session-manager.d.ts +21 -6
- package/dist/src/tools/session-manager.js +134 -18
- package/dist/src/tools/upload-file-tool.d.ts +2 -1
- package/dist/src/tools/upload-file-tool.js +80 -84
- package/dist/src/tools/upload-photo-tool.d.ts +2 -1
- package/dist/src/tools/upload-photo-tool.js +70 -74
- package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-add-collection-tool.js +143 -147
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-collection-tool.js +112 -116
- package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +124 -128
- package/dist/src/tools/xiaoyi-gui-tool.d.ts +2 -1
- package/dist/src/tools/xiaoyi-gui-tool.js +84 -88
- package/dist/src/utils/runtime-manager.js +24 -2
- package/dist/src/utils/self-evolution-manager.d.ts +10 -0
- package/dist/src/utils/self-evolution-manager.js +68 -0
- package/dist/src/utils/tool-call-nudge-manager.d.ts +16 -0
- package/dist/src/utils/tool-call-nudge-manager.js +47 -0
- package/dist/src/websocket.d.ts +3 -0
- package/dist/src/websocket.js +94 -24
- package/openclaw.plugin.json +21 -0
- 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
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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.
|
|
27
|
+
3. 其余不涉及修改的参数,如果search_alarm 或 create_alarm的结果中有相应的值,需要一并填上,需要与原有的保持一致,防止不填采用默认值
|
|
40
28
|
|
|
41
29
|
注意事项:操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。
|
|
42
30
|
|
|
43
31
|
回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。`,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
|
141
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
|
151
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
|
161
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (
|
|
177
|
-
|
|
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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
187
|
-
throw new Error(
|
|
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
|
-
|
|
191
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
240
|
-
{
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
//
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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
|
|
10
|
+
export declare function createModifyNoteTool(ctx: SessionContext): any;
|