@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,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
+ };
@@ -87,8 +87,8 @@ async function processImageInput(imageInput, uploadService) {
87
87
  /**
88
88
  * Call image understanding API with streaming response
89
89
  */
90
- async function callImageUnderstandingAPI(imageUrl, text, apiKey, uid) {
91
- const apiUrl = "https://hag-drcn.op.dbankcloud.com/celia-claw/v1/sse-api/skill/execute";
90
+ async function callImageUnderstandingAPI(imageUrl, text, apiKey, uid, fileUploadUrl) {
91
+ const apiUrl = `${fileUploadUrl}/celia-claw/v1/sse-api/skill/execute`;
92
92
  const traceId = uuidv4();
93
93
  const headers = {
94
94
  "Content-Type": "application/json",
@@ -276,7 +276,7 @@ d. 返回图像理解的文本描述内容`,
276
276
  downloadedFile = processedImage.localPath;
277
277
  }
278
278
  // Call image understanding API
279
- const caption = await callImageUnderstandingAPI(processedImage.imageUrl, prompt, config.apiKey, config.uid);
279
+ const caption = await callImageUnderstandingAPI(processedImage.imageUrl, prompt, config.apiKey, config.uid, config.fileUploadUrl);
280
280
  // Clean up downloaded file if any
281
281
  if (downloadedFile) {
282
282
  try {
@@ -6,7 +6,7 @@ const ALARM_SNOOZE_DURATION_VALUES = [5, 10, 15, 20, 25, 30];
6
6
  const ALARM_SNOOZE_TOTAL_VALUES = [0, 1, 3, 5, 10];
7
7
  const ALARM_RING_DURATION_VALUES = [1, 5, 10, 15, 20, 30];
8
8
  const DAYS_OF_WAKE_TYPE_VALUES = [0, 1, 2, 3, 4];
9
- const DAYS_OF_WEEK_VALUES = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
9
+ const DAYS_OF_WEEK_VALUES = ["Mon", "Tues", "Wed", "Thur", "Fri", "Sat", "Sun"];
10
10
  /**
11
11
  * XY modify alarm tool - modifies an existing alarm on user's device.
12
12
  * Requires entityId from search_alarm or create_alarm tool.
@@ -31,7 +31,7 @@ export const modifyAlarmTool = {
31
31
  - alarmSnoozeTotal: 再响次数,枚举值:0,1,3,5,10
32
32
  - alarmRingDuration: 响铃时长(分钟),枚举值:1,5,10,15,20,30
33
33
  - daysOfWakeType: 闹钟响铃类型,枚举值:0=单次,1=法定节假日,2=每天,3=自定义,4=法定工作日
34
- - daysOfWeek: 自定义响铃星期,仅当daysOfWakeType=3(自定义时间)时必需且有效,其他情况不要传递此参数。数组或JSON字符串,枚举值:Mon,Tue,Wed,Thu,Fri,Sat,Sun。注意:仅支持长度为1的数组,如果需要一周中不同的几天,需要多次调用此工具
34
+ - daysOfWeek: 自定义响铃星期,仅当daysOfWakeType=3(自定义时间)时必需且有效,其他情况不要传递此参数。数组或JSON字符串,枚举值:Mon,Tues,Wed,Thur,Fri,Sat,Sun。
35
35
 
36
36
  使用流程:
37
37
  1. 先调用 search_alarm 工具查询闹钟,获取 entityId,
@@ -79,7 +79,7 @@ export const modifyAlarmTool = {
79
79
  daysOfWeek: {
80
80
  // 不指定 type,允许传入数组或 JSON 字符串
81
81
  // 具体的类型验证和转换在 execute 函数内部进行
82
- description: "自定义响铃星期(仅当daysOfWakeType=3时需要,其他情况不要传递),数组或JSON字符串,枚举值:Mon,Tue,Wed,Thu,Fri,Sat,Sun。注意:仅支持长度为1的数组,如果需要一周中不同的几天,需要多次调用此工具",
82
+ description: "自定义响铃星期(仅当daysOfWakeType=3时需要,其他情况不要传递),数组或JSON字符串,枚举值:Mon,Tues,Wed,Thur,Fri,Sat,Sun。",
83
83
  },
84
84
  },
85
85
  required: ["entityId"],
@@ -199,10 +199,6 @@ export const modifyAlarmTool = {
199
199
  if (!normalizedDaysOfWeek || normalizedDaysOfWeek.length === 0) {
200
200
  throw new Error("daysOfWeek array cannot be empty");
201
201
  }
202
- // 验证数组长度必须为1
203
- if (normalizedDaysOfWeek.length !== 1) {
204
- throw new Error("daysOfWeek 仅支持长度为1的数组。如果需要一周中不同的几天,需要多次调用此工具");
205
- }
206
202
  // Validate each day
207
203
  for (const day of normalizedDaysOfWeek) {
208
204
  if (typeof day !== "string" || !DAYS_OF_WEEK_VALUES.includes(day)) {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * XY save file to phone tool - saves files to user's device file manager.
3
+ * Supports local file paths (auto-uploaded to get public URL) and public URLs.
4
+ */
5
+ export declare const saveFileToPhoneTool: any;
@@ -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
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * XY save media to gallery tool - saves image or video files to user's device gallery.
3
+ * Supports local file paths (auto-uploaded to get public URL) and public URLs.
4
+ */
5
+ export declare const saveMediaToGalleryTool: any;
@@ -0,0 +1,178 @@
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 media to gallery tool - saves image or video files to user's device gallery.
19
+ * Supports local file paths (auto-uploaded to get public URL) and public URLs.
20
+ */
21
+ export const saveMediaToGalleryTool = {
22
+ name: "save_media_to_gallery",
23
+ label: "Save Media to Gallery",
24
+ description: `将图片文件或者视频文件保存到手机图库。
25
+ 工具参数说明:
26
+ a. mediaType:非必填,string类型,不传端侧默认为pic。支持传 pic(图片) 或 video(视频)。
27
+ b. fileName:非必填,string类型,文件名称,不传手机侧默认生成随机uuid。
28
+ c. url:必填,string类型,支持本地路径或者公网url路径。如果是本地路径,会先上传获取公网url再保存到图库。
29
+
30
+ 注意:
31
+ a. 操作超时时间为60秒,请勿重复调用此工具
32
+ b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
33
+ c. 调用工具前需认真检查调用参数是否满足工具要求
34
+
35
+ 回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
36
+ `,
37
+ parameters: {
38
+ type: "object",
39
+ properties: {
40
+ mediaType: {
41
+ type: "string",
42
+ description: "非必填,不传默认为pic。支持 pic(图片) 或 video(视频)。",
43
+ },
44
+ fileName: {
45
+ type: "string",
46
+ description: "非必填,文件名称,不传手机侧默认生成随机uuid。",
47
+ },
48
+ url: {
49
+ type: "string",
50
+ description: "必填,支持本地路径或者公网url路径。如果是本地路径会先上传获取公网url。",
51
+ },
52
+ },
53
+ required: ["url"],
54
+ },
55
+ async execute(toolCallId, params) {
56
+ // Validate parameters
57
+ const { mediaType, fileName, url } = params;
58
+ if (!url || typeof url !== "string") {
59
+ throw new ToolInputError("缺少必填参数: url");
60
+ }
61
+ if (mediaType && !["pic", "video"].includes(mediaType)) {
62
+ throw new ToolInputError(`mediaType只支持 pic 或 video,当前值: ${mediaType}`);
63
+ }
64
+ // Strip file extension from fileName if present
65
+ let sanitizedFileName = fileName;
66
+ if (sanitizedFileName && typeof sanitizedFileName === "string") {
67
+ const lastDot = sanitizedFileName.lastIndexOf(".");
68
+ if (lastDot > 0) {
69
+ sanitizedFileName = sanitizedFileName.substring(0, lastDot);
70
+ }
71
+ }
72
+ // Get session context
73
+ const sessionContext = getCurrentSessionContext();
74
+ if (!sessionContext) {
75
+ throw new Error("No active XY session found. SaveMediaToGallery tool can only be used during an active conversation.");
76
+ }
77
+ const { config, sessionId, taskId, messageId } = sessionContext;
78
+ // Get WebSocket manager
79
+ const wsManager = getXYWebSocketManager(config);
80
+ // Determine the URL: if it's a local path, upload first to get public URL
81
+ let publicUrl = url;
82
+ if (!url.startsWith("http://") && !url.startsWith("https://")) {
83
+ // Local file path - upload to get public URL
84
+ const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
85
+ publicUrl = await uploadService.uploadFileAndGetUrl(url);
86
+ if (!publicUrl) {
87
+ throw new Error("本地文件上传失败,无法获取公网URL");
88
+ }
89
+ }
90
+ // Build intentParam
91
+ const intentParam = {
92
+ url: publicUrl,
93
+ };
94
+ if (mediaType) {
95
+ intentParam.mediaType = mediaType;
96
+ }
97
+ if (sanitizedFileName) {
98
+ intentParam.fileName = sanitizedFileName;
99
+ }
100
+ // Build SaveMediaToGallery command
101
+ const command = {
102
+ header: {
103
+ namespace: "Common",
104
+ name: "Action",
105
+ },
106
+ payload: {
107
+ cardParam: {},
108
+ executeParam: {
109
+ executeMode: "background",
110
+ intentName: "SaveMediaToGallery",
111
+ bundleName: "com.huawei.hmos.vassistant",
112
+ dimension: "",
113
+ needUnlock: true,
114
+ actionResponse: true,
115
+ appType: "OHOS_APP",
116
+ timeOut: 5,
117
+ intentParam,
118
+ permissionId: ["ohos.permission.WRITE_IMAGEVIDEO"],
119
+ achieveType: "INTENT",
120
+ },
121
+ responses: [
122
+ {
123
+ resultCode: "",
124
+ displayText: "",
125
+ ttsText: "",
126
+ },
127
+ ],
128
+ needUploadResult: true,
129
+ noHalfPage: false,
130
+ pageControlRelated: false,
131
+ },
132
+ };
133
+ // Send command and wait for response (60 second timeout)
134
+ return new Promise((resolve, reject) => {
135
+ const timeout = setTimeout(() => {
136
+ wsManager.off("data-event", handler);
137
+ reject(new Error("保存媒体到图库超时(60秒)"));
138
+ }, 60000);
139
+ // Listen for data events from WebSocket
140
+ const handler = (event) => {
141
+ if (event.intentName === "SaveMediaToGallery") {
142
+ clearTimeout(timeout);
143
+ wsManager.off("data-event", handler);
144
+ if (event.status === "success" && event.outputs) {
145
+ resolve({
146
+ content: [
147
+ {
148
+ type: "text",
149
+ text: JSON.stringify(event.outputs),
150
+ }
151
+ ]
152
+ });
153
+ }
154
+ else {
155
+ reject(new Error(`保存媒体到图库失败: ${event.status}`));
156
+ }
157
+ }
158
+ };
159
+ // Register event handler
160
+ wsManager.on("data-event", handler);
161
+ // Send the command
162
+ sendCommand({
163
+ config,
164
+ sessionId,
165
+ taskId,
166
+ messageId,
167
+ command,
168
+ })
169
+ .then(() => {
170
+ })
171
+ .catch((error) => {
172
+ clearTimeout(timeout);
173
+ wsManager.off("data-event", handler);
174
+ reject(error);
175
+ });
176
+ });
177
+ },
178
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Send command to car (小艺车机) tool - sends an output command to the car's Xiaoyi system.
3
+ * The command will be received and executed on the car's Xiaoyi device.
4
+ */
5
+ export declare const sendCommandToCarTool: any;
@@ -0,0 +1,85 @@
1
+ // Send Command To Car tool implementation
2
+ import { sendCommand } from "../formatter.js";
3
+ import { getCurrentSessionContext } from "./session-manager.js";
4
+ import { logger } from "../utils/logger.js";
5
+ /**
6
+ * Send command to car (小艺车机) tool - sends an output command to the car's Xiaoyi system.
7
+ * The command will be received and executed on the car's Xiaoyi device.
8
+ */
9
+ export const sendCommandToCarTool = {
10
+ name: "send_command_to_car",
11
+ label: "Send Command To Car",
12
+ description: "将输出指令发送给小艺车机,车机小艺会接收并执行该指令。注意:请勿重复调用此工具,如果超时或失败,最多重试一次。回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案。",
13
+ parameters: {
14
+ type: "object",
15
+ properties: {
16
+ command: {
17
+ type: "string",
18
+ description: "要发送给车机的指令内容(对应intentParam中的out字段)",
19
+ },
20
+ },
21
+ required: ["command"],
22
+ },
23
+ async execute(toolCallId, params) {
24
+ // Validate command parameter
25
+ if (!params.command || typeof params.command !== "string" || params.command.trim() === "") {
26
+ throw new Error("Missing required parameter: command must be a non-empty string");
27
+ }
28
+ // Get session context
29
+ const sessionContext = getCurrentSessionContext();
30
+ if (!sessionContext) {
31
+ throw new Error("No active XY session found. Send command to car tool can only be used during an active conversation.");
32
+ }
33
+ const { config, sessionId, taskId, messageId } = sessionContext;
34
+ // Build PlayStoryBook command
35
+ const command = {
36
+ header: {
37
+ namespace: "Common",
38
+ name: "Action",
39
+ },
40
+ payload: {
41
+ cardParam: {},
42
+ executeParam: {
43
+ achieveType: "INTENT",
44
+ actionResponse: true,
45
+ bundleName: "com.huawei.vassistantcar",
46
+ dimension: "",
47
+ executeMode: "background",
48
+ intentName: "PlayStoryBook",
49
+ intentParam: {
50
+ out: params.command,
51
+ },
52
+ needUnlock: true,
53
+ permissionId: [],
54
+ timeOut: 5,
55
+ },
56
+ needUploadResult: true,
57
+ pageControlRelated: false,
58
+ responses: [
59
+ {
60
+ displayText: "",
61
+ resultCode: "",
62
+ ttsText: "",
63
+ },
64
+ ],
65
+ },
66
+ };
67
+ // Send command - fire and forget, return success once sent
68
+ await sendCommand({
69
+ config,
70
+ sessionId,
71
+ taskId,
72
+ messageId,
73
+ command,
74
+ });
75
+ logger.log("[sendCommandToCar] command sent to car successfully");
76
+ return {
77
+ content: [
78
+ {
79
+ type: "text",
80
+ text: JSON.stringify({ success: true, message: "指令已成功下发给车机" }),
81
+ },
82
+ ],
83
+ };
84
+ },
85
+ };
@@ -244,6 +244,7 @@ b. 操作超时时间为2分钟(120秒),请勿重复调用此工具,如
244
244
  };
245
245
  // Send WebSocket message
246
246
  await wsManager.sendMessage(sessionId, agentResponse);
247
+ console.log(`send ${fileName} file to user success`);
247
248
  sentFiles.push({ fileName, fileId });
248
249
  }
249
250
  return {
@@ -5,6 +5,7 @@ export interface SessionContext {
5
5
  taskId: string;
6
6
  messageId: string;
7
7
  agentId: string;
8
+ deviceType?: string;
8
9
  }
9
10
  /**
10
11
  * Register a session context for tool access.
@@ -0,0 +1,12 @@
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 declare const timestampToUtc8Tool: any;