@ynhcj/xiaoyi-channel 0.0.49-next → 0.0.50-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.js +5 -4
- package/dist/src/channel.js +3 -1
- package/dist/src/cspl/call-api.js +14 -11
- package/dist/src/cspl/config.js +3 -3
- package/dist/src/cspl/constants.d.ts +1 -0
- package/dist/src/provider.js +0 -1
- package/dist/src/tools/find-pc-devices-tool.d.ts +5 -0
- package/dist/src/tools/find-pc-devices-tool.js +98 -0
- package/dist/src/tools/save-file-to-phone-tool.d.ts +5 -0
- package/dist/src/tools/save-file-to-phone-tool.js +170 -0
- package/dist/src/tools/save-media-to-gallery-tool.js +1 -1
- package/dist/src/tools/search-file-tool.js +10 -7
- package/dist/src/tools/upload-file-tool.js +14 -4
- package/dist/src/tools/xiaoyi-add-collection-tool.js +1 -1
- package/dist/src/tools/xiaoyi-collection-tool.js +1 -1
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20,13 +20,13 @@ const plugin = {
|
|
|
20
20
|
setXYRuntime(api.runtime);
|
|
21
21
|
api.registerChannel({ plugin: xyPlugin });
|
|
22
22
|
api.registerProvider(xiaoyiProvider);
|
|
23
|
-
//
|
|
23
|
+
// SENTINEL HOOK after_tool_call hook: 监听工具结果,发送至安全检测 API 进行安全检测
|
|
24
24
|
// 如果响应为 REJECT,注入 steer 消息中止当前对话
|
|
25
25
|
api.on("after_tool_call", async (event, ctx) => {
|
|
26
26
|
if (!ALLOWED_TOOLS.includes(event.toolName)) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
console.log(`[
|
|
29
|
+
console.log(`[SENTINEL HOOK] after_tool_call triggered: toolName=${event.toolName}, sessionKey=${ctx.sessionKey ?? "none"}`);
|
|
30
30
|
try {
|
|
31
31
|
const resultText = extractResultText(event, event.toolName);
|
|
32
32
|
const resultLength = resultText.length;
|
|
@@ -35,6 +35,7 @@ const plugin = {
|
|
|
35
35
|
}
|
|
36
36
|
// 构造 sentinel_hook 格式的 payload: { tool, output: [{ content }] }
|
|
37
37
|
const questionText = {
|
|
38
|
+
subSceneID: 'TOOL_OUTPUT',
|
|
38
39
|
tool: event.toolName,
|
|
39
40
|
output: [{ content: "" }],
|
|
40
41
|
};
|
|
@@ -49,13 +50,13 @@ const plugin = {
|
|
|
49
50
|
}
|
|
50
51
|
const response = await callCsplApi(finalJson, api.config);
|
|
51
52
|
const result = parseSecurityResult(response);
|
|
52
|
-
console.log(`[
|
|
53
|
+
console.log(`[SENTINEL HOOK] Security result: status=${result.status}`);
|
|
53
54
|
if (result.status === "REJECT") {
|
|
54
55
|
await tryInjectSteer(ctx.sessionKey, STEER_ABORT_MESSAGE);
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
catch (err) {
|
|
58
|
-
api.logger.error(`[
|
|
59
|
+
api.logger.error(`[SENTINEL HOOK] after_tool_call error: ${err}`);
|
|
59
60
|
}
|
|
60
61
|
});
|
|
61
62
|
},
|
package/dist/src/channel.js
CHANGED
|
@@ -28,6 +28,8 @@ import { xiaoyiCollectionTool } from "./tools/xiaoyi-collection-tool.js";
|
|
|
28
28
|
import { xiaoyiAddCollectionTool } from "./tools/xiaoyi-add-collection-tool.js";
|
|
29
29
|
import { xiaoyiDeleteCollectionTool } from "./tools/xiaoyi-delete-collection-tool.js";
|
|
30
30
|
import { saveMediaToGalleryTool } from "./tools/save-media-to-gallery-tool.js";
|
|
31
|
+
import { saveFileToPhoneTool } from "./tools/save-file-to-phone-tool.js";
|
|
32
|
+
import { findPcDevicesTool } from "./tools/find-pc-devices-tool.js";
|
|
31
33
|
import { filterToolsByDevice } from "./tools/device-tool-map.js";
|
|
32
34
|
import { getCurrentSessionContext } from "./tools/session-manager.js";
|
|
33
35
|
import { logger } from "./utils/logger.js";
|
|
@@ -70,7 +72,7 @@ export const xyPlugin = {
|
|
|
70
72
|
},
|
|
71
73
|
outbound: xyOutbound,
|
|
72
74
|
agentTools: () => {
|
|
73
|
-
const allTools = [locationTool, noteTool, searchNoteTool, modifyNoteTool, calendarTool, searchCalendarTool, searchContactTool, searchPhotoGalleryTool, uploadPhotoTool, xiaoyiGuiTool, callPhoneTool, searchMessageTool, sendMessageTool, searchFileTool, uploadFileTool, createAlarmTool, searchAlarmTool, modifyAlarmTool, deleteAlarmTool, sendFileToUserTool, viewPushResultTool, imageReadingTool, timestampToUtc8Tool, xiaoyiCollectionTool, xiaoyiAddCollectionTool, xiaoyiDeleteCollectionTool, saveMediaToGalleryTool];
|
|
75
|
+
const allTools = [locationTool, noteTool, searchNoteTool, modifyNoteTool, calendarTool, searchCalendarTool, searchContactTool, searchPhotoGalleryTool, uploadPhotoTool, xiaoyiGuiTool, callPhoneTool, searchMessageTool, sendMessageTool, searchFileTool, uploadFileTool, createAlarmTool, searchAlarmTool, modifyAlarmTool, deleteAlarmTool, sendFileToUserTool, viewPushResultTool, imageReadingTool, timestampToUtc8Tool, xiaoyiCollectionTool, xiaoyiAddCollectionTool, xiaoyiDeleteCollectionTool, saveMediaToGalleryTool, saveFileToPhoneTool, findPcDevicesTool];
|
|
74
76
|
const ctx = getCurrentSessionContext();
|
|
75
77
|
const filtered = filterToolsByDevice(allTools, ctx?.deviceType);
|
|
76
78
|
logger.log(`[DEVICE-FILTER] deviceType=${ctx?.deviceType ?? "(none)"}, tools: ${allTools.length} → ${filtered.length} (${filtered.map(t => t.name).join(", ")})`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// SENTINEL HOOK API 请求模块
|
|
2
2
|
import https from "node:https";
|
|
3
3
|
import { URL } from "node:url";
|
|
4
4
|
import { randomBytes } from "node:crypto";
|
|
@@ -8,8 +8,10 @@ function generateTraceId() {
|
|
|
8
8
|
return randomBytes(16).toString("hex");
|
|
9
9
|
}
|
|
10
10
|
function buildHeaders(config) {
|
|
11
|
+
const traceId = generateTraceId();
|
|
12
|
+
console.log(`[SENTINEL HOOK] trace-id: ${traceId}`);
|
|
11
13
|
return {
|
|
12
|
-
"x-hag-trace-id":
|
|
14
|
+
"x-hag-trace-id": traceId,
|
|
13
15
|
"x-uid": config.uid,
|
|
14
16
|
"x-api-key": config.apiKey,
|
|
15
17
|
"x-request-from": config.requestFrom,
|
|
@@ -30,13 +32,13 @@ function buildRequestOptions(url, headers, timeout) {
|
|
|
30
32
|
}
|
|
31
33
|
function parseResponse(data) {
|
|
32
34
|
if (!data?.trim())
|
|
33
|
-
throw new Error("[
|
|
35
|
+
throw new Error("[SENTINEL HOOK] API response is empty");
|
|
34
36
|
const json = JSON.parse(data);
|
|
35
37
|
if (json.retCode && json.retCode !== "0") {
|
|
36
|
-
throw new Error(`[
|
|
38
|
+
throw new Error(`[SENTINEL HOOK] API error: ${json.retMsg || "unknown"}`);
|
|
37
39
|
}
|
|
38
40
|
if (!json.retCode && json.code) {
|
|
39
|
-
throw new Error(`[
|
|
41
|
+
throw new Error(`[SENTINEL HOOK] Backend error: ${json.desc || "unknown"}`);
|
|
40
42
|
}
|
|
41
43
|
return json;
|
|
42
44
|
}
|
|
@@ -47,12 +49,13 @@ export async function callCsplApi(questionText, cfg) {
|
|
|
47
49
|
questionText,
|
|
48
50
|
textSource: config.textSource,
|
|
49
51
|
action: config.action,
|
|
52
|
+
extra: JSON.stringify({ userId: config.uid }),
|
|
50
53
|
};
|
|
51
54
|
return new Promise((resolve, reject) => {
|
|
52
55
|
const options = buildRequestOptions(config.api.url, headers, config.api.timeout);
|
|
53
56
|
const req = https.request(options, (res) => {
|
|
54
57
|
if (res.statusCode && res.statusCode >= HTTP_STATUS_BAD_REQUEST) {
|
|
55
|
-
reject(new Error(`[
|
|
58
|
+
reject(new Error(`[SENTINEL HOOK] HTTP error: ${res.statusCode}`));
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
58
61
|
let data = "";
|
|
@@ -62,23 +65,23 @@ export async function callCsplApi(questionText, cfg) {
|
|
|
62
65
|
res.on("end", () => {
|
|
63
66
|
try {
|
|
64
67
|
const result = parseResponse(data);
|
|
65
|
-
console.log(`[
|
|
68
|
+
console.log(`[SENTINEL HOOK] ✅ 请求成功`);
|
|
66
69
|
resolve(result);
|
|
67
70
|
}
|
|
68
71
|
catch (e) {
|
|
69
|
-
console.error(`[
|
|
72
|
+
console.error(`[SENTINEL HOOK] ❌ 请求失败: ${e instanceof Error ? e.message : String(e)}`);
|
|
70
73
|
reject(e);
|
|
71
74
|
}
|
|
72
75
|
});
|
|
73
76
|
});
|
|
74
77
|
req.on("error", (error) => {
|
|
75
|
-
console.error(`[
|
|
78
|
+
console.error(`[SENTINEL HOOK] ❌ 请求错误: ${error instanceof Error ? error.message : String(error)}`);
|
|
76
79
|
reject(error);
|
|
77
80
|
});
|
|
78
81
|
req.on("timeout", () => {
|
|
79
|
-
console.error(`[
|
|
82
|
+
console.error(`[SENTINEL HOOK] ⏰ 请求超时 (${config.api.timeout}ms)`);
|
|
80
83
|
req.destroy();
|
|
81
|
-
reject(new Error("[
|
|
84
|
+
reject(new Error("[SENTINEL HOOK] Request timeout"));
|
|
82
85
|
});
|
|
83
86
|
req.write(JSON.stringify(payload));
|
|
84
87
|
req.end();
|
package/dist/src/cspl/config.js
CHANGED
|
@@ -7,7 +7,7 @@ import { logger } from "../utils/logger.js";
|
|
|
7
7
|
let cachedConfig = null;
|
|
8
8
|
function readServiceUrl() {
|
|
9
9
|
if (!fs.existsSync(ENV_FILE_PATH)) {
|
|
10
|
-
throw new Error(`[
|
|
10
|
+
throw new Error(`[SENTINEL HOOK] Environment file not found: ${ENV_FILE_PATH}`);
|
|
11
11
|
}
|
|
12
12
|
const envData = fs.readFileSync(ENV_FILE_PATH, "utf-8");
|
|
13
13
|
for (const line of envData.split("\n")) {
|
|
@@ -22,7 +22,7 @@ function readServiceUrl() {
|
|
|
22
22
|
if (key === "SERVICE_URL" && value)
|
|
23
23
|
return value;
|
|
24
24
|
}
|
|
25
|
-
throw new Error("[
|
|
25
|
+
throw new Error("[SENTINEL HOOK] Missing SERVICE_URL in env file");
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* 构建 CSPL 配置。uid 和 apiKey 复用 XYChannelConfig,避免重复配置。
|
|
@@ -45,6 +45,6 @@ export function getCsplConfig(cfg) {
|
|
|
45
45
|
textSource: CSPL_STATIC_CONFIG.textSource,
|
|
46
46
|
action: CSPL_STATIC_CONFIG.action,
|
|
47
47
|
};
|
|
48
|
-
logger.log("[
|
|
48
|
+
logger.log("[SENTINEL HOOK] Config loaded (uid/apiKey from XYChannelConfig)");
|
|
49
49
|
return cachedConfig;
|
|
50
50
|
}
|
package/dist/src/provider.js
CHANGED
|
@@ -101,7 +101,6 @@ export const xiaoyiProvider = {
|
|
|
101
101
|
if (context.systemPrompt) {
|
|
102
102
|
console.log(`[xiaoyiprovider] system prompt length: ${context.systemPrompt.length}`);
|
|
103
103
|
}
|
|
104
|
-
console.log(`[xiaoyiprovider] dynamic headers: ${JSON.stringify(dynamicHeaders)}`);
|
|
105
104
|
const stream = await underlying(model, context, {
|
|
106
105
|
...options,
|
|
107
106
|
headers: {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { getXYWebSocketManager } from "../client.js";
|
|
2
|
+
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
|
+
/**
|
|
5
|
+
* XY find PC devices tool - finds all PC devices associated with the user.
|
|
6
|
+
* Returns device IDs for use in subsequent file search operations.
|
|
7
|
+
*/
|
|
8
|
+
export const findPcDevicesTool = {
|
|
9
|
+
name: "find_pc_devices",
|
|
10
|
+
label: "Find PC Devices",
|
|
11
|
+
description: `查找用户所有PC/电脑设备,获取设备ID列表。当用户说"帮我找一下PC/电脑上的xxx文件"、"帮我搜索电脑上的xxx"等涉及PC设备的请求时,先调用此工具获取设备ID,再进行后续操作。注意:操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,请严格遵守。`,
|
|
12
|
+
parameters: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {},
|
|
15
|
+
required: [],
|
|
16
|
+
},
|
|
17
|
+
async execute(toolCallId, params) {
|
|
18
|
+
// Get session context
|
|
19
|
+
const sessionContext = getCurrentSessionContext();
|
|
20
|
+
if (!sessionContext) {
|
|
21
|
+
throw new Error("No active XY session found. Find PC devices tool can only be used during an active conversation.");
|
|
22
|
+
}
|
|
23
|
+
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
24
|
+
// Get WebSocket manager
|
|
25
|
+
const wsManager = getXYWebSocketManager(config);
|
|
26
|
+
// Build GetAllDevice command
|
|
27
|
+
const command = {
|
|
28
|
+
header: {
|
|
29
|
+
namespace: "Common",
|
|
30
|
+
name: "Action",
|
|
31
|
+
},
|
|
32
|
+
payload: {
|
|
33
|
+
cardParam: {},
|
|
34
|
+
executeParam: {
|
|
35
|
+
achieveType: "INTENT",
|
|
36
|
+
actionResponse: true,
|
|
37
|
+
bundleName: "com.huawei.hmos.aidispatchservice",
|
|
38
|
+
dimension: "",
|
|
39
|
+
executeMode: "background",
|
|
40
|
+
intentName: "GetAllDevice",
|
|
41
|
+
intentParam: {},
|
|
42
|
+
needUnlock: true,
|
|
43
|
+
permissionId: [],
|
|
44
|
+
timeOut: 5,
|
|
45
|
+
},
|
|
46
|
+
needUploadResult: true,
|
|
47
|
+
pageControlRelated: false,
|
|
48
|
+
responses: [{
|
|
49
|
+
displayText: "",
|
|
50
|
+
resultCode: "",
|
|
51
|
+
ttsText: "",
|
|
52
|
+
}],
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
// Send command and wait for response (60 second timeout)
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
const timeout = setTimeout(() => {
|
|
58
|
+
wsManager.off("data-event", handler);
|
|
59
|
+
reject(new Error("查找PC设备超时(60秒)"));
|
|
60
|
+
}, 60000);
|
|
61
|
+
// Listen for data events from WebSocket
|
|
62
|
+
const handler = (event) => {
|
|
63
|
+
if (event.intentName === "GetAllDevice") {
|
|
64
|
+
clearTimeout(timeout);
|
|
65
|
+
wsManager.off("data-event", handler);
|
|
66
|
+
if (event.status === "success" && event.outputs) {
|
|
67
|
+
resolve({
|
|
68
|
+
content: [
|
|
69
|
+
{
|
|
70
|
+
type: "text",
|
|
71
|
+
text: JSON.stringify(event.outputs),
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
reject(new Error(`查找PC设备失败: ${event.status}`));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
// Register event handler
|
|
82
|
+
wsManager.on("data-event", handler);
|
|
83
|
+
// Send the command
|
|
84
|
+
sendCommand({
|
|
85
|
+
config,
|
|
86
|
+
sessionId,
|
|
87
|
+
taskId,
|
|
88
|
+
messageId,
|
|
89
|
+
command,
|
|
90
|
+
}).then(() => {
|
|
91
|
+
}).catch((error) => {
|
|
92
|
+
clearTimeout(timeout);
|
|
93
|
+
wsManager.off("data-event", handler);
|
|
94
|
+
reject(error);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { getXYWebSocketManager } from "../client.js";
|
|
2
|
+
import { sendCommand } from "../formatter.js";
|
|
3
|
+
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
|
+
import { XYFileUploadService } from "../file-upload.js";
|
|
5
|
+
/**
|
|
6
|
+
* Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
|
|
7
|
+
* 抛出此错误会让 openclaw 返回 HTTP 400 而非 500,
|
|
8
|
+
* LLM 会将其识别为参数错误而非瞬时故障,不会触发重试。
|
|
9
|
+
*/
|
|
10
|
+
class ToolInputError extends Error {
|
|
11
|
+
status = 400;
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "ToolInputError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* XY save file to phone tool - saves files to user's device file manager.
|
|
19
|
+
* Supports local file paths (auto-uploaded to get public URL) and public URLs.
|
|
20
|
+
*/
|
|
21
|
+
export const saveFileToPhoneTool = {
|
|
22
|
+
name: "save_file_to_file_manager",
|
|
23
|
+
label: "Save File to Phone",
|
|
24
|
+
description: `将文件保存到手机文件管理器。
|
|
25
|
+
工具参数说明:
|
|
26
|
+
a. fileName:必填,string类型,文件名称。
|
|
27
|
+
b. url:必填,string类型,支持本地路径或者公网url路径。如果是本地路径,会先上传获取公网url再保存到手机。
|
|
28
|
+
c. suffix:必填,string类型,文件后缀,例如 ppt、doc、pdf 等。
|
|
29
|
+
|
|
30
|
+
注意:
|
|
31
|
+
a. 操作超时时间为60秒,请勿重复调用此工具
|
|
32
|
+
b. 如果遇到各类调用失败场景,不可以重试,直接返回错误。
|
|
33
|
+
c. 调用工具前需认真检查调用参数是否满足工具要求
|
|
34
|
+
|
|
35
|
+
回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
|
|
36
|
+
`,
|
|
37
|
+
parameters: {
|
|
38
|
+
type: "object",
|
|
39
|
+
properties: {
|
|
40
|
+
fileName: {
|
|
41
|
+
type: "string",
|
|
42
|
+
description: "必填,文件名称。",
|
|
43
|
+
},
|
|
44
|
+
url: {
|
|
45
|
+
type: "string",
|
|
46
|
+
description: "必填,支持本地路径或者公网url路径。如果是本地路径会先上传获取公网url。",
|
|
47
|
+
},
|
|
48
|
+
suffix: {
|
|
49
|
+
type: "string",
|
|
50
|
+
description: "必填,文件后缀,例如 ppt、doc、pdf 等。",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
required: ["fileName", "url", "suffix"],
|
|
54
|
+
},
|
|
55
|
+
async execute(toolCallId, params) {
|
|
56
|
+
// Validate parameters
|
|
57
|
+
const { fileName, url, suffix } = params;
|
|
58
|
+
if (!url || typeof url !== "string") {
|
|
59
|
+
throw new ToolInputError("缺少必填参数: url");
|
|
60
|
+
}
|
|
61
|
+
if (!fileName || typeof fileName !== "string") {
|
|
62
|
+
throw new ToolInputError("缺少必填参数: fileName");
|
|
63
|
+
}
|
|
64
|
+
if (!suffix || typeof suffix !== "string") {
|
|
65
|
+
throw new ToolInputError("缺少必填参数: suffix");
|
|
66
|
+
}
|
|
67
|
+
// Get session context
|
|
68
|
+
const sessionContext = getCurrentSessionContext();
|
|
69
|
+
if (!sessionContext) {
|
|
70
|
+
throw new Error("No active XY session found. SaveFileToFileManager tool can only be used during an active conversation.");
|
|
71
|
+
}
|
|
72
|
+
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
73
|
+
// Get WebSocket manager
|
|
74
|
+
const wsManager = getXYWebSocketManager(config);
|
|
75
|
+
// Determine the URL: if it's a local path, upload first to get public URL
|
|
76
|
+
let publicUrl = url;
|
|
77
|
+
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
|
78
|
+
// Local file path - upload to get public URL
|
|
79
|
+
const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
|
|
80
|
+
publicUrl = await uploadService.uploadFileAndGetUrl(url);
|
|
81
|
+
if (!publicUrl) {
|
|
82
|
+
throw new Error("本地文件上传失败,无法获取公网URL");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Build intentParam
|
|
86
|
+
const intentParam = {
|
|
87
|
+
fileName: fileName,
|
|
88
|
+
url: publicUrl,
|
|
89
|
+
suffix: suffix,
|
|
90
|
+
};
|
|
91
|
+
// Build SaveFileToFileManager command
|
|
92
|
+
const command = {
|
|
93
|
+
header: {
|
|
94
|
+
namespace: "Common",
|
|
95
|
+
name: "Action",
|
|
96
|
+
},
|
|
97
|
+
payload: {
|
|
98
|
+
cardParam: {},
|
|
99
|
+
executeParam: {
|
|
100
|
+
executeMode: "background",
|
|
101
|
+
intentName: "SaveFileToFileManager",
|
|
102
|
+
bundleName: "com.huawei.hmos.vassistant",
|
|
103
|
+
dimension: "",
|
|
104
|
+
needUnlock: true,
|
|
105
|
+
actionResponse: true,
|
|
106
|
+
appType: "OHOS_APP",
|
|
107
|
+
timeOut: 5,
|
|
108
|
+
timeout: 55000,
|
|
109
|
+
intentParam,
|
|
110
|
+
permissionId: ["ohos.permission.WRITE_IMAGEVIDEO"],
|
|
111
|
+
achieveType: "INTENT",
|
|
112
|
+
},
|
|
113
|
+
responses: [
|
|
114
|
+
{
|
|
115
|
+
resultCode: "",
|
|
116
|
+
displayText: "",
|
|
117
|
+
ttsText: "",
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
needUploadResult: true,
|
|
121
|
+
noHalfPage: false,
|
|
122
|
+
pageControlRelated: false,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
// Send command and wait for response (60 second timeout)
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
const timeout = setTimeout(() => {
|
|
128
|
+
wsManager.off("data-event", handler);
|
|
129
|
+
reject(new Error("保存文件到手机超时(60秒)"));
|
|
130
|
+
}, 60000);
|
|
131
|
+
// Listen for data events from WebSocket
|
|
132
|
+
const handler = (event) => {
|
|
133
|
+
if (event.intentName === "SaveFileToFileManager") {
|
|
134
|
+
clearTimeout(timeout);
|
|
135
|
+
wsManager.off("data-event", handler);
|
|
136
|
+
if (event.status === "success" && event.outputs) {
|
|
137
|
+
resolve({
|
|
138
|
+
content: [
|
|
139
|
+
{
|
|
140
|
+
type: "text",
|
|
141
|
+
text: JSON.stringify(event.outputs),
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
reject(new Error(`保存文件到手机失败: ${event.status}`));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
// Register event handler
|
|
152
|
+
wsManager.on("data-event", handler);
|
|
153
|
+
// Send the command
|
|
154
|
+
sendCommand({
|
|
155
|
+
config,
|
|
156
|
+
sessionId,
|
|
157
|
+
taskId,
|
|
158
|
+
messageId,
|
|
159
|
+
command,
|
|
160
|
+
})
|
|
161
|
+
.then(() => {
|
|
162
|
+
})
|
|
163
|
+
.catch((error) => {
|
|
164
|
+
clearTimeout(timeout);
|
|
165
|
+
wsManager.off("data-event", handler);
|
|
166
|
+
reject(error);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
};
|
|
@@ -19,7 +19,7 @@ class ToolInputError extends Error {
|
|
|
19
19
|
* Supports local file paths (auto-uploaded to get public URL) and public URLs.
|
|
20
20
|
*/
|
|
21
21
|
export const saveMediaToGalleryTool = {
|
|
22
|
-
name: "
|
|
22
|
+
name: "save_media_to_gallery",
|
|
23
23
|
label: "Save Media to Gallery",
|
|
24
24
|
description: `将图片文件或者视频文件保存到手机图库。
|
|
25
25
|
工具参数说明:
|
|
@@ -8,15 +8,13 @@ import { getCurrentSessionContext } from "./session-manager.js";
|
|
|
8
8
|
export const searchFileTool = {
|
|
9
9
|
name: "search_file",
|
|
10
10
|
label: "Search File",
|
|
11
|
-
description:
|
|
11
|
+
description: `搜索手机或PC/电脑文件系统的文件。
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- "在手机上查找文件xxxx"
|
|
17
|
-
- "搜索手机里的文件"
|
|
13
|
+
【重要】使用场景与调用流程:
|
|
14
|
+
1. 搜索手机文件:当用户明确说明要从手机搜索时(如"从手机里面搜索xxxx"、"在手机上查找文件xxxx"),直接调用此工具,无需传入 udid。
|
|
15
|
+
2. 搜索PC/电脑文件:当用户要求搜索PC/电脑上的文件时(如"帮我找一下PC上的xxx文件"、"搜索电脑上的xxx"),必须先调用 find_pc_devices 工具获取设备ID(udid),然后将 udid 传入此工具进行搜索。
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
如果用户没有明确说明从手机或PC搜索(如仅说"搜索文件"、"找一下xxxx"),应默认从 openclaw 本地的文件系统查询,不要调用此工具。
|
|
20
18
|
|
|
21
19
|
功能说明:根据关键词搜索文件名称或内容,返回匹配的文件列表(包括文件名、路径、大小、修改时间等信息)。
|
|
22
20
|
|
|
@@ -28,6 +26,10 @@ export const searchFileTool = {
|
|
|
28
26
|
type: "string",
|
|
29
27
|
description: "搜索关键词,用于匹配文件名称、后缀名或文件内容",
|
|
30
28
|
},
|
|
29
|
+
udid: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "PC/电脑设备ID。当搜索PC/电脑上的文件时,需要先通过 find_pc_devices 工具获取设备ID后传入。搜索手机文件时不需要传入此参数。",
|
|
32
|
+
},
|
|
31
33
|
},
|
|
32
34
|
required: ["query"],
|
|
33
35
|
},
|
|
@@ -62,6 +64,7 @@ export const searchFileTool = {
|
|
|
62
64
|
timeOut: 5,
|
|
63
65
|
intentParam: {
|
|
64
66
|
query: params.query.trim(),
|
|
67
|
+
...(params.udid ? { udid: params.udid } : {}),
|
|
65
68
|
},
|
|
66
69
|
permissionId: [],
|
|
67
70
|
achieveType: "INTENT",
|
|
@@ -16,14 +16,19 @@ import { getCurrentSessionContext } from "./session-manager.js";
|
|
|
16
16
|
export const uploadFileTool = {
|
|
17
17
|
name: "upload_file",
|
|
18
18
|
label: "Upload File",
|
|
19
|
-
description:
|
|
19
|
+
description: `工具能力描述:将手机或PC/电脑本地文件上传并获取可公网访问的 URL。
|
|
20
20
|
|
|
21
21
|
前置工具调用:此工具使用前必须先调用 search_file 或者 QueryCollection 工具获取文件的 uri
|
|
22
22
|
|
|
23
|
+
使用场景与调用流程:
|
|
24
|
+
1. 上传手机文件:直接调用此工具,无需传入 udid。
|
|
25
|
+
2. 上传PC/电脑文件:当用户要求上传PC/电脑上的文件时,需要先通过 find_pc_devices 工具获取设备ID(udid),然后将 udid 传入此工具。
|
|
26
|
+
|
|
23
27
|
工具参数说明:
|
|
24
28
|
a. 入参中的fileInfos数组,每个元素必须包含mediaUri字段(对应于search_file工具或者QueryCollection返回结果中的uri),必须与search_file或者QueryCollection结果中对应的uri完全保持一致,不要自行修改。
|
|
25
29
|
b. fileInfos中的timeout字段是可选的,表示上传文件超时时间,单位是毫秒,默认是20000(20秒)。
|
|
26
|
-
c. fileInfos
|
|
30
|
+
c. fileInfos 是文件在本地的信息数组(从 search_file 工具响应中获取)。限制:每次最多支持传入 5 条文件信息。
|
|
31
|
+
d. udid 是PC/电脑设备ID,仅在上传PC/电脑文件时需要传入(通过 find_pc_devices 工具获取)。
|
|
27
32
|
|
|
28
33
|
注意事项:
|
|
29
34
|
a. 操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。
|
|
@@ -36,6 +41,10 @@ export const uploadFileTool = {
|
|
|
36
41
|
// 具体的类型验证和转换在 execute 函数内部进行
|
|
37
42
|
description: "文件信息数组,每个元素包含mediaUri(必需)和timeout(可选,默认20000)。必须先通过 search_file 工具获取。每次最多支持 5 条文件信息。",
|
|
38
43
|
},
|
|
44
|
+
udid: {
|
|
45
|
+
type: "string",
|
|
46
|
+
description: "PC/电脑设备ID。当上传PC/电脑上的文件时,需要先通过 find_pc_devices 工具获取设备ID后传入。上传手机文件时不需要传入此参数。",
|
|
47
|
+
},
|
|
39
48
|
},
|
|
40
49
|
required: ["fileInfos"],
|
|
41
50
|
},
|
|
@@ -99,7 +108,7 @@ export const uploadFileTool = {
|
|
|
99
108
|
// Get WebSocket manager
|
|
100
109
|
const wsManager = getXYWebSocketManager(config);
|
|
101
110
|
// Get public URLs for the files
|
|
102
|
-
const fileUrls = await getFileUrls(wsManager, config, sessionId, taskId, messageId, fileInfos);
|
|
111
|
+
const fileUrls = await getFileUrls(wsManager, config, sessionId, taskId, messageId, fileInfos, params.udid);
|
|
103
112
|
return {
|
|
104
113
|
content: [
|
|
105
114
|
{
|
|
@@ -118,7 +127,7 @@ export const uploadFileTool = {
|
|
|
118
127
|
* Get public URLs for files using fileInfos
|
|
119
128
|
* Returns array of publicly accessible file URLs
|
|
120
129
|
*/
|
|
121
|
-
async function getFileUrls(wsManager, config, sessionId, taskId, messageId, fileInfos) {
|
|
130
|
+
async function getFileUrls(wsManager, config, sessionId, taskId, messageId, fileInfos, udid) {
|
|
122
131
|
const command = {
|
|
123
132
|
header: {
|
|
124
133
|
namespace: "Common",
|
|
@@ -136,6 +145,7 @@ async function getFileUrls(wsManager, config, sessionId, taskId, messageId, file
|
|
|
136
145
|
timeOut: 5,
|
|
137
146
|
intentParam: {
|
|
138
147
|
fileInfos: fileInfos,
|
|
148
|
+
...(udid ? { udid } : {}),
|
|
139
149
|
},
|
|
140
150
|
permissionId: [],
|
|
141
151
|
achieveType: "INTENT",
|
|
@@ -18,7 +18,7 @@ class ToolInputError extends Error {
|
|
|
18
18
|
* XY add collection tool - adds data to user's XiaoYi collection.
|
|
19
19
|
*/
|
|
20
20
|
export const xiaoyiAddCollectionTool = {
|
|
21
|
-
name: "
|
|
21
|
+
name: "add_collection",
|
|
22
22
|
label: "Add XiaoYi Collection",
|
|
23
23
|
description: `向小艺收藏中添加公共知识数据,可以给用户提供个性化体验。任何用户希望保存到个人化知识库中的数据都可以调用本技能。不同类型的数据对应的数据要求如下:
|
|
24
24
|
请求入参说明:
|
|
@@ -18,7 +18,7 @@ class ToolInputError extends Error {
|
|
|
18
18
|
* Returns personalized knowledge data saved in user's collection.
|
|
19
19
|
*/
|
|
20
20
|
export const xiaoyiCollectionTool = {
|
|
21
|
-
name: "
|
|
21
|
+
name: "query_collection",
|
|
22
22
|
label: "XiaoYi Collection",
|
|
23
23
|
description: `检索用户在小艺收藏中记下来的公共知识数据,本技能支持查询用户收藏的公共知识数据,也可以根据特定语义化描述进行特定内容的检索,通过参数进行控制。本技能返回结果中,linkTitle是收藏内容的标题,description是对收藏内容的总结,label是收藏内容的标签,linkUrl是可以直接访问的原始内容链接。如果你认为某条数据对用户交互有用,可以通过linkUrl抓取更加丰富的原始数据。
|
|
24
24
|
注意:
|
|
@@ -17,7 +17,7 @@ class ToolInputError extends Error {
|
|
|
17
17
|
* XY delete collection tool - deletes data from user's XiaoYi collection.
|
|
18
18
|
*/
|
|
19
19
|
export const xiaoyiDeleteCollectionTool = {
|
|
20
|
-
name: "
|
|
20
|
+
name: "delete_collection",
|
|
21
21
|
label: "Delete XiaoYi Collection",
|
|
22
22
|
description: `从小艺收藏中删除之前已保存的公共知识数据。任何用户希望删除已保存到个人知识库的数据都可以调用本技能。如果用户想更新之前的收藏数据,需要先query获取itemId然后再delete,最后执行Add,按照这个步骤完成收藏数据更新。
|
|
23
23
|
注意:
|