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