@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.
- 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 -30
- 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 +440 -31
- 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 +227 -231
- 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 -135
- package/dist/src/tools/device-tool-map.js +2 -0
- 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 +86 -90
- 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 +232 -236
- 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 -131
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +2 -1
- package/dist/src/tools/save-media-to-gallery-tool.js +134 -138
- 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 -175
- 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 +2 -1
- package/dist/src/tools/search-email-tool.js +107 -111
- package/dist/src/tools/search-file-tool.d.ts +2 -1
- package/dist/src/tools/search-file-tool.js +99 -103
- 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 +34 -38
- 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 +153 -155
- 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 +135 -18
- package/dist/src/tools/upload-file-tool.d.ts +2 -1
- package/dist/src/tools/upload-file-tool.js +79 -83
- 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,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
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
|
128
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
|
138
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
|
148
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (
|
|
164
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
174
|
-
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)}`);
|
|
175
180
|
}
|
|
176
181
|
}
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
227
|
-
{
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
//
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
|
10
|
+
export declare function createModifyNoteTool(ctx: SessionContext): any;
|