@ynhcj/xiaoyi-channel 0.0.157-beta → 0.0.158-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.157-beta",
3
+ "version": "0.0.158-beta",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",