@ynhcj/xiaoyi-channel 0.0.157-beta → 0.0.159-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/tools/agent-as-skill-tool.js +55 -4
- package/dist/src/tools/get-collection-tool-schema.js +1 -1
- package/dist/src/tools/xiaoyi-add-collection-tool.js +2 -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
|
@@ -3,6 +3,7 @@ import { getXYWebSocketManager } from "../client.js";
|
|
|
3
3
|
import { sendCommand } from "../formatter.js";
|
|
4
4
|
import { getCurrentTaskId } from "../task-manager.js";
|
|
5
5
|
import { logger } from "../utils/logger.js";
|
|
6
|
+
import { XYFileUploadService } from "../file-upload.js";
|
|
6
7
|
/**
|
|
7
8
|
* Agent-as-skill tool - invokes a registered agent by agentId as a skill.
|
|
8
9
|
* The tool receives the agentId, query, and optional file attachments,
|
|
@@ -11,7 +12,7 @@ import { logger } from "../utils/logger.js";
|
|
|
11
12
|
export function createAgentAsSkillTool(ctx) {
|
|
12
13
|
const { config, sessionId, taskId, messageId } = ctx;
|
|
13
14
|
return {
|
|
14
|
-
name: "
|
|
15
|
+
name: "agent_as_a_tool",
|
|
15
16
|
label: "Agent as Skill Tool",
|
|
16
17
|
description: `智能体作为skill的执行元工具。当需要调用其他已注册的Agent来执行特定任务时使用此工具。
|
|
17
18
|
该工具会将用户请求和可选的附件文件转发给目标Agent执行,并返回执行结果。
|
|
@@ -37,8 +38,7 @@ export function createAgentAsSkillTool(ctx) {
|
|
|
37
38
|
description: "用户原始请求文本,原样转发给目标Agent执行",
|
|
38
39
|
},
|
|
39
40
|
filesInfo: {
|
|
40
|
-
|
|
41
|
-
description: "附件文件/图片信息列表,无文件时可传null或空数组",
|
|
41
|
+
description: "附件文件/图片信息列表,无文件时可传null或空数组,支持传入数组或JSON字符串",
|
|
42
42
|
items: {
|
|
43
43
|
type: "object",
|
|
44
44
|
properties: {
|
|
@@ -55,6 +55,10 @@ export function createAgentAsSkillTool(ctx) {
|
|
|
55
55
|
type: "string",
|
|
56
56
|
description: "文件可访问下载链接(完整HTTP/HTTPS地址)",
|
|
57
57
|
},
|
|
58
|
+
fileUrlLocal: {
|
|
59
|
+
type: "string",
|
|
60
|
+
description: "文件本地路径,如果提供此字段,工具会自动上传文件并将公网URL填入fileUrl",
|
|
61
|
+
},
|
|
58
62
|
},
|
|
59
63
|
},
|
|
60
64
|
},
|
|
@@ -71,6 +75,53 @@ export function createAgentAsSkillTool(ctx) {
|
|
|
71
75
|
if (!params.query || typeof params.query !== "string") {
|
|
72
76
|
throw new Error("Missing or invalid required parameter: query must be a non-empty string");
|
|
73
77
|
}
|
|
78
|
+
// Robust parsing: normalize filesInfo from array or JSON string
|
|
79
|
+
let filesInfo = null;
|
|
80
|
+
if (params.filesInfo) {
|
|
81
|
+
if (Array.isArray(params.filesInfo)) {
|
|
82
|
+
filesInfo = params.filesInfo;
|
|
83
|
+
}
|
|
84
|
+
else if (typeof params.filesInfo === 'string') {
|
|
85
|
+
try {
|
|
86
|
+
const parsed = JSON.parse(params.filesInfo);
|
|
87
|
+
if (Array.isArray(parsed)) {
|
|
88
|
+
filesInfo = parsed;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new Error("filesInfo must be an array or a JSON string representing an array");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (parseError) {
|
|
95
|
+
throw new Error(`filesInfo JSON解析失败: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
filesInfo = null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Upload local files and fill fileUrl
|
|
103
|
+
if (filesInfo && filesInfo.length > 0) {
|
|
104
|
+
const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
|
|
105
|
+
for (const fileInfo of filesInfo) {
|
|
106
|
+
if (fileInfo.fileUrlLocal && !fileInfo.fileUrl) {
|
|
107
|
+
try {
|
|
108
|
+
const publicUrl = await uploadService.uploadFileAndGetUrl(fileInfo.fileUrlLocal, "TEMPORARY_MATERIAL_DOC");
|
|
109
|
+
if (publicUrl) {
|
|
110
|
+
fileInfo.fileUrl = publicUrl;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
logger.warn("[AGENT-AS-SKILL] 上传文件未返回公网URL", { fileUrlLocal: fileInfo.fileUrlLocal });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (uploadError) {
|
|
117
|
+
logger.error("[AGENT-AS-SKILL] 上传本地文件失败", { fileUrlLocal: fileInfo.fileUrlLocal, error: uploadError });
|
|
118
|
+
throw new Error(`上传本地文件失败 (${fileInfo.fileUrlLocal}): ${uploadError instanceof Error ? uploadError.message : String(uploadError)}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Remove fileUrlLocal from the final payload
|
|
122
|
+
delete fileInfo.fileUrlLocal;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
74
125
|
// Get WebSocket manager
|
|
75
126
|
const wsManager = getXYWebSocketManager(config);
|
|
76
127
|
// Build ExecuteAgentAsSkill command
|
|
@@ -82,7 +133,7 @@ export function createAgentAsSkillTool(ctx) {
|
|
|
82
133
|
payload: {
|
|
83
134
|
agentId: params.agentId,
|
|
84
135
|
query: params.query,
|
|
85
|
-
filesInfo:
|
|
136
|
+
filesInfo: filesInfo || null,
|
|
86
137
|
},
|
|
87
138
|
};
|
|
88
139
|
// Send command and wait for response (5 minute timeout)
|
|
@@ -6,7 +6,7 @@ export function createGetCollectionToolSchemaTool(ctx) {
|
|
|
6
6
|
return createSchemaTool({
|
|
7
7
|
name: "get_collection_tool_schema",
|
|
8
8
|
label: "Get Collection Tool Schema",
|
|
9
|
-
description: "
|
|
9
|
+
description: "获取可在用户设备上添加、检索、删除小艺收藏(也叫小艺帮记)中的公共知识数据的相关端工具列表。",
|
|
10
10
|
tools: [createXiaoyiAddCollectionTool(ctx), createXiaoyiCollectionTool(ctx), createXiaoyiDeleteCollectionTool(ctx)],
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -23,7 +23,7 @@ export function createXiaoyiAddCollectionTool(ctx) {
|
|
|
23
23
|
return {
|
|
24
24
|
name: "add_collection",
|
|
25
25
|
label: "Add XiaoYi Collection",
|
|
26
|
-
description:
|
|
26
|
+
description: `向小艺收藏(也叫小艺帮记)中添加公共知识数据,可以给用户提供个性化体验。任何用户希望保存到个人化知识库中的数据都可以调用本技能。不同类型的数据对应的数据要求如下:
|
|
27
27
|
请求入参说明:
|
|
28
28
|
● content:必填字段,数据类型为string,功能描述是该字段是用户添加收藏的链接url或文本原文。适用于HYPER_LINK和TEXT类型。
|
|
29
29
|
● uri:必填字段,数据类型为string,功能描述是该字段是图片或文件的端存储地址链接。适用于IMAGE和FILE类型。
|
|
@@ -32,6 +32,7 @@ export function createXiaoyiAddCollectionTool(ctx) {
|
|
|
32
32
|
● title:非必填字段,数据类型为string,功能描述是标识文件类型数据的文件名称。适用于FILE类型。
|
|
33
33
|
说明:如果dataType为HYPER_LINK或TEXT,则content字段必填且不能为空;如果dataType为IMAGE或FILE,则uri字段必填且不能为空。当用户希望收藏海报、截图等图片类数据时,请将数据以图片IMAGE的形式存入到小艺帮记;当用户希望收藏电子书、笔记、报告、素材、文档、合同、协议、简历、证书、报表、日志、安装包、压缩包等描述的文件时,请将数据以文件FILE的形式存入到小艺帮记。
|
|
34
34
|
当你成功收藏这个数据到小艺帮记后,请在最后显示"已成功把数据添加到[小艺帮记](vassistant://voice/main?page=CollectionPage&jumpHomePageTab=myCollection)",
|
|
35
|
+
请额外注意,如果当前用户的设备是鸿蒙PC,则最后显示的内容需要额外定制,内容是"已成功把数据添加到[小艺帮记](vassistant://voice/main?agentId=celia_collection_share&agentPage=CollectionPage)"
|
|
35
36
|
注意:
|
|
36
37
|
a. 操作超时时间为60秒,请勿重复调用此工具
|
|
37
38
|
b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
|
|
@@ -23,7 +23,7 @@ export function createXiaoyiCollectionTool(ctx) {
|
|
|
23
23
|
return {
|
|
24
24
|
name: "query_collection",
|
|
25
25
|
label: "XiaoYi Collection",
|
|
26
|
-
description:
|
|
26
|
+
description: `检索用户在小艺收藏(也叫小艺帮记)中记下来的公共知识数据,本技能支持查询用户收藏的公共知识数据,也可以根据特定语义化描述进行特定内容的检索,通过参数进行控制。本技能返回结果中,linkTitle是收藏内容的标题,description是对收藏内容的总结,label是收藏内容的标签,linkUrl是可以直接访问的原始内容链接。如果你认为某条数据对用户交互有用,可以通过linkUrl抓取更加丰富的原始数据。
|
|
27
27
|
注意:
|
|
28
28
|
a. 操作超时时间为60秒,请勿重复调用此工具
|
|
29
29
|
b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
|
|
@@ -22,7 +22,7 @@ export function createXiaoyiDeleteCollectionTool(ctx) {
|
|
|
22
22
|
return {
|
|
23
23
|
name: "delete_collection",
|
|
24
24
|
label: "Delete XiaoYi Collection",
|
|
25
|
-
description:
|
|
25
|
+
description: `从小艺收藏(也叫小艺帮记)中删除之前已保存的公共知识数据。任何用户希望删除已保存到个人知识库的数据都可以调用本技能。如果用户想更新之前的收藏数据,需要先query获取itemId然后再delete,最后执行Add,按照这个步骤完成收藏数据更新。
|
|
26
26
|
注意:
|
|
27
27
|
a. 操作超时时间为60秒,请勿重复调用此工具
|
|
28
28
|
b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
|