@ynhcj/xiaoyi-channel 0.0.82-beta → 0.0.84-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.
package/dist/src/file-upload.js
CHANGED
|
@@ -2,8 +2,25 @@
|
|
|
2
2
|
// OSMS file upload implementation
|
|
3
3
|
import fetch from "node-fetch";
|
|
4
4
|
import fs from "fs/promises";
|
|
5
|
+
import os from "os";
|
|
5
6
|
import path from "path";
|
|
6
7
|
import { calculateSHA256 } from "./utils/crypto.js";
|
|
8
|
+
function isRemoteUrl(filePath) {
|
|
9
|
+
return filePath.startsWith("http://") || filePath.startsWith("https://");
|
|
10
|
+
}
|
|
11
|
+
async function downloadToTempFile(url) {
|
|
12
|
+
console.log(`[XY File Upload] Downloading remote file: ${url}`);
|
|
13
|
+
const response = await fetch(url);
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
throw new Error(`Failed to download remote file: HTTP ${response.status}`);
|
|
16
|
+
}
|
|
17
|
+
const buffer = await response.buffer();
|
|
18
|
+
const urlFileName = path.basename(new URL(url).pathname) || "download";
|
|
19
|
+
const tempPath = path.join(os.tmpdir(), `xy-upload-${Date.now()}-${urlFileName}`);
|
|
20
|
+
await fs.writeFile(tempPath, buffer);
|
|
21
|
+
console.log(`[XY File Upload] Downloaded to temp file: ${tempPath}`);
|
|
22
|
+
return tempPath;
|
|
23
|
+
}
|
|
7
24
|
/**
|
|
8
25
|
* Service for uploading files to XY file storage.
|
|
9
26
|
* Implements three-phase upload: prepare → upload → complete.
|
|
@@ -23,10 +40,17 @@ export class XYFileUploadService {
|
|
|
23
40
|
*/
|
|
24
41
|
async uploadFile(filePath, objectType = "TEMPORARY_MATERIAL_DOC") {
|
|
25
42
|
console.log(`[XY File Upload] Starting file upload: ${filePath}`);
|
|
43
|
+
let localFilePath = filePath;
|
|
44
|
+
let isTempFile = false;
|
|
26
45
|
try {
|
|
46
|
+
// Handle remote URLs by downloading first
|
|
47
|
+
if (isRemoteUrl(filePath)) {
|
|
48
|
+
localFilePath = await downloadToTempFile(filePath);
|
|
49
|
+
isTempFile = true;
|
|
50
|
+
}
|
|
27
51
|
// Read file
|
|
28
|
-
const fileBuffer = await fs.readFile(
|
|
29
|
-
const fileName = path.basename(
|
|
52
|
+
const fileBuffer = await fs.readFile(localFilePath);
|
|
53
|
+
const fileName = path.basename(localFilePath);
|
|
30
54
|
const fileSha256 = calculateSHA256(fileBuffer);
|
|
31
55
|
const fileSize = fileBuffer.length;
|
|
32
56
|
// Phase 1: Prepare
|
|
@@ -96,7 +120,15 @@ export class XYFileUploadService {
|
|
|
96
120
|
}
|
|
97
121
|
catch (error) {
|
|
98
122
|
console.error(`[XY File Upload] File upload failed for ${filePath}:`, error);
|
|
99
|
-
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
if (isTempFile) {
|
|
127
|
+
try {
|
|
128
|
+
await fs.unlink(localFilePath);
|
|
129
|
+
}
|
|
130
|
+
catch { }
|
|
131
|
+
}
|
|
100
132
|
}
|
|
101
133
|
}
|
|
102
134
|
/**
|
|
@@ -104,10 +136,17 @@ export class XYFileUploadService {
|
|
|
104
136
|
* Uses completeAndQuery endpoint to get the file URL directly.
|
|
105
137
|
*/
|
|
106
138
|
async uploadFileAndGetUrl(filePath, objectType = "TEMPORARY_MATERIAL_DOC") {
|
|
139
|
+
let localFilePath = filePath;
|
|
140
|
+
let isTempFile = false;
|
|
107
141
|
try {
|
|
142
|
+
// Handle remote URLs by downloading first
|
|
143
|
+
if (isRemoteUrl(filePath)) {
|
|
144
|
+
localFilePath = await downloadToTempFile(filePath);
|
|
145
|
+
isTempFile = true;
|
|
146
|
+
}
|
|
108
147
|
// Read file
|
|
109
|
-
const fileBuffer = await fs.readFile(
|
|
110
|
-
const fileName = path.basename(
|
|
148
|
+
const fileBuffer = await fs.readFile(localFilePath);
|
|
149
|
+
const fileName = path.basename(localFilePath);
|
|
111
150
|
const fileSha256 = calculateSHA256(fileBuffer);
|
|
112
151
|
const fileSize = fileBuffer.length;
|
|
113
152
|
// Phase 1: Prepare
|
|
@@ -186,6 +225,14 @@ export class XYFileUploadService {
|
|
|
186
225
|
console.error(`[XY File Upload] File upload with URL retrieval failed for ${filePath}:`, error);
|
|
187
226
|
throw error;
|
|
188
227
|
}
|
|
228
|
+
finally {
|
|
229
|
+
if (isTempFile) {
|
|
230
|
+
try {
|
|
231
|
+
await fs.unlink(localFilePath);
|
|
232
|
+
}
|
|
233
|
+
catch { }
|
|
234
|
+
}
|
|
235
|
+
}
|
|
189
236
|
}
|
|
190
237
|
/**
|
|
191
238
|
* Upload multiple files and return their file IDs.
|
package/dist/src/outbound.js
CHANGED
|
@@ -174,14 +174,9 @@ export const xyOutbound = {
|
|
|
174
174
|
}
|
|
175
175
|
// Upload file
|
|
176
176
|
const fileId = await uploadService.uploadFile(mediaUrl);
|
|
177
|
-
// Check if fileId is empty
|
|
177
|
+
// Check if fileId is empty (should not happen if uploadFile throws on failure)
|
|
178
178
|
if (!fileId) {
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
channel: "xiaoyi-channel",
|
|
182
|
-
messageId: "",
|
|
183
|
-
chatId: to,
|
|
184
|
-
};
|
|
179
|
+
throw new Error(`File upload returned empty fileId for: ${mediaUrl}`);
|
|
185
180
|
}
|
|
186
181
|
console.log(`[xyOutbound.sendMedia] File uploaded:`, {
|
|
187
182
|
fileId,
|
package/dist/src/provider.js
CHANGED
|
@@ -107,11 +107,11 @@ export const xiaoyiProvider = {
|
|
|
107
107
|
const beforeLen = sp.length;
|
|
108
108
|
// 删除 ## Tooling 与 TOOLS.md 声明之间的内容
|
|
109
109
|
sp = sp.replace(/(## Tooling)[\s\S]*?(TOOLS\.md does not control tool availability; it is user guidance for how to use external tools\.)/, "$1\n\n$2");
|
|
110
|
-
// (1) 提取
|
|
111
|
-
const skillsMatch = sp.match(
|
|
110
|
+
// (1) 提取 ## Skills (mandatory) 到 </available_skills> 作为第一部分
|
|
111
|
+
const skillsMatch = sp.match(/(## Skills \(mandatory\)[\s\S]*?<\/available_skills>)/);
|
|
112
112
|
const part1 = skillsMatch ? skillsMatch[0] : '';
|
|
113
|
-
// (2) 提取
|
|
114
|
-
const soulMatch = sp.match(/(
|
|
113
|
+
// (2) 提取 ## /home/sandbox/.openclaw/workspace/SOUL.md 到 ## /home/sandbox/.openclaw/workspace/TOOLS.md 之前的内容作为第二部分
|
|
114
|
+
const soulMatch = sp.match(/(## \/home\/sandbox\/\.openclaw\/workspace\/SOUL\.md[\s\S]*?)(?=## \/home\/sandbox\/\.openclaw\/workspace\/TOOLS\.md)/);
|
|
115
115
|
const part2 = soulMatch ? soulMatch[1].trim() : '';
|
|
116
116
|
if (part1 || part2) {
|
|
117
117
|
// 从原始位置删除已提取的部分
|
|
@@ -45,7 +45,11 @@ export const xiaoyiAddCollectionTool = {
|
|
|
45
45
|
},
|
|
46
46
|
uri: {
|
|
47
47
|
type: "string",
|
|
48
|
-
description:
|
|
48
|
+
description: `必填字段(IMAGE/FILE类型时)。图片或文件的地址链接。
|
|
49
|
+
uri具备三种严格的格式
|
|
50
|
+
(1) http或者https开头的公网链接,一般是用户通过联网搜索获取的文件地址,不允许自行编造,此类链接填入时必须确保真实
|
|
51
|
+
(2) file://开头的链接,此类链接必须来源于query_collection结果或者search_file或者search_photo_gallery的结果,不允许自行编造
|
|
52
|
+
(3) 本地路径例,如/tmp/xy_channel/xxx,此类路径是文件保存在当前openclaw运行环境的本地目录,可以直接填入,不要擅自拼接http://或者file://前缀`,
|
|
49
53
|
},
|
|
50
54
|
sourceAppBundleName: {
|
|
51
55
|
type: "string",
|
|
@@ -25,6 +25,7 @@ export const xiaoyiCollectionTool = {
|
|
|
25
25
|
a. 操作超时时间为60秒,请勿重复调用此工具
|
|
26
26
|
b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
|
|
27
27
|
c. 调用工具前需认真检查调用参数是否满足工具要求
|
|
28
|
+
d. 如果用户希望获取文件,可以使用upload_file工具完成文件上传
|
|
28
29
|
|
|
29
30
|
回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
|
|
30
31
|
`,
|