@ynhcj/xiaoyi-channel 1.1.1 → 1.1.2
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/src/channel.js
CHANGED
|
@@ -6,6 +6,7 @@ import { locationTool } from "./tools/location-tool.js";
|
|
|
6
6
|
import { noteTool } from "./tools/note-tool.js";
|
|
7
7
|
import { searchNoteTool } from "./tools/search-note-tool.js";
|
|
8
8
|
import { calendarTool } from "./tools/calendar-tool.js";
|
|
9
|
+
import { searchCalendarTool } from "./tools/search-calendar-tool.js";
|
|
9
10
|
/**
|
|
10
11
|
* Xiaoyi Channel Plugin for OpenClaw.
|
|
11
12
|
* Implements Xiaoyi A2A protocol with dual WebSocket connections.
|
|
@@ -45,7 +46,7 @@ export const xyPlugin = {
|
|
|
45
46
|
},
|
|
46
47
|
outbound: xyOutbound,
|
|
47
48
|
onboarding: xyOnboardingAdapter,
|
|
48
|
-
agentTools: [locationTool, noteTool, searchNoteTool, calendarTool],
|
|
49
|
+
agentTools: [locationTool, noteTool, searchNoteTool, calendarTool, searchCalendarTool],
|
|
49
50
|
messaging: {
|
|
50
51
|
normalizeTarget: (raw) => {
|
|
51
52
|
const trimmed = raw.trim();
|
package/dist/src/formatter.js
CHANGED
|
@@ -107,7 +107,6 @@ export async function sendReasoningTextUpdate(params) {
|
|
|
107
107
|
msgDetail: JSON.stringify(jsonRpcResponse),
|
|
108
108
|
};
|
|
109
109
|
log(`[REASONING_TEXT] 📤 Sending reasoningText update: sessionId=${sessionId}, taskId=${taskId}, text.length=${text.length}`);
|
|
110
|
-
log(JSON.stringify(outboundMessage, null, 2));
|
|
111
110
|
await wsManager.sendMessage(sessionId, outboundMessage);
|
|
112
111
|
log(`[REASONING_TEXT] ✅ Sent successfully`);
|
|
113
112
|
}
|
|
@@ -156,14 +156,38 @@ export function createXYReplyDispatcher(params) {
|
|
|
156
156
|
}
|
|
157
157
|
else {
|
|
158
158
|
log(`[ON_IDLE] Skipping final message: hasSentResponse=${hasSentResponse}, finalSent=${finalSent}`);
|
|
159
|
+
// Task was interrupted - send failure status and error response
|
|
160
|
+
try {
|
|
161
|
+
await sendStatusUpdate({
|
|
162
|
+
config,
|
|
163
|
+
sessionId,
|
|
164
|
+
taskId,
|
|
165
|
+
messageId,
|
|
166
|
+
text: "任务处理中断了~",
|
|
167
|
+
state: "failed",
|
|
168
|
+
});
|
|
169
|
+
log(`[ON_IDLE] ✅ Sent failure status update`);
|
|
170
|
+
await sendA2AResponse({
|
|
171
|
+
config,
|
|
172
|
+
sessionId,
|
|
173
|
+
taskId,
|
|
174
|
+
messageId,
|
|
175
|
+
text: "任务执行异常,请重试~",
|
|
176
|
+
append: false,
|
|
177
|
+
final: true,
|
|
178
|
+
});
|
|
179
|
+
finalSent = true;
|
|
180
|
+
log(`[ON_IDLE] ✅ Sent error response`);
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
error(`[ON_IDLE] Failed to send failure status and error response:`, err);
|
|
184
|
+
}
|
|
159
185
|
}
|
|
160
186
|
// Stop status updates
|
|
161
187
|
stopStatusInterval();
|
|
162
188
|
},
|
|
163
189
|
onCleanup: () => {
|
|
164
190
|
log(`[ON_CLEANUP] Reply cleanup for session ${sessionId}, hasSentResponse=${hasSentResponse}, finalSent=${finalSent}`);
|
|
165
|
-
// Stop status updates
|
|
166
|
-
stopStatusInterval();
|
|
167
191
|
},
|
|
168
192
|
});
|
|
169
193
|
return {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XY search calendar event tool - searches calendar events on user's device.
|
|
3
|
+
* Returns matching events based on time range and optional title filter.
|
|
4
|
+
*
|
|
5
|
+
* Time range guidelines:
|
|
6
|
+
* - For a specific day: use 00:00:00 to 23:59:59 of that day
|
|
7
|
+
* - For morning: 06:00:00 to 12:00:00
|
|
8
|
+
* - For afternoon: 12:00:00 to 18:00:00
|
|
9
|
+
* - For evening: 18:00:00 to 24:00:00
|
|
10
|
+
* - For a specific time: use ±1 hour range (e.g., for 3PM, use 14:00:00 to 16:00:00)
|
|
11
|
+
*/
|
|
12
|
+
export declare const searchCalendarTool: any;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { getXYWebSocketManager } from "../client.js";
|
|
2
|
+
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getLatestSessionContext } from "./session-manager.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
5
|
+
/**
|
|
6
|
+
* XY search calendar event tool - searches calendar events on user's device.
|
|
7
|
+
* Returns matching events based on time range and optional title filter.
|
|
8
|
+
*
|
|
9
|
+
* Time range guidelines:
|
|
10
|
+
* - For a specific day: use 00:00:00 to 23:59:59 of that day
|
|
11
|
+
* - For morning: 06:00:00 to 12:00:00
|
|
12
|
+
* - For afternoon: 12:00:00 to 18:00:00
|
|
13
|
+
* - For evening: 18:00:00 to 24:00:00
|
|
14
|
+
* - For a specific time: use ±1 hour range (e.g., for 3PM, use 14:00:00 to 16:00:00)
|
|
15
|
+
*/
|
|
16
|
+
export const searchCalendarTool = {
|
|
17
|
+
name: "search_calendar_event",
|
|
18
|
+
label: "Search Calendar Event",
|
|
19
|
+
description: `检索用户日历中的日程安排。根据时间范围和可选的日程标题进行检索。时间格式必须为:YYYYMMDD hhmmss(例如:20240115 143000)。
|
|
20
|
+
|
|
21
|
+
时间范围说明:
|
|
22
|
+
- 查询某一天的日程:使用该天的 00:00:00 到 23:59:59(例如:20240115 000000 到 20240115 235959)
|
|
23
|
+
- 查询上午的日程:使用 06:00:00 到 12:00:00
|
|
24
|
+
- 查询下午的日程:使用 12:00:00 到 18:00:00
|
|
25
|
+
- 查询晚上的日程:使用 18:00:00 到 23:59:59
|
|
26
|
+
- 查询某个时刻附近的日程:使用该时刻前后1小时的区间(例如:查询3点左右的日程,使用 14:00:00 到 16:00:00)
|
|
27
|
+
|
|
28
|
+
注意:该工具执行时间较长(最多60秒),请勿重复调用,超时或失败时最多重试一次。`,
|
|
29
|
+
parameters: {
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: {
|
|
32
|
+
startTime: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description: "日程起始时间,格式必须为:YYYYMMDD hhmmss(例如:20240115 143000 表示 2024年1月15日 14:30:00)",
|
|
35
|
+
},
|
|
36
|
+
endTime: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "日程结束时间,格式必须为:YYYYMMDD hhmmss(例如:20240115 173000 表示 2024年1月15日 17:30:00)",
|
|
39
|
+
},
|
|
40
|
+
title: {
|
|
41
|
+
type: "string",
|
|
42
|
+
description: "日程标题/类型(可选),用于过滤特定类型的日程",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
required: ["startTime", "endTime"],
|
|
46
|
+
},
|
|
47
|
+
async execute(toolCallId, params) {
|
|
48
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] 🚀 Starting execution`);
|
|
49
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - toolCallId: ${toolCallId}`);
|
|
50
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - params:`, JSON.stringify(params));
|
|
51
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - timestamp: ${new Date().toISOString()}`);
|
|
52
|
+
// Validate parameters
|
|
53
|
+
if (!params.startTime || !params.endTime) {
|
|
54
|
+
logger.error(`[SEARCH_CALENDAR_TOOL] ❌ Missing required parameters`);
|
|
55
|
+
throw new Error("Missing required parameters: startTime and endTime are required");
|
|
56
|
+
}
|
|
57
|
+
// Convert time strings to millisecond timestamps
|
|
58
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] 🕒 Converting time strings to timestamps...`);
|
|
59
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - startTime input: ${params.startTime}`);
|
|
60
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - endTime input: ${params.endTime}`);
|
|
61
|
+
// Parse YYYYMMDD hhmmss format
|
|
62
|
+
const parseTimeString = (timeStr) => {
|
|
63
|
+
// Remove any extra spaces and split
|
|
64
|
+
const cleaned = timeStr.trim().replace(/\s+/g, ' ');
|
|
65
|
+
const parts = cleaned.split(' ');
|
|
66
|
+
if (parts.length !== 2) {
|
|
67
|
+
throw new Error(`Invalid time format: ${timeStr}. Expected format: YYYYMMDD hhmmss`);
|
|
68
|
+
}
|
|
69
|
+
const datePart = parts[0]; // YYYYMMDD
|
|
70
|
+
const timePart = parts[1]; // hhmmss
|
|
71
|
+
if (datePart.length !== 8 || timePart.length !== 6) {
|
|
72
|
+
throw new Error(`Invalid time format: ${timeStr}. Expected format: YYYYMMDD hhmmss`);
|
|
73
|
+
}
|
|
74
|
+
const year = parseInt(datePart.substring(0, 4), 10);
|
|
75
|
+
const month = parseInt(datePart.substring(4, 6), 10) - 1; // Month is 0-indexed
|
|
76
|
+
const day = parseInt(datePart.substring(6, 8), 10);
|
|
77
|
+
const hours = parseInt(timePart.substring(0, 2), 10);
|
|
78
|
+
const minutes = parseInt(timePart.substring(2, 4), 10);
|
|
79
|
+
const seconds = parseInt(timePart.substring(4, 6), 10);
|
|
80
|
+
const date = new Date(year, month, day, hours, minutes, seconds);
|
|
81
|
+
return date.getTime();
|
|
82
|
+
};
|
|
83
|
+
let startTimeMs;
|
|
84
|
+
let endTimeMs;
|
|
85
|
+
try {
|
|
86
|
+
startTimeMs = parseTimeString(params.startTime);
|
|
87
|
+
endTimeMs = parseTimeString(params.endTime);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
logger.error(`[SEARCH_CALENDAR_TOOL] ❌ Time parsing error:`, error);
|
|
91
|
+
throw new Error(`Invalid time format. Required format: YYYYMMDD hhmmss (e.g., 20240115 143000). Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
92
|
+
}
|
|
93
|
+
if (isNaN(startTimeMs) || isNaN(endTimeMs)) {
|
|
94
|
+
logger.error(`[SEARCH_CALENDAR_TOOL] ❌ Invalid time format`);
|
|
95
|
+
throw new Error("Invalid time format. Required format: YYYYMMDD hhmmss (e.g., 20240115 143000)");
|
|
96
|
+
}
|
|
97
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] ✅ Time conversion successful`);
|
|
98
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - startTime timestamp: ${startTimeMs}`);
|
|
99
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - endTime timestamp: ${endTimeMs}`);
|
|
100
|
+
// Get session context
|
|
101
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] 🔍 Attempting to get session context...`);
|
|
102
|
+
const sessionContext = getLatestSessionContext();
|
|
103
|
+
if (!sessionContext) {
|
|
104
|
+
logger.error(`[SEARCH_CALENDAR_TOOL] ❌ FAILED: No active session found!`);
|
|
105
|
+
logger.error(`[SEARCH_CALENDAR_TOOL] - toolCallId: ${toolCallId}`);
|
|
106
|
+
throw new Error("No active XY session found. Search calendar tool can only be used during an active conversation.");
|
|
107
|
+
}
|
|
108
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] ✅ Session context found`);
|
|
109
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - sessionId: ${sessionContext.sessionId}`);
|
|
110
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - taskId: ${sessionContext.taskId}`);
|
|
111
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - messageId: ${sessionContext.messageId}`);
|
|
112
|
+
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
113
|
+
// Get WebSocket manager
|
|
114
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] 🔌 Getting WebSocket manager...`);
|
|
115
|
+
const wsManager = getXYWebSocketManager(config);
|
|
116
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] ✅ WebSocket manager obtained`);
|
|
117
|
+
// Build SearchCalendarEvent command
|
|
118
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] 📦 Building SearchCalendarEvent command...`);
|
|
119
|
+
// Build intentParam with timeInterval and optional title
|
|
120
|
+
const intentParam = {
|
|
121
|
+
timeInterval: [startTimeMs, endTimeMs],
|
|
122
|
+
};
|
|
123
|
+
if (params.title) {
|
|
124
|
+
intentParam.title = params.title;
|
|
125
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - Including title filter: ${params.title}`);
|
|
126
|
+
}
|
|
127
|
+
const command = {
|
|
128
|
+
header: {
|
|
129
|
+
namespace: "Common",
|
|
130
|
+
name: "Action",
|
|
131
|
+
},
|
|
132
|
+
payload: {
|
|
133
|
+
cardParam: {},
|
|
134
|
+
executeParam: {
|
|
135
|
+
executeMode: "background",
|
|
136
|
+
intentName: "SearchCalendarEvent",
|
|
137
|
+
bundleName: "com.huawei.hmos.calendardata",
|
|
138
|
+
dimension: "",
|
|
139
|
+
needUnlock: true,
|
|
140
|
+
actionResponse: true,
|
|
141
|
+
appType: "OHOS_APP",
|
|
142
|
+
timeOut: 5,
|
|
143
|
+
intentParam,
|
|
144
|
+
permissionId: [],
|
|
145
|
+
achieveType: "INTENT",
|
|
146
|
+
},
|
|
147
|
+
responses: [
|
|
148
|
+
{
|
|
149
|
+
resultCode: "",
|
|
150
|
+
displayText: "",
|
|
151
|
+
ttsText: "",
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
needUploadResult: true,
|
|
155
|
+
noHalfPage: false,
|
|
156
|
+
pageControlRelated: false,
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
// Send command and wait for response (60 second timeout)
|
|
160
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] ⏳ Setting up promise to wait for calendar search response...`);
|
|
161
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - Timeout: 60 seconds`);
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
const timeout = setTimeout(() => {
|
|
164
|
+
logger.error(`[SEARCH_CALENDAR_TOOL] ⏰ Timeout: No response received within 60 seconds`);
|
|
165
|
+
wsManager.off("data-event", handler);
|
|
166
|
+
reject(new Error("检索日程超时(60秒)"));
|
|
167
|
+
}, 60000);
|
|
168
|
+
// Listen for data events from WebSocket
|
|
169
|
+
const handler = (event) => {
|
|
170
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] 📨 Received data event:`, JSON.stringify(event));
|
|
171
|
+
if (event.intentName === "SearchCalendarEvent") {
|
|
172
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] 🎯 SearchCalendarEvent event received`);
|
|
173
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - status: ${event.status}`);
|
|
174
|
+
clearTimeout(timeout);
|
|
175
|
+
wsManager.off("data-event", handler);
|
|
176
|
+
if (event.status === "success" && event.outputs) {
|
|
177
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] ✅ Calendar events retrieved successfully`);
|
|
178
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] - outputs:`, JSON.stringify(event.outputs));
|
|
179
|
+
// Return the result directly as requested
|
|
180
|
+
const result = event.outputs.result;
|
|
181
|
+
resolve({
|
|
182
|
+
content: [
|
|
183
|
+
{
|
|
184
|
+
type: "text",
|
|
185
|
+
text: JSON.stringify(result),
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
logger.error(`[SEARCH_CALENDAR_TOOL] ❌ Calendar event search failed`);
|
|
192
|
+
logger.error(`[SEARCH_CALENDAR_TOOL] - status: ${event.status}`);
|
|
193
|
+
reject(new Error(`检索日程失败: ${event.status}`));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
// Register event handler
|
|
198
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] 📡 Registering data-event handler on WebSocket manager`);
|
|
199
|
+
wsManager.on("data-event", handler);
|
|
200
|
+
// Send the command
|
|
201
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] 📤 Sending SearchCalendarEvent command...`);
|
|
202
|
+
sendCommand({
|
|
203
|
+
config,
|
|
204
|
+
sessionId,
|
|
205
|
+
taskId,
|
|
206
|
+
messageId,
|
|
207
|
+
command,
|
|
208
|
+
})
|
|
209
|
+
.then(() => {
|
|
210
|
+
logger.log(`[SEARCH_CALENDAR_TOOL] ✅ Command sent successfully, waiting for response...`);
|
|
211
|
+
})
|
|
212
|
+
.catch((error) => {
|
|
213
|
+
logger.error(`[SEARCH_CALENDAR_TOOL] ❌ Failed to send command:`, error);
|
|
214
|
+
clearTimeout(timeout);
|
|
215
|
+
wsManager.off("data-event", handler);
|
|
216
|
+
reject(error);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
},
|
|
220
|
+
};
|