@aiyiran/myclaw 1.1.10 → 1.1.12
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/injects/inject-minimax.js +27 -51
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* 2. 注册 minimax provider + 模型定义 (openclaw.json)
|
|
11
11
|
* 3. 设置默认聊天模型为 MiniMax (openclaw.json)
|
|
12
12
|
* 4. 将 MiniMax 模型加入白名单 (openclaw.json)
|
|
13
|
-
* 5. 为所有 agent 写入 API Key (
|
|
13
|
+
* 5. 为所有 agent 写入 API Key (auth-profiles.json,不存在则创建)
|
|
14
14
|
*
|
|
15
15
|
* 不触碰: 图片模型、其他 provider、onboard 流程
|
|
16
16
|
*
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
const fs = require('fs');
|
|
21
21
|
const path = require('path');
|
|
22
|
+
const os = require('os');
|
|
22
23
|
const { readConfig, writeConfig } = require('../find-config');
|
|
23
24
|
|
|
24
25
|
const DEFAULT_MINIMAX_KEY = "sk-cp-DC5lWd2Stt9CBFzLIT2awP4K-ZEn5AkYwjl3Cdj-mIBmgjxod518F2LaVF2L9c35Wv5-Eox0F1ctJD5vXtB9p3OmxoWLd9ge9zIUIMrCVuqBYdL_s6kb8Qs";
|
|
@@ -49,7 +50,7 @@ function run(cliArgs) {
|
|
|
49
50
|
|
|
50
51
|
console.log('📍 找到配置: ' + configPath);
|
|
51
52
|
|
|
52
|
-
// ─── 1. auth profile
|
|
53
|
+
// ─── 1. auth profile ───
|
|
53
54
|
if (!config.auth) config.auth = {};
|
|
54
55
|
if (!config.auth.profiles) config.auth.profiles = {};
|
|
55
56
|
config.auth.profiles["minimax:cn"] = {
|
|
@@ -66,7 +67,6 @@ function run(cliArgs) {
|
|
|
66
67
|
baseUrl: "https://api.minimaxi.com/anthropic",
|
|
67
68
|
api: "anthropic-messages",
|
|
68
69
|
authHeader: true,
|
|
69
|
-
apiKey: apiKey,
|
|
70
70
|
models: [
|
|
71
71
|
{
|
|
72
72
|
id: "MiniMax-M2.7-highspeed",
|
|
@@ -92,44 +92,41 @@ function run(cliArgs) {
|
|
|
92
92
|
primary: "minimax/MiniMax-M2.7-highspeed"
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
// ─── 4.
|
|
95
|
+
// ─── 4. 白名单,清理残留 ───
|
|
96
96
|
if (!config.agents.defaults.models) config.agents.defaults.models = {};
|
|
97
97
|
config.agents.defaults.models["minimax/MiniMax-M2.7-highspeed"] = {};
|
|
98
|
-
|
|
99
|
-
// 清理 onboard 可能写入的残留
|
|
100
|
-
if (config.agents.defaults.models["minimax/MiniMax-M2.7"]) {
|
|
101
|
-
delete config.agents.defaults.models["minimax/MiniMax-M2.7"];
|
|
102
|
-
}
|
|
98
|
+
delete config.agents.defaults.models["minimax/MiniMax-M2.7"];
|
|
103
99
|
|
|
104
100
|
// ─── 写入 openclaw.json ───
|
|
105
101
|
writeConfig(config, configPath);
|
|
106
102
|
console.log('✅ openclaw.json 已更新');
|
|
107
103
|
|
|
108
104
|
// ─── 5. 为所有 agent 写入 auth-profiles.json ───
|
|
105
|
+
// 始终包含 main agent 默认路径,防止 fresh onboard 后 agents.list 为空
|
|
106
|
+
const DEFAULT_MAIN_DIR = path.join(os.homedir(), '.openclaw', 'agents', 'main', 'agent');
|
|
109
107
|
const agentList = (config.agents && config.agents.list) || [];
|
|
110
|
-
let okCount = 0;
|
|
111
|
-
let skipCount = 0;
|
|
112
108
|
|
|
109
|
+
// 构建去重的 agentDir 列表,main 默认路径始终存在
|
|
110
|
+
const agentDirs = new Map();
|
|
111
|
+
agentDirs.set(DEFAULT_MAIN_DIR, 'main');
|
|
113
112
|
for (const agent of agentList) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
skipCount++;
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
113
|
+
if (agent.agentDir) agentDirs.set(agent.agentDir, agent.id);
|
|
114
|
+
}
|
|
119
115
|
|
|
116
|
+
let okCount = 0;
|
|
117
|
+
let skipCount = 0;
|
|
118
|
+
|
|
119
|
+
for (const [agentDir, agentId] of agentDirs) {
|
|
120
120
|
const profilesPath = path.join(agentDir, 'auth-profiles.json');
|
|
121
121
|
|
|
122
|
-
//
|
|
122
|
+
// 读取现有文件,不存在则初始化骨架
|
|
123
123
|
let profiles = { version: 1, profiles: {}, lastGood: {} };
|
|
124
124
|
if (fs.existsSync(profilesPath)) {
|
|
125
125
|
try {
|
|
126
|
-
|
|
127
|
-
if (
|
|
126
|
+
const parsed = JSON.parse(fs.readFileSync(profilesPath, 'utf8'));
|
|
127
|
+
if (parsed.profiles) profiles = parsed;
|
|
128
128
|
if (!profiles.lastGood) profiles.lastGood = {};
|
|
129
|
-
} catch {
|
|
130
|
-
// 解析失败则重建
|
|
131
|
-
profiles = { version: 1, profiles: {}, lastGood: {} };
|
|
132
|
-
}
|
|
129
|
+
} catch { /* 解析失败则用空骨架 */ }
|
|
133
130
|
}
|
|
134
131
|
|
|
135
132
|
// 写入 minimax:cn,保留其他 profile 不动
|
|
@@ -141,42 +138,21 @@ function run(cliArgs) {
|
|
|
141
138
|
profiles.lastGood["minimax"] = "minimax:cn";
|
|
142
139
|
|
|
143
140
|
try {
|
|
144
|
-
|
|
145
|
-
if (!fs.existsSync(agentDir)) {
|
|
146
|
-
fs.mkdirSync(agentDir, { recursive: true });
|
|
147
|
-
}
|
|
141
|
+
if (!fs.existsSync(agentDir)) fs.mkdirSync(agentDir, { recursive: true });
|
|
148
142
|
fs.writeFileSync(profilesPath, JSON.stringify(profiles, null, 2) + '\n', 'utf8');
|
|
149
|
-
|
|
150
|
-
// 同时更新 models.json 里的 minimax.apiKey 占位符
|
|
151
|
-
const modelsPath = path.join(agentDir, 'models.json');
|
|
152
|
-
if (fs.existsSync(modelsPath)) {
|
|
153
|
-
try {
|
|
154
|
-
const models = JSON.parse(fs.readFileSync(modelsPath, 'utf8'));
|
|
155
|
-
if (models.providers && models.providers.minimax) {
|
|
156
|
-
models.providers.minimax.apiKey = apiKey;
|
|
157
|
-
}
|
|
158
|
-
if (models.providers && models.providers['minimax-portal']) {
|
|
159
|
-
models.providers['minimax-portal'].apiKey = apiKey;
|
|
160
|
-
}
|
|
161
|
-
fs.writeFileSync(modelsPath, JSON.stringify(models, null, 2) + '\n', 'utf8');
|
|
162
|
-
} catch {
|
|
163
|
-
// models.json 解析失败则跳过
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
console.log(' ✅ ' + agent.id);
|
|
143
|
+
console.log(' ✅ ' + agentId);
|
|
168
144
|
okCount++;
|
|
169
145
|
} catch (err) {
|
|
170
|
-
console.log(' ⚠ ' +
|
|
146
|
+
console.log(' ⚠ ' + agentId + ': ' + err.message);
|
|
171
147
|
skipCount++;
|
|
172
148
|
}
|
|
173
149
|
}
|
|
174
150
|
|
|
175
151
|
console.log('');
|
|
176
|
-
console.log('✅ MiniMax
|
|
177
|
-
console.log(' 模型:
|
|
178
|
-
console.log(' 默认:
|
|
179
|
-
console.log(' Agent:
|
|
152
|
+
console.log('✅ MiniMax 注入完成');
|
|
153
|
+
console.log(' 模型: MiniMax-M2.7-highspeed');
|
|
154
|
+
console.log(' 默认: minimax/MiniMax-M2.7-highspeed');
|
|
155
|
+
console.log(' Agent: ' + okCount + ' 个写入,' + skipCount + ' 个跳过');
|
|
180
156
|
console.log('');
|
|
181
157
|
}
|
|
182
158
|
|