@ynhcj/xiaoyi-channel 0.0.152-beta → 0.0.152-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 +23 -0
- package/dist/src/bot.js +21 -5
- package/dist/src/channel.js +59 -5
- package/dist/src/cron-command.d.ts +15 -0
- package/dist/src/cron-command.js +49 -0
- package/dist/src/cron-query-handler.d.ts +7 -0
- package/dist/src/cron-query-handler.js +188 -0
- package/dist/src/cspl/call_api.d.ts +1 -1
- package/dist/src/cspl/call_api.js +2 -2
- package/dist/src/cspl/config.js +30 -10
- package/dist/src/cspl/constants.d.ts +3 -0
- package/dist/src/cspl/constants.js +5 -0
- package/dist/src/cspl/sentinel_hook.js +26 -7
- package/dist/src/cspl/utils.d.ts +9 -3
- package/dist/src/cspl/utils.js +17 -11
- package/dist/src/formatter.d.ts +14 -1
- package/dist/src/formatter.js +31 -8
- package/dist/src/monitor.js +44 -23
- package/dist/src/parser.d.ts +8 -1
- package/dist/src/parser.js +71 -0
- package/dist/src/provider.js +25 -17
- package/dist/src/push.d.ts +11 -1
- package/dist/src/push.js +93 -2
- package/dist/src/reply-dispatcher.js +118 -14
- package/dist/src/self-evolution-handler.d.ts +1 -1
- package/dist/src/self-evolution-handler.js +13 -2
- package/dist/src/tools/agent-as-skill-tool.js +56 -4
- package/dist/src/tools/calendar-tool.js +2 -1
- package/dist/src/tools/call-device-tool.js +0 -3
- package/dist/src/tools/call-phone-tool.js +2 -1
- package/dist/src/tools/check-plugin-privilege-tool.d.ts +6 -0
- package/dist/src/tools/check-plugin-privilege-tool.js +182 -0
- package/dist/src/tools/create-alarm-tool.js +2 -1
- package/dist/src/tools/create-all-tools.js +10 -4
- package/dist/src/tools/delete-alarm-tool.js +2 -1
- package/dist/src/tools/device-tool-map.d.ts +1 -1
- package/dist/src/tools/device-tool-map.js +12 -5
- package/dist/src/tools/discover-cross-devices-tool.d.ts +2 -0
- package/dist/src/tools/discover-cross-devices-tool.js +235 -0
- package/dist/src/tools/display-a2ui-card-tool.d.ts +2 -0
- package/dist/src/tools/display-a2ui-card-tool.js +85 -0
- package/dist/src/tools/find-pc-devices-tool.js +1 -0
- package/dist/src/tools/get-collection-tool-schema.js +1 -1
- package/dist/src/tools/get-device-file-tool-schema.js +2 -3
- package/dist/src/tools/location-tool.js +2 -1
- package/dist/src/tools/modify-alarm-tool.js +2 -1
- package/dist/src/tools/modify-note-tool.js +2 -1
- package/dist/src/tools/note-tool.js +2 -1
- package/dist/src/tools/query-app-message-tool.js +4 -3
- package/dist/src/tools/query-memory-data-tool.js +4 -3
- package/dist/src/tools/query-todo-task-tool.js +4 -3
- package/dist/src/tools/save-file-to-phone-tool.js +2 -1
- package/dist/src/tools/save-media-to-gallery-tool.js +2 -1
- package/dist/src/tools/schema-tool-factory.js +1 -1
- package/dist/src/tools/search-alarm-tool.js +2 -1
- package/dist/src/tools/search-calendar-tool.js +2 -1
- package/dist/src/tools/search-contact-tool.js +2 -1
- package/dist/src/tools/search-email-tool.js +4 -3
- package/dist/src/tools/search-file-tool.js +6 -10
- package/dist/src/tools/search-message-tool.js +1 -0
- package/dist/src/tools/search-note-tool.js +2 -1
- package/dist/src/tools/search-photo-gallery-tool.js +4 -3
- package/dist/src/tools/send-cross-device-task-tool.d.ts +2 -0
- package/dist/src/tools/send-cross-device-task-tool.js +299 -0
- package/dist/src/tools/send-email-tool.js +4 -3
- package/dist/src/tools/send-file-to-user-tool.d.ts +1 -1
- package/dist/src/tools/send-file-to-user-tool.js +35 -6
- package/dist/src/tools/send-message-tool.js +1 -0
- package/dist/src/tools/session-manager.d.ts +17 -1
- package/dist/src/tools/session-manager.js +73 -0
- package/dist/src/tools/upload-file-tool.js +6 -14
- package/dist/src/tools/upload-photo-tool.js +4 -3
- package/dist/src/tools/xiaoyi-add-collection-tool.js +4 -2
- package/dist/src/tools/xiaoyi-collection-tool.js +3 -2
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +3 -2
- package/dist/src/tools/xiaoyi-gui-tool.js +6 -0
- package/dist/src/types.d.ts +25 -1
- package/dist/src/websocket.d.ts +3 -0
- package/dist/src/websocket.js +207 -15
- package/package.json +1 -1
|
@@ -1,11 +1,56 @@
|
|
|
1
1
|
import { getXYRuntime } from "./runtime.js";
|
|
2
|
-
import { sendA2AResponse, sendStatusUpdate, sendReasoningTextUpdate } from "./formatter.js";
|
|
2
|
+
import { sendA2AResponse, sendStatusUpdate, sendReasoningTextUpdate, sendCommand } from "./formatter.js";
|
|
3
3
|
import { resolveXYConfig } from "./config.js";
|
|
4
4
|
import { getCurrentTaskId, getCurrentMessageId } from "./task-manager.js";
|
|
5
|
+
import { clearRunCrossTaskSentFiles, getCurrentSessionContext } from "./tools/session-manager.js";
|
|
5
6
|
import fs from "fs/promises";
|
|
6
7
|
import path from "path";
|
|
7
8
|
import { logger } from "./utils/logger.js";
|
|
8
9
|
const TEMP_FILE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
10
|
+
const RUN_CROSS_TASK_LOG_TAG = "[RunCrossTask]";
|
|
11
|
+
function buildDistributionStatusCommand(context) {
|
|
12
|
+
return {
|
|
13
|
+
header: {
|
|
14
|
+
namespace: "DistributionInteraction",
|
|
15
|
+
name: "DistributionStatus",
|
|
16
|
+
},
|
|
17
|
+
payload: {
|
|
18
|
+
agentId: context.agentId,
|
|
19
|
+
isDistributed: true,
|
|
20
|
+
networkId: context.networkId,
|
|
21
|
+
distributionType: "softbus",
|
|
22
|
+
distributionExecutePolicy: "backgroundExecution",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function buildCrossTaskExecuteResultCommand(code, message, sentFiles = []) {
|
|
27
|
+
return {
|
|
28
|
+
header: {
|
|
29
|
+
namespace: "DistributionInteraction",
|
|
30
|
+
name: "CrossTaskExecuteResult",
|
|
31
|
+
},
|
|
32
|
+
payload: {
|
|
33
|
+
code,
|
|
34
|
+
message,
|
|
35
|
+
sentFiles,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async function sendRunCrossTaskResult(params) {
|
|
40
|
+
const { config, sessionId, taskId, messageId, context, resultCode, resultMessage } = params;
|
|
41
|
+
const sentFiles = Array.isArray(context.sentFiles) ? context.sentFiles : [];
|
|
42
|
+
const statusCommand = buildDistributionStatusCommand(context);
|
|
43
|
+
const resultCommand = buildCrossTaskExecuteResultCommand(resultCode, resultMessage, sentFiles);
|
|
44
|
+
await sendCommand({
|
|
45
|
+
config,
|
|
46
|
+
sessionId,
|
|
47
|
+
taskId,
|
|
48
|
+
messageId,
|
|
49
|
+
commands: [statusCommand, resultCommand],
|
|
50
|
+
});
|
|
51
|
+
clearRunCrossTaskSentFiles(context);
|
|
52
|
+
logger.log(`${RUN_CROSS_TASK_LOG_TAG} sent cross-task result, sessionId=${sessionId}, taskId=${taskId}, code=${resultCode}, sentFileCount=${sentFiles.length}, clearedSentFileCount=${sentFiles.length}, messageLength=${resultMessage.length}`);
|
|
53
|
+
}
|
|
9
54
|
/**
|
|
10
55
|
* 清理 /tmp/xy_channel 目录中超过 24 小时的旧文件
|
|
11
56
|
*/
|
|
@@ -71,6 +116,10 @@ export function createXYReplyDispatcher(params) {
|
|
|
71
116
|
let hasSentResponse = false;
|
|
72
117
|
let finalSent = false;
|
|
73
118
|
let accumulatedText = "";
|
|
119
|
+
const initialRunCrossTaskContext = getCurrentSessionContext()?.runCrossTaskContext;
|
|
120
|
+
const getRunCrossTaskContext = () => {
|
|
121
|
+
return getCurrentSessionContext()?.runCrossTaskContext ?? initialRunCrossTaskContext;
|
|
122
|
+
};
|
|
74
123
|
/**
|
|
75
124
|
* Start the status update interval
|
|
76
125
|
*/
|
|
@@ -123,18 +172,23 @@ export function createXYReplyDispatcher(params) {
|
|
|
123
172
|
scopedLog().log(`[DELIVER SKIP] Empty text, skipping`);
|
|
124
173
|
return;
|
|
125
174
|
}
|
|
175
|
+
// 🔑 如果 onPartialReply 已经流式发送过文本,deliver 不再重复发送
|
|
176
|
+
if (hasSentResponse) {
|
|
177
|
+
scopedLog().log(`[DELIVER SKIP] Already sent via onPartialReply`);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
126
180
|
accumulatedText += text;
|
|
127
181
|
hasSentResponse = true;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
await sendReasoningTextUpdate({
|
|
182
|
+
// 🔑 使用动态taskId发送A2A响应(流式append)
|
|
183
|
+
await sendA2AResponse({
|
|
131
184
|
config,
|
|
132
185
|
sessionId,
|
|
133
186
|
taskId: currentTaskId,
|
|
134
187
|
messageId: currentMessageId,
|
|
135
188
|
text,
|
|
189
|
+
append: true,
|
|
190
|
+
final: false,
|
|
136
191
|
});
|
|
137
|
-
scopedLog().log(`[DELIVER] Sent deliver text as reasoningText update`);
|
|
138
192
|
}
|
|
139
193
|
catch (deliverError) {
|
|
140
194
|
scopedLog().error(`Failed to deliver message:`, deliverError);
|
|
@@ -180,6 +234,18 @@ export function createXYReplyDispatcher(params) {
|
|
|
180
234
|
if (hasSentResponse && !finalSent) {
|
|
181
235
|
scopedLog().log(`[ON-IDLE] Sending accumulated text, length=${accumulatedText.length}`);
|
|
182
236
|
try {
|
|
237
|
+
const runCrossTaskContext = getRunCrossTaskContext();
|
|
238
|
+
if (runCrossTaskContext) {
|
|
239
|
+
await sendRunCrossTaskResult({
|
|
240
|
+
config,
|
|
241
|
+
sessionId,
|
|
242
|
+
taskId: currentTaskId,
|
|
243
|
+
messageId: currentMessageId,
|
|
244
|
+
context: runCrossTaskContext,
|
|
245
|
+
resultCode: "0",
|
|
246
|
+
resultMessage: accumulatedText,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
183
249
|
// 🔑 使用动态taskId发送完成状态
|
|
184
250
|
await sendStatusUpdate({
|
|
185
251
|
config,
|
|
@@ -190,18 +256,18 @@ export function createXYReplyDispatcher(params) {
|
|
|
190
256
|
state: "completed",
|
|
191
257
|
});
|
|
192
258
|
scopedLog().log(`[ON-IDLE] Sent completion status update`);
|
|
193
|
-
// 🔑 使用动态taskId
|
|
259
|
+
// 🔑 使用动态taskId发送最终响应(空字符串表示流结束)
|
|
194
260
|
await sendA2AResponse({
|
|
195
261
|
config,
|
|
196
262
|
sessionId,
|
|
197
263
|
taskId: currentTaskId,
|
|
198
264
|
messageId: currentMessageId,
|
|
199
|
-
text:
|
|
265
|
+
text: "",
|
|
200
266
|
append: false,
|
|
201
267
|
final: true,
|
|
202
268
|
});
|
|
203
269
|
finalSent = true;
|
|
204
|
-
scopedLog().log(`[ON-IDLE] Sent final response`);
|
|
270
|
+
scopedLog().log(`[ON-IDLE] Sent final response (empty, stream end)`);
|
|
205
271
|
}
|
|
206
272
|
catch (err) {
|
|
207
273
|
scopedLog().error(`[ON-IDLE] Failed to send final response:`, err);
|
|
@@ -211,6 +277,18 @@ export function createXYReplyDispatcher(params) {
|
|
|
211
277
|
// 正常失败场景(非steered)
|
|
212
278
|
scopedLog().log(`[ON-IDLE] Skipping final message: hasSentResponse=${hasSentResponse}, finalSent=${finalSent}`);
|
|
213
279
|
try {
|
|
280
|
+
const runCrossTaskContext = getRunCrossTaskContext();
|
|
281
|
+
if (runCrossTaskContext) {
|
|
282
|
+
await sendRunCrossTaskResult({
|
|
283
|
+
config,
|
|
284
|
+
sessionId,
|
|
285
|
+
taskId: currentTaskId,
|
|
286
|
+
messageId: currentMessageId,
|
|
287
|
+
context: runCrossTaskContext,
|
|
288
|
+
resultCode: "1",
|
|
289
|
+
resultMessage: "任务执行异常,请重试",
|
|
290
|
+
});
|
|
291
|
+
}
|
|
214
292
|
await sendStatusUpdate({
|
|
215
293
|
config,
|
|
216
294
|
sessionId,
|
|
@@ -249,6 +327,7 @@ export function createXYReplyDispatcher(params) {
|
|
|
249
327
|
dispatcher,
|
|
250
328
|
replyOptions: {
|
|
251
329
|
...replyOptions,
|
|
330
|
+
suppressToolErrorWarnings: true,
|
|
252
331
|
onModelSelected: prefixContext.onModelSelected,
|
|
253
332
|
onToolStart: async ({ name, phase }) => {
|
|
254
333
|
// 🔑 steered dispatch不发送tool状态(让主dispatcher处理)
|
|
@@ -315,10 +394,30 @@ export function createXYReplyDispatcher(params) {
|
|
|
315
394
|
if (steerState.steered) {
|
|
316
395
|
return;
|
|
317
396
|
}
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
//
|
|
397
|
+
const currentTaskId = getActiveTaskId();
|
|
398
|
+
const currentMessageId = getActiveMessageId();
|
|
399
|
+
let text = payload.text ?? "";
|
|
400
|
+
// Strip "Reasoning:" prefix that some reasoning models add to their thinking output
|
|
401
|
+
const lines = text.split(/\r?\n/);
|
|
402
|
+
if (lines[0]?.trim() === "Reasoning:") {
|
|
403
|
+
text = lines.slice(1).join("\n").trim();
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
if (text.length > 0) {
|
|
407
|
+
// 🔑 将模型真实的thinking/reasoning内容通过reasoningText转发
|
|
408
|
+
await sendReasoningTextUpdate({
|
|
409
|
+
config,
|
|
410
|
+
sessionId,
|
|
411
|
+
taskId: currentTaskId,
|
|
412
|
+
messageId: currentMessageId,
|
|
413
|
+
text,
|
|
414
|
+
append: false,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
catch (err) {
|
|
419
|
+
scopedLog().error(`[REASONING-STREAM] Failed to send reasoning text:`, err);
|
|
420
|
+
}
|
|
322
421
|
},
|
|
323
422
|
onPartialReply: async (payload) => {
|
|
324
423
|
// 🔑 steered dispatch不发送partial reply(让主dispatcher处理)
|
|
@@ -330,18 +429,23 @@ export function createXYReplyDispatcher(params) {
|
|
|
330
429
|
const text = payload.text ?? "";
|
|
331
430
|
try {
|
|
332
431
|
if (text.length > 0) {
|
|
333
|
-
|
|
432
|
+
accumulatedText += text;
|
|
433
|
+
hasSentResponse = true;
|
|
434
|
+
// 🔑 流式文本通过 A2A text 通道发送(而非 reasoningText)
|
|
435
|
+
await sendA2AResponse({
|
|
334
436
|
config,
|
|
335
437
|
sessionId,
|
|
336
438
|
taskId: currentTaskId,
|
|
337
439
|
messageId: currentMessageId,
|
|
338
440
|
text,
|
|
339
441
|
append: false,
|
|
442
|
+
final: false,
|
|
443
|
+
log: false,
|
|
340
444
|
});
|
|
341
445
|
}
|
|
342
446
|
}
|
|
343
447
|
catch (err) {
|
|
344
|
-
scopedLog().error(`[PARTIAL
|
|
448
|
+
scopedLog().error(`[PARTIAL-REPLY] Failed to send partial reply:`, err);
|
|
345
449
|
}
|
|
346
450
|
},
|
|
347
451
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { XYWebSocketManager } from "./websocket.js";
|
|
2
|
-
export declare function handleSelfEvolutionEvent(context: any,
|
|
2
|
+
export declare function handleSelfEvolutionEvent(context: any, cfg: any): Promise<void>;
|
|
3
3
|
/**
|
|
4
4
|
* 读取 .xiaoyiruntime 中的 selfEvolutionState 并直接通过 wsManager 下发指令回复设备
|
|
5
5
|
* 参考trigger实现:直接使用当前已连接的 wsManager 发送消息,避免 getXYWebSocketManager 返回未连接实例
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from "fs";
|
|
2
2
|
import { v4 as uuidv4 } from "uuid";
|
|
3
|
+
import { resolveXYConfig } from "./config.js";
|
|
4
|
+
import { sendA2AResponse } from "./formatter.js";
|
|
3
5
|
import { logger } from "./utils/logger.js";
|
|
4
6
|
const XIAOYIRUNTIME_PATH = "/home/sandbox/.openclaw/.xiaoyiruntime";
|
|
5
|
-
export function handleSelfEvolutionEvent(context,
|
|
7
|
+
export async function handleSelfEvolutionEvent(context, cfg) {
|
|
6
8
|
try {
|
|
7
9
|
const state = context.event?.payload?.selfEvolutionState;
|
|
8
10
|
if (typeof state !== "string") {
|
|
9
11
|
logger.error("[SELF_EVOLUTION] invalid payload: missing selfEvolutionState");
|
|
10
12
|
return;
|
|
11
13
|
}
|
|
14
|
+
const sessionId = context.sessionId ?? "";
|
|
15
|
+
const taskId = context.taskId ?? sessionId;
|
|
16
|
+
const messageId = context.messageId ?? uuidv4();
|
|
17
|
+
const config = resolveXYConfig(cfg);
|
|
12
18
|
logger.log(`[SELF_EVOLUTION] received state: ${state}`);
|
|
13
19
|
let content;
|
|
14
20
|
try {
|
|
@@ -19,6 +25,8 @@ export function handleSelfEvolutionEvent(context, runtime) {
|
|
|
19
25
|
logger.log(`[SELF_EVOLUTION] ${XIAOYIRUNTIME_PATH} not found, creating new file`);
|
|
20
26
|
writeFileSync(XIAOYIRUNTIME_PATH, `selfEvolutionState=${state}\n`, "utf-8");
|
|
21
27
|
logger.log(`[SELF_EVOLUTION] wrote selfEvolutionState=${state}`);
|
|
28
|
+
await sendA2AResponse({ config, sessionId, taskId, messageId, text: "", append: false, final: true });
|
|
29
|
+
logger.log(`[SELF_EVOLUTION] Sent final response (empty, stream end)`);
|
|
22
30
|
return;
|
|
23
31
|
}
|
|
24
32
|
const lines = content.split("\n");
|
|
@@ -40,6 +48,9 @@ export function handleSelfEvolutionEvent(context, runtime) {
|
|
|
40
48
|
writeFileSync(XIAOYIRUNTIME_PATH, updated.join("\n"), "utf-8");
|
|
41
49
|
}
|
|
42
50
|
logger.log(`[SELF_EVOLUTION] updated selfEvolutionState=${state} in ${XIAOYIRUNTIME_PATH}`);
|
|
51
|
+
// Reply with final empty response to acknowledge the state update
|
|
52
|
+
await sendA2AResponse({ config, sessionId, taskId, messageId, text: "", append: false, final: true });
|
|
53
|
+
logger.log(`[SELF_EVOLUTION] Sent final response (empty, stream end)`);
|
|
43
54
|
}
|
|
44
55
|
catch (err) {
|
|
45
56
|
logger.error("[SELF_EVOLUTION] failed to handle event:", err);
|
|
@@ -108,7 +119,7 @@ export async function handleSelfEvolutionStateGetEvent(context, cfg, runtime, ws
|
|
|
108
119
|
kind: "artifact-update",
|
|
109
120
|
append: false,
|
|
110
121
|
lastChunk: true,
|
|
111
|
-
final:
|
|
122
|
+
final: true,
|
|
112
123
|
artifact: {
|
|
113
124
|
artifactId: uuidv4(),
|
|
114
125
|
parts: [{
|
|
@@ -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)
|
|
@@ -125,6 +176,7 @@ export function createAgentAsSkillTool(ctx) {
|
|
|
125
176
|
taskId: currentTaskId,
|
|
126
177
|
messageId,
|
|
127
178
|
command,
|
|
179
|
+
toolCallId,
|
|
128
180
|
}).then(() => {
|
|
129
181
|
logger.log("[AGENT-AS-SKILL] Command sent successfully", { agentId: params.agentId });
|
|
130
182
|
}).catch((error) => {
|
|
@@ -106,7 +106,7 @@ export function createCalendarTool(ctx) {
|
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
109
|
-
reject(new Error(`创建日程失败: ${event.
|
|
109
|
+
reject(new Error(`创建日程失败: ${JSON.stringify(event.outputs)}`));
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
};
|
|
@@ -120,6 +120,7 @@ export function createCalendarTool(ctx) {
|
|
|
120
120
|
taskId: currentTaskId,
|
|
121
121
|
messageId,
|
|
122
122
|
command,
|
|
123
|
+
toolCallId,
|
|
123
124
|
})
|
|
124
125
|
.then(() => {
|
|
125
126
|
})
|
|
@@ -22,7 +22,6 @@ import { createUploadFileTool } from "./upload-file-tool.js";
|
|
|
22
22
|
import { createSaveFileToPhoneTool } from "./save-file-to-phone-tool.js";
|
|
23
23
|
import { createSendEmailTool } from "./send-email-tool.js";
|
|
24
24
|
import { createSearchEmailTool } from "./search-email-tool.js";
|
|
25
|
-
import { createFindPcDevicesTool } from "./find-pc-devices-tool.js";
|
|
26
25
|
import { sendStatusUpdate } from "../formatter.js";
|
|
27
26
|
import { getCurrentTaskId, getCurrentMessageId } from "../task-manager.js";
|
|
28
27
|
/**
|
|
@@ -55,7 +54,6 @@ export function createCallDeviceTool(ctx) {
|
|
|
55
54
|
const searchFileTool = createSearchFileTool(ctx);
|
|
56
55
|
const saveFileToPhoneTool = createSaveFileToPhoneTool(ctx);
|
|
57
56
|
const searchEmailTool = createSearchEmailTool(ctx);
|
|
58
|
-
const findPcDevicesTool = createFindPcDevicesTool(ctx);
|
|
59
57
|
/**
|
|
60
58
|
* 端工具注册表 —— 按 name 索引所有可通过 call_device_tool 调度的工具。
|
|
61
59
|
*/
|
|
@@ -84,7 +82,6 @@ export function createCallDeviceTool(ctx) {
|
|
|
84
82
|
[saveFileToPhoneTool.name, saveFileToPhoneTool],
|
|
85
83
|
[sendEmailTool.name, sendEmailTool],
|
|
86
84
|
[searchEmailTool.name, searchEmailTool],
|
|
87
|
-
[findPcDevicesTool.name, findPcDevicesTool],
|
|
88
85
|
]);
|
|
89
86
|
return {
|
|
90
87
|
name: "call_device_tool",
|
|
@@ -98,7 +98,7 @@ export function createCallPhoneTool(ctx) {
|
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
101
|
-
reject(new Error(`拨打电话失败: ${event.
|
|
101
|
+
reject(new Error(`拨打电话失败: ${JSON.stringify(event.outputs)}`));
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
};
|
|
@@ -112,6 +112,7 @@ export function createCallPhoneTool(ctx) {
|
|
|
112
112
|
taskId: currentTaskId,
|
|
113
113
|
messageId,
|
|
114
114
|
command,
|
|
115
|
+
toolCallId,
|
|
115
116
|
})
|
|
116
117
|
.then(() => {
|
|
117
118
|
})
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Check plugin privilege tool implementation
|
|
2
|
+
import { getXYWebSocketManager } from "../client.js";
|
|
3
|
+
import { sendCommand } from "../formatter.js";
|
|
4
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
5
|
+
import { logger } from "../utils/logger.js";
|
|
6
|
+
/**
|
|
7
|
+
* Mapping from intent name to required permission IDs.
|
|
8
|
+
*/
|
|
9
|
+
const INTENT_PERMISSION_MAP = {
|
|
10
|
+
GetCurrentLocation: ["ohos.permission.LOCATION", "ohos.permission.APPROXIMATELY_LOCATION"],
|
|
11
|
+
SearchCalendarEvent: ["ohos.permission.READ_WHOLE_CALENDAR"],
|
|
12
|
+
CreateCalendarEvent: ["ohos.permission.WRITE_WHOLE_CALENDAR"],
|
|
13
|
+
DeleteCalendarEvent: ["ohos.permission.WRITE_WHOLE_CALENDAR"],
|
|
14
|
+
ModifyCalendarEvent: ["ohos.permission.WRITE_WHOLE_CALENDAR"],
|
|
15
|
+
SearchNote: ["ohos.permission.READ_NOTE"],
|
|
16
|
+
CreateNote: ["ohos.permission.WRITE_NOTE"],
|
|
17
|
+
ModifyNote: ["ohos.permission.WRITE_NOTE"],
|
|
18
|
+
SearchContactLocal: ["ohos.permission.READ_CONTACTS"],
|
|
19
|
+
SearchPhotoVideo: ["ohos.permission.READ_IMAGEVIDEO"],
|
|
20
|
+
SaveMediaToGallery: ["ohos.permission.WRITE_IMAGEVIDEO"],
|
|
21
|
+
SearchFile: ["ohos.permission.FILE_ACCESS_MANAGER"],
|
|
22
|
+
SaveFileToFileManager: ["ohos.permission.FILE_SAVE_MANAGER"],
|
|
23
|
+
SearchAlarm: ["ohos.permission.READ_ALARM"],
|
|
24
|
+
CreateAlarm: ["ohos.permission.WRITE_ALARM"],
|
|
25
|
+
ModifyAlarm: ["ohos.permission.WRITE_ALARM"],
|
|
26
|
+
DeleteAlarm: ["ohos.permission.WRITE_ALARM"],
|
|
27
|
+
SearchMessage: ["ohos.permission.READ_SMS"],
|
|
28
|
+
SendShortMessage: ["ohos.permission.SEND_MESSAGES"],
|
|
29
|
+
StartCall: ["ohos.permission.PLACE_CALL"],
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* XY check plugin privilege tool - checks user authorization for device-side tools
|
|
33
|
+
* used in scheduled tasks.
|
|
34
|
+
*/
|
|
35
|
+
export function createCheckPluginPrivilegeTool(ctx) {
|
|
36
|
+
const { config, sessionId, taskId, messageId } = ctx;
|
|
37
|
+
return {
|
|
38
|
+
name: "check_plugin_privilege",
|
|
39
|
+
label: "Check Plugin Privilege",
|
|
40
|
+
description: "定时任务权限检查工具。" +
|
|
41
|
+
"【使用场景】仅在创建定时任务时使用,严禁在其他场景调用。当识别到定时任务中需要使用用户设备侧工具时,必须调用此工具进行权限检查。" +
|
|
42
|
+
"【调用前提】调用此工具前,必须确认用户定时任务中提到的工具在当前模型可使用的工具列表中存在。如果当前工具列表中不存在符合用户诉求的工具定义,则不要调用此工具,而是直接告知用户当前设备不支持该功能。" +
|
|
43
|
+
"【支持的意图名称及对应权限】" +
|
|
44
|
+
"GetCurrentLocation(获取用户位置), " +
|
|
45
|
+
"SearchCalendarEvent(搜索用户日程), " +
|
|
46
|
+
"CreateCalendarEvent(新建用户日程), " +
|
|
47
|
+
"DeleteCalendarEvent(删除用户日程), " +
|
|
48
|
+
"ModifyCalendarEvent(修改用户日程), " +
|
|
49
|
+
"SearchNote(搜索用户备忘录), " +
|
|
50
|
+
"CreateNote(新建用户备忘录), " +
|
|
51
|
+
"ModifyNote(修改用户备忘录), " +
|
|
52
|
+
"SearchContactLocal(搜索用户联系人), " +
|
|
53
|
+
"SearchPhotoVideo(搜索用户图库照片或视频), " +
|
|
54
|
+
"SaveMediaToGallery(保存图片/视频到图库), " +
|
|
55
|
+
"SearchFile(搜索用户文件管理里面的文件), " +
|
|
56
|
+
"SaveFileToFileManager(保存文件到文件管理), " +
|
|
57
|
+
"SearchAlarm(搜索闹钟), " +
|
|
58
|
+
"CreateAlarm(新建闹钟), " +
|
|
59
|
+
"ModifyAlarm(修改闹钟), " +
|
|
60
|
+
"DeleteAlarm(删除闹钟), " +
|
|
61
|
+
"SearchMessage(搜索短信), " +
|
|
62
|
+
"SendShortMessage(发送短信), " +
|
|
63
|
+
"StartCall(打电话)。" +
|
|
64
|
+
"【多次调用】如果用户的定时任务指令中涉及多个端侧工具,则依次分别调用此工具检查每个工具的权限。如果调用超时失败,最多重试一次。" +
|
|
65
|
+
"【回复约束】如果工具返回没有授权或其他报错,只需要完整描述没有授权或其他报错内容即可,不需要主动给用户提供解决方案。" +
|
|
66
|
+
"【使用约束1】只要是创建定时任务且涉及端插件的使用,则必须调用此工具检查权限" +
|
|
67
|
+
"【使用约束2】如果是定时任务执行过程中,禁止调用此工具,此工具仅在创建定时任务时按需调用",
|
|
68
|
+
parameters: {
|
|
69
|
+
type: "object",
|
|
70
|
+
properties: {
|
|
71
|
+
checkIntentName: {
|
|
72
|
+
type: "string",
|
|
73
|
+
description: "需要检查权限的意图名称,必须是支持的意图名称之一,例如:GetCurrentLocation、SearchCalendarEvent、CreateCalendarEvent 等。",
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
required: ["checkIntentName"],
|
|
77
|
+
},
|
|
78
|
+
async execute(toolCallId, params) {
|
|
79
|
+
const { checkIntentName } = params;
|
|
80
|
+
// Look up permission IDs for the given intent name
|
|
81
|
+
const permissionId = INTENT_PERMISSION_MAP[checkIntentName];
|
|
82
|
+
if (!permissionId) {
|
|
83
|
+
return {
|
|
84
|
+
content: [
|
|
85
|
+
{
|
|
86
|
+
type: "text",
|
|
87
|
+
text: `不支持的工具意图名称: ${checkIntentName}。请确认该意图名称在支持列表中。`,
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// Get WebSocket manager
|
|
93
|
+
const wsManager = getXYWebSocketManager(config);
|
|
94
|
+
// Build CheckPlugInPrivilege command
|
|
95
|
+
const command = {
|
|
96
|
+
header: {
|
|
97
|
+
namespace: "Common",
|
|
98
|
+
name: "Action",
|
|
99
|
+
},
|
|
100
|
+
payload: {
|
|
101
|
+
cardParam: {},
|
|
102
|
+
executeParam: {
|
|
103
|
+
achieveType: "INTENT",
|
|
104
|
+
actionResponse: true,
|
|
105
|
+
bundleName: "com.huawei.hmos.vassistant",
|
|
106
|
+
dimension: "",
|
|
107
|
+
executeMode: "background",
|
|
108
|
+
intentName: "CheckPlugInPrivilege",
|
|
109
|
+
intentParam: {
|
|
110
|
+
checkIntentName: "CheckPluginPrivilege",
|
|
111
|
+
permissionId,
|
|
112
|
+
},
|
|
113
|
+
needUnlock: false,
|
|
114
|
+
permissionId: [],
|
|
115
|
+
timeOut: 5,
|
|
116
|
+
},
|
|
117
|
+
needUploadResult: true,
|
|
118
|
+
pageControlRelated: false,
|
|
119
|
+
responses: [
|
|
120
|
+
{
|
|
121
|
+
displayText: "",
|
|
122
|
+
resultCode: "",
|
|
123
|
+
ttsText: "",
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
// Send command and wait for response (60 second timeout)
|
|
129
|
+
return new Promise((resolve, reject) => {
|
|
130
|
+
const timeout = setTimeout(() => {
|
|
131
|
+
wsManager.off("data-event", handler);
|
|
132
|
+
logger.error("超时: 检查插件权限超时(60秒)", { toolCallId, checkIntentName });
|
|
133
|
+
reject(new Error(`检查插件权限超时(60秒), intentName: ${checkIntentName}`));
|
|
134
|
+
}, 60000);
|
|
135
|
+
// Listen for data events from WebSocket
|
|
136
|
+
const handler = (event) => {
|
|
137
|
+
if (event.intentName === "CheckPlugInPrivilege") {
|
|
138
|
+
clearTimeout(timeout);
|
|
139
|
+
wsManager.off("data-event", handler);
|
|
140
|
+
if (event.status === "success" && event.outputs) {
|
|
141
|
+
resolve({
|
|
142
|
+
content: [
|
|
143
|
+
{
|
|
144
|
+
type: "text",
|
|
145
|
+
text: JSON.stringify(event.outputs),
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
resolve({
|
|
152
|
+
content: [
|
|
153
|
+
{
|
|
154
|
+
type: "text",
|
|
155
|
+
text: JSON.stringify(event.outputs),
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
// Register event handler
|
|
163
|
+
wsManager.on("data-event", handler);
|
|
164
|
+
// Send the command
|
|
165
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
166
|
+
sendCommand({
|
|
167
|
+
config,
|
|
168
|
+
sessionId,
|
|
169
|
+
taskId: currentTaskId,
|
|
170
|
+
messageId,
|
|
171
|
+
command,
|
|
172
|
+
toolCallId,
|
|
173
|
+
}).then(() => {
|
|
174
|
+
}).catch((error) => {
|
|
175
|
+
clearTimeout(timeout);
|
|
176
|
+
wsManager.off("data-event", handler);
|
|
177
|
+
reject(error);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
@@ -244,7 +244,7 @@ b. 使用该工具之前需获取当前真实时间
|
|
|
244
244
|
});
|
|
245
245
|
}
|
|
246
246
|
else {
|
|
247
|
-
reject(new Error(`创建闹钟失败: ${event.
|
|
247
|
+
reject(new Error(`创建闹钟失败: ${JSON.stringify(event.outputs)}`));
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
};
|
|
@@ -258,6 +258,7 @@ b. 使用该工具之前需获取当前真实时间
|
|
|
258
258
|
taskId: currentTaskId,
|
|
259
259
|
messageId,
|
|
260
260
|
command,
|
|
261
|
+
toolCallId,
|
|
261
262
|
})
|
|
262
263
|
.then(() => {
|
|
263
264
|
})
|