@ynhcj/xiaoyi-channel 0.0.85-beta → 0.0.86-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/channel.js +2 -1
- package/dist/src/provider.js +8 -0
- package/dist/src/tools/create-alarm-tool.js +5 -16
- package/dist/src/tools/delete-alarm-tool.js +1 -4
- package/dist/src/tools/device-tool-map.js +3 -3
- package/dist/src/tools/image-reading-tool.js +4 -7
- package/dist/src/tools/modify-alarm-tool.js +10 -23
- package/dist/src/tools/save-file-to-phone-tool.js +0 -4
- package/dist/src/tools/save-media-to-gallery-tool.js +2 -6
- package/dist/src/tools/search-alarm-tool.js +6 -13
- package/dist/src/tools/search-email-tool.d.ts +5 -0
- package/dist/src/tools/search-email-tool.js +137 -0
- package/dist/src/tools/search-file-tool.js +4 -4
- package/dist/src/tools/search-photo-gallery-tool.js +2 -2
- package/dist/src/tools/send-file-to-user-tool.js +2 -4
- package/dist/src/tools/upload-file-tool.js +3 -3
- package/dist/src/tools/upload-photo-tool.js +1 -1
- package/package.json +1 -1
package/dist/src/channel.js
CHANGED
|
@@ -29,6 +29,7 @@ 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
31
|
import { saveFileToPhoneTool } from "./tools/save-file-to-phone-tool.js";
|
|
32
|
+
import { searchEmailTool } from "./tools/search-email-tool.js";
|
|
32
33
|
import { filterToolsByDevice } from "./tools/device-tool-map.js";
|
|
33
34
|
import { getCurrentSessionContext } from "./tools/session-manager.js";
|
|
34
35
|
import { logger } from "./utils/logger.js";
|
|
@@ -71,7 +72,7 @@ export const xyPlugin = {
|
|
|
71
72
|
},
|
|
72
73
|
outbound: xyOutbound,
|
|
73
74
|
agentTools: () => {
|
|
74
|
-
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];
|
|
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, searchEmailTool];
|
|
75
76
|
const ctx = getCurrentSessionContext();
|
|
76
77
|
const filtered = filterToolsByDevice(allTools, ctx?.deviceType);
|
|
77
78
|
logger.log(`[DEVICE-FILTER] deviceType=${ctx?.deviceType ?? "(none)"}, tools: ${allTools.length} → ${filtered.length} (${filtered.map(t => t.name).join(", ")})`);
|
package/dist/src/provider.js
CHANGED
|
@@ -130,6 +130,14 @@ export const xiaoyiProvider = {
|
|
|
130
130
|
console.log(`[xiaoyiprovider] system prompt optimized: ${beforeLen} -> ${sp.length}`);
|
|
131
131
|
context.systemPrompt = sp;
|
|
132
132
|
}
|
|
133
|
+
// Append device context to systemPrompt
|
|
134
|
+
const sessionCtx = getCurrentSessionContext();
|
|
135
|
+
if (sessionCtx?.deviceType) {
|
|
136
|
+
const rawDevice = sessionCtx.deviceType;
|
|
137
|
+
const displayDevice = (rawDevice === "phone") ? "phone" : "鸿蒙PC";
|
|
138
|
+
const deviceSection = `\n\n## Current User Device Context\nThe current user is using the following device: ${displayDevice}\n`;
|
|
139
|
+
context.systemPrompt = (context.systemPrompt ?? "") + deviceSection;
|
|
140
|
+
}
|
|
133
141
|
const stream = await underlying(model, context, {
|
|
134
142
|
...options,
|
|
135
143
|
headers: {
|
|
@@ -17,18 +17,7 @@ export const createAlarmTool = {
|
|
|
17
17
|
name: "create_alarm",
|
|
18
18
|
label: "Create Alarm",
|
|
19
19
|
description: `在用户设备上创建闹钟。
|
|
20
|
-
|
|
21
|
-
必需参数:
|
|
22
|
-
- alarmTime: 闹钟时间,格式必须为:YYYYMMDD hhmmss(例如:20240315 143000,表示2024年3月15日14:30:00)
|
|
23
|
-
|
|
24
|
-
可选参数(针对用户没有提及的参数,如果有默认参数,则发送请求时使用默认参数):
|
|
25
|
-
- alarmTitle: 闹钟名称/标题,默认为"闹钟"
|
|
26
|
-
- alarmSnoozeDuration: 小睡间隔(分钟),枚举值:5,10,15,20,25,30,默认10
|
|
27
|
-
- alarmSnoozeTotal: 再响次数,枚举值:0,1,3,5,10,默认0(表示不再响)
|
|
28
|
-
- alarmRingDuration: 响铃时长(分钟),枚举值:1,5,10,15,20,30,默认5
|
|
29
|
-
- daysOfWakeType: 闹钟响铃类型,枚举值:0=单次响铃,1=法定节假日,2=每天,3=自定义时间,4=法定工作日,默认0
|
|
30
|
-
- daysOfWeek: 自定义响铃星期,仅当daysOfWakeType=3(自定义时间)时必需且有效,其他情况不要传递此参数。数组或JSON字符串,枚举值:Mon,Tues,Wed,Thur,Fri,Sat,Sun。
|
|
31
|
-
|
|
20
|
+
|
|
32
21
|
注意事项:
|
|
33
22
|
a. 操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。
|
|
34
23
|
b. 使用该工具之前需获取当前真实时间
|
|
@@ -39,7 +28,7 @@ b. 使用该工具之前需获取当前真实时间
|
|
|
39
28
|
properties: {
|
|
40
29
|
alarmTime: {
|
|
41
30
|
type: "string",
|
|
42
|
-
description: "闹钟时间,格式必须为:YYYYMMDD hhmmss(例如:20240315 143000)",
|
|
31
|
+
description: "闹钟时间,格式必须为:YYYYMMDD hhmmss(例如:20240315 143000,表示2024年3月15日14:30:00)",
|
|
43
32
|
},
|
|
44
33
|
alarmTitle: {
|
|
45
34
|
type: "string",
|
|
@@ -51,7 +40,7 @@ b. 使用该工具之前需获取当前真实时间
|
|
|
51
40
|
},
|
|
52
41
|
alarmSnoozeTotal: {
|
|
53
42
|
type: "number",
|
|
54
|
-
description: "再响次数,枚举值:0,1,3,5,10,默认0",
|
|
43
|
+
description: "再响次数,枚举值:0,1,3,5,10,默认0(表示不再响)",
|
|
55
44
|
},
|
|
56
45
|
alarmRingDuration: {
|
|
57
46
|
type: "number",
|
|
@@ -59,12 +48,12 @@ b. 使用该工具之前需获取当前真实时间
|
|
|
59
48
|
},
|
|
60
49
|
daysOfWakeType: {
|
|
61
50
|
type: "number",
|
|
62
|
-
description: "
|
|
51
|
+
description: "闹钟响铃类型,枚举值:0=单次响铃,1=法定节假日,2=每天,3=自定义时间,4=法定工作日,默认0",
|
|
63
52
|
},
|
|
64
53
|
daysOfWeek: {
|
|
65
54
|
// 不指定 type,允许传入数组或 JSON 字符串
|
|
66
55
|
// 具体的类型验证和转换在 execute 函数内部进行
|
|
67
|
-
description: "
|
|
56
|
+
description: "自定义响铃星期,仅当daysOfWakeType=3(自定义时间)时必需且有效,其他情况不要传递此参数。数组或JSON字符串,枚举值:Mon,Tues,Wed,Thur,Fri,Sat,Sun。",
|
|
68
57
|
},
|
|
69
58
|
},
|
|
70
59
|
required: ["alarmTime"],
|
|
@@ -16,9 +16,6 @@ export const deleteAlarmTool = {
|
|
|
16
16
|
label: "Delete Alarm",
|
|
17
17
|
description: `删除用户设备上的闹钟。使用前必须先调用 search_alarm 或 create_alarm 工具获取闹钟的 entityId。
|
|
18
18
|
|
|
19
|
-
工具参数:
|
|
20
|
-
- items: 要删除的闹钟列表,每个元素包含 entityId 字段。支持数组或 JSON 字符串格式。entityId 是闹钟的唯一标识符(从 search_alarm 或 create_alarm 工具获取)。
|
|
21
|
-
|
|
22
19
|
使用示例:
|
|
23
20
|
- 删除单个闹钟:{"items": [{"entityId": "6"}]}
|
|
24
21
|
- 删除多个闹钟:{"items": [{"entityId": "6"}, {"entityId": "8"}]}
|
|
@@ -35,7 +32,7 @@ export const deleteAlarmTool = {
|
|
|
35
32
|
items: {
|
|
36
33
|
// 不指定 type,允许传入数组或 JSON 字符串
|
|
37
34
|
// 具体的类型验证和转换在 execute 函数内部进行
|
|
38
|
-
description: "要删除的闹钟列表,每个元素包含 entityId 字段。支持数组或 JSON 字符串格式。",
|
|
35
|
+
description: "要删除的闹钟列表,每个元素包含 entityId 字段。支持数组或 JSON 字符串格式。entityId 是闹钟的唯一标识符(从 search_alarm 或 create_alarm 工具获取)。",
|
|
39
36
|
},
|
|
40
37
|
},
|
|
41
38
|
required: ["items"],
|
|
@@ -223,10 +223,7 @@ export const imageReadingTool = {
|
|
|
223
223
|
工具能力描述:对图片进行理解和分析,返回图片的描述内容。
|
|
224
224
|
|
|
225
225
|
工具参数说明:
|
|
226
|
-
|
|
227
|
-
b. remoteUrl:公网图片地址(可选)
|
|
228
|
-
c. prompt:对图片的提示问题,默认为"描述这张图片内容",可根据用户的具体问题自定义
|
|
229
|
-
d. localUrl 与 remoteUrl 任意一个不为空即可,优先使用 localUrl
|
|
226
|
+
localUrl 与 remoteUrl 任意一个不为空即可,优先使用 localUrl
|
|
230
227
|
|
|
231
228
|
注意事项:
|
|
232
229
|
a. 支持常见图片格式(jpg, png, gif等)
|
|
@@ -238,15 +235,15 @@ d. 返回图像理解的文本描述内容`,
|
|
|
238
235
|
properties: {
|
|
239
236
|
localUrl: {
|
|
240
237
|
type: "string",
|
|
241
|
-
description: "
|
|
238
|
+
description: "本地图片文件路径(可选,通常从用户消息的 mediaPath 字段获取)",
|
|
242
239
|
},
|
|
243
240
|
remoteUrl: {
|
|
244
241
|
type: "string",
|
|
245
|
-
description: "
|
|
242
|
+
description: "公网图片地址(可选),公网图片地址(HTTP/HTTPS URL)",
|
|
246
243
|
},
|
|
247
244
|
prompt: {
|
|
248
245
|
type: "string",
|
|
249
|
-
description: "对图片的提示问题,默认为'描述这张图片内容'",
|
|
246
|
+
description: "对图片的提示问题,默认为'描述这张图片内容',可根据用户的具体问题自定义",
|
|
250
247
|
},
|
|
251
248
|
},
|
|
252
249
|
},
|
|
@@ -20,23 +20,10 @@ export const modifyAlarmTool = {
|
|
|
20
20
|
label: "Modify Alarm",
|
|
21
21
|
description: `修改用户设备上已存在的闹钟。
|
|
22
22
|
|
|
23
|
-
必需参数:
|
|
24
|
-
- entityId: 闹钟的唯一标识符,必须先通过 search_alarm 或 create_alarm 工具获取
|
|
25
|
-
|
|
26
|
-
可选参数(与创建闹钟的参数完全一致):
|
|
27
|
-
- alarmTime: 闹钟时间,格式必须为:YYYYMMDD hhmmss(例如:20240315 143000)
|
|
28
|
-
- alarmTitle: 闹钟名称/标题
|
|
29
|
-
- alarmState: 闹钟开启状态,0=关闭,1=开启
|
|
30
|
-
- alarmSnoozeDuration: 小睡间隔(分钟),枚举值:5,10,15,20,25,30
|
|
31
|
-
- alarmSnoozeTotal: 再响次数,枚举值:0,1,3,5,10
|
|
32
|
-
- alarmRingDuration: 响铃时长(分钟),枚举值:1,5,10,15,20,30
|
|
33
|
-
- daysOfWakeType: 闹钟响铃类型,枚举值:0=单次,1=法定节假日,2=每天,3=自定义,4=法定工作日
|
|
34
|
-
- daysOfWeek: 自定义响铃星期,仅当daysOfWakeType=3(自定义时间)时必需且有效,其他情况不要传递此参数。数组或JSON字符串,枚举值:Mon,Tues,Wed,Thur,Fri,Sat,Sun。
|
|
35
|
-
|
|
36
23
|
使用流程:
|
|
37
24
|
1. 先调用 search_alarm 工具查询闹钟,获取 entityId,
|
|
38
25
|
2. 调用此工具修改闹钟,传入 entityId 和需要修改的参数
|
|
39
|
-
3.
|
|
26
|
+
3. 其余不涉及修改的参数,如果search_alarm 或 create_alarm的结果中有相应的值,需要一并填上,需要与原有的保持一致,防止不填采用默认值
|
|
40
27
|
|
|
41
28
|
注意事项:操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。
|
|
42
29
|
|
|
@@ -46,40 +33,40 @@ export const modifyAlarmTool = {
|
|
|
46
33
|
properties: {
|
|
47
34
|
entityId: {
|
|
48
35
|
type: "string",
|
|
49
|
-
description: "
|
|
36
|
+
description: "(必需)闹钟的唯一标识符,必须先通过 search_alarm 或 create_alarm 工具获取",
|
|
50
37
|
},
|
|
51
38
|
alarmTime: {
|
|
52
39
|
type: "string",
|
|
53
|
-
description: "
|
|
40
|
+
description: "(可选)闹钟时间,格式必须为:YYYYMMDD hhmmss(例如:20240315 143000)",
|
|
54
41
|
},
|
|
55
42
|
alarmTitle: {
|
|
56
43
|
type: "string",
|
|
57
|
-
description: "
|
|
44
|
+
description: "(可选)闹钟名称/标题",
|
|
58
45
|
},
|
|
59
46
|
alarmState: {
|
|
60
47
|
type: "number",
|
|
61
|
-
description: "
|
|
48
|
+
description: "(可选)闹钟开启状态,枚举值:0=关闭,1=开启",
|
|
62
49
|
},
|
|
63
50
|
alarmSnoozeDuration: {
|
|
64
51
|
type: "number",
|
|
65
|
-
description: "
|
|
52
|
+
description: "(可选)小睡间隔(分钟),枚举值:5,10,15,20,25,30",
|
|
66
53
|
},
|
|
67
54
|
alarmSnoozeTotal: {
|
|
68
55
|
type: "number",
|
|
69
|
-
description: "
|
|
56
|
+
description: "(可选)再响次数,枚举值:0,1,3,5,10",
|
|
70
57
|
},
|
|
71
58
|
alarmRingDuration: {
|
|
72
59
|
type: "number",
|
|
73
|
-
description: "
|
|
60
|
+
description: "(可选)响铃时长(分钟),枚举值:1,5,10,15,20,30",
|
|
74
61
|
},
|
|
75
62
|
daysOfWakeType: {
|
|
76
63
|
type: "number",
|
|
77
|
-
description: "
|
|
64
|
+
description: "(可选)闹钟响铃类型,枚举值:0=单次,1=法定节假日,2=每天,3=自定义,4=法定工作日",
|
|
78
65
|
},
|
|
79
66
|
daysOfWeek: {
|
|
80
67
|
// 不指定 type,允许传入数组或 JSON 字符串
|
|
81
68
|
// 具体的类型验证和转换在 execute 函数内部进行
|
|
82
|
-
description: "
|
|
69
|
+
description: "(可选)自定义响铃星期,仅当daysOfWakeType=3(自定义时间)时必需且有效,其他情况不要传递此参数。数组或JSON字符串,枚举值:Mon,Tues,Wed,Thur,Fri,Sat,Sun",
|
|
83
70
|
},
|
|
84
71
|
},
|
|
85
72
|
required: ["entityId"],
|
|
@@ -22,10 +22,6 @@ export const saveFileToPhoneTool = {
|
|
|
22
22
|
name: "save_file_to_file_manager",
|
|
23
23
|
label: "Save File to Phone",
|
|
24
24
|
description: `将文件保存到手机文件管理器。
|
|
25
|
-
工具参数说明:
|
|
26
|
-
a. fileName:必填,string类型,文件名称。
|
|
27
|
-
b. url:必填,string类型,支持本地路径或者公网url路径。如果是本地路径,会先上传获取公网url再保存到手机。
|
|
28
|
-
c. suffix:必填,string类型,文件后缀,例如 ppt、doc、pdf 等。
|
|
29
25
|
|
|
30
26
|
注意:
|
|
31
27
|
a. 操作超时时间为60秒,请勿重复调用此工具
|
|
@@ -21,11 +21,7 @@ class ToolInputError extends Error {
|
|
|
21
21
|
export const saveMediaToGalleryTool = {
|
|
22
22
|
name: "save_media_to_gallery",
|
|
23
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再保存到图库。
|
|
24
|
+
description: `将图片文件或者视频文件保存到设备图库。
|
|
29
25
|
|
|
30
26
|
注意:
|
|
31
27
|
a. 操作超时时间为60秒,请勿重复调用此工具
|
|
@@ -47,7 +43,7 @@ export const saveMediaToGalleryTool = {
|
|
|
47
43
|
},
|
|
48
44
|
url: {
|
|
49
45
|
type: "string",
|
|
50
|
-
description: "必填,支持本地路径或者公网url
|
|
46
|
+
description: "必填,支持本地路径或者公网url路径。如果是本地路径,会先上传获取公网url再保存到图库",
|
|
51
47
|
},
|
|
52
48
|
},
|
|
53
49
|
required: ["url"],
|
|
@@ -15,14 +15,7 @@ const DAYS_OF_WAKE_TYPE_VALUES = [0, 1, 2, 3, 4];
|
|
|
15
15
|
export const searchAlarmTool = {
|
|
16
16
|
name: "search_alarm",
|
|
17
17
|
label: "Search Alarm",
|
|
18
|
-
description:
|
|
19
|
-
|
|
20
|
-
检索条件(至少提供一个):
|
|
21
|
-
- rangeType: 查询范围,枚举值:all=查询所有闹钟,next=查找下一个响铃闹钟,current=一小时内最近一次增查改的闹钟
|
|
22
|
-
- alarmState: 闹钟开启状态,0=关闭,1=开启
|
|
23
|
-
- daysOfWakeType: 闹钟响铃类型,0=单次响铃,1=法定节假日,2=每天,3=自定义时间,4=法定工作日
|
|
24
|
-
- startTime: 时间间隔开始,格式 YYYYMMDD hhmmss(例如:20240315 000000),需要与 endTime 一起使用
|
|
25
|
-
- endTime: 时间间隔结束,格式 YYYYMMDD hhmmss(例如:20240315 235959),需要与 startTime 一起使用
|
|
18
|
+
description: `检索用户设备上的闹钟。至少需要提供一个检索条件,多个条件可以组合使用。
|
|
26
19
|
|
|
27
20
|
使用示例:
|
|
28
21
|
- 查询所有闹钟:{"rangeType": "all"}
|
|
@@ -41,25 +34,25 @@ b. 使用该工具之前需获取当前真实时间
|
|
|
41
34
|
rangeType: {
|
|
42
35
|
type: "string",
|
|
43
36
|
enum: ["all", "next", "current"],
|
|
44
|
-
description: "
|
|
37
|
+
description: "(检索条件之一)查询范围,枚举值:all=查询所有闹钟,next=查找下一个响铃闹钟,current=一小时内最近一次增查改的闹钟",
|
|
45
38
|
},
|
|
46
39
|
alarmState: {
|
|
47
40
|
type: "number",
|
|
48
41
|
enum: [0, 1],
|
|
49
|
-
description: "
|
|
42
|
+
description: "(检索条件之一)闹钟开启状态,枚举值:0=关闭,1=开启",
|
|
50
43
|
},
|
|
51
44
|
daysOfWakeType: {
|
|
52
45
|
type: "number",
|
|
53
46
|
enum: [0, 1, 2, 3, 4],
|
|
54
|
-
description: "
|
|
47
|
+
description: "(检索条件之一)闹钟响铃类型,枚举值:0=单次响铃,1=法定节假日,2=每天,3=自定义时间,4=法定工作日",
|
|
55
48
|
},
|
|
56
49
|
startTime: {
|
|
57
50
|
type: "string",
|
|
58
|
-
description: "
|
|
51
|
+
description: "(检索条件之一)时间间隔开始,格式 YYYYMMDD hhmmss(例如:20240315 000000),必须与 endTime 一起使用",
|
|
59
52
|
},
|
|
60
53
|
endTime: {
|
|
61
54
|
type: "string",
|
|
62
|
-
description: "
|
|
55
|
+
description: "(检索条件之一)时间间隔结束,格式 YYYYMMDD hhmmss(例如:20240315 235959),必须与 startTime 一起使用",
|
|
63
56
|
},
|
|
64
57
|
},
|
|
65
58
|
},
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Search Email tool implementation
|
|
2
|
+
import { getXYWebSocketManager } from "../client.js";
|
|
3
|
+
import { sendCommand } from "../formatter.js";
|
|
4
|
+
import { getCurrentSessionContext } from "./session-manager.js";
|
|
5
|
+
/**
|
|
6
|
+
* XY search email tool - searches emails on user's device (花瓣邮箱).
|
|
7
|
+
* Returns matching emails based on query text and search type.
|
|
8
|
+
*/
|
|
9
|
+
export const searchEmailTool = {
|
|
10
|
+
name: "search_email",
|
|
11
|
+
label: "Search Email",
|
|
12
|
+
description: `检索用户花瓣邮箱中的邮件。根据查询语料和搜索类型检索邮件。
|
|
13
|
+
|
|
14
|
+
使用示例:
|
|
15
|
+
- 通用搜索:{"queryText": "个人所得税邮件", "type": 0}
|
|
16
|
+
- 按主题搜索:{"queryText": "会议纪要", "type": 1}
|
|
17
|
+
- 按发件人搜索:{"queryText": "张三", "type": 2}
|
|
18
|
+
- 按收件人搜索:{"queryText": "李四", "type": 3}
|
|
19
|
+
|
|
20
|
+
注意:
|
|
21
|
+
a. 操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。
|
|
22
|
+
b. 使用该工具之前需获取当前真实时间
|
|
23
|
+
|
|
24
|
+
回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。`,
|
|
25
|
+
parameters: {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
queryText: {
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "查询语料,用于搜索邮件的关键词或语句",
|
|
31
|
+
},
|
|
32
|
+
type: {
|
|
33
|
+
type: "number",
|
|
34
|
+
enum: [0, 1, 2, 3],
|
|
35
|
+
description: "搜索类型:0=全部(all),1=主题(subject),2=发件人(fromList),3=收件人(toList)。默认为0",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
required: ["queryText"],
|
|
39
|
+
},
|
|
40
|
+
async execute(_toolCallId, params) {
|
|
41
|
+
// ===== Validate queryText =====
|
|
42
|
+
if (!params.queryText || typeof params.queryText !== "string" || !params.queryText.trim()) {
|
|
43
|
+
throw new Error("queryText 为必填参数,且不能为空字符串");
|
|
44
|
+
}
|
|
45
|
+
// ===== Validate type =====
|
|
46
|
+
const searchType = params.type ?? 0;
|
|
47
|
+
if (typeof searchType !== "number" || ![0, 1, 2, 3].includes(searchType)) {
|
|
48
|
+
throw new Error("type 必须是 0-3 的整数:0=全部,1=主题,2=发件人,3=收件人");
|
|
49
|
+
}
|
|
50
|
+
// Get session context
|
|
51
|
+
const sessionContext = getCurrentSessionContext();
|
|
52
|
+
if (!sessionContext) {
|
|
53
|
+
throw new Error("No active XY session found. Search email tool can only be used during an active conversation.");
|
|
54
|
+
}
|
|
55
|
+
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
56
|
+
// Get WebSocket manager
|
|
57
|
+
const wsManager = getXYWebSocketManager(config);
|
|
58
|
+
// Build SearchEmails command
|
|
59
|
+
const command = {
|
|
60
|
+
header: {
|
|
61
|
+
namespace: "Common",
|
|
62
|
+
name: "Action",
|
|
63
|
+
},
|
|
64
|
+
payload: {
|
|
65
|
+
cardParam: {},
|
|
66
|
+
executeParam: {
|
|
67
|
+
executeMode: "background",
|
|
68
|
+
intentName: "SearchEmails",
|
|
69
|
+
bundleName: "com.huawei.hmos.email",
|
|
70
|
+
needUnlock: true,
|
|
71
|
+
actionResponse: true,
|
|
72
|
+
appType: "OHOS_APP",
|
|
73
|
+
timeOut: 5,
|
|
74
|
+
intentParam: {
|
|
75
|
+
type: searchType,
|
|
76
|
+
queryText: params.queryText.trim(),
|
|
77
|
+
},
|
|
78
|
+
permissionId: [],
|
|
79
|
+
achieveType: "INTENT",
|
|
80
|
+
},
|
|
81
|
+
responses: [
|
|
82
|
+
{
|
|
83
|
+
resultCode: "",
|
|
84
|
+
displayText: "",
|
|
85
|
+
ttsText: "",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
needUploadResult: true,
|
|
89
|
+
noHalfPage: false,
|
|
90
|
+
pageControlRelated: false,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
// Send command and wait for response (60 second timeout)
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const timeout = setTimeout(() => {
|
|
96
|
+
wsManager.off("data-event", handler);
|
|
97
|
+
reject(new Error("检索邮件超时(60秒)"));
|
|
98
|
+
}, 60000);
|
|
99
|
+
// Listen for data events from WebSocket
|
|
100
|
+
const handler = (event) => {
|
|
101
|
+
if (event.intentName === "SearchEmails") {
|
|
102
|
+
clearTimeout(timeout);
|
|
103
|
+
wsManager.off("data-event", handler);
|
|
104
|
+
if (event.status === "success" && event.outputs) {
|
|
105
|
+
resolve({
|
|
106
|
+
content: [
|
|
107
|
+
{
|
|
108
|
+
type: "text",
|
|
109
|
+
text: JSON.stringify(event.outputs),
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
reject(new Error(`检索邮件失败: ${event.status}`));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
// Register event handler
|
|
120
|
+
wsManager.on("data-event", handler);
|
|
121
|
+
// Send the command
|
|
122
|
+
sendCommand({
|
|
123
|
+
config,
|
|
124
|
+
sessionId,
|
|
125
|
+
taskId,
|
|
126
|
+
messageId,
|
|
127
|
+
command,
|
|
128
|
+
})
|
|
129
|
+
.then(() => { })
|
|
130
|
+
.catch((error) => {
|
|
131
|
+
clearTimeout(timeout);
|
|
132
|
+
wsManager.off("data-event", handler);
|
|
133
|
+
reject(error);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
};
|
|
@@ -8,15 +8,15 @@ 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: `搜索用户设备文件系统的文件。
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
- "
|
|
13
|
+
【重要】使用约束:此工具仅在用户显著说明要从手机/PC等用户设备搜索时才执行,例如:
|
|
14
|
+
- "从我手机/鸿蒙PC里面搜索xxxx"
|
|
15
15
|
- "从手机文件系统找一下xxxx"
|
|
16
16
|
- "在手机上查找文件xxxx"
|
|
17
17
|
- "搜索手机里的文件"
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
如果用户没有明确说明从手机或者PC搜索(如仅说"搜索文件"、"找一下xxxx"),应默认从当前runtime运行环境的本地的文件系统查询,不要调用此工具。
|
|
20
20
|
|
|
21
21
|
功能说明:根据关键词搜索文件名称或内容,返回匹配的文件列表(包括文件名、路径、大小、修改时间等信息)。
|
|
22
22
|
|
|
@@ -11,9 +11,9 @@ import { getCurrentSessionContext } from "./session-manager.js";
|
|
|
11
11
|
export const searchPhotoGalleryTool = {
|
|
12
12
|
name: "search_photo_gallery",
|
|
13
13
|
label: "Search Photo Gallery",
|
|
14
|
-
description:
|
|
14
|
+
description: `插件功能描述:搜索用户设备图库中的照片
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
工具使用约束:如果用户说从手机/鸿蒙PC图库中或者从相册中查询xx图片时调用此工具,注意此工具仅支持从本地图库检索,不支持云空间相册检索。
|
|
17
17
|
|
|
18
18
|
工具输入输出简介:
|
|
19
19
|
a. 根据图像描述语料检索匹配的照片,返回照片在手机本地的 mediaUri以及thumbnailUri。
|
|
@@ -99,12 +99,10 @@ async function downloadRemoteFile(url) {
|
|
|
99
99
|
export const sendFileToUserTool = {
|
|
100
100
|
name: "send_file_to_user",
|
|
101
101
|
label: "Send File to User",
|
|
102
|
-
description:
|
|
102
|
+
description: `工具能力描述:帮助用户把本地的文件或者公网地址的文件传到用户设备。
|
|
103
103
|
|
|
104
104
|
工具参数说明:
|
|
105
|
-
a. fileLocalUrls
|
|
106
|
-
b. fileRemoteUrls:公网地址数组,包含用户需要回传的文件的公网地址(会先下载到本地再发送)
|
|
107
|
-
c. fileLocalUrls 与 fileRemoteUrls 任意一个不为空即可,两者都提供时都会处理
|
|
105
|
+
a. fileLocalUrls 与 fileRemoteUrls 任意一个不为空即可,两者都提供时都会处理
|
|
108
106
|
|
|
109
107
|
注意事项:
|
|
110
108
|
a. 支持传入数组或 JSON 字符串格式
|
|
@@ -16,14 +16,14 @@ 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: `工具能力描述:将用户本地设备文件上传并获取可公网访问的 URL。
|
|
20
20
|
|
|
21
|
-
前置工具调用:此工具使用前必须先调用 search_file 或者 query_collection 工具获取文件的 uri
|
|
21
|
+
前置工具调用:此工具使用前必须先调用 search_file 或者 query_collection 工具获取文件的 uri
|
|
22
22
|
|
|
23
23
|
工具参数说明:
|
|
24
24
|
a. 入参中的fileInfos数组,每个元素必须包含mediaUri字段(对应于search_file工具或者query_collection返回结果中的uri),必须与search_file或者query_collection结果中对应的uri完全保持一致,不要自行修改。
|
|
25
25
|
b. fileInfos中的timeout字段是可选的,表示上传文件超时时间,单位是毫秒,默认是20000(20秒)。
|
|
26
|
-
c. fileInfos
|
|
26
|
+
c. fileInfos 是文件在用户设备本地的信息数组(从 search_file 工具或者query_collection 工具响应中获取)。限制:每次最多支持传入 5 条文件信息。
|
|
27
27
|
|
|
28
28
|
注意事项:
|
|
29
29
|
a. 操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。
|
|
@@ -12,7 +12,7 @@ import { getCurrentSessionContext } from "./session-manager.js";
|
|
|
12
12
|
export const uploadPhotoTool = {
|
|
13
13
|
name: "upload_photo",
|
|
14
14
|
label: "Upload Photo",
|
|
15
|
-
description:
|
|
15
|
+
description: `工具能力描述:将用户本地设备文件回传并获取可公网访问的 URL。
|
|
16
16
|
|
|
17
17
|
前置工具调用:此工具使用前必须先调用 search_photo_gallery 工具获取照片的 mediaUri或者thumbnailUri
|
|
18
18
|
工具参数说明:
|