@ynhcj/xiaoyi-channel 0.0.53-beta → 0.0.53-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 (50) hide show
  1. package/dist/index.js +7 -4
  2. package/dist/src/bot.d.ts +1 -0
  3. package/dist/src/bot.js +45 -32
  4. package/dist/src/channel.js +16 -2
  5. package/dist/src/client.js +0 -6
  6. package/dist/src/cspl/call-api.js +14 -32
  7. package/dist/src/cspl/config.js +3 -3
  8. package/dist/src/cspl/constants.d.ts +1 -0
  9. package/dist/src/file-download.js +5 -6
  10. package/dist/src/file-upload.js +1 -11
  11. package/dist/src/formatter.d.ts +2 -0
  12. package/dist/src/formatter.js +11 -6
  13. package/dist/src/monitor.js +8 -10
  14. package/dist/src/outbound.js +1 -19
  15. package/dist/src/parser.d.ts +6 -0
  16. package/dist/src/parser.js +16 -0
  17. package/dist/src/provider.d.ts +2 -0
  18. package/dist/src/provider.js +124 -0
  19. package/dist/src/push.js +0 -21
  20. package/dist/src/reply-dispatcher.d.ts +4 -0
  21. package/dist/src/reply-dispatcher.js +15 -11
  22. package/dist/src/tools/call-phone-tool.js +2 -18
  23. package/dist/src/tools/create-alarm-tool.js +3 -7
  24. package/dist/src/tools/device-tool-map.d.ts +4 -0
  25. package/dist/src/tools/device-tool-map.js +35 -0
  26. package/dist/src/tools/find-pc-devices-tool.d.ts +5 -0
  27. package/dist/src/tools/find-pc-devices-tool.js +98 -0
  28. package/dist/src/tools/image-reading-tool.js +3 -3
  29. package/dist/src/tools/modify-alarm-tool.js +3 -7
  30. package/dist/src/tools/save-file-to-phone-tool.d.ts +5 -0
  31. package/dist/src/tools/save-file-to-phone-tool.js +170 -0
  32. package/dist/src/tools/save-media-to-gallery-tool.d.ts +5 -0
  33. package/dist/src/tools/save-media-to-gallery-tool.js +178 -0
  34. package/dist/src/tools/send-command-to-car-tool.d.ts +5 -0
  35. package/dist/src/tools/send-command-to-car-tool.js +85 -0
  36. package/dist/src/tools/send-file-to-user-tool.js +1 -0
  37. package/dist/src/tools/session-manager.d.ts +1 -0
  38. package/dist/src/tools/timestamp-to-utc8-tool.d.ts +12 -0
  39. package/dist/src/tools/timestamp-to-utc8-tool.js +104 -0
  40. package/dist/src/tools/upload-file-tool.js +2 -2
  41. package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +4 -0
  42. package/dist/src/tools/xiaoyi-add-collection-tool.js +188 -0
  43. package/dist/src/tools/xiaoyi-collection-tool.js +42 -7
  44. package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +4 -0
  45. package/dist/src/tools/xiaoyi-delete-collection-tool.js +163 -0
  46. package/dist/src/utils/runtime-manager.d.ts +7 -0
  47. package/dist/src/utils/runtime-manager.js +42 -0
  48. package/dist/src/websocket.js +15 -9
  49. package/openclaw.plugin.json +1 -0
  50. package/package.json +2 -3
@@ -0,0 +1,104 @@
1
+ /**
2
+ * XY timestamp to UTC+8 time tool - converts timestamp to UTC+8 time format.
3
+ * Supports both second-level and millisecond-level timestamps.
4
+ *
5
+ * This is a utility tool that doesn't require device communication.
6
+ * It converts Unix timestamp to UTC+8 time in YYYYMMDD hhmmss format.
7
+ *
8
+ * Important: The search_calendar_event and search_alarm tools return timestamps.
9
+ * Call this tool first to convert timestamps to readable UTC+8 time format before
10
+ * presenting results to users or performing further operations.
11
+ */
12
+ export const timestampToUtc8Tool = {
13
+ name: "convert_timestamp_to_utc8_time",
14
+ label: "Convert Timestamp to UTC+8 Time",
15
+ description: `将时间戳转换为标准 UTC+8 时间格式。支持秒级时间戳和毫秒级时间戳。
16
+
17
+ 输入参数:
18
+ - timestamp: 时间戳(数字类型),可以是秒级(10位)或毫秒级(13位)
19
+
20
+ 输出格式:
21
+ - YYYYMMDD hhmmss(例如:20240315 143000 表示 2024年3月15日 14:30:00 北京时间)
22
+
23
+ 重要说明:
24
+ 搜索日程工具(search_calendar_event)和搜索闹钟工具(search_alarm)等工具中返回结果如果包含时间戳。
25
+ 建议优先调用本时间戳转换工具,将时间戳转换为标准北京时间格式,再基于标准时间进行用户回答或下一步操作。
26
+
27
+ 示例:
28
+ - 输入:1710498600(秒级)或 1710498600000(毫秒级)
29
+ - 输出:20240315 143000`,
30
+ parameters: {
31
+ type: "object",
32
+ properties: {
33
+ timestamp: {
34
+ type: "number",
35
+ description: "时间戳,支持秒级(10位)或毫秒级(13位)时间戳",
36
+ },
37
+ },
38
+ required: ["timestamp"],
39
+ },
40
+ async execute(toolCallId, params) {
41
+ // Validate timestamp parameter
42
+ if (params.timestamp === undefined || params.timestamp === null) {
43
+ throw new Error("缺少必需参数:timestamp");
44
+ }
45
+ const timestamp = params.timestamp;
46
+ // Validate it's a number
47
+ if (typeof timestamp !== "number") {
48
+ throw new Error("timestamp 必须是数字类型");
49
+ }
50
+ // Check if timestamp is valid
51
+ if (isNaN(timestamp)) {
52
+ throw new Error("timestamp 不是有效数字");
53
+ }
54
+ // Determine if it's seconds or milliseconds
55
+ // Millisecond timestamps are typically 13 digits (year 2024+)
56
+ // Second timestamps are typically 10 digits
57
+ let timestampInMs;
58
+ const timestampStr = Math.abs(timestamp).toString();
59
+ if (timestampStr.length === 13) {
60
+ // It's already in milliseconds
61
+ timestampInMs = timestamp;
62
+ }
63
+ else if (timestampStr.length === 10) {
64
+ // It's in seconds, convert to milliseconds
65
+ timestampInMs = timestamp * 1000;
66
+ }
67
+ else if (timestamp > 1000000000000) {
68
+ // Likely milliseconds (greater than year 2001 in milliseconds)
69
+ timestampInMs = timestamp;
70
+ }
71
+ else {
72
+ // Likely seconds, convert to milliseconds
73
+ timestampInMs = timestamp * 1000;
74
+ }
75
+ // Create Date object from timestamp
76
+ const date = new Date(timestampInMs);
77
+ // Check if date is valid
78
+ if (isNaN(date.getTime())) {
79
+ throw new Error("无效的时间戳,无法转换为日期");
80
+ }
81
+ // Convert to Beijing time (UTC+8)
82
+ const beijingTime = new Date(date.getTime() + (8 * 60 * 60 * 1000));
83
+ // Format: YYYYMMDD hhmmss
84
+ const year = beijingTime.getUTCFullYear();
85
+ const month = beijingTime.getUTCMonth() + 1; // Months are 0-indexed
86
+ const day = beijingTime.getUTCDate();
87
+ const hours = beijingTime.getUTCHours();
88
+ const minutes = beijingTime.getUTCMinutes();
89
+ const seconds = beijingTime.getUTCSeconds();
90
+ // Pad with leading zeros
91
+ const formattedDate = `${year}${String(month).padStart(2, '0')}${String(day).padStart(2, '0')}`;
92
+ const formattedTime = `${String(hours).padStart(2, '0')}${String(minutes).padStart(2, '0')}${String(seconds).padStart(2, '0')}`;
93
+ const result = `${formattedDate} ${formattedTime}`;
94
+ // Return the formatted time
95
+ return {
96
+ content: [
97
+ {
98
+ type: "text",
99
+ text: result,
100
+ },
101
+ ],
102
+ };
103
+ },
104
+ };
@@ -18,10 +18,10 @@ export const uploadFileTool = {
18
18
  label: "Upload File",
19
19
  description: `工具能力描述:将手机本地文件上传并获取可公网访问的 URL。
20
20
 
21
- 前置工具调用:此工具使用前必须先调用 search_file 工具获取文件的 uri
21
+ 前置工具调用:此工具使用前必须先调用 search_file 或者 query_collection 工具获取文件的 uri=
22
22
 
23
23
  工具参数说明:
24
- a. 入参中的fileInfos数组,每个元素必须包含mediaUri字段(对应于search_file工具返回结果中的uri),必须与search_file结果中对应的uri完全保持一致,不要自行修改。
24
+ a. 入参中的fileInfos数组,每个元素必须包含mediaUri字段(对应于search_file工具或者query_collection返回结果中的uri),必须与search_file或者query_collection结果中对应的uri完全保持一致,不要自行修改。
25
25
  b. fileInfos中的timeout字段是可选的,表示上传文件超时时间,单位是毫秒,默认是20000(20秒)。
26
26
  c. fileInfos 是文件在手机本地的信息数组(从 search_file 工具响应中获取)。限制:每次最多支持传入 5 条文件信息。
27
27
 
@@ -0,0 +1,4 @@
1
+ /**
2
+ * XY add collection tool - adds data to user's XiaoYi collection.
3
+ */
4
+ export declare const xiaoyiAddCollectionTool: any;
@@ -0,0 +1,188 @@
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 add collection tool - adds data to user's XiaoYi collection.
19
+ */
20
+ export const xiaoyiAddCollectionTool = {
21
+ name: "add_collection",
22
+ label: "Add XiaoYi Collection",
23
+ description: `向小艺收藏中添加公共知识数据,可以给用户提供个性化体验。任何用户希望保存到个人化知识库中的数据都可以调用本技能。不同类型的数据对应的数据要求如下:
24
+ 请求入参说明:
25
+ ● content:必填字段,数据类型为string,功能描述是该字段是用户添加收藏的链接url或文本原文。适用于HYPER_LINK和TEXT类型。
26
+ ● uri:必填字段,数据类型为string,功能描述是该字段是图片或文件的端存储地址链接。适用于IMAGE和FILE类型。
27
+ ● sourceAppBundleName:非必填字段,数据类型为string,功能描述是标识该数据的来源应用。
28
+ ● dataType:必填字段,数据类型为string,功能描述是标识数据类型。HYPER_LINK标识网页,TEXT标识文本,IMAGE标识图片,FILE标识文件。
29
+ ● title:非必填字段,数据类型为string,功能描述是标识文件类型数据的文件名称。适用于FILE类型。
30
+ 说明:如果dataType为HYPER_LINK或TEXT,则content字段必填且不能为空;如果dataType为IMAGE或FILE,则uri字段必填且不能为空。当用户希望收藏海报、截图等图片类数据时,请将数据以图片IMAGE的形式存入到小艺帮记;当用户希望收藏电子书、笔记、报告、素材、文档、合同、协议、简历、证书、报表、日志、安装包、压缩包等描述的文件时,请将数据以文件FILE的形式存入到小艺帮记。
31
+ 当你成功收藏这个数据到小艺帮记后,请在最后显示"已成功把数据添加到[小艺帮记](vassistant://voice/main?page=CollectionPage&jumpHomePageTab=myCollection)",
32
+ 注意:
33
+ a. 操作超时时间为60秒,请勿重复调用此工具
34
+ b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
35
+ c. 调用工具前需认真检查调用参数是否满足工具要求
36
+
37
+ 回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
38
+ `,
39
+ parameters: {
40
+ type: "object",
41
+ properties: {
42
+ content: {
43
+ type: "string",
44
+ description: "必填字段(HYPER_LINK/TEXT类型时)。用户添加收藏的链接url或文本原文。",
45
+ },
46
+ uri: {
47
+ type: "string",
48
+ description: "必填字段(IMAGE/FILE类型时)。图片或文件的地址链接。",
49
+ },
50
+ sourceAppBundleName: {
51
+ type: "string",
52
+ description: "非必填字段。标识该数据的来源应用。",
53
+ },
54
+ dataType: {
55
+ type: "string",
56
+ description: "必填字段。标识数据类型:HYPER_LINK表示网页,TEXT表示文本,IMAGE表示图片,FILE表示文件。",
57
+ },
58
+ title: {
59
+ type: "string",
60
+ description: "非必填字段。标识文件类型数据的文件名称。适用于FILE类型。",
61
+ },
62
+ },
63
+ required: ["dataType"],
64
+ },
65
+ async execute(toolCallId, params) {
66
+ // Validate parameters
67
+ const { content, uri, sourceAppBundleName, dataType, title } = params;
68
+ const validTypes = ["HYPER_LINK", "TEXT", "IMAGE", "FILE"];
69
+ if (!dataType || !validTypes.includes(dataType)) {
70
+ throw new ToolInputError(`dataType必填且必须为 HYPER_LINK、TEXT、IMAGE、FILE 之一,当前值: ${dataType}`);
71
+ }
72
+ if ((dataType === "HYPER_LINK" || dataType === "TEXT") && (!content || typeof content !== "string")) {
73
+ throw new ToolInputError(`dataType为${dataType}时,content字段必填且不能为空`);
74
+ }
75
+ if ((dataType === "IMAGE" || dataType === "FILE") && (!uri || typeof uri !== "string")) {
76
+ throw new ToolInputError(`dataType为${dataType}时,uri字段必填且不能为空`);
77
+ }
78
+ // Get session context
79
+ const sessionContext = getCurrentSessionContext();
80
+ if (!sessionContext) {
81
+ throw new Error("No active XY session found. AddCollection tool can only be used during an active conversation.");
82
+ }
83
+ const { config, sessionId, taskId, messageId } = sessionContext;
84
+ // Get WebSocket manager
85
+ const wsManager = getXYWebSocketManager(config);
86
+ // Handle uri: upload local paths to get public URL
87
+ let publicUri = uri;
88
+ if (uri && !uri.startsWith("http://") && !uri.startsWith("https://") && !uri.startsWith("file://")) {
89
+ const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
90
+ publicUri = await uploadService.uploadFileAndGetUrl(uri);
91
+ if (!publicUri) {
92
+ throw new Error("本地文件上传失败,无法获取公网URL");
93
+ }
94
+ }
95
+ // Build intentParam
96
+ const intentParam = {
97
+ dataType,
98
+ };
99
+ if (content) {
100
+ intentParam.content = content;
101
+ }
102
+ if (publicUri) {
103
+ intentParam.uri = publicUri;
104
+ }
105
+ if (sourceAppBundleName) {
106
+ intentParam.sourceAppBundleName = sourceAppBundleName;
107
+ }
108
+ if (title) {
109
+ intentParam.title = title;
110
+ }
111
+ // Build AddCollection command
112
+ const command = {
113
+ header: {
114
+ namespace: "Common",
115
+ name: "Action",
116
+ },
117
+ payload: {
118
+ cardParam: {},
119
+ executeParam: {
120
+ executeMode: "background",
121
+ intentName: "AddCollection",
122
+ bundleName: "com.huawei.hmos.vassistant",
123
+ needUnlock: true,
124
+ actionResponse: true,
125
+ appType: "OHOS_APP",
126
+ timeOut: 5,
127
+ intentParam,
128
+ permissionId: [],
129
+ achieveType: "INTENT",
130
+ },
131
+ responses: [
132
+ {
133
+ resultCode: "",
134
+ displayText: "",
135
+ ttsText: "",
136
+ },
137
+ ],
138
+ needUploadResult: true,
139
+ noHalfPage: false,
140
+ pageControlRelated: false,
141
+ },
142
+ };
143
+ // Send command and wait for response (60 second timeout)
144
+ return new Promise((resolve, reject) => {
145
+ const timeout = setTimeout(() => {
146
+ wsManager.off("data-event", handler);
147
+ reject(new Error("添加小艺收藏超时(60秒)"));
148
+ }, 60000);
149
+ // Listen for data events from WebSocket
150
+ const handler = (event) => {
151
+ if (event.intentName === "AddCollection") {
152
+ clearTimeout(timeout);
153
+ wsManager.off("data-event", handler);
154
+ if (event.status === "success" && event.outputs) {
155
+ resolve({
156
+ content: [
157
+ {
158
+ type: "text",
159
+ text: JSON.stringify(event.outputs),
160
+ }
161
+ ]
162
+ });
163
+ }
164
+ else {
165
+ reject(new Error(`添加小艺收藏失败: ${event.status}`));
166
+ }
167
+ }
168
+ };
169
+ // Register event handler
170
+ wsManager.on("data-event", handler);
171
+ // Send the command
172
+ sendCommand({
173
+ config,
174
+ sessionId,
175
+ taskId,
176
+ messageId,
177
+ command,
178
+ })
179
+ .then(() => {
180
+ })
181
+ .catch((error) => {
182
+ clearTimeout(timeout);
183
+ wsManager.off("data-event", handler);
184
+ reject(error);
185
+ });
186
+ });
187
+ },
188
+ };
@@ -1,26 +1,54 @@
1
1
  import { getXYWebSocketManager } from "../client.js";
2
2
  import { sendCommand } from "../formatter.js";
3
3
  import { getCurrentSessionContext } from "./session-manager.js";
4
+ /**
5
+ * Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
6
+ * 抛出此错误会让 openclaw 返回 HTTP 400 而非 500,
7
+ * LLM 会将其识别为参数错误而非瞬时故障,不会触发重试。
8
+ */
9
+ class ToolInputError extends Error {
10
+ status = 400;
11
+ constructor(message) {
12
+ super(message);
13
+ this.name = "ToolInputError";
14
+ }
15
+ }
4
16
  /**
5
17
  * XY collection tool - retrieves user's collection data from XiaoYi.
6
18
  * Returns personalized knowledge data saved in user's collection.
7
19
  */
8
20
  export const xiaoyiCollectionTool = {
9
- name: "xiaoyi_collection",
21
+ name: "query_collection",
10
22
  label: "XiaoYi Collection",
11
- description: "检索用户在小艺收藏中记下来的公共知识数据,可以给用户提供个性化体验。当用户语料中涉及从我的小艺收藏或者查看我的收藏或者我xx时候收藏的xxx帮我看一下这种类型的语料的时候需要使用此工具。注意:操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。",
23
+ description: `检索用户在小艺收藏中记下来的公共知识数据,本技能支持查询用户收藏的公共知识数据,也可以根据特定语义化描述进行特定内容的检索,通过参数进行控制。本技能返回结果中,linkTitle是收藏内容的标题,description是对收藏内容的总结,label是收藏内容的标签,linkUrl是可以直接访问的原始内容链接。如果你认为某条数据对用户交互有用,可以通过linkUrl抓取更加丰富的原始数据。
24
+ 注意:
25
+ a. 操作超时时间为60秒,请勿重复调用此工具
26
+ b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
27
+ c. 调用工具前需认真检查调用参数是否满足工具要求
28
+
29
+ 回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
30
+ `,
12
31
  parameters: {
13
32
  type: "object",
14
33
  properties: {
15
34
  queryAll: {
16
35
  type: "string",
17
- description: "描述是否需要查询用户所有收藏数据,默认为true",
18
- default: "true",
36
+ description: "非必填参数,描述是否需要查询用户所有收藏数据。如果填入true则表示获取用户所有公共知识数据,其他参数无效。",
37
+ },
38
+ query: {
39
+ type: "string",
40
+ description: "非必填参数,queryAll不填或者为false则必填。用户的查询条件,可按照用户query进行检索。",
19
41
  },
20
42
  },
21
43
  required: [],
22
44
  },
23
45
  async execute(toolCallId, params) {
46
+ // Validate parameters
47
+ const queryAll = params.queryAll;
48
+ const query = params.query;
49
+ if (queryAll !== "true" && (!query || typeof query !== "string")) {
50
+ throw new ToolInputError("queryAll不为true时,query参数必填");
51
+ }
24
52
  // Get session context
25
53
  const sessionContext = getCurrentSessionContext();
26
54
  if (!sessionContext) {
@@ -29,6 +57,15 @@ export const xiaoyiCollectionTool = {
29
57
  const { config, sessionId, taskId, messageId } = sessionContext;
30
58
  // Get WebSocket manager
31
59
  const wsManager = getXYWebSocketManager(config);
60
+ // Build intentParam
61
+ const intentParam = {};
62
+ if (queryAll === "true") {
63
+ intentParam.queryAll = "true";
64
+ }
65
+ else {
66
+ intentParam.queryAll = "false";
67
+ intentParam.query = query;
68
+ }
32
69
  // Build QueryCollection command
33
70
  const command = {
34
71
  header: {
@@ -45,9 +82,7 @@ export const xiaoyiCollectionTool = {
45
82
  actionResponse: true,
46
83
  appType: "OHOS_APP",
47
84
  timeOut: 5,
48
- intentParam: {
49
- queryAll: params.queryAll || "true",
50
- },
85
+ intentParam,
51
86
  permissionId: [],
52
87
  achieveType: "INTENT",
53
88
  },
@@ -0,0 +1,4 @@
1
+ /**
2
+ * XY delete collection tool - deletes data from user's XiaoYi collection.
3
+ */
4
+ export declare const xiaoyiDeleteCollectionTool: any;
@@ -0,0 +1,163 @@
1
+ import { getXYWebSocketManager } from "../client.js";
2
+ import { sendCommand } from "../formatter.js";
3
+ import { getCurrentSessionContext } from "./session-manager.js";
4
+ /**
5
+ * Duck-typed ToolInputError: openclaw 按 .name 字段匹配,不用 instanceof。
6
+ * 抛出此错误会让 openclaw 返回 HTTP 400 而非 500,
7
+ * LLM 会将其识别为参数错误而非瞬时故障,不会触发重试。
8
+ */
9
+ class ToolInputError extends Error {
10
+ status = 400;
11
+ constructor(message) {
12
+ super(message);
13
+ this.name = "ToolInputError";
14
+ }
15
+ }
16
+ /**
17
+ * XY delete collection tool - deletes data from user's XiaoYi collection.
18
+ */
19
+ export const xiaoyiDeleteCollectionTool = {
20
+ name: "delete_collection",
21
+ label: "Delete XiaoYi Collection",
22
+ description: `从小艺收藏中删除之前已保存的公共知识数据。任何用户希望删除已保存到个人知识库的数据都可以调用本技能。如果用户想更新之前的收藏数据,需要先query获取itemId然后再delete,最后执行Add,按照这个步骤完成收藏数据更新。
23
+ 注意:
24
+ a. 操作超时时间为60秒,请勿重复调用此工具
25
+ b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
26
+ c. 调用工具前需认真检查调用参数是否满足工具要求
27
+
28
+ 回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
29
+ `,
30
+ parameters: {
31
+ type: "object",
32
+ properties: {
33
+ itemIds: {
34
+ // 不指定 type,允许传入数组或 JSON 字符串
35
+ // 具体的类型验证和转换在 execute 函数内部进行
36
+ description: "准备删除的数据的itemId合集。itemId可以由用户指定,也可以从之前检索回来的收藏数据项的itemId字段获取。",
37
+ },
38
+ },
39
+ required: ["itemIds"],
40
+ },
41
+ async execute(toolCallId, params) {
42
+ // ===== 参数规范化:兼容数组和 JSON 字符串 =====
43
+ let itemIds = null;
44
+ if (!params.itemIds) {
45
+ throw new ToolInputError("缺少必填参数: itemIds");
46
+ }
47
+ // 情况1: 已经是数组
48
+ if (Array.isArray(params.itemIds)) {
49
+ itemIds = params.itemIds;
50
+ }
51
+ // 情况2: 是字符串,尝试解析为 JSON 数组
52
+ else if (typeof params.itemIds === 'string') {
53
+ try {
54
+ const parsed = JSON.parse(params.itemIds);
55
+ if (Array.isArray(parsed)) {
56
+ itemIds = parsed;
57
+ }
58
+ else {
59
+ throw new ToolInputError("itemIds must be an array or a JSON string representing an array");
60
+ }
61
+ }
62
+ catch (parseError) {
63
+ if (parseError instanceof ToolInputError)
64
+ throw parseError;
65
+ throw new ToolInputError(`itemIds must be a valid JSON array string. Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
66
+ }
67
+ }
68
+ // 情况3: 其他类型,报错
69
+ else {
70
+ throw new ToolInputError(`itemIds must be an array or a JSON string, got ${typeof params.itemIds}`);
71
+ }
72
+ // 验证数组非空
73
+ if (!itemIds || itemIds.length === 0) {
74
+ throw new ToolInputError("itemIds array cannot be empty");
75
+ }
76
+ // Get session context
77
+ const sessionContext = getCurrentSessionContext();
78
+ if (!sessionContext) {
79
+ throw new Error("No active XY session found. DeleteCollection tool can only be used during an active conversation.");
80
+ }
81
+ const { config, sessionId, taskId, messageId } = sessionContext;
82
+ // Get WebSocket manager
83
+ const wsManager = getXYWebSocketManager(config);
84
+ // Build DeleteCollection command
85
+ const command = {
86
+ header: {
87
+ namespace: "Common",
88
+ name: "Action",
89
+ },
90
+ payload: {
91
+ cardParam: {},
92
+ executeParam: {
93
+ executeMode: "background",
94
+ intentName: "DeleteCollection",
95
+ bundleName: "com.huawei.hmos.vassistant",
96
+ needUnlock: true,
97
+ actionResponse: true,
98
+ appType: "OHOS_APP",
99
+ timeOut: 5,
100
+ intentParam: {
101
+ itemIds,
102
+ },
103
+ permissionId: [],
104
+ achieveType: "INTENT",
105
+ },
106
+ responses: [
107
+ {
108
+ resultCode: "",
109
+ displayText: "",
110
+ ttsText: "",
111
+ },
112
+ ],
113
+ needUploadResult: true,
114
+ noHalfPage: false,
115
+ pageControlRelated: false,
116
+ },
117
+ };
118
+ // Send command and wait for response (60 second timeout)
119
+ return new Promise((resolve, reject) => {
120
+ const timeout = setTimeout(() => {
121
+ wsManager.off("data-event", handler);
122
+ reject(new Error("删除小艺收藏超时(60秒)"));
123
+ }, 60000);
124
+ // Listen for data events from WebSocket
125
+ const handler = (event) => {
126
+ if (event.intentName === "DeleteCollection") {
127
+ clearTimeout(timeout);
128
+ wsManager.off("data-event", handler);
129
+ if (event.status === "success" && event.outputs) {
130
+ resolve({
131
+ content: [
132
+ {
133
+ type: "text",
134
+ text: JSON.stringify(event.outputs),
135
+ }
136
+ ]
137
+ });
138
+ }
139
+ else {
140
+ reject(new Error(`删除小艺收藏失败: ${event.status}`));
141
+ }
142
+ }
143
+ };
144
+ // Register event handler
145
+ wsManager.on("data-event", handler);
146
+ // Send the command
147
+ sendCommand({
148
+ config,
149
+ sessionId,
150
+ taskId,
151
+ messageId,
152
+ command,
153
+ })
154
+ .then(() => {
155
+ })
156
+ .catch((error) => {
157
+ clearTimeout(timeout);
158
+ wsManager.off("data-event", handler);
159
+ reject(error);
160
+ });
161
+ });
162
+ },
163
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 保存 runtime 信息到 .xiaoyiruntime 文件
3
+ * @param webSocketSessionId - WebSocket 层级的 sessionId (SESSION_ID)
4
+ * @param conversationId - param 里的 sessionId (CONVERSATION_ID)
5
+ * @param taskId - 任务 ID (param.id)
6
+ */
7
+ export declare function saveRuntimeInfo(webSocketSessionId: string, conversationId: string, taskId: string): Promise<void>;
@@ -0,0 +1,42 @@
1
+ // xiaoyi runtime 持久化管理器
2
+ import { promises as fs } from "fs";
3
+ import * as path from "path";
4
+ import { logger } from "./logger.js";
5
+ const RUNTIME_FILE = "/home/sandbox/.openclaw/.xiaoyiruntime";
6
+ /**
7
+ * 确保目录存在
8
+ */
9
+ async function ensureDirectoryExists(filePath) {
10
+ const dir = path.dirname(filePath);
11
+ try {
12
+ await fs.mkdir(dir, { recursive: true });
13
+ }
14
+ catch (error) {
15
+ logger.error(`[RuntimeManager] Failed to create directory ${dir}:`, error);
16
+ }
17
+ }
18
+ /**
19
+ * 保存 runtime 信息到 .xiaoyiruntime 文件
20
+ * @param webSocketSessionId - WebSocket 层级的 sessionId (SESSION_ID)
21
+ * @param conversationId - param 里的 sessionId (CONVERSATION_ID)
22
+ * @param taskId - 任务 ID (param.id)
23
+ */
24
+ export async function saveRuntimeInfo(webSocketSessionId, conversationId, taskId) {
25
+ if (!webSocketSessionId || !conversationId || !taskId) {
26
+ logger.warn(`[RuntimeManager] Invalid params: SESSION_ID=${webSocketSessionId}, CONVERSATION_ID=${conversationId}, TASK_ID=${taskId}`);
27
+ return;
28
+ }
29
+ try {
30
+ await ensureDirectoryExists(RUNTIME_FILE);
31
+ const content = `SESSION_ID=${webSocketSessionId}\nCONVERSATION_ID=${conversationId}\nTASK_ID=${taskId}\n`;
32
+ await fs.writeFile(RUNTIME_FILE, content, "utf-8");
33
+ logger.log(`[RuntimeManager] ✅ Saved runtime info to .xiaoyiruntime`);
34
+ logger.log(`[RuntimeManager] - SESSION_ID: ${webSocketSessionId}`);
35
+ logger.log(`[RuntimeManager] - CONVERSATION_ID: ${conversationId}`);
36
+ logger.log(`[RuntimeManager] - TASK_ID: ${taskId}`);
37
+ }
38
+ catch (error) {
39
+ logger.error(`[RuntimeManager] Failed to save runtime info:`, error);
40
+ // 不抛出异常,避免影响主流程
41
+ }
42
+ }
@@ -318,30 +318,37 @@ export class XYWebSocketManager extends EventEmitter {
318
318
  * Handle incoming message from server.
319
319
  */
320
320
  handleMessage(data) {
321
- console.log("[WEBSOCKET-HANDLE] >>>>>>> Receiving message... <<<<<<<");
322
321
  try {
323
322
  const messageStr = data.toString();
324
- console.log(`[WS-RECV] Raw message frame, size: ${messageStr.length} bytes`);
323
+ console.log(`[WS-RECV] Raw message frame, size: ${messageStr.length} characters`);
325
324
  const parsed = JSON.parse(messageStr);
326
325
  // 提取并打印消息内容(只显示 text,data 只打印提示)
327
326
  const parts = parsed.params?.message?.parts;
328
327
  if (parts && Array.isArray(parts) && parts.length > 0) {
329
328
  const textParts = parts.filter((p) => p?.kind === "text");
330
329
  const dataParts = parts.filter((p) => p?.kind === "data");
331
- // 打印 text 内容
330
+ // 打印 text 内容(隐藏敏感信息)
332
331
  if (textParts.length > 0) {
333
332
  const textContents = textParts
334
333
  .map((p) => p?.text || "")
335
334
  .filter((text) => text.length > 0)
336
335
  .join(" ");
337
336
  if (textContents.length > 0) {
338
- console.log("[WS-RECV] Text:", textContents);
337
+ // 隐藏中间内容,只保留前后各5个字符
338
+ let maskedText;
339
+ if (textContents.length <= 8) {
340
+ // 如果长度 <= 8,显示前2个 + *** + 后2个
341
+ maskedText = textContents.length >= 4
342
+ ? `${textContents.slice(0, 2)}***${textContents.slice(-2)}`
343
+ : `${textContents.slice(0, 1)}***${textContents.slice(-1)}`;
344
+ }
345
+ else {
346
+ // 如果长度 > 8,显示前5个 + *** + 后5个
347
+ maskedText = `${textContents.slice(0, 5)}***${textContents.slice(-5)}`;
348
+ }
349
+ console.log("[WS-RECV] Text:", maskedText);
339
350
  }
340
351
  }
341
- // 打印 data 提示
342
- if (dataParts.length > 0) {
343
- console.log("[WS-RECV] Data: received data message(s)");
344
- }
345
352
  }
346
353
  // Check if message is in direct A2A JSON-RPC format (server push)
347
354
  if (parsed.jsonrpc === "2.0") {
@@ -392,7 +399,6 @@ export class XYWebSocketManager extends EventEmitter {
392
399
  return;
393
400
  }
394
401
  // Emit message event for non-data-only messages
395
- console.log("[XY] *** EMITTING message event (Direct A2A path) ***");
396
402
  this.emit("message", a2aRequest, sessionId);
397
403
  return;
398
404
  }