@ynhcj/xiaoyi-channel 0.0.154-beta → 0.0.154-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/src/bot.js +13 -5
- package/dist/src/cron-command.d.ts +4 -5
- package/dist/src/cron-command.js +19 -34
- 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/file-upload.d.ts +5 -0
- package/dist/src/file-upload.js +101 -0
- package/dist/src/formatter.d.ts +32 -0
- package/dist/src/formatter.js +62 -6
- package/dist/src/monitor.js +44 -23
- package/dist/src/parser.d.ts +6 -0
- package/dist/src/parser.js +47 -1
- 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 +51 -19
- 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 +55 -4
- package/dist/src/tools/calendar-tool.js +1 -1
- package/dist/src/tools/call-device-tool.js +0 -3
- package/dist/src/tools/call-phone-tool.js +1 -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 +1 -1
- package/dist/src/tools/create-all-tools.js +8 -4
- package/dist/src/tools/delete-alarm-tool.js +1 -1
- package/dist/src/tools/device-tool-map.js +1 -0
- package/dist/src/tools/discover-cross-devices-tool.js +1 -1
- 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/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 +1 -1
- package/dist/src/tools/modify-alarm-tool.js +1 -1
- package/dist/src/tools/modify-note-tool.js +1 -1
- package/dist/src/tools/note-tool.js +1 -1
- package/dist/src/tools/query-app-message-tool.js +1 -1
- package/dist/src/tools/query-memory-data-tool.js +1 -1
- package/dist/src/tools/query-todo-task-tool.js +1 -1
- package/dist/src/tools/save-file-to-phone-tool.js +1 -1
- package/dist/src/tools/save-media-to-gallery-tool.js +1 -1
- package/dist/src/tools/schema-tool-factory.js +1 -1
- package/dist/src/tools/search-alarm-tool.js +1 -1
- package/dist/src/tools/search-calendar-tool.js +1 -1
- package/dist/src/tools/search-contact-tool.js +1 -1
- package/dist/src/tools/search-email-tool.js +1 -1
- package/dist/src/tools/search-file-tool.js +5 -10
- package/dist/src/tools/search-note-tool.js +1 -1
- package/dist/src/tools/search-photo-gallery-tool.js +1 -1
- package/dist/src/tools/send-cross-device-task-tool.js +18 -22
- package/dist/src/tools/send-email-tool.js +1 -1
- 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-html-card-tool.d.ts +7 -0
- package/dist/src/tools/send-html-card-tool.js +113 -0
- package/dist/src/tools/session-manager.d.ts +6 -2
- package/dist/src/tools/session-manager.js +42 -7
- package/dist/src/tools/upload-file-tool.d.ts +1 -1
- package/dist/src/tools/upload-file-tool.js +3 -17
- package/dist/src/tools/upload-photo-tool.js +1 -1
- package/dist/src/tools/xiaoyi-add-collection-tool.js +3 -2
- package/dist/src/tools/xiaoyi-collection-tool.js +2 -2
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +2 -2
- package/dist/src/tools/xiaoyi-gui-tool.js +5 -0
- package/dist/src/types.d.ts +10 -3
- package/dist/src/websocket.js +44 -5
- package/package.json +1 -2
package/dist/src/push.js
CHANGED
|
@@ -8,11 +8,24 @@ import { logger } from "./utils/logger.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export class XYPushService {
|
|
10
10
|
config;
|
|
11
|
-
|
|
11
|
+
PROD_PUSH_URL = "https://hag.cloud.huawei.com/open-ability-agent/v1/agent-webhook";
|
|
12
|
+
TEST_PUSH_URL = "https://lfhagcp.hwcloudtest.cn:58447/open-ability-agent/v1/agent-webhook";
|
|
12
13
|
REQUEST_FROM = "openclaw";
|
|
13
14
|
constructor(config) {
|
|
14
15
|
this.config = config;
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolve push URL: config.pushUrl > inferred from fileUploadUrl > production default.
|
|
19
|
+
*/
|
|
20
|
+
resolvePushUrl() {
|
|
21
|
+
if (this.config.pushUrl) {
|
|
22
|
+
return this.config.pushUrl;
|
|
23
|
+
}
|
|
24
|
+
if (this.config.fileUploadUrl?.includes("lfhagmirror")) {
|
|
25
|
+
return this.TEST_PUSH_URL;
|
|
26
|
+
}
|
|
27
|
+
return this.PROD_PUSH_URL;
|
|
28
|
+
}
|
|
16
29
|
/**
|
|
17
30
|
* Generate a random trace ID for request tracking.
|
|
18
31
|
*/
|
|
@@ -30,7 +43,7 @@ export class XYPushService {
|
|
|
30
43
|
* @param pushId - Push ID to use (required)
|
|
31
44
|
*/
|
|
32
45
|
async sendPush(content, title, data, sessionId, pushDataId, pushId) {
|
|
33
|
-
const pushUrl = this.
|
|
46
|
+
const pushUrl = this.resolvePushUrl();
|
|
34
47
|
const traceId = this.generateTraceId();
|
|
35
48
|
// Use provided pushId or fall back to config pushId
|
|
36
49
|
const actualPushId = pushId || this.config.pushId;
|
|
@@ -114,6 +127,84 @@ export class XYPushService {
|
|
|
114
127
|
throw error;
|
|
115
128
|
}
|
|
116
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Send a push message with command directives embedded directly.
|
|
132
|
+
* Used for cron-triggered commands where pushText is empty and pushType=101.
|
|
133
|
+
*/
|
|
134
|
+
async sendPushWithDirectives(pushId, sessionId, directives) {
|
|
135
|
+
const pushUrl = this.resolvePushUrl();
|
|
136
|
+
const traceId = this.generateTraceId();
|
|
137
|
+
logger.log(`[PUSH] Preparing to send push with directives, pushId: ${pushId.substring(0, 20)}...`);
|
|
138
|
+
const requestBody = {
|
|
139
|
+
jsonrpc: "2.0",
|
|
140
|
+
id: randomUUID(),
|
|
141
|
+
result: {
|
|
142
|
+
id: randomUUID(),
|
|
143
|
+
apiId: this.config.apiId,
|
|
144
|
+
pushId,
|
|
145
|
+
pushText: "",
|
|
146
|
+
pushType: 101,
|
|
147
|
+
kind: "task",
|
|
148
|
+
sessionId,
|
|
149
|
+
artifacts: [
|
|
150
|
+
{
|
|
151
|
+
artifactId: randomUUID(),
|
|
152
|
+
parts: [
|
|
153
|
+
{
|
|
154
|
+
kind: "data",
|
|
155
|
+
data: { directives },
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
try {
|
|
163
|
+
const response = await fetch(pushUrl, {
|
|
164
|
+
method: "POST",
|
|
165
|
+
headers: {
|
|
166
|
+
"Content-Type": "application/json",
|
|
167
|
+
"Accept": "application/json",
|
|
168
|
+
"x-hag-trace-id": traceId,
|
|
169
|
+
"x-uid": this.config.uid,
|
|
170
|
+
"x-api-key": this.config.apiKey,
|
|
171
|
+
"x-request-from": this.REQUEST_FROM,
|
|
172
|
+
},
|
|
173
|
+
body: JSON.stringify(requestBody),
|
|
174
|
+
});
|
|
175
|
+
logger.log(`[PUSH] Response received, HTTP Status: ${response.status} ${response.statusText}`);
|
|
176
|
+
if (!response.ok) {
|
|
177
|
+
const errorText = await response.text();
|
|
178
|
+
logger.error(`[PUSH] Push request failed, HTTP Status: ${response.status}`);
|
|
179
|
+
throw new Error(`Push failed: HTTP ${response.status} - ${errorText}`);
|
|
180
|
+
}
|
|
181
|
+
let result;
|
|
182
|
+
try {
|
|
183
|
+
const responseText = await response.text();
|
|
184
|
+
if (!responseText || responseText.trim() === '') {
|
|
185
|
+
logger.error(`[PUSH] Received empty response body`);
|
|
186
|
+
result = {};
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
result = JSON.parse(responseText);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch (parseError) {
|
|
193
|
+
logger.error(`[PUSH] Failed to parse JSON response: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
194
|
+
throw new Error(`Invalid JSON response from push service: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
195
|
+
}
|
|
196
|
+
logger.log(`[PUSH] Push message sent successfully, Trace ID: ${traceId}`);
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
if (error instanceof Error) {
|
|
200
|
+
logger.error(`[PUSH] Failed to send push message: ${error.name} - ${error.message}`);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
logger.error(`[PUSH] Failed to send push message:`, error);
|
|
204
|
+
}
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
117
208
|
/**
|
|
118
209
|
* Send a push message with file attachments.
|
|
119
210
|
*/
|
|
@@ -2,7 +2,7 @@ import { getXYRuntime } from "./runtime.js";
|
|
|
2
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 { getCurrentSessionContext } from "./tools/session-manager.js";
|
|
5
|
+
import { clearRunCrossTaskSentFiles, getCurrentSessionContext } from "./tools/session-manager.js";
|
|
6
6
|
import fs from "fs/promises";
|
|
7
7
|
import path from "path";
|
|
8
8
|
import { logger } from "./utils/logger.js";
|
|
@@ -23,7 +23,7 @@ function buildDistributionStatusCommand(context) {
|
|
|
23
23
|
},
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
function buildCrossTaskExecuteResultCommand(code, message,
|
|
26
|
+
function buildCrossTaskExecuteResultCommand(code, message, sentFiles = []) {
|
|
27
27
|
return {
|
|
28
28
|
header: {
|
|
29
29
|
namespace: "DistributionInteraction",
|
|
@@ -32,15 +32,15 @@ function buildCrossTaskExecuteResultCommand(code, message, fileUrls = []) {
|
|
|
32
32
|
payload: {
|
|
33
33
|
code,
|
|
34
34
|
message,
|
|
35
|
-
|
|
35
|
+
sentFiles,
|
|
36
36
|
},
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
async function sendRunCrossTaskResult(params) {
|
|
40
40
|
const { config, sessionId, taskId, messageId, context, resultCode, resultMessage } = params;
|
|
41
|
-
const
|
|
41
|
+
const sentFiles = Array.isArray(context.sentFiles) ? context.sentFiles : [];
|
|
42
42
|
const statusCommand = buildDistributionStatusCommand(context);
|
|
43
|
-
const resultCommand = buildCrossTaskExecuteResultCommand(resultCode, resultMessage,
|
|
43
|
+
const resultCommand = buildCrossTaskExecuteResultCommand(resultCode, resultMessage, sentFiles);
|
|
44
44
|
await sendCommand({
|
|
45
45
|
config,
|
|
46
46
|
sessionId,
|
|
@@ -48,7 +48,8 @@ async function sendRunCrossTaskResult(params) {
|
|
|
48
48
|
messageId,
|
|
49
49
|
commands: [statusCommand, resultCommand],
|
|
50
50
|
});
|
|
51
|
-
|
|
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}`);
|
|
52
53
|
}
|
|
53
54
|
/**
|
|
54
55
|
* 清理 /tmp/xy_channel 目录中超过 24 小时的旧文件
|
|
@@ -171,18 +172,23 @@ export function createXYReplyDispatcher(params) {
|
|
|
171
172
|
scopedLog().log(`[DELIVER SKIP] Empty text, skipping`);
|
|
172
173
|
return;
|
|
173
174
|
}
|
|
175
|
+
// 🔑 如果 onPartialReply 已经流式发送过文本,deliver 不再重复发送
|
|
176
|
+
if (hasSentResponse) {
|
|
177
|
+
scopedLog().log(`[DELIVER SKIP] Already sent via onPartialReply`);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
174
180
|
accumulatedText += text;
|
|
175
181
|
hasSentResponse = true;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
await sendReasoningTextUpdate({
|
|
182
|
+
// 🔑 使用动态taskId发送A2A响应(流式append)
|
|
183
|
+
await sendA2AResponse({
|
|
179
184
|
config,
|
|
180
185
|
sessionId,
|
|
181
186
|
taskId: currentTaskId,
|
|
182
187
|
messageId: currentMessageId,
|
|
183
188
|
text,
|
|
189
|
+
append: true,
|
|
190
|
+
final: false,
|
|
184
191
|
});
|
|
185
|
-
scopedLog().log(`[DELIVER] Sent deliver text as reasoningText update`);
|
|
186
192
|
}
|
|
187
193
|
catch (deliverError) {
|
|
188
194
|
scopedLog().error(`Failed to deliver message:`, deliverError);
|
|
@@ -250,18 +256,18 @@ export function createXYReplyDispatcher(params) {
|
|
|
250
256
|
state: "completed",
|
|
251
257
|
});
|
|
252
258
|
scopedLog().log(`[ON-IDLE] Sent completion status update`);
|
|
253
|
-
// 🔑 使用动态taskId
|
|
259
|
+
// 🔑 使用动态taskId发送最终响应(空字符串表示流结束)
|
|
254
260
|
await sendA2AResponse({
|
|
255
261
|
config,
|
|
256
262
|
sessionId,
|
|
257
263
|
taskId: currentTaskId,
|
|
258
264
|
messageId: currentMessageId,
|
|
259
|
-
text:
|
|
265
|
+
text: "",
|
|
260
266
|
append: false,
|
|
261
267
|
final: true,
|
|
262
268
|
});
|
|
263
269
|
finalSent = true;
|
|
264
|
-
scopedLog().log(`[ON-IDLE] Sent final response`);
|
|
270
|
+
scopedLog().log(`[ON-IDLE] Sent final response (empty, stream end)`);
|
|
265
271
|
}
|
|
266
272
|
catch (err) {
|
|
267
273
|
scopedLog().error(`[ON-IDLE] Failed to send final response:`, err);
|
|
@@ -321,6 +327,7 @@ export function createXYReplyDispatcher(params) {
|
|
|
321
327
|
dispatcher,
|
|
322
328
|
replyOptions: {
|
|
323
329
|
...replyOptions,
|
|
330
|
+
suppressToolErrorWarnings: true,
|
|
324
331
|
onModelSelected: prefixContext.onModelSelected,
|
|
325
332
|
onToolStart: async ({ name, phase }) => {
|
|
326
333
|
// 🔑 steered dispatch不发送tool状态(让主dispatcher处理)
|
|
@@ -387,10 +394,30 @@ export function createXYReplyDispatcher(params) {
|
|
|
387
394
|
if (steerState.steered) {
|
|
388
395
|
return;
|
|
389
396
|
}
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
//
|
|
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
|
+
}
|
|
394
421
|
},
|
|
395
422
|
onPartialReply: async (payload) => {
|
|
396
423
|
// 🔑 steered dispatch不发送partial reply(让主dispatcher处理)
|
|
@@ -402,18 +429,23 @@ export function createXYReplyDispatcher(params) {
|
|
|
402
429
|
const text = payload.text ?? "";
|
|
403
430
|
try {
|
|
404
431
|
if (text.length > 0) {
|
|
405
|
-
|
|
432
|
+
accumulatedText += text;
|
|
433
|
+
hasSentResponse = true;
|
|
434
|
+
// 🔑 流式文本通过 A2A text 通道发送(而非 reasoningText)
|
|
435
|
+
await sendA2AResponse({
|
|
406
436
|
config,
|
|
407
437
|
sessionId,
|
|
408
438
|
taskId: currentTaskId,
|
|
409
439
|
messageId: currentMessageId,
|
|
410
440
|
text,
|
|
411
441
|
append: false,
|
|
442
|
+
final: false,
|
|
443
|
+
log: false,
|
|
412
444
|
});
|
|
413
445
|
}
|
|
414
446
|
}
|
|
415
447
|
catch (err) {
|
|
416
|
-
scopedLog().error(`[PARTIAL
|
|
448
|
+
scopedLog().error(`[PARTIAL-REPLY] Failed to send partial reply:`, err);
|
|
417
449
|
}
|
|
418
450
|
},
|
|
419
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)
|
|
@@ -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",
|