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