@ynhcj/xiaoyi-channel 0.0.185-beta → 0.0.185-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 +141 -1
- package/dist/src/acp-session-binding.d.ts +37 -0
- package/dist/src/acp-session-binding.js +237 -0
- package/dist/src/bot.js +62 -33
- package/dist/src/channel.js +68 -64
- package/dist/src/client.d.ts +5 -0
- package/dist/src/client.js +10 -0
- package/dist/src/cron-command.d.ts +2 -0
- package/dist/src/cron-command.js +14 -8
- package/dist/src/cron-query-handler.js +36 -0
- package/dist/src/cspl/call_api.js +4 -2
- package/dist/src/cspl/sentinel_hook.js +9 -8
- package/dist/src/cspl/upload_file.js +2 -2
- package/dist/src/formatter.js +72 -36
- package/dist/src/log-reporter/config-loader.d.ts +11 -0
- package/dist/src/log-reporter/config-loader.js +68 -0
- package/dist/src/log-reporter/cursor-store.d.ts +5 -0
- package/dist/src/log-reporter/cursor-store.js +26 -0
- package/dist/src/log-reporter/index.d.ts +10 -0
- package/dist/src/log-reporter/index.js +77 -0
- package/dist/src/log-reporter/reporter.d.ts +6 -0
- package/dist/src/log-reporter/reporter.js +17 -0
- package/dist/src/log-reporter/scanner.d.ts +6 -0
- package/dist/src/log-reporter/scanner.js +82 -0
- package/dist/src/log-reporter/types.d.ts +59 -0
- package/dist/src/log-reporter/types.js +2 -0
- package/dist/src/log-reporter/uploader.d.ts +6 -0
- package/dist/src/log-reporter/uploader.js +32 -0
- package/dist/src/memory-query-handler.d.ts +1 -0
- package/dist/src/memory-query-handler.js +283 -0
- package/dist/src/monitor.js +29 -9
- package/dist/src/outbound.js +5 -0
- package/dist/src/parser.d.ts +12 -0
- package/dist/src/parser.js +39 -13
- package/dist/src/provider.js +79 -16
- package/dist/src/reply-dispatcher.d.ts +3 -0
- package/dist/src/reply-dispatcher.js +166 -164
- package/dist/src/self-evolution-handler.js +2 -1
- package/dist/src/task-manager.d.ts +5 -6
- package/dist/src/task-manager.js +5 -9
- package/dist/src/tools/agent-as-skill-tool.d.ts +41 -2
- package/dist/src/tools/agent-as-skill-tool.js +144 -151
- package/dist/src/tools/calendar-tool.d.ts +24 -2
- package/dist/src/tools/calendar-tool.js +115 -117
- package/dist/src/tools/call-device-tool.d.ts +20 -6
- package/dist/src/tools/call-device-tool.js +116 -138
- package/dist/src/tools/call-phone-tool.d.ts +21 -2
- package/dist/src/tools/call-phone-tool.js +112 -114
- package/dist/src/tools/check-plugin-privilege-tool.d.ts +16 -2
- package/dist/src/tools/check-plugin-privilege-tool.js +141 -143
- package/dist/src/tools/create-alarm-tool.d.ts +39 -2
- package/dist/src/tools/create-alarm-tool.js +229 -231
- package/dist/src/tools/create-all-tools.js +8 -4
- package/dist/src/tools/delete-alarm-tool.d.ts +15 -2
- package/dist/src/tools/delete-alarm-tool.js +134 -136
- package/dist/src/tools/device-tool-map.d.ts +1 -1
- package/dist/src/tools/device-tool-map.js +9 -2
- package/dist/src/tools/discover-cross-devices-tool.d.ts +16 -2
- package/dist/src/tools/discover-cross-devices-tool.js +121 -124
- package/dist/src/tools/display-a2ui-card-bypath-tool.d.ts +21 -0
- package/dist/src/tools/display-a2ui-card-bypath-tool.js +65 -0
- package/dist/src/tools/get-alarm-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-alarm-tool-schema.js +10 -16
- package/dist/src/tools/get-calendar-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-calendar-tool-schema.js +8 -12
- package/dist/src/tools/get-collection-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-collection-tool-schema.js +9 -11
- package/dist/src/tools/get-contact-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-contact-tool-schema.js +10 -16
- package/dist/src/tools/get-device-file-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-device-file-tool-schema.js +9 -13
- package/dist/src/tools/get-email-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-email-tool-schema.js +8 -11
- package/dist/src/tools/get-note-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-note-tool-schema.js +9 -14
- package/dist/src/tools/get-photo-tool-schema.d.ts +1 -2
- package/dist/src/tools/get-photo-tool-schema.js +9 -12
- package/dist/src/tools/image-reading-tool.d.ts +28 -2
- package/dist/src/tools/image-reading-tool.js +76 -76
- package/dist/src/tools/location-tool.d.ts +11 -2
- package/dist/src/tools/location-tool.js +93 -92
- package/dist/src/tools/login-token-tool.d.ts +20 -2
- package/dist/src/tools/login-token-tool.js +123 -125
- package/dist/src/tools/modify-alarm-tool.d.ts +47 -2
- package/dist/src/tools/modify-alarm-tool.js +250 -252
- package/dist/src/tools/modify-note-tool.d.ts +20 -2
- package/dist/src/tools/modify-note-tool.js +107 -109
- package/dist/src/tools/note-tool.d.ts +20 -2
- package/dist/src/tools/note-tool.js +106 -108
- package/dist/src/tools/query-app-message-tool.d.ts +28 -2
- package/dist/src/tools/query-app-message-tool.js +111 -113
- package/dist/src/tools/query-memory-data-tool.d.ts +28 -2
- package/dist/src/tools/query-memory-data-tool.js +112 -114
- package/dist/src/tools/query-todo-task-tool.d.ts +24 -2
- package/dist/src/tools/query-todo-task-tool.js +106 -108
- package/dist/src/tools/save-file-to-phone-tool.d.ts +24 -2
- package/dist/src/tools/save-file-to-phone-tool.js +130 -132
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +24 -2
- package/dist/src/tools/save-media-to-gallery-tool.js +137 -139
- package/dist/src/tools/save-self-evolution-skill-tool.d.ts +54 -2
- package/dist/src/tools/save-self-evolution-skill-tool.js +194 -194
- package/dist/src/tools/search-alarm-tool.d.ts +34 -2
- package/dist/src/tools/search-alarm-tool.js +174 -176
- package/dist/src/tools/search-calendar-tool.d.ts +24 -2
- package/dist/src/tools/search-calendar-tool.js +148 -150
- package/dist/src/tools/search-contact-tool.d.ts +16 -2
- package/dist/src/tools/search-contact-tool.js +101 -103
- package/dist/src/tools/search-email-tool.d.ts +21 -2
- package/dist/src/tools/search-email-tool.js +110 -112
- package/dist/src/tools/search-file-tool.d.ts +16 -2
- package/dist/src/tools/search-file-tool.js +104 -106
- package/dist/src/tools/search-message-tool.d.ts +16 -2
- package/dist/src/tools/search-message-tool.js +103 -105
- package/dist/src/tools/search-note-tool.d.ts +16 -2
- package/dist/src/tools/search-note-tool.js +98 -100
- package/dist/src/tools/search-photo-gallery-tool.d.ts +21 -2
- package/dist/src/tools/search-photo-gallery-tool.js +35 -37
- package/dist/src/tools/send-cross-device-task-tool.d.ts +35 -2
- package/dist/src/tools/send-cross-device-task-tool.js +216 -150
- package/dist/src/tools/send-email-tool.d.ts +24 -2
- package/dist/src/tools/send-email-tool.js +108 -110
- package/dist/src/tools/send-file-to-user-tool.d.ts +20 -2
- package/dist/src/tools/send-file-to-user-tool.js +174 -178
- package/dist/src/tools/send-html-card-tool.d.ts +20 -2
- package/dist/src/tools/send-html-card-tool.js +85 -87
- package/dist/src/tools/send-message-tool.d.ts +20 -2
- package/dist/src/tools/send-message-tool.js +122 -124
- package/dist/src/tools/session-manager.d.ts +19 -52
- package/dist/src/tools/session-manager.js +95 -247
- package/dist/src/tools/upload-file-tool.d.ts +20 -2
- package/dist/src/tools/upload-file-tool.js +80 -82
- package/dist/src/tools/upload-photo-tool.d.ts +20 -2
- package/dist/src/tools/upload-photo-tool.js +68 -70
- package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +32 -2
- package/dist/src/tools/xiaoyi-add-collection-tool.js +146 -148
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +20 -2
- package/dist/src/tools/xiaoyi-collection-tool.js +114 -116
- package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +15 -2
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +127 -129
- package/dist/src/tools/xiaoyi-gui-tool.d.ts +16 -2
- package/dist/src/tools/xiaoyi-gui-tool.js +92 -95
- package/dist/src/types.d.ts +6 -6
- package/dist/src/utils/config-manager.d.ts +3 -2
- package/dist/src/utils/config-manager.js +22 -2
- package/dist/src/utils/cron-push-map.d.ts +26 -0
- package/dist/src/utils/cron-push-map.js +131 -0
- package/dist/src/utils/logger.js +3 -14
- package/dist/src/websocket.d.ts +1 -1
- package/dist/src/websocket.js +29 -13
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Agent-as-skill tool implementation - invokes another agent as a skill
|
|
2
|
-
import {
|
|
2
|
+
import { getCachedXYWebSocketManager } from "../client.js";
|
|
3
3
|
import { sendCommand } from "../formatter.js";
|
|
4
|
-
import {
|
|
4
|
+
import { getCurrentSessionContext } from './session-manager.js';
|
|
5
5
|
import { logger } from "../utils/logger.js";
|
|
6
6
|
import { XYFileUploadService } from "../file-upload.js";
|
|
7
7
|
/**
|
|
@@ -9,12 +9,10 @@ import { XYFileUploadService } from "../file-upload.js";
|
|
|
9
9
|
* The tool receives the agentId, query, and optional file attachments,
|
|
10
10
|
* forwards the request to the target agent via WebSocket, and returns the result.
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
label: "Agent as Skill Tool",
|
|
17
|
-
description: `智能体作为skill的执行元工具。当需要调用其他已注册的Agent来执行特定任务时使用此工具。
|
|
12
|
+
export const agentAsSkillTool = {
|
|
13
|
+
name: "agent_as_a_tool",
|
|
14
|
+
label: "Agent as Skill Tool",
|
|
15
|
+
description: `智能体作为skill的执行元工具。当需要调用其他已注册的Agent来执行特定任务时使用此工具。
|
|
18
16
|
该工具会将用户请求和可选的附件文件转发给目标Agent执行,并返回执行结果。
|
|
19
17
|
|
|
20
18
|
使用场景:
|
|
@@ -26,165 +24,160 @@ export function createAgentAsSkillTool(ctx) {
|
|
|
26
24
|
- 操作超时时间为5分钟
|
|
27
25
|
- 该工具执行期间必须严格等待结果返回,不要执行其他操作
|
|
28
26
|
- 如果超时或失败,最多重试一次`,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
fileUrlLocal: {
|
|
59
|
-
type: "string",
|
|
60
|
-
description: "文件本地路径,如果提供此字段,工具会自动上传文件并将公网URL填入fileUrl",
|
|
61
|
-
},
|
|
27
|
+
parameters: {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: {
|
|
30
|
+
agentId: {
|
|
31
|
+
type: "string",
|
|
32
|
+
description: "待执行的AgentId,精准匹配系统注册的AgentId",
|
|
33
|
+
},
|
|
34
|
+
query: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "用户原始请求文本,原样转发给目标Agent执行",
|
|
37
|
+
},
|
|
38
|
+
filesInfo: {
|
|
39
|
+
description: "附件文件/图片信息列表,无文件时可传null或空数组,支持传入数组或JSON字符串",
|
|
40
|
+
items: {
|
|
41
|
+
type: "object",
|
|
42
|
+
properties: {
|
|
43
|
+
fileType: {
|
|
44
|
+
type: "string",
|
|
45
|
+
description: "文件类型:file 或 image",
|
|
46
|
+
enum: ["file", "image"],
|
|
47
|
+
},
|
|
48
|
+
fileId: {
|
|
49
|
+
type: "string",
|
|
50
|
+
description: "文件全局唯一标识",
|
|
51
|
+
},
|
|
52
|
+
fileUrl: {
|
|
53
|
+
type: "string",
|
|
54
|
+
description: "文件可访问下载链接(完整HTTP/HTTPS地址)或文件本地路径。若为本地路径,工具会自动上传文件并替换为公网URL",
|
|
62
55
|
},
|
|
63
56
|
},
|
|
64
57
|
},
|
|
65
58
|
},
|
|
66
|
-
required: ["agentId", "query"],
|
|
67
59
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
required: ["agentId", "query"],
|
|
61
|
+
},
|
|
62
|
+
async execute(toolCallId, params) {
|
|
63
|
+
const _c = getCurrentSessionContext();
|
|
64
|
+
const { config, sessionId, taskId, messageId } = _c;
|
|
65
|
+
// Dynamic lookup: use latest taskId from task-manager (handles steer/interrupt)
|
|
66
|
+
// Validate parameters
|
|
67
|
+
if (!params.agentId || typeof params.agentId !== "string") {
|
|
68
|
+
throw new Error("Missing or invalid required parameter: agentId must be a non-empty string");
|
|
69
|
+
}
|
|
70
|
+
if (!params.query || typeof params.query !== "string") {
|
|
71
|
+
throw new Error("Missing or invalid required parameter: query must be a non-empty string");
|
|
72
|
+
}
|
|
73
|
+
// Robust parsing: normalize filesInfo from array or JSON string
|
|
74
|
+
let filesInfo = null;
|
|
75
|
+
if (params.filesInfo) {
|
|
76
|
+
if (Array.isArray(params.filesInfo)) {
|
|
77
|
+
filesInfo = params.filesInfo;
|
|
74
78
|
}
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
}
|
|
79
|
+
else if (typeof params.filesInfo === 'string') {
|
|
80
|
+
try {
|
|
81
|
+
const parsed = JSON.parse(params.filesInfo);
|
|
82
|
+
if (Array.isArray(parsed)) {
|
|
83
|
+
filesInfo = parsed;
|
|
93
84
|
}
|
|
94
|
-
|
|
95
|
-
throw new Error(
|
|
85
|
+
else {
|
|
86
|
+
throw new Error("filesInfo must be an array or a JSON string representing an array");
|
|
96
87
|
}
|
|
97
88
|
}
|
|
98
|
-
|
|
99
|
-
filesInfo
|
|
89
|
+
catch (parseError) {
|
|
90
|
+
throw new Error(`filesInfo JSON解析失败: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
100
91
|
}
|
|
101
92
|
}
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
}
|
|
93
|
+
else {
|
|
94
|
+
filesInfo = null;
|
|
124
95
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
filesInfo: filesInfo || null,
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
// Send command and wait for response (5 minute timeout)
|
|
140
|
-
return new Promise((resolve, reject) => {
|
|
141
|
-
const timeout = setTimeout(() => {
|
|
142
|
-
wsManager.off("agent-as-skill-response", handler);
|
|
143
|
-
logger.error("超时: Agent-as-Skill 操作超时(5分钟)", { agentId: params.agentId, toolCallId });
|
|
144
|
-
reject(new Error("Agent-as-Skill 操作超时(5分钟)"));
|
|
145
|
-
}, 300000); // 5 minutes timeout
|
|
146
|
-
// Listen for Agent-as-Skill response events
|
|
147
|
-
const handler = (event) => {
|
|
148
|
-
// Check if this is the ExecuteAgentAsSkillResponse we're waiting for
|
|
149
|
-
if (event.header?.namespace === "System" &&
|
|
150
|
-
event.header?.name === "ExecuteAgentAsSkillResponse") {
|
|
151
|
-
clearTimeout(timeout);
|
|
152
|
-
wsManager.off("agent-as-skill-response", handler);
|
|
153
|
-
// Return the payload directly as the tool result
|
|
154
|
-
const payload = event.payload;
|
|
155
|
-
if (payload) {
|
|
156
|
-
resolve({
|
|
157
|
-
content: [
|
|
158
|
-
{
|
|
159
|
-
type: "text",
|
|
160
|
-
text: typeof payload === "string" ? payload : JSON.stringify(payload),
|
|
161
|
-
},
|
|
162
|
-
],
|
|
163
|
-
});
|
|
96
|
+
}
|
|
97
|
+
// Upload local files and fill fileUrl
|
|
98
|
+
if (filesInfo && filesInfo.length > 0) {
|
|
99
|
+
const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
|
|
100
|
+
for (const fileInfo of filesInfo) {
|
|
101
|
+
if (fileInfo.fileUrl && !/^https?:\/\//i.test(fileInfo.fileUrl)) {
|
|
102
|
+
const localPath = fileInfo.fileUrl;
|
|
103
|
+
try {
|
|
104
|
+
const publicUrl = await uploadService.uploadFileAndGetUrl(localPath, "TEMPORARY_MATERIAL_DOC");
|
|
105
|
+
if (publicUrl) {
|
|
106
|
+
fileInfo.fileUrl = publicUrl;
|
|
164
107
|
}
|
|
165
108
|
else {
|
|
166
|
-
|
|
109
|
+
logger.warn("[AGENT-AS-SKILL] 上传文件未返回公网URL", { localPath });
|
|
167
110
|
}
|
|
168
111
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
112
|
+
catch (uploadError) {
|
|
113
|
+
logger.error("[AGENT-AS-SKILL] 上传本地文件失败", { localPath, error: uploadError });
|
|
114
|
+
throw new Error(`上传本地文件失败 (${localPath}): ${uploadError instanceof Error ? uploadError.message : String(uploadError)}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Get WebSocket manager
|
|
120
|
+
const wsManager = getCachedXYWebSocketManager();
|
|
121
|
+
// Build ExecuteAgentAsSkill command
|
|
122
|
+
const command = {
|
|
123
|
+
header: {
|
|
124
|
+
namespace: "System",
|
|
125
|
+
name: "ExecuteAgentAsSkill",
|
|
126
|
+
},
|
|
127
|
+
payload: {
|
|
128
|
+
agentId: params.agentId,
|
|
129
|
+
query: params.query,
|
|
130
|
+
filesInfo: filesInfo || null,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
// Send command and wait for response (5 minute timeout)
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
const timeout = setTimeout(() => {
|
|
136
|
+
wsManager.off("agent-as-skill-response", handler);
|
|
137
|
+
logger.error("超时: Agent-as-Skill 操作超时(5分钟)", { agentId: params.agentId, toolCallId });
|
|
138
|
+
reject(new Error("Agent-as-Skill 操作超时(5分钟)"));
|
|
139
|
+
}, 300000); // 5 minutes timeout
|
|
140
|
+
// Listen for Agent-as-Skill response events
|
|
141
|
+
const handler = (event) => {
|
|
142
|
+
// Check if this is the ExecuteAgentAsSkillResponse we're waiting for
|
|
143
|
+
if (event.header?.namespace === "System" &&
|
|
144
|
+
event.header?.name === "ExecuteAgentAsSkillResponse") {
|
|
183
145
|
clearTimeout(timeout);
|
|
184
146
|
wsManager.off("agent-as-skill-response", handler);
|
|
185
|
-
|
|
186
|
-
|
|
147
|
+
// Return the payload directly as the tool result
|
|
148
|
+
const payload = event.payload;
|
|
149
|
+
if (payload) {
|
|
150
|
+
resolve({
|
|
151
|
+
content: [
|
|
152
|
+
{
|
|
153
|
+
type: "text",
|
|
154
|
+
text: typeof payload === "string" ? payload : JSON.stringify(payload),
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
reject(new Error("Agent-as-Skill 响应格式错误:缺少 payload"));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
// Register event handler
|
|
165
|
+
wsManager.on("agent-as-skill-response", handler);
|
|
166
|
+
// Send the command
|
|
167
|
+
sendCommand({
|
|
168
|
+
config,
|
|
169
|
+
sessionId,
|
|
170
|
+
taskId,
|
|
171
|
+
messageId,
|
|
172
|
+
command,
|
|
173
|
+
toolCallId,
|
|
174
|
+
}).then(() => {
|
|
175
|
+
logger.log("[AGENT-AS-SKILL] Command sent successfully", { agentId: params.agentId });
|
|
176
|
+
}).catch((error) => {
|
|
177
|
+
clearTimeout(timeout);
|
|
178
|
+
wsManager.off("agent-as-skill-response", handler);
|
|
179
|
+
reject(error);
|
|
187
180
|
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
};
|
|
@@ -1,7 +1,29 @@
|
|
|
1
|
-
import type { SessionContext } from "./session-manager.js";
|
|
2
1
|
/**
|
|
3
2
|
* XY calendar event tool - creates a calendar event on user's device.
|
|
4
3
|
* Requires title, dtStart (start time), and dtEnd (end time) parameters.
|
|
5
4
|
* Time format must be: yyyy-mm-dd hh:mm:ss
|
|
6
5
|
*/
|
|
7
|
-
export declare
|
|
6
|
+
export declare const calendarTool: {
|
|
7
|
+
name: string;
|
|
8
|
+
label: string;
|
|
9
|
+
description: string;
|
|
10
|
+
parameters: {
|
|
11
|
+
type: string;
|
|
12
|
+
properties: {
|
|
13
|
+
title: {
|
|
14
|
+
type: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
dtStart: {
|
|
18
|
+
type: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
dtEnd: {
|
|
22
|
+
type: string;
|
|
23
|
+
description: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
required: string[];
|
|
27
|
+
};
|
|
28
|
+
execute(toolCallId: string, params: any): Promise<unknown>;
|
|
29
|
+
};
|
|
@@ -1,135 +1,133 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getCachedXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getCurrentSessionContext } from './session-manager.js';
|
|
4
4
|
import { logger } from "../utils/logger.js";
|
|
5
5
|
/**
|
|
6
6
|
* XY calendar event tool - creates a calendar event on user's device.
|
|
7
7
|
* Requires title, dtStart (start time), and dtEnd (end time) parameters.
|
|
8
8
|
* Time format must be: yyyy-mm-dd hh:mm:ss
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
label: "Create Calendar Event",
|
|
15
|
-
description: `在用户设备上创建日程。需要提供日程标题、开始时间和结束时间。时间格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 14:30:00)。注意:该工具执行时间较长(最多60秒),请勿重复调用,超时或失败时最多重试一次。
|
|
10
|
+
export const calendarTool = {
|
|
11
|
+
name: "create_calendar_event",
|
|
12
|
+
label: "Create Calendar Event",
|
|
13
|
+
description: `在用户设备上创建日程。需要提供日程标题、开始时间和结束时间。时间格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 14:30:00)。注意:该工具执行时间较长(最多60秒),请勿重复调用,超时或失败时最多重试一次。
|
|
16
14
|
注意事项:使用该工具之前需获取当前真实时间
|
|
17
15
|
|
|
18
16
|
回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
|
|
19
17
|
`,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
18
|
+
parameters: {
|
|
19
|
+
type: "object",
|
|
20
|
+
properties: {
|
|
21
|
+
title: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "日程标题/名称",
|
|
24
|
+
},
|
|
25
|
+
dtStart: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "日程开始时间,格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 14:30:00)",
|
|
28
|
+
},
|
|
29
|
+
dtEnd: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "日程结束时间,格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 17:30:00)",
|
|
35
32
|
},
|
|
36
|
-
required: ["title", "dtStart", "dtEnd"],
|
|
37
33
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
34
|
+
required: ["title", "dtStart", "dtEnd"],
|
|
35
|
+
},
|
|
36
|
+
async execute(toolCallId, params) {
|
|
37
|
+
const _c = getCurrentSessionContext();
|
|
38
|
+
const { config, sessionId, taskId, messageId } = _c;
|
|
39
|
+
// Validate parameters
|
|
40
|
+
if (!params.title || !params.dtStart || !params.dtEnd) {
|
|
41
|
+
throw new Error("Missing required parameters: title, dtStart, and dtEnd are required");
|
|
42
|
+
}
|
|
43
|
+
// Convert time strings to millisecond timestamps
|
|
44
|
+
const dtStartMs = new Date(params.dtStart).getTime();
|
|
45
|
+
const dtEndMs = new Date(params.dtEnd).getTime();
|
|
46
|
+
if (isNaN(dtStartMs) || isNaN(dtEndMs)) {
|
|
47
|
+
throw new Error("Invalid time format. Required format: yyyy-mm-dd hh:mm:ss (e.g., 2024-01-15 14:30:00)");
|
|
48
|
+
}
|
|
49
|
+
// Get WebSocket manager
|
|
50
|
+
const wsManager = getCachedXYWebSocketManager();
|
|
51
|
+
// Build CreateCalendarEvent command
|
|
52
|
+
const command = {
|
|
53
|
+
header: {
|
|
54
|
+
namespace: "Common",
|
|
55
|
+
name: "ActionAndResult",
|
|
56
|
+
},
|
|
57
|
+
payload: {
|
|
58
|
+
cardParam: {},
|
|
59
|
+
executeParam: {
|
|
60
|
+
executeMode: "background",
|
|
61
|
+
intentName: "CreateCalendarEvent",
|
|
62
|
+
bundleName: "com.huawei.hmos.calendardata",
|
|
63
|
+
dimension: "",
|
|
64
|
+
needUnlock: true,
|
|
65
|
+
actionResponse: true,
|
|
66
|
+
timeOut: 5,
|
|
67
|
+
intentParam: {
|
|
68
|
+
title: params.title,
|
|
69
|
+
dtStart: dtStartMs,
|
|
70
|
+
dtEnd: dtEndMs,
|
|
73
71
|
},
|
|
74
|
-
|
|
75
|
-
{
|
|
76
|
-
resultCode: "",
|
|
77
|
-
displayText: "",
|
|
78
|
-
ttsText: "",
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
needUploadResult: true,
|
|
82
|
-
noHalfPage: false,
|
|
83
|
-
pageControlRelated: false,
|
|
72
|
+
achieveType: "INTENT",
|
|
84
73
|
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
reject(new Error(`创建日程失败: ${JSON.stringify(event.outputs)}`));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
// Register event handler
|
|
114
|
-
wsManager.on("data-event", handler);
|
|
115
|
-
// Send the command
|
|
116
|
-
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
117
|
-
sendCommand({
|
|
118
|
-
config,
|
|
119
|
-
sessionId,
|
|
120
|
-
taskId: currentTaskId,
|
|
121
|
-
messageId,
|
|
122
|
-
command,
|
|
123
|
-
toolCallId,
|
|
124
|
-
})
|
|
125
|
-
.then(() => {
|
|
126
|
-
})
|
|
127
|
-
.catch((error) => {
|
|
74
|
+
responses: [
|
|
75
|
+
{
|
|
76
|
+
resultCode: "",
|
|
77
|
+
displayText: "",
|
|
78
|
+
ttsText: "",
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
needUploadResult: true,
|
|
82
|
+
noHalfPage: false,
|
|
83
|
+
pageControlRelated: false,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
// Send command and wait for response (60 second timeout)
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
const timeout = setTimeout(() => {
|
|
89
|
+
wsManager.off("data-event", handler);
|
|
90
|
+
logger.error("超时: 创建日程超时(60秒)", { toolCallId });
|
|
91
|
+
reject(new Error("创建日程超时(60秒)"));
|
|
92
|
+
}, 60000);
|
|
93
|
+
// Listen for data events from WebSocket
|
|
94
|
+
const handler = (event) => {
|
|
95
|
+
if (event.intentName === "CreateCalendarEvent") {
|
|
128
96
|
clearTimeout(timeout);
|
|
129
97
|
wsManager.off("data-event", handler);
|
|
130
|
-
|
|
131
|
-
|
|
98
|
+
if (event.status === "success" && event.outputs) {
|
|
99
|
+
resolve({
|
|
100
|
+
content: [
|
|
101
|
+
{
|
|
102
|
+
type: "text",
|
|
103
|
+
text: JSON.stringify(event.outputs),
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
reject(new Error(`创建日程失败: ${JSON.stringify(event.outputs)}`));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
// Register event handler
|
|
114
|
+
wsManager.on("data-event", handler);
|
|
115
|
+
// Send the command
|
|
116
|
+
sendCommand({
|
|
117
|
+
config,
|
|
118
|
+
sessionId,
|
|
119
|
+
taskId,
|
|
120
|
+
messageId,
|
|
121
|
+
command,
|
|
122
|
+
toolCallId,
|
|
123
|
+
})
|
|
124
|
+
.then(() => {
|
|
125
|
+
})
|
|
126
|
+
.catch((error) => {
|
|
127
|
+
clearTimeout(timeout);
|
|
128
|
+
wsManager.off("data-event", handler);
|
|
129
|
+
reject(error);
|
|
132
130
|
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
};
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export declare const callDeviceTool: {
|
|
2
|
+
name: string;
|
|
3
|
+
label: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
toolName: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
arguments: {
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
required: string[];
|
|
18
|
+
};
|
|
19
|
+
execute(toolCallId: string, params: any): Promise<any>;
|
|
20
|
+
};
|