@ynhcj/xiaoyi-channel 0.0.80-beta → 0.0.82-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/bot.js +1 -0
- package/dist/src/file-download.js +3 -6
- package/dist/src/provider.js +27 -4
- package/package.json +1 -1
package/dist/src/bot.js
CHANGED
|
@@ -177,6 +177,7 @@ export async function handleXYMessage(params) {
|
|
|
177
177
|
const fileParts = extractFileParts(parsed.parts);
|
|
178
178
|
// Download files to local disk
|
|
179
179
|
const downloadedFiles = await downloadFilesFromParts(fileParts);
|
|
180
|
+
console.log("Downloaded files:", JSON.stringify(downloadedFiles, null, 2));
|
|
180
181
|
const mediaPayload = buildXYMediaPayload(downloadedFiles);
|
|
181
182
|
// Resolve envelope format options (following feishu pattern)
|
|
182
183
|
const envelopeOptions = core.channel.reply.resolveEnvelopeFormatOptions(cfg);
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
import fetch from "node-fetch";
|
|
3
3
|
import fs from "fs/promises";
|
|
4
4
|
import path from "path";
|
|
5
|
-
import { logger } from "./utils/logger.js";
|
|
6
5
|
/**
|
|
7
6
|
* Download a file from URL to local path.
|
|
8
7
|
*/
|
|
9
8
|
export async function downloadFile(url, destPath) {
|
|
10
|
-
logger.debug(`Downloading file from ${url} to ${destPath}`);
|
|
11
9
|
const controller = new AbortController();
|
|
12
10
|
const timeout = setTimeout(() => controller.abort(), 30000); // 30 seconds timeout
|
|
13
11
|
try {
|
|
@@ -18,14 +16,13 @@ export async function downloadFile(url, destPath) {
|
|
|
18
16
|
const arrayBuffer = await response.arrayBuffer();
|
|
19
17
|
const buffer = Buffer.from(arrayBuffer);
|
|
20
18
|
await fs.writeFile(destPath, buffer);
|
|
21
|
-
logger.debug(`File downloaded successfully: ${destPath}`);
|
|
22
19
|
}
|
|
23
20
|
catch (error) {
|
|
24
21
|
if (error.name === 'AbortError') {
|
|
25
|
-
|
|
22
|
+
console.log(`Download timeout (30s) for ${url}`);
|
|
26
23
|
throw new Error(`Download timeout after 30 seconds`);
|
|
27
24
|
}
|
|
28
|
-
|
|
25
|
+
console.log(`Failed to download file from ${url}:`);
|
|
29
26
|
throw error;
|
|
30
27
|
}
|
|
31
28
|
finally {
|
|
@@ -54,7 +51,7 @@ export async function downloadFilesFromParts(fileParts, tempDir = "/tmp/xy_chann
|
|
|
54
51
|
});
|
|
55
52
|
}
|
|
56
53
|
catch (error) {
|
|
57
|
-
|
|
54
|
+
console.log(`Failed to download file ${name}:`);
|
|
58
55
|
// Continue with other files
|
|
59
56
|
}
|
|
60
57
|
}
|
package/dist/src/provider.js
CHANGED
|
@@ -101,11 +101,34 @@ export const xiaoyiProvider = {
|
|
|
101
101
|
if (context.systemPrompt) {
|
|
102
102
|
console.log(`[xiaoyiprovider] system prompt length: ${context.systemPrompt.length}`);
|
|
103
103
|
}
|
|
104
|
-
//
|
|
104
|
+
// 在发送给模型前,优化 systemPrompt 结构
|
|
105
105
|
if (context.systemPrompt) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
let sp = context.systemPrompt;
|
|
107
|
+
const beforeLen = sp.length;
|
|
108
|
+
// 删除 ## Tooling 与 TOOLS.md 声明之间的内容
|
|
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) 提取 <available_skills>...</available_skills> 作为第一部分
|
|
111
|
+
const skillsMatch = sp.match(/<available_skills>[\s\S]*?<\/available_skills>/);
|
|
112
|
+
const part1 = skillsMatch ? skillsMatch[0] : '';
|
|
113
|
+
// (2) 提取 # SOUL.md - Who You Are 到 # TOOLS.md - Local Notes 之前的内容作为第二部分
|
|
114
|
+
const soulMatch = sp.match(/(# SOUL\.md - Who You Are[\s\S]*?)(?=# TOOLS\.md - Local Notes)/);
|
|
115
|
+
const part2 = soulMatch ? soulMatch[1].trim() : '';
|
|
116
|
+
if (part1 || part2) {
|
|
117
|
+
// 从原始位置删除已提取的部分
|
|
118
|
+
if (skillsMatch)
|
|
119
|
+
sp = sp.replace(skillsMatch[0], '');
|
|
120
|
+
if (soulMatch)
|
|
121
|
+
sp = sp.replace(soulMatch[1], '');
|
|
122
|
+
// 清理多余空行
|
|
123
|
+
sp = sp.replace(/\n{3,}/g, '\n\n');
|
|
124
|
+
// (3) 将 第二部分 + 第一部分 插入到 ## Runtime 上面
|
|
125
|
+
const combined = (part2 + '\n\n' + part1).trim();
|
|
126
|
+
if (combined && sp.includes('## Runtime')) {
|
|
127
|
+
sp = sp.replace('## Runtime', combined + '\n\n## Runtime');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
console.log(`[xiaoyiprovider] system prompt optimized: ${beforeLen} -> ${sp.length}`);
|
|
131
|
+
context.systemPrompt = sp;
|
|
109
132
|
}
|
|
110
133
|
const stream = await underlying(model, context, {
|
|
111
134
|
...options,
|