openclawmp 1.0.0-alpha.2 → 1.0.0
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 +76 -75
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -4,129 +4,130 @@ const fs = require("node:fs");
|
|
|
4
4
|
const path = require("node:path");
|
|
5
5
|
const os = require("node:os");
|
|
6
6
|
|
|
7
|
-
const DEFAULT_API_BASE_URL = "https://seafood.c.stepfun-inc.net";
|
|
7
|
+
// const DEFAULT_API_BASE_URL = "https://seafood.c.stepfun-inc.net";
|
|
8
|
+
const DEFAULT_API_BASE_URL = "https://openclawmp.stepfun.com/";
|
|
8
9
|
|
|
9
10
|
const projectRoot = path.resolve(__dirname, "..");
|
|
10
11
|
const repoRoot = path.resolve(projectRoot, "..");
|
|
11
12
|
const INSTALL_ROOT_BY_TYPE = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
skill: ["skills"],
|
|
14
|
+
plugin: ["extensions"],
|
|
15
|
+
channel: ["extensions"],
|
|
16
|
+
trigger: ["triggers"],
|
|
17
|
+
experience: ["experiences"],
|
|
18
|
+
template: ["templates"],
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
function parseEnvFile(content) {
|
|
21
|
-
|
|
22
|
+
const result = {};
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
content.split(/\r?\n/u).forEach(function eachLine(rawLine) {
|
|
25
|
+
const line = rawLine.trim();
|
|
26
|
+
if (!line || line.startsWith("#")) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const separatorIndex = line.indexOf("=");
|
|
31
|
+
if (separatorIndex <= 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
const key = line.slice(0, separatorIndex).trim();
|
|
36
|
+
let value = line.slice(separatorIndex + 1).trim();
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
if (
|
|
39
|
+
(value.startsWith('"') && value.endsWith('"')) ||
|
|
40
|
+
(value.startsWith("'") && value.endsWith("'"))
|
|
41
|
+
) {
|
|
42
|
+
value = value.slice(1, -1);
|
|
43
|
+
}
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
result[key] = value;
|
|
46
|
+
});
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
return result;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
function readRepoEnv() {
|
|
51
|
-
|
|
52
|
+
const env = {};
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
[".env.local", ".env", ".env.prod"].forEach(function eachFile(fileName) {
|
|
55
|
+
const filePath = path.join(repoRoot, fileName);
|
|
56
|
+
if (!fs.existsSync(filePath)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
Object.assign(env, parseEnvFile(fs.readFileSync(filePath, "utf8")));
|
|
60
|
+
});
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
return env;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
function firstDefined(values) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
return values.find(function findValue(value) {
|
|
67
|
+
return typeof value === "string" && value.trim();
|
|
68
|
+
});
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
function normalizeBaseUrl(value) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
return String(value)
|
|
73
|
+
.trim()
|
|
74
|
+
.replace(/\/api\/?$/u, "")
|
|
75
|
+
.replace(/\/+$/u, "");
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
const repoEnv = readRepoEnv();
|
|
78
79
|
|
|
79
80
|
function resolveApiBaseUrl(explicitValue) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
81
|
+
const resolved = firstDefined([
|
|
82
|
+
explicitValue,
|
|
83
|
+
process.env.OPENCLAWMP_API_BASE_URL,
|
|
84
|
+
process.env.OPENCLAWMP_BASE_URL,
|
|
85
|
+
process.env.API_BASE_URL,
|
|
86
|
+
process.env.NEXT_PUBLIC_API_BASE_URL,
|
|
87
|
+
repoEnv.API_BASE_URL,
|
|
88
|
+
repoEnv.NEXT_PUBLIC_API_BASE_URL,
|
|
89
|
+
DEFAULT_API_BASE_URL,
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
return normalizeBaseUrl(resolved || DEFAULT_API_BASE_URL);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
function resolveConnectBaseUrl(explicitValue) {
|
|
95
|
-
|
|
96
|
+
return resolveApiBaseUrl(explicitValue) + "/api";
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
function getOpenClawHome() {
|
|
99
|
-
|
|
100
|
+
return path.join(os.homedir(), ".openclaw");
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
function defaultCredentialsPath() {
|
|
103
|
-
|
|
104
|
+
return path.join(getOpenClawHome(), "hub-credentials.json");
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
function getLockfilePath() {
|
|
107
|
-
|
|
108
|
+
return path.join(getOpenClawHome(), "hub-lock.json");
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
function getManagedAssetsRoot() {
|
|
111
|
-
|
|
112
|
+
return getOpenClawHome();
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
function getInstallRoot(assetType) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
const segments = INSTALL_ROOT_BY_TYPE[assetType];
|
|
117
|
+
if (!segments) {
|
|
118
|
+
throw new Error("未知资产类型: " + assetType);
|
|
119
|
+
}
|
|
120
|
+
return path.join.apply(path, [getManagedAssetsRoot()].concat(segments));
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
module.exports = {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
projectRoot,
|
|
125
|
+
repoRoot,
|
|
126
|
+
resolveApiBaseUrl,
|
|
127
|
+
resolveConnectBaseUrl,
|
|
128
|
+
getOpenClawHome,
|
|
129
|
+
defaultCredentialsPath,
|
|
130
|
+
getLockfilePath,
|
|
131
|
+
getManagedAssetsRoot,
|
|
132
|
+
getInstallRoot,
|
|
132
133
|
};
|