@openclaw-cn/cli 1.2.8 → 1.2.9
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/config.js +20 -5
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Conf from 'conf';
|
|
2
2
|
import axios from 'axios';
|
|
3
|
-
import path from 'path';
|
|
4
3
|
|
|
5
4
|
const config = new Conf({
|
|
6
5
|
projectName: 'openclaw-cli',
|
|
@@ -8,8 +7,11 @@ const config = new Conf({
|
|
|
8
7
|
cwd: process.env.OPENCLAW_CONFIG_DIR
|
|
9
8
|
});
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const DEBUG = process.env.DEBUG === '1' || process.env.OPENCLAW_DEBUG === '1';
|
|
11
|
+
|
|
12
|
+
if (DEBUG) {
|
|
13
|
+
console.error(`[Config] Path: ${config.path}`);
|
|
14
|
+
}
|
|
13
15
|
|
|
14
16
|
export const getApiUrl = () => {
|
|
15
17
|
return process.env.OPENCLAW_API_URL || config.get('api_url') || 'https://backend.clawd.org.cn/api';
|
|
@@ -29,11 +31,21 @@ export const clearToken = () => {
|
|
|
29
31
|
|
|
30
32
|
export const getClient = () => {
|
|
31
33
|
const token = getToken();
|
|
32
|
-
|
|
34
|
+
if (DEBUG) {
|
|
35
|
+
console.error(`[Config] Using Token: ${token ? token.slice(0, 5) + '...' : 'NONE'}`);
|
|
36
|
+
console.error(`[Config] API URL: ${getApiUrl()}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 默认禁用系统代理(axios 会自动读取 HTTP_PROXY/HTTPS_PROXY 环境变量,
|
|
40
|
+
// agent 环境通常将代理指向境外,会导致访问国内后端超时或失败)。
|
|
41
|
+
// 如有特殊需求,可设置环境变量 OPENCLAW_USE_PROXY=1 来恢复代理。
|
|
42
|
+
const useProxy = process.env.OPENCLAW_USE_PROXY === '1';
|
|
43
|
+
|
|
33
44
|
return axios.create({
|
|
34
45
|
baseURL: getApiUrl(),
|
|
35
|
-
timeout:
|
|
46
|
+
timeout: 60000, // 60s timeout(原 30s,适当放宽以兼容慢速网络)
|
|
36
47
|
maxBodyLength: 5 * 1024 * 1024, // 5MB max request body
|
|
48
|
+
proxy: useProxy ? undefined : false, // false = 忽略系统代理环境变量
|
|
37
49
|
headers: token ? { Authorization: `Bearer ${token}` } : {}
|
|
38
50
|
});
|
|
39
51
|
};
|
|
@@ -42,5 +54,8 @@ export const formatError = (err) => {
|
|
|
42
54
|
if (err.response) {
|
|
43
55
|
return `Error ${err.response.status}: ${err.response.data.error || err.response.statusText}`;
|
|
44
56
|
}
|
|
57
|
+
if (err.code === 'ECONNABORTED') {
|
|
58
|
+
return `Request timed out. Try again, or set OPENCLAW_API_URL to a faster endpoint.`;
|
|
59
|
+
}
|
|
45
60
|
return err.message;
|
|
46
61
|
};
|