@ynhcj/xiaoyi-channel 0.0.12-next → 0.0.13-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 +10 -35
- package/dist/src/file-download.d.ts +1 -6
- package/dist/src/file-download.js +3 -12
- package/package.json +1 -1
package/dist/src/bot.js
CHANGED
|
@@ -174,10 +174,8 @@ export async function handleXYMessage(params) {
|
|
|
174
174
|
const text = extractTextFromParts(parsed.parts);
|
|
175
175
|
const fileParts = extractFileParts(parsed.parts);
|
|
176
176
|
// Download files to local disk
|
|
177
|
-
// MediaPath will be local path (faster for openclaw to read)
|
|
178
|
-
// MediaUrl will be remote URL (fallback if needed)
|
|
179
177
|
const downloadedFiles = await downloadFilesFromParts(fileParts);
|
|
180
|
-
const mediaPayload = buildXYMediaPayload(
|
|
178
|
+
const mediaPayload = buildXYMediaPayload(downloadedFiles);
|
|
181
179
|
// Resolve envelope format options (following feishu pattern)
|
|
182
180
|
const envelopeOptions = core.channel.reply.resolveEnvelopeFormatOptions(cfg);
|
|
183
181
|
// Build message body with speaker prefix (following feishu pattern)
|
|
@@ -322,41 +320,18 @@ export async function handleXYMessage(params) {
|
|
|
322
320
|
* Build media payload for inbound context.
|
|
323
321
|
* Following feishu pattern: buildFeishuMediaPayload().
|
|
324
322
|
*
|
|
325
|
-
* @param
|
|
326
|
-
* @param downloadedFiles - Downloaded files with local paths (optional)
|
|
327
|
-
*
|
|
328
|
-
* If downloadedFiles provided:
|
|
329
|
-
* MediaPath will be local path (faster for openclaw to read)
|
|
330
|
-
* MediaUrl will be remote URL (fallback if local read fails)
|
|
331
|
-
*
|
|
332
|
-
* If not provided:
|
|
333
|
-
* Both will be remote URL (openclaw will download)
|
|
323
|
+
* @param mediaList - Downloaded files with local paths
|
|
334
324
|
*/
|
|
335
|
-
function buildXYMediaPayload(
|
|
336
|
-
const first =
|
|
337
|
-
const
|
|
338
|
-
const mediaTypes =
|
|
339
|
-
// If files were downloaded locally, use local paths for MediaPath
|
|
340
|
-
// and remote URLs for MediaUrl (best of both worlds)
|
|
341
|
-
if (downloadedFiles && downloadedFiles.length > 0) {
|
|
342
|
-
const localPaths = downloadedFiles.map((f) => f.path);
|
|
343
|
-
const firstLocal = downloadedFiles[0];
|
|
344
|
-
return {
|
|
345
|
-
MediaPath: firstLocal?.path, // ⭐ Local path (/tmp/xy_channel/...)
|
|
346
|
-
MediaType: first?.mimeType,
|
|
347
|
-
MediaUrl: firstLocal?.uri, // ⭐ Remote URL (https://cdn...)
|
|
348
|
-
MediaPaths: localPaths.length > 0 ? localPaths : undefined,
|
|
349
|
-
MediaUrls: uris.length > 0 ? uris : undefined,
|
|
350
|
-
MediaTypes: mediaTypes.length > 0 ? mediaTypes : undefined,
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
// Fallback: use remote URLs for both (original behavior)
|
|
325
|
+
function buildXYMediaPayload(mediaList) {
|
|
326
|
+
const first = mediaList[0];
|
|
327
|
+
const mediaPaths = mediaList.map((media) => media.path);
|
|
328
|
+
const mediaTypes = mediaList.map((media) => media.mimeType).filter(Boolean);
|
|
354
329
|
return {
|
|
355
|
-
MediaPath: first?.
|
|
330
|
+
MediaPath: first?.path,
|
|
356
331
|
MediaType: first?.mimeType,
|
|
357
|
-
MediaUrl: first?.
|
|
358
|
-
MediaPaths:
|
|
359
|
-
MediaUrls:
|
|
332
|
+
MediaUrl: first?.path,
|
|
333
|
+
MediaPaths: mediaPaths.length > 0 ? mediaPaths : undefined,
|
|
334
|
+
MediaUrls: mediaPaths.length > 0 ? mediaPaths : undefined,
|
|
360
335
|
MediaTypes: mediaTypes.length > 0 ? mediaTypes : undefined,
|
|
361
336
|
};
|
|
362
337
|
}
|
|
@@ -4,11 +4,7 @@
|
|
|
4
4
|
export declare function downloadFile(url: string, destPath: string): Promise<void>;
|
|
5
5
|
/**
|
|
6
6
|
* Download files from A2A file parts.
|
|
7
|
-
* Returns array of local file paths
|
|
8
|
-
*
|
|
9
|
-
* @param fileParts - Array of file info from A2A message
|
|
10
|
-
* @param tempDir - Temporary directory for downloaded files
|
|
11
|
-
* @returns Array of downloaded file info (includes local path, name, mime type, and original URI)
|
|
7
|
+
* Returns array of local file paths.
|
|
12
8
|
*/
|
|
13
9
|
export declare function downloadFilesFromParts(fileParts: Array<{
|
|
14
10
|
name: string;
|
|
@@ -18,5 +14,4 @@ export declare function downloadFilesFromParts(fileParts: Array<{
|
|
|
18
14
|
path: string;
|
|
19
15
|
name: string;
|
|
20
16
|
mimeType: string;
|
|
21
|
-
uri: string;
|
|
22
17
|
}>>;
|
|
@@ -34,11 +34,7 @@ export async function downloadFile(url, destPath) {
|
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Download files from A2A file parts.
|
|
37
|
-
* Returns array of local file paths
|
|
38
|
-
*
|
|
39
|
-
* @param fileParts - Array of file info from A2A message
|
|
40
|
-
* @param tempDir - Temporary directory for downloaded files
|
|
41
|
-
* @returns Array of downloaded file info (includes local path, name, mime type, and original URI)
|
|
37
|
+
* Returns array of local file paths.
|
|
42
38
|
*/
|
|
43
39
|
export async function downloadFilesFromParts(fileParts, tempDir = "/tmp/xy_channel") {
|
|
44
40
|
// Create temp directory if it doesn't exist
|
|
@@ -52,20 +48,15 @@ export async function downloadFilesFromParts(fileParts, tempDir = "/tmp/xy_chann
|
|
|
52
48
|
try {
|
|
53
49
|
await downloadFile(uri, destPath);
|
|
54
50
|
downloadedFiles.push({
|
|
55
|
-
path: destPath,
|
|
51
|
+
path: destPath,
|
|
56
52
|
name,
|
|
57
53
|
mimeType,
|
|
58
|
-
uri, // ⭐ Original remote URL
|
|
59
54
|
});
|
|
60
|
-
logger.log(`✅ Downloaded: ${name} -> ${destPath}`);
|
|
61
55
|
}
|
|
62
56
|
catch (error) {
|
|
63
|
-
logger.error(
|
|
57
|
+
logger.error(`Failed to download file ${name}:`, error);
|
|
64
58
|
// Continue with other files
|
|
65
59
|
}
|
|
66
60
|
}
|
|
67
|
-
if (downloadedFiles.length > 0) {
|
|
68
|
-
logger.log(`📦 Downloaded ${downloadedFiles.length}/${fileParts.length} files successfully`);
|
|
69
|
-
}
|
|
70
61
|
return downloadedFiles;
|
|
71
62
|
}
|