@ynhcj/xiaoyi-channel 0.0.26-beta → 0.0.26-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 +0 -2
- package/dist/index.js +48 -2
- package/dist/src/bot.js +81 -28
- package/dist/src/channel.js +33 -7
- package/dist/src/client.js +11 -27
- package/dist/src/config.js +2 -2
- package/dist/src/cspl/call-api.d.ts +3 -0
- package/dist/src/cspl/call-api.js +107 -0
- package/dist/src/cspl/config.d.ts +19 -0
- package/dist/src/cspl/config.js +50 -0
- package/dist/src/cspl/constants.d.ts +43 -0
- package/dist/src/cspl/constants.js +22 -0
- package/dist/src/cspl/utils.d.ts +10 -0
- package/dist/src/cspl/utils.js +57 -0
- package/dist/src/file-upload.d.ts +5 -0
- package/dist/src/file-upload.js +92 -0
- package/dist/src/formatter.d.ts +14 -0
- package/dist/src/formatter.js +49 -25
- package/dist/src/heartbeat.js +0 -4
- package/dist/src/monitor.js +12 -0
- package/dist/src/onboarding.d.ts +3 -4
- package/dist/src/onboarding.js +2 -2
- package/dist/src/outbound.d.ts +2 -1
- package/dist/src/outbound.js +52 -6
- package/dist/src/parser.d.ts +7 -0
- package/dist/src/parser.js +22 -0
- package/dist/src/push.d.ts +8 -1
- package/dist/src/push.js +30 -22
- package/dist/src/reply-dispatcher.js +39 -5
- package/dist/src/steer-injector.d.ts +16 -0
- package/dist/src/steer-injector.js +74 -0
- package/dist/src/thread-bindings.d.ts +54 -0
- package/dist/src/thread-bindings.js +214 -0
- package/dist/src/tools/calendar-tool.js +7 -40
- package/dist/src/tools/call-phone-tool.d.ts +5 -0
- package/dist/src/tools/call-phone-tool.js +142 -0
- package/dist/src/tools/create-alarm-tool.d.ts +7 -0
- package/dist/src/tools/create-alarm-tool.js +349 -0
- package/dist/src/tools/delete-alarm-tool.d.ts +11 -0
- package/dist/src/tools/delete-alarm-tool.js +174 -0
- package/dist/src/tools/image-reading-tool.d.ts +5 -0
- package/dist/src/tools/image-reading-tool.js +328 -0
- package/dist/src/tools/location-tool.js +8 -42
- package/dist/src/tools/modify-alarm-tool.d.ts +9 -0
- package/dist/src/tools/modify-alarm-tool.js +365 -0
- package/dist/src/tools/modify-note-tool.js +5 -43
- package/dist/src/tools/note-tool.js +33 -24
- package/dist/src/tools/search-alarm-tool.d.ts +8 -0
- package/dist/src/tools/search-alarm-tool.js +285 -0
- package/dist/src/tools/search-calendar-tool.js +10 -84
- package/dist/src/tools/search-contact-tool.js +4 -57
- package/dist/src/tools/search-file-tool.d.ts +5 -0
- package/dist/src/tools/search-file-tool.js +128 -0
- package/dist/src/tools/search-message-tool.d.ts +5 -0
- package/dist/src/tools/search-message-tool.js +116 -0
- package/dist/src/tools/search-note-tool.js +6 -24
- package/dist/src/tools/search-photo-gallery-tool.js +40 -61
- package/dist/src/tools/send-file-to-user-tool.d.ts +5 -0
- package/dist/src/tools/send-file-to-user-tool.js +279 -0
- package/dist/src/tools/send-message-tool.d.ts +5 -0
- package/dist/src/tools/send-message-tool.js +138 -0
- package/dist/src/tools/session-manager.d.ts +15 -0
- package/dist/src/tools/session-manager.js +43 -31
- package/dist/src/tools/upload-file-tool.d.ts +13 -0
- package/dist/src/tools/upload-file-tool.js +216 -0
- package/dist/src/tools/upload-photo-tool.js +2 -44
- package/dist/src/tools/view-push-result-tool.d.ts +5 -0
- package/dist/src/tools/view-push-result-tool.js +107 -0
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +5 -0
- package/dist/src/tools/xiaoyi-collection-tool.js +112 -0
- package/dist/src/tools/xiaoyi-gui-tool.js +2 -36
- package/dist/src/trigger-handler.d.ts +22 -0
- package/dist/src/trigger-handler.js +59 -0
- package/dist/src/types.d.ts +1 -8
- package/dist/src/types.js +4 -0
- package/dist/src/utils/pushdata-manager.d.ts +28 -0
- package/dist/src/utils/pushdata-manager.js +171 -0
- package/dist/src/utils/pushid-manager.d.ts +12 -0
- package/dist/src/utils/pushid-manager.js +105 -0
- package/dist/src/websocket.d.ts +25 -31
- package/dist/src/websocket.js +233 -271
- package/package.json +2 -2
- package/dist/src/tools/search-photo-tool.d.ts +0 -9
- package/dist/src/tools/search-photo-tool.js +0 -270
- package/dist/src/utils/session.d.ts +0 -34
- package/dist/src/utils/session.js +0 -50
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { getXYWebSocketManager } from "../client.js";
|
|
2
|
+
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
|
+
/**
|
|
5
|
+
* XY upload file tool - uploads local files to get publicly accessible URLs.
|
|
6
|
+
* Requires file URIs from search_file tool as prerequisite.
|
|
7
|
+
*
|
|
8
|
+
* Prerequisites:
|
|
9
|
+
* 1. Call search_file tool first to get URIs of files
|
|
10
|
+
* 2. Use the URIs to get public URLs
|
|
11
|
+
*
|
|
12
|
+
* Usage Note:
|
|
13
|
+
* - After getting public URLs, if further processing is needed, download the file first
|
|
14
|
+
* - URLs returned are publicly accessible
|
|
15
|
+
*/
|
|
16
|
+
export const uploadFileTool = {
|
|
17
|
+
name: "upload_file",
|
|
18
|
+
label: "Upload File",
|
|
19
|
+
description: `工具能力描述:将手机本地文件上传并获取可公网访问的 URL。
|
|
20
|
+
|
|
21
|
+
前置工具调用:此工具使用前必须先调用 search_file 工具获取文件的 uri
|
|
22
|
+
|
|
23
|
+
工具参数说明:
|
|
24
|
+
a. 入参中的fileInfos数组,每个元素必须包含mediaUri字段(对应于search_file工具返回结果中的uri),必须与search_file结果中对应的uri完全保持一致,不要自行修改。
|
|
25
|
+
b. fileInfos中的timeout字段是可选的,表示上传文件超时时间,单位是毫秒,默认是20000(20秒)。
|
|
26
|
+
c. fileInfos 是文件在手机本地的信息数组(从 search_file 工具响应中获取)。限制:每次最多支持传入 5 条文件信息。
|
|
27
|
+
|
|
28
|
+
注意事项:
|
|
29
|
+
a. 操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。
|
|
30
|
+
b. 此工具返回的文件链接为用户公网可访问的链接,如果需要对文件进行额外的操作,需要先根据返回的url下载文件,然后进行下一步处理。`,
|
|
31
|
+
parameters: {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
fileInfos: {
|
|
35
|
+
// 不指定 type,允许传入数组或 JSON 字符串
|
|
36
|
+
// 具体的类型验证和转换在 execute 函数内部进行
|
|
37
|
+
description: "文件信息数组,每个元素包含mediaUri(必需)和timeout(可选,默认20000)。必须先通过 search_file 工具获取。每次最多支持 5 条文件信息。",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
required: ["fileInfos"],
|
|
41
|
+
},
|
|
42
|
+
async execute(toolCallId, params) {
|
|
43
|
+
// ===== 参数规范化:兼容数组和 JSON 字符串 =====
|
|
44
|
+
let fileInfos = null;
|
|
45
|
+
if (!params.fileInfos) {
|
|
46
|
+
throw new Error("Missing required parameter: fileInfos");
|
|
47
|
+
}
|
|
48
|
+
// 情况1: 已经是数组
|
|
49
|
+
if (Array.isArray(params.fileInfos)) {
|
|
50
|
+
fileInfos = params.fileInfos;
|
|
51
|
+
}
|
|
52
|
+
// 情况2: 是字符串,尝试解析为 JSON 数组
|
|
53
|
+
else if (typeof params.fileInfos === 'string') {
|
|
54
|
+
try {
|
|
55
|
+
const parsed = JSON.parse(params.fileInfos);
|
|
56
|
+
if (Array.isArray(parsed)) {
|
|
57
|
+
fileInfos = parsed;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw new Error("fileInfos must be an array or a JSON string representing an array");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (parseError) {
|
|
64
|
+
throw new Error(`fileInfos must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// 情况3: 其他类型,报错
|
|
68
|
+
else {
|
|
69
|
+
throw new Error(`fileInfos must be an array or a JSON string, got ${typeof params.fileInfos}`);
|
|
70
|
+
}
|
|
71
|
+
// 验证数组非空
|
|
72
|
+
if (!fileInfos || fileInfos.length === 0) {
|
|
73
|
+
throw new Error("fileInfos array cannot be empty");
|
|
74
|
+
}
|
|
75
|
+
// Validate maximum 5 file infos
|
|
76
|
+
if (fileInfos.length > 5) {
|
|
77
|
+
throw new Error(`最多支持 5 条文件信息,当前提供了 ${fileInfos.length} 条。请分批处理。`);
|
|
78
|
+
}
|
|
79
|
+
// Validate each fileInfo has required mediaUri field
|
|
80
|
+
for (let i = 0; i < fileInfos.length; i++) {
|
|
81
|
+
const fileInfo = fileInfos[i];
|
|
82
|
+
if (!fileInfo || typeof fileInfo !== 'object') {
|
|
83
|
+
throw new Error(`fileInfos[${i}] must be an object with mediaUri property`);
|
|
84
|
+
}
|
|
85
|
+
if (!fileInfo.mediaUri || typeof fileInfo.mediaUri !== 'string') {
|
|
86
|
+
throw new Error(`fileInfos[${i}] must have a valid mediaUri string property`);
|
|
87
|
+
}
|
|
88
|
+
// Set default timeout if not provided
|
|
89
|
+
if (!fileInfo.timeout) {
|
|
90
|
+
fileInfo.timeout = "20000";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Get session context
|
|
94
|
+
const sessionContext = getCurrentSessionContext();
|
|
95
|
+
if (!sessionContext) {
|
|
96
|
+
throw new Error("No active XY session found. Upload file tool can only be used during an active conversation.");
|
|
97
|
+
}
|
|
98
|
+
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
99
|
+
// Get WebSocket manager
|
|
100
|
+
const wsManager = getXYWebSocketManager(config);
|
|
101
|
+
// Get public URLs for the files
|
|
102
|
+
const fileUrls = await getFileUrls(wsManager, config, sessionId, taskId, messageId, fileInfos);
|
|
103
|
+
return {
|
|
104
|
+
content: [
|
|
105
|
+
{
|
|
106
|
+
type: "text",
|
|
107
|
+
text: JSON.stringify({
|
|
108
|
+
fileUrls,
|
|
109
|
+
count: fileUrls.length,
|
|
110
|
+
message: `成功获取 ${fileUrls.length} 个文件的公网访问 URL`
|
|
111
|
+
}),
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Get public URLs for files using fileInfos
|
|
119
|
+
* Returns array of publicly accessible file URLs
|
|
120
|
+
*/
|
|
121
|
+
async function getFileUrls(wsManager, config, sessionId, taskId, messageId, fileInfos) {
|
|
122
|
+
const command = {
|
|
123
|
+
header: {
|
|
124
|
+
namespace: "Common",
|
|
125
|
+
name: "Action",
|
|
126
|
+
},
|
|
127
|
+
payload: {
|
|
128
|
+
cardParam: {},
|
|
129
|
+
executeParam: {
|
|
130
|
+
executeMode: "background",
|
|
131
|
+
intentName: "FileUploadForClaw",
|
|
132
|
+
bundleName: "com.huawei.hmos.vassistant",
|
|
133
|
+
needUnlock: true,
|
|
134
|
+
actionResponse: true,
|
|
135
|
+
appType: "OHOS_APP",
|
|
136
|
+
timeOut: 5,
|
|
137
|
+
intentParam: {
|
|
138
|
+
fileInfos: fileInfos,
|
|
139
|
+
},
|
|
140
|
+
permissionId: [],
|
|
141
|
+
achieveType: "INTENT",
|
|
142
|
+
},
|
|
143
|
+
responses: [
|
|
144
|
+
{
|
|
145
|
+
resultCode: "",
|
|
146
|
+
displayText: "",
|
|
147
|
+
ttsText: "",
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
needUploadResult: true,
|
|
151
|
+
noHalfPage: false,
|
|
152
|
+
pageControlRelated: false,
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
const timeout = setTimeout(() => {
|
|
157
|
+
wsManager.off("data-event", handler);
|
|
158
|
+
reject(new Error("获取文件URL超时(60秒)"));
|
|
159
|
+
}, 60000);
|
|
160
|
+
const handler = (event) => {
|
|
161
|
+
if (event.intentName === "FileUploadForClaw") {
|
|
162
|
+
clearTimeout(timeout);
|
|
163
|
+
wsManager.off("data-event", handler);
|
|
164
|
+
if (event.status === "success" && event.outputs) {
|
|
165
|
+
// Check for error code in outputs
|
|
166
|
+
const code = event.outputs.code !== undefined ? event.outputs.code : null;
|
|
167
|
+
if (code !== null && code !== 0) {
|
|
168
|
+
const errorMsg = event.outputs.errorMsg || event.outputs.errMsg || "未知错误";
|
|
169
|
+
reject(new Error(`获取文件URL失败: ${errorMsg} (错误代码: ${code})`));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// Safe navigation through outputs structure
|
|
173
|
+
const outputs = event.outputs;
|
|
174
|
+
const result = outputs?.result;
|
|
175
|
+
let fileUrls = [];
|
|
176
|
+
if (result && typeof result === 'object') {
|
|
177
|
+
const urls = result.fileUrls;
|
|
178
|
+
if (Array.isArray(urls)) {
|
|
179
|
+
fileUrls = urls;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Decode Unicode escape sequences in URLs
|
|
183
|
+
// Replace \u003d with = and \u0026 with &
|
|
184
|
+
fileUrls = fileUrls.map((url) => {
|
|
185
|
+
if (typeof url !== 'string') {
|
|
186
|
+
return '';
|
|
187
|
+
}
|
|
188
|
+
const decodedUrl = url
|
|
189
|
+
.replace(/\\u003d/g, '=')
|
|
190
|
+
.replace(/\\u0026/g, '&');
|
|
191
|
+
return decodedUrl;
|
|
192
|
+
}).filter((url) => url.length > 0);
|
|
193
|
+
resolve(fileUrls);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
reject(new Error(`获取文件URL失败: ${event.status}`));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
wsManager.on("data-event", handler);
|
|
201
|
+
sendCommand({
|
|
202
|
+
config,
|
|
203
|
+
sessionId,
|
|
204
|
+
taskId,
|
|
205
|
+
messageId,
|
|
206
|
+
command,
|
|
207
|
+
})
|
|
208
|
+
.then(() => {
|
|
209
|
+
})
|
|
210
|
+
.catch((error) => {
|
|
211
|
+
clearTimeout(timeout);
|
|
212
|
+
wsManager.off("data-event", handler);
|
|
213
|
+
reject(error);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
-
import {
|
|
4
|
-
import { logger } from "../utils/logger.js";
|
|
3
|
+
import { getCurrentSessionContext } from "./session-manager.js";
|
|
5
4
|
/**
|
|
6
5
|
* XY upload photo tool - uploads local photos to get publicly accessible URLs.
|
|
7
6
|
* Requires mediaUris from search_photo_gallery tool as prerequisite.
|
|
@@ -36,79 +35,52 @@ export const uploadPhotoTool = {
|
|
|
36
35
|
required: ["mediaUris"],
|
|
37
36
|
},
|
|
38
37
|
async execute(toolCallId, params) {
|
|
39
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] 🚀 Starting execution`);
|
|
40
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] - toolCallId: ${toolCallId}`);
|
|
41
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] - params (raw):`, JSON.stringify(params));
|
|
42
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] - params.mediaUris type:`, typeof params.mediaUris);
|
|
43
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] - timestamp: ${new Date().toISOString()}`);
|
|
44
38
|
// ===== 参数规范化:兼容数组和 JSON 字符串 =====
|
|
45
39
|
let mediaUris = null;
|
|
46
40
|
if (!params.mediaUris) {
|
|
47
|
-
logger.error(`[UPLOAD_PHOTO_TOOL] ❌ Missing parameter: mediaUris`);
|
|
48
41
|
throw new Error("Missing required parameter: mediaUris");
|
|
49
42
|
}
|
|
50
43
|
// 情况1: 已经是数组
|
|
51
44
|
if (Array.isArray(params.mediaUris)) {
|
|
52
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] ✅ mediaUris is already an array`);
|
|
53
45
|
mediaUris = params.mediaUris;
|
|
54
46
|
}
|
|
55
47
|
// 情况2: 是字符串,尝试解析为 JSON 数组
|
|
56
48
|
else if (typeof params.mediaUris === 'string') {
|
|
57
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] 🔄 mediaUris is a string, attempting to parse as JSON...`);
|
|
58
49
|
try {
|
|
59
50
|
const parsed = JSON.parse(params.mediaUris);
|
|
60
51
|
if (Array.isArray(parsed)) {
|
|
61
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] ✅ Successfully parsed JSON string to array`);
|
|
62
52
|
mediaUris = parsed;
|
|
63
53
|
}
|
|
64
54
|
else {
|
|
65
|
-
logger.error(`[UPLOAD_PHOTO_TOOL] ❌ Parsed JSON is not an array:`, typeof parsed);
|
|
66
55
|
throw new Error("mediaUris must be an array or a JSON string representing an array");
|
|
67
56
|
}
|
|
68
57
|
}
|
|
69
58
|
catch (parseError) {
|
|
70
|
-
logger.error(`[UPLOAD_PHOTO_TOOL] ❌ Failed to parse mediaUris as JSON:`, parseError);
|
|
71
59
|
throw new Error(`mediaUris must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
72
60
|
}
|
|
73
61
|
}
|
|
74
62
|
// 情况3: 其他类型,报错
|
|
75
63
|
else {
|
|
76
|
-
logger.error(`[UPLOAD_PHOTO_TOOL] ❌ Invalid mediaUris type:`, typeof params.mediaUris);
|
|
77
64
|
throw new Error(`mediaUris must be an array or a JSON string, got ${typeof params.mediaUris}`);
|
|
78
65
|
}
|
|
79
66
|
// 验证数组非空
|
|
80
67
|
if (!mediaUris || mediaUris.length === 0) {
|
|
81
|
-
logger.error(`[UPLOAD_PHOTO_TOOL] ❌ mediaUris array is empty`);
|
|
82
68
|
throw new Error("mediaUris array cannot be empty");
|
|
83
69
|
}
|
|
84
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] ✅ Normalized mediaUris:`, JSON.stringify(mediaUris));
|
|
85
70
|
// Validate maximum 5 URIs
|
|
86
71
|
if (mediaUris.length > 5) {
|
|
87
|
-
logger.error(`[UPLOAD_PHOTO_TOOL] ❌ Too many mediaUris: ${mediaUris.length}`);
|
|
88
72
|
throw new Error(`最多支持 5 条 mediaUri,当前提供了 ${mediaUris.length} 条。请分批处理。`);
|
|
89
73
|
}
|
|
90
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] - mediaUris count: ${mediaUris.length}`);
|
|
91
74
|
// Get session context
|
|
92
|
-
|
|
93
|
-
const sessionContext = getLatestSessionContext();
|
|
75
|
+
const sessionContext = getCurrentSessionContext();
|
|
94
76
|
if (!sessionContext) {
|
|
95
|
-
logger.error(`[UPLOAD_PHOTO_TOOL] ❌ FAILED: No active session found!`);
|
|
96
|
-
logger.error(`[UPLOAD_PHOTO_TOOL] - toolCallId: ${toolCallId}`);
|
|
97
77
|
throw new Error("No active XY session found. Upload photo tool can only be used during an active conversation.");
|
|
98
78
|
}
|
|
99
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] ✅ Session context found`);
|
|
100
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] - sessionId: ${sessionContext.sessionId}`);
|
|
101
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] - taskId: ${sessionContext.taskId}`);
|
|
102
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] - messageId: ${sessionContext.messageId}`);
|
|
103
79
|
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
104
80
|
// Get WebSocket manager
|
|
105
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] 🔌 Getting WebSocket manager...`);
|
|
106
81
|
const wsManager = getXYWebSocketManager(config);
|
|
107
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] ✅ WebSocket manager obtained`);
|
|
108
82
|
// Get public URLs for the photos
|
|
109
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] 🌐 Getting public URLs for photos...`);
|
|
110
83
|
const imageUrls = await getPhotoUrls(wsManager, config, sessionId, taskId, messageId, mediaUris);
|
|
111
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] 🎉 Successfully retrieved ${imageUrls.length} photo URLs`);
|
|
112
84
|
return {
|
|
113
85
|
content: [
|
|
114
86
|
{
|
|
@@ -128,7 +100,6 @@ export const uploadPhotoTool = {
|
|
|
128
100
|
* Returns array of publicly accessible image URLs
|
|
129
101
|
*/
|
|
130
102
|
async function getPhotoUrls(wsManager, config, sessionId, taskId, messageId, mediaUris) {
|
|
131
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] 📦 Building ImageUploadForClaw command...`);
|
|
132
103
|
// Build imageInfos array from mediaUris
|
|
133
104
|
const imageInfos = mediaUris.map(mediaUri => ({ mediaUri }));
|
|
134
105
|
const command = {
|
|
@@ -166,19 +137,14 @@ async function getPhotoUrls(wsManager, config, sessionId, taskId, messageId, med
|
|
|
166
137
|
};
|
|
167
138
|
return new Promise((resolve, reject) => {
|
|
168
139
|
const timeout = setTimeout(() => {
|
|
169
|
-
logger.error(`[UPLOAD_PHOTO_TOOL] ⏰ Timeout: No response for ImageUploadForClaw within 60 seconds`);
|
|
170
140
|
wsManager.off("data-event", handler);
|
|
171
141
|
reject(new Error("获取照片URL超时(60秒)"));
|
|
172
142
|
}, 60000);
|
|
173
143
|
const handler = (event) => {
|
|
174
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] 📨 Received data event:`, JSON.stringify(event));
|
|
175
144
|
if (event.intentName === "ImageUploadForClaw") {
|
|
176
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] 🎯 ImageUploadForClaw event received`);
|
|
177
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] - status: ${event.status}`);
|
|
178
145
|
clearTimeout(timeout);
|
|
179
146
|
wsManager.off("data-event", handler);
|
|
180
147
|
if (event.status === "success" && event.outputs) {
|
|
181
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] ✅ Image URL retrieval completed successfully`);
|
|
182
148
|
const result = event.outputs.result;
|
|
183
149
|
let imageUrls = result?.imageUrls || [];
|
|
184
150
|
// Decode Unicode escape sequences in URLs
|
|
@@ -187,22 +153,16 @@ async function getPhotoUrls(wsManager, config, sessionId, taskId, messageId, med
|
|
|
187
153
|
const decodedUrl = url
|
|
188
154
|
.replace(/\\u003d/g, '=')
|
|
189
155
|
.replace(/\\u0026/g, '&');
|
|
190
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] 🔄 Decoded URL: ${url} -> ${decodedUrl}`);
|
|
191
156
|
return decodedUrl;
|
|
192
157
|
});
|
|
193
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] 📊 Retrieved and decoded ${imageUrls.length} image URLs`);
|
|
194
158
|
resolve(imageUrls);
|
|
195
159
|
}
|
|
196
160
|
else {
|
|
197
|
-
logger.error(`[UPLOAD_PHOTO_TOOL] ❌ Image URL retrieval failed`);
|
|
198
|
-
logger.error(`[UPLOAD_PHOTO_TOOL] - status: ${event.status}`);
|
|
199
161
|
reject(new Error(`获取照片URL失败: ${event.status}`));
|
|
200
162
|
}
|
|
201
163
|
}
|
|
202
164
|
};
|
|
203
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] 📡 Registering data-event handler for ImageUploadForClaw`);
|
|
204
165
|
wsManager.on("data-event", handler);
|
|
205
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] 📤 Sending ImageUploadForClaw command...`);
|
|
206
166
|
sendCommand({
|
|
207
167
|
config,
|
|
208
168
|
sessionId,
|
|
@@ -211,10 +171,8 @@ async function getPhotoUrls(wsManager, config, sessionId, taskId, messageId, med
|
|
|
211
171
|
command,
|
|
212
172
|
})
|
|
213
173
|
.then(() => {
|
|
214
|
-
logger.log(`[UPLOAD_PHOTO_TOOL] ✅ ImageUploadForClaw command sent successfully`);
|
|
215
174
|
})
|
|
216
175
|
.catch((error) => {
|
|
217
|
-
logger.error(`[UPLOAD_PHOTO_TOOL] ❌ Failed to send ImageUploadForClaw command:`, error);
|
|
218
176
|
clearTimeout(timeout);
|
|
219
177
|
wsManager.off("data-event", handler);
|
|
220
178
|
reject(error);
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { searchPushData, getAllPushData } from "../utils/pushdata-manager.js";
|
|
2
|
+
/**
|
|
3
|
+
* 查看推送任务执行结果工具
|
|
4
|
+
* 支持关键词搜索或查看最近的推送记录
|
|
5
|
+
*/
|
|
6
|
+
export const viewPushResultTool = {
|
|
7
|
+
name: "view_push_result",
|
|
8
|
+
label: "View Push Task Result",
|
|
9
|
+
description: `查看定时任务或推送消息的执行结果。当用户说"查看我xxx的定时任务执行结果"、"查看我的xxxx的推送消息"或类似语料时调用此工具。
|
|
10
|
+
|
|
11
|
+
功能说明:
|
|
12
|
+
- 支持关键词搜索:如果用户提到具体任务名称或内容,可以按关键词筛选
|
|
13
|
+
- 无关键词时:返回最近的推送记录(默认10条)
|
|
14
|
+
- 返回内容包括:推送ID、时间、内容摘要
|
|
15
|
+
|
|
16
|
+
使用场景:
|
|
17
|
+
- "查看我昨天的定时任务执行结果"
|
|
18
|
+
- "帮我看看天气推送消息"
|
|
19
|
+
- "查看最近的推送记录"
|
|
20
|
+
- "我的提醒任务执行了吗"`,
|
|
21
|
+
parameters: {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
keywords: {
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "可选的搜索关键词,用于筛选推送记录。如果用户提到具体任务名称或内容,将其作为关键词传入。例如:'天气'、'提醒'、'会议'等。",
|
|
27
|
+
},
|
|
28
|
+
limit: {
|
|
29
|
+
type: "number",
|
|
30
|
+
description: "返回的最大记录数,默认10条,最多50条",
|
|
31
|
+
default: 10,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
required: [],
|
|
35
|
+
},
|
|
36
|
+
async execute(toolCallId, params) {
|
|
37
|
+
const keywords = params.keywords?.trim();
|
|
38
|
+
const limit = Math.min(params.limit || 10, 50); // 限制最多50条
|
|
39
|
+
try {
|
|
40
|
+
// 根据是否有关键词决定调用哪个方法
|
|
41
|
+
let results = keywords
|
|
42
|
+
? await searchPushData(keywords)
|
|
43
|
+
: await getAllPushData();
|
|
44
|
+
// 按时间倒序排序(最新的在前)
|
|
45
|
+
results.sort((a, b) => b.time.localeCompare(a.time));
|
|
46
|
+
// 限制返回条数
|
|
47
|
+
results = results.slice(0, limit);
|
|
48
|
+
if (results.length === 0) {
|
|
49
|
+
return {
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
52
|
+
type: "text",
|
|
53
|
+
text: JSON.stringify({
|
|
54
|
+
success: true,
|
|
55
|
+
count: 0,
|
|
56
|
+
items: [],
|
|
57
|
+
message: keywords
|
|
58
|
+
? `未找到包含关键词"${keywords}"的推送记录`
|
|
59
|
+
: "暂无推送记录",
|
|
60
|
+
}),
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// 格式化返回结果
|
|
66
|
+
const formattedItems = results.map((item) => ({
|
|
67
|
+
pushDataId: item.pushDataId.substring(0, 8), // 只显示前8位
|
|
68
|
+
fullPushDataId: item.pushDataId, // 完整ID用于追溯
|
|
69
|
+
time: item.time,
|
|
70
|
+
dataDetail: item.dataDetail.length > 200
|
|
71
|
+
? item.dataDetail.substring(0, 200) + "..."
|
|
72
|
+
: item.dataDetail,
|
|
73
|
+
fullLength: item.dataDetail.length,
|
|
74
|
+
}));
|
|
75
|
+
return {
|
|
76
|
+
content: [
|
|
77
|
+
{
|
|
78
|
+
type: "text",
|
|
79
|
+
text: JSON.stringify({
|
|
80
|
+
success: true,
|
|
81
|
+
count: formattedItems.length,
|
|
82
|
+
totalMatched: results.length,
|
|
83
|
+
items: formattedItems,
|
|
84
|
+
message: keywords
|
|
85
|
+
? `找到 ${formattedItems.length} 条包含"${keywords}"的推送记录`
|
|
86
|
+
: `返回最近 ${formattedItems.length} 条推送记录`,
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
return {
|
|
94
|
+
content: [
|
|
95
|
+
{
|
|
96
|
+
type: "text",
|
|
97
|
+
text: JSON.stringify({
|
|
98
|
+
success: false,
|
|
99
|
+
error: error instanceof Error ? error.message : String(error),
|
|
100
|
+
message: "查询推送记录失败",
|
|
101
|
+
}),
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { getXYWebSocketManager } from "../client.js";
|
|
2
|
+
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
|
+
/**
|
|
5
|
+
* XY collection tool - retrieves user's collection data from XiaoYi.
|
|
6
|
+
* Returns personalized knowledge data saved in user's collection.
|
|
7
|
+
*/
|
|
8
|
+
export const xiaoyiCollectionTool = {
|
|
9
|
+
name: "xiaoyi_collection",
|
|
10
|
+
label: "XiaoYi Collection",
|
|
11
|
+
description: "检索用户在小艺收藏中记下来的公共知识数据,可以给用户提供个性化体验。当用户语料中涉及从我的小艺收藏或者查看我的收藏或者我xx时候收藏的xxx帮我看一下这种类型的语料的时候需要使用此工具。注意:操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。",
|
|
12
|
+
parameters: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
queryAll: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "描述是否需要查询用户所有收藏数据,默认为true",
|
|
18
|
+
default: "true",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
required: [],
|
|
22
|
+
},
|
|
23
|
+
async execute(toolCallId, params) {
|
|
24
|
+
// Get session context
|
|
25
|
+
const sessionContext = getCurrentSessionContext();
|
|
26
|
+
if (!sessionContext) {
|
|
27
|
+
throw new Error("No active XY session found. XiaoYi collection tool can only be used during an active conversation.");
|
|
28
|
+
}
|
|
29
|
+
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
30
|
+
// Get WebSocket manager
|
|
31
|
+
const wsManager = getXYWebSocketManager(config);
|
|
32
|
+
// Build QueryCollection command
|
|
33
|
+
const command = {
|
|
34
|
+
header: {
|
|
35
|
+
namespace: "Common",
|
|
36
|
+
name: "Action",
|
|
37
|
+
},
|
|
38
|
+
payload: {
|
|
39
|
+
cardParam: {},
|
|
40
|
+
executeParam: {
|
|
41
|
+
executeMode: "background",
|
|
42
|
+
intentName: "QueryCollection",
|
|
43
|
+
bundleName: "com.huawei.hmos.vassistant",
|
|
44
|
+
needUnlock: true,
|
|
45
|
+
actionResponse: true,
|
|
46
|
+
appType: "OHOS_APP",
|
|
47
|
+
timeOut: 5,
|
|
48
|
+
intentParam: {
|
|
49
|
+
queryAll: params.queryAll || "true",
|
|
50
|
+
},
|
|
51
|
+
permissionId: [],
|
|
52
|
+
achieveType: "INTENT",
|
|
53
|
+
},
|
|
54
|
+
responses: [
|
|
55
|
+
{
|
|
56
|
+
resultCode: "",
|
|
57
|
+
displayText: "",
|
|
58
|
+
ttsText: "",
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
needUploadResult: true,
|
|
62
|
+
noHalfPage: false,
|
|
63
|
+
pageControlRelated: false,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
// Send command and wait for response (60 second timeout)
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
const timeout = setTimeout(() => {
|
|
69
|
+
wsManager.off("data-event", handler);
|
|
70
|
+
reject(new Error("查询小艺收藏超时(60秒)"));
|
|
71
|
+
}, 60000);
|
|
72
|
+
// Listen for data events from WebSocket
|
|
73
|
+
const handler = (event) => {
|
|
74
|
+
if (event.intentName === "QueryCollection") {
|
|
75
|
+
clearTimeout(timeout);
|
|
76
|
+
wsManager.off("data-event", handler);
|
|
77
|
+
if (event.status === "success" && event.outputs) {
|
|
78
|
+
// 成功,直接返回完整的 event.outputs JSON 字符串
|
|
79
|
+
resolve({
|
|
80
|
+
content: [
|
|
81
|
+
{
|
|
82
|
+
type: "text",
|
|
83
|
+
text: JSON.stringify(event.outputs),
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
reject(new Error(`查询小艺收藏失败: ${event.status}`));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
// Register event handler
|
|
94
|
+
wsManager.on("data-event", handler);
|
|
95
|
+
// Send the command
|
|
96
|
+
sendCommand({
|
|
97
|
+
config,
|
|
98
|
+
sessionId,
|
|
99
|
+
taskId,
|
|
100
|
+
messageId,
|
|
101
|
+
command,
|
|
102
|
+
})
|
|
103
|
+
.then(() => {
|
|
104
|
+
})
|
|
105
|
+
.catch((error) => {
|
|
106
|
+
clearTimeout(timeout);
|
|
107
|
+
wsManager.off("data-event", handler);
|
|
108
|
+
reject(error);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
};
|