xiaozhou-chat 1.0.17 → 1.0.19
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/lib/chat.js +31 -0
- package/lib/config.js +17 -0
- package/package.json +1 -1
package/lib/chat.js
CHANGED
|
@@ -34,6 +34,37 @@ export async function requestWithRetry(url, options, maxRetries = 3) {
|
|
|
34
34
|
const text = await res.text();
|
|
35
35
|
// 4xx errors: do not retry
|
|
36
36
|
if (res.status >= 400 && res.status < 500) {
|
|
37
|
+
if (res.status === 400) {
|
|
38
|
+
console.log(`\n❌ API请求参数错误 (400)。调试信息:`);
|
|
39
|
+
console.log(`- Endpoint: ${url}`);
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const bodyObj = options.body ? JSON.parse(options.body) : {};
|
|
43
|
+
console.log(`- Model: ${bodyObj.model}`);
|
|
44
|
+
console.log(`- Max Tokens: ${bodyObj.max_tokens}`);
|
|
45
|
+
console.log(`- Stream: ${bodyObj.stream}`);
|
|
46
|
+
console.log(`- Messages Count: ${bodyObj.messages?.length}`);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.log(`- Body Parsing Failed: ${e.message}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 尝试解析并打印更友好的错误
|
|
52
|
+
try {
|
|
53
|
+
const errJson = JSON.parse(text);
|
|
54
|
+
console.log(`- Server Message: ${errJson.error?.message || text}`);
|
|
55
|
+
} catch {
|
|
56
|
+
console.log(`- Server Response: ${text}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 提示用户检查配置
|
|
60
|
+
if (url.includes("tribiosapi")) {
|
|
61
|
+
console.log("- 提示: 默认模型 'claude-sonnet-4-5-20250929' 可能已过期或不可用。");
|
|
62
|
+
console.log(" 请尝试运行 'npx xiaozhou-chat config --model=gpt-4o' 切换模型。");
|
|
63
|
+
} else {
|
|
64
|
+
console.log("- 提示: 请检查当前模型名称是否与您的 API 提供商兼容。");
|
|
65
|
+
}
|
|
66
|
+
console.log(`- Config Source: 检查当前目录或 ~ 目录下是否存在 .newapi-chat-config.json`);
|
|
67
|
+
}
|
|
37
68
|
throw new Error(`API Error (${res.status}): ${text}`);
|
|
38
69
|
}
|
|
39
70
|
// 5xx errors: retry
|
package/lib/config.js
CHANGED
|
@@ -88,9 +88,26 @@ function loadConfigFrom(file) {
|
|
|
88
88
|
// 加载配置 (Home < Project)
|
|
89
89
|
export function loadConfig() {
|
|
90
90
|
const home = loadConfigFrom(homeConfigFile);
|
|
91
|
+
|
|
92
|
+
// 显式打印当前加载的配置文件,辅助调试
|
|
93
|
+
// 只有在存在项目级配置时才打印,避免在普通目录下显得啰嗦
|
|
94
|
+
const hasProjectConfig = fs.existsSync(projectConfigFile);
|
|
95
|
+
const hasAltConfig = fs.existsSync(projectAltConfigFile);
|
|
96
|
+
|
|
97
|
+
if (hasProjectConfig) {
|
|
98
|
+
console.log(`\n📂 [Config] 检测到项目级配置文件: ${projectConfigFile}`);
|
|
99
|
+
} else if (hasAltConfig) {
|
|
100
|
+
console.log(`\n📂 [Config] 检测到项目级配置文件: ${projectAltConfigFile}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
91
103
|
const project =
|
|
92
104
|
loadConfigFrom(projectConfigFile) ||
|
|
93
105
|
loadConfigFrom(projectAltConfigFile);
|
|
106
|
+
|
|
107
|
+
// 检查是否加载了空配置导致覆盖
|
|
108
|
+
if ((hasProjectConfig || hasAltConfig) && !project.apiKey && !project.profiles) {
|
|
109
|
+
console.log(`⚠️ [Config] 警告: 项目级配置文件似乎为空或格式不正确,可能会覆盖全局配置!`);
|
|
110
|
+
}
|
|
94
111
|
|
|
95
112
|
// Deep merge profiles if needed, but simple merge is okay for now
|
|
96
113
|
const config = { ...home, ...project };
|