@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.
Files changed (76) hide show
  1. package/dist/src/bot.js +13 -5
  2. package/dist/src/cron-command.d.ts +4 -5
  3. package/dist/src/cron-command.js +19 -34
  4. package/dist/src/cron-query-handler.d.ts +7 -0
  5. package/dist/src/cron-query-handler.js +188 -0
  6. package/dist/src/cspl/call_api.d.ts +1 -1
  7. package/dist/src/cspl/call_api.js +2 -2
  8. package/dist/src/cspl/config.js +30 -10
  9. package/dist/src/cspl/constants.d.ts +3 -0
  10. package/dist/src/cspl/constants.js +5 -0
  11. package/dist/src/cspl/sentinel_hook.js +26 -7
  12. package/dist/src/cspl/utils.d.ts +9 -3
  13. package/dist/src/cspl/utils.js +17 -11
  14. package/dist/src/file-upload.d.ts +5 -0
  15. package/dist/src/file-upload.js +101 -0
  16. package/dist/src/formatter.d.ts +32 -0
  17. package/dist/src/formatter.js +62 -6
  18. package/dist/src/monitor.js +44 -23
  19. package/dist/src/parser.d.ts +6 -0
  20. package/dist/src/parser.js +47 -1
  21. package/dist/src/provider.js +25 -17
  22. package/dist/src/push.d.ts +11 -1
  23. package/dist/src/push.js +93 -2
  24. package/dist/src/reply-dispatcher.js +51 -19
  25. package/dist/src/self-evolution-handler.d.ts +1 -1
  26. package/dist/src/self-evolution-handler.js +13 -2
  27. package/dist/src/tools/agent-as-skill-tool.js +55 -4
  28. package/dist/src/tools/calendar-tool.js +1 -1
  29. package/dist/src/tools/call-device-tool.js +0 -3
  30. package/dist/src/tools/call-phone-tool.js +1 -1
  31. package/dist/src/tools/check-plugin-privilege-tool.d.ts +6 -0
  32. package/dist/src/tools/check-plugin-privilege-tool.js +182 -0
  33. package/dist/src/tools/create-alarm-tool.js +1 -1
  34. package/dist/src/tools/create-all-tools.js +8 -4
  35. package/dist/src/tools/delete-alarm-tool.js +1 -1
  36. package/dist/src/tools/device-tool-map.js +1 -0
  37. package/dist/src/tools/discover-cross-devices-tool.js +1 -1
  38. package/dist/src/tools/display-a2ui-card-tool.d.ts +2 -0
  39. package/dist/src/tools/display-a2ui-card-tool.js +85 -0
  40. package/dist/src/tools/get-collection-tool-schema.js +1 -1
  41. package/dist/src/tools/get-device-file-tool-schema.js +2 -3
  42. package/dist/src/tools/location-tool.js +1 -1
  43. package/dist/src/tools/modify-alarm-tool.js +1 -1
  44. package/dist/src/tools/modify-note-tool.js +1 -1
  45. package/dist/src/tools/note-tool.js +1 -1
  46. package/dist/src/tools/query-app-message-tool.js +1 -1
  47. package/dist/src/tools/query-memory-data-tool.js +1 -1
  48. package/dist/src/tools/query-todo-task-tool.js +1 -1
  49. package/dist/src/tools/save-file-to-phone-tool.js +1 -1
  50. package/dist/src/tools/save-media-to-gallery-tool.js +1 -1
  51. package/dist/src/tools/schema-tool-factory.js +1 -1
  52. package/dist/src/tools/search-alarm-tool.js +1 -1
  53. package/dist/src/tools/search-calendar-tool.js +1 -1
  54. package/dist/src/tools/search-contact-tool.js +1 -1
  55. package/dist/src/tools/search-email-tool.js +1 -1
  56. package/dist/src/tools/search-file-tool.js +5 -10
  57. package/dist/src/tools/search-note-tool.js +1 -1
  58. package/dist/src/tools/search-photo-gallery-tool.js +1 -1
  59. package/dist/src/tools/send-cross-device-task-tool.js +18 -22
  60. package/dist/src/tools/send-email-tool.js +1 -1
  61. package/dist/src/tools/send-file-to-user-tool.d.ts +1 -1
  62. package/dist/src/tools/send-file-to-user-tool.js +35 -6
  63. package/dist/src/tools/send-html-card-tool.d.ts +7 -0
  64. package/dist/src/tools/send-html-card-tool.js +113 -0
  65. package/dist/src/tools/session-manager.d.ts +6 -2
  66. package/dist/src/tools/session-manager.js +42 -7
  67. package/dist/src/tools/upload-file-tool.d.ts +1 -1
  68. package/dist/src/tools/upload-file-tool.js +3 -17
  69. package/dist/src/tools/upload-photo-tool.js +1 -1
  70. package/dist/src/tools/xiaoyi-add-collection-tool.js +3 -2
  71. package/dist/src/tools/xiaoyi-collection-tool.js +2 -2
  72. package/dist/src/tools/xiaoyi-delete-collection-tool.js +2 -2
  73. package/dist/src/tools/xiaoyi-gui-tool.js +5 -0
  74. package/dist/src/types.d.ts +10 -3
  75. package/dist/src/websocket.js +44 -5
  76. 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
- DEFAULT_PUSH_URL = "https://hag.cloud.huawei.com/open-ability-agent/v1/agent-webhook";
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.config.pushUrl || this.DEFAULT_PUSH_URL;
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, fileUrls = []) {
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
- fileUrls,
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 fileUrls = Array.isArray(context.fileUrls) ? context.fileUrls : [];
41
+ const sentFiles = Array.isArray(context.sentFiles) ? context.sentFiles : [];
42
42
  const statusCommand = buildDistributionStatusCommand(context);
43
- const resultCommand = buildCrossTaskExecuteResultCommand(resultCode, resultMessage, fileUrls);
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
- logger.log(`${RUN_CROSS_TASK_LOG_TAG} sent cross-task result, sessionId=${sessionId}, taskId=${taskId}, code=${resultCode}, fileUrlCount=${fileUrls.length}, messageLength=${resultMessage.length}`);
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
- scopedLog().log(`[DELIVER] Accumulated text, length=${accumulatedText.length}`);
177
- // 🔑 使用动态taskId发送reasoningText更新
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: accumulatedText,
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 text = payload.text ?? "";
391
- scopedLog().log(`[REASONING-STREAM] Reasoning chunk received, text.length: ${text.length}`);
392
- // Reasoning stream 目前被注释掉
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
- await sendReasoningTextUpdate({
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 REPLY] Failed to send partial reply:`, err);
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, runtime: any): void;
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, runtime) {
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: false,
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: "agent-as-skill-tool",
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
- type: "array",
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: params.filesInfo || null,
136
+ filesInfo: filesInfo || null,
86
137
  },
87
138
  };
88
139
  // Send command and wait for response (5 minute timeout)
@@ -106,7 +106,7 @@ export function createCalendarTool(ctx) {
106
106
  });
107
107
  }
108
108
  else {
109
- reject(new Error(`创建日程失败: ${event.status}`));
109
+ reject(new Error(`创建日程失败: ${JSON.stringify(event.outputs)}`));
110
110
  }
111
111
  }
112
112
  };
@@ -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.status}`));
101
+ reject(new Error(`拨打电话失败: ${JSON.stringify(event.outputs)}`));
102
102
  }
103
103
  }
104
104
  };
@@ -0,0 +1,6 @@
1
+ import type { SessionContext } from "./session-manager.js";
2
+ /**
3
+ * XY check plugin privilege tool - checks user authorization for device-side tools
4
+ * used in scheduled tasks.
5
+ */
6
+ export declare function createCheckPluginPrivilegeTool(ctx: SessionContext): any;