-
-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy pathopenclaw-zero.config.js
More file actions
93 lines (70 loc) · 2.81 KB
/
openclaw-zero.config.js
File metadata and controls
93 lines (70 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* OpenClaw Zero Token Configuration
* 集中管理所有路径和端口配置
*/
import path from 'path';
import os from 'os';
// 基本配置
export const config = {
// 状态目录
stateDir: '.openclaw-zero',
// 配置文件名
configFilename: 'openclaw.json',
// 工作区目录名
workspaceDir: 'workspace',
// 网关锁目录后缀
gatewayLockSuffix: 'openclaw-zero',
// 默认网关端口
defaultGatewayPort: 18790,
// OAuth 目录
oauthDir: 'credentials',
// OAuth 文件名
oauthFilename: 'oauth.json',
// 工作区状态目录名
workspaceStateDirname: '.openclaw-zero',
// 工作区状态文件名
workspaceStateFilename: 'workspace-state.json',
// 环境变量前缀
envPrefix: 'OPENCLAW_ZERO_',
// 旧的环境变量前缀
legacyEnvPrefix: 'OPENCLAW_',
// 遗留的状态目录名
legacyStateDirs: ['.clawdbot', '.moldbot', '.moltbot'],
// 遗留的配置文件名
legacyConfigFilenames: ['clawdbot.json', 'moldbot.json', 'moltbot.json']
};
// 解析完整路径
export function resolvePaths(env = process.env, homedir = os.homedir) {
const home = homedir();
// 状态目录
const stateDirOverride = env[`${config.envPrefix}STATE_DIR`] || env[`${config.legacyEnvPrefix}STATE_DIR`] || env.CLAWDBOT_STATE_DIR;
const stateDir = stateDirOverride ? path.resolve(stateDirOverride) : path.join(home, config.stateDir);
// 配置文件路径
const configPathOverride = env[`${config.envPrefix}CONFIG_PATH`] || env[`${config.legacyEnvPrefix}CONFIG_PATH`] || env.CLAWDBOT_CONFIG_PATH;
const configPath = configPathOverride ? path.resolve(configPathOverride) : path.join(stateDir, config.configFilename);
// 工作区目录
const workspaceDir = path.join(stateDir, config.workspaceDir);
// 会话目录
const sessionDir = path.join(stateDir, 'agents', 'main', 'sessions');
// OAuth 目录
const oauthDirOverride = env[`${config.envPrefix}OAUTH_DIR`] || env[`${config.legacyEnvPrefix}OAUTH_DIR`];
const oauthDir = oauthDirOverride ? path.resolve(oauthDirOverride) : path.join(stateDir, config.oauthDir);
// 网关锁目录
const tmpdir = os.tmpdir();
const uid = typeof process.getuid === 'function' ? process.getuid() : undefined;
const gatewayLockSuffix = uid != null ? `${config.gatewayLockSuffix}-${uid}` : config.gatewayLockSuffix;
const gatewayLockDir = path.join(tmpdir, gatewayLockSuffix);
// 网关端口
const gatewayPortOverride = env[`${config.envPrefix}GATEWAY_PORT`] || env[`${config.legacyEnvPrefix}GATEWAY_PORT`] || env.CLAWDBOT_GATEWAY_PORT;
const gatewayPort = gatewayPortOverride ? parseInt(gatewayPortOverride, 10) : config.defaultGatewayPort;
return {
stateDir,
configPath,
workspaceDir,
sessionDir,
oauthDir,
gatewayLockDir,
gatewayPort,
...config
};
}