@aiyiran/myclaw 1.1.133 → 1.1.135
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 +79 -16
- package/package.json +1 -1
|
@@ -9,8 +9,14 @@
|
|
|
9
9
|
* myclaw inject-minimax # 仅追加 minimax provider,不改默认,副作用最小
|
|
10
10
|
* myclaw inject-minimax --default # 追加 + 设为默认 + 全部对话迁移到 MiniMax-M3
|
|
11
11
|
* myclaw inject-minimax --only # 追加 + 设为默认 + 全部对话迁移 + 清掉所有其他 provider
|
|
12
|
-
* myclaw inject-minimax --beta #
|
|
13
|
-
* myclaw inject-minimax --key sk-xxx # 使用指定 API Key
|
|
12
|
+
* myclaw inject-minimax --beta # 6.X 模式: minimax + zai 共存,写 SQLite 鉴权,默认 minimax
|
|
13
|
+
* myclaw inject-minimax --key sk-xxx # 使用指定 API Key (仅 minimax)
|
|
14
|
+
*
|
|
15
|
+
* --beta 说明:
|
|
16
|
+
* - 适配 openclaw 6.X: 直接写 openclaw-agent.sqlite (6.X 运行时唯一鉴权源)
|
|
17
|
+
* - 去掉 minimax 的 authHeader
|
|
18
|
+
* - 附带配置 zai: glm-5.2 / glm-5-turbo,同样写 SQLite 让其在 6.X 可用
|
|
19
|
+
* - 独占清理时保留 minimax + zai 两个 provider,默认模型仍为 minimax
|
|
14
20
|
*/
|
|
15
21
|
|
|
16
22
|
const fs = require('fs');
|
|
@@ -23,6 +29,29 @@ const DEFAULT_MINIMAX_KEY = "sk-cp-dZnzWB-ScLfjo8bO7DKTqSutkBXQsLWUmjhNDBRkgJd5e
|
|
|
23
29
|
const PROVIDER_ID = "minimax";
|
|
24
30
|
const DEFAULT_MODEL = "minimax/MiniMax-M2.7-highspeed";
|
|
25
31
|
|
|
32
|
+
// ── zai (智谱 GLM) 配置:仅 --beta 模式下附带注入 ──
|
|
33
|
+
const DEFAULT_ZAI_KEY = "a7ae7806dea8406bb85eea5d859c00ad.pVnBuagTz6942JHp";
|
|
34
|
+
const ZAI_BETA_MODELS = [
|
|
35
|
+
{
|
|
36
|
+
id: "glm-5.2",
|
|
37
|
+
name: "GLM-5.2",
|
|
38
|
+
reasoning: true,
|
|
39
|
+
input: ["text"],
|
|
40
|
+
cost: { input: 1.2, output: 4, cacheRead: 0.24, cacheWrite: 0 },
|
|
41
|
+
contextWindow: 202800,
|
|
42
|
+
maxTokens: 131100
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "glm-5-turbo",
|
|
46
|
+
name: "GLM-5 Turbo",
|
|
47
|
+
reasoning: true,
|
|
48
|
+
input: ["text"],
|
|
49
|
+
cost: { input: 1.2, output: 4, cacheRead: 0.24, cacheWrite: 0 },
|
|
50
|
+
contextWindow: 202800,
|
|
51
|
+
maxTokens: 131100
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
|
|
26
55
|
function run(cliArgs) {
|
|
27
56
|
// ── 解析参数 ──
|
|
28
57
|
let apiKey = null;
|
|
@@ -63,14 +92,19 @@ function run(cliArgs) {
|
|
|
63
92
|
console.log('📍 找到配置: ' + configPath);
|
|
64
93
|
console.log('📌 模式: ' + (betaMode ? '--beta (独占+6.X兼容)' : onlyMode ? '--only (独占)' : setDefault ? '--default (设默认)' : '追加'));
|
|
65
94
|
|
|
66
|
-
// ──
|
|
95
|
+
// ── 保留集合:--beta 同时保留 minimax + zai,普通 --only 仅保留 minimax ──
|
|
96
|
+
const keepProviders = betaMode ? [PROVIDER_ID, 'zai'] : [PROVIDER_ID];
|
|
97
|
+
const keepProfile = (key) => keepProviders.some((p) => key.startsWith(p + ':'));
|
|
98
|
+
const keepModel = (key) => keepProviders.some((p) => key.startsWith(p + '/'));
|
|
99
|
+
|
|
100
|
+
// ── Step 1:--only 清掉其他 provider(保留集合除外)──
|
|
67
101
|
if (onlyMode) {
|
|
68
102
|
console.log('');
|
|
69
|
-
console.log('🧹 [--only]
|
|
103
|
+
console.log('🧹 [--only] 清理其他 provider (保留: ' + keepProviders.join(' + ') + ')...');
|
|
70
104
|
|
|
71
105
|
if (config.models?.providers) {
|
|
72
106
|
for (const key of Object.keys(config.models.providers)) {
|
|
73
|
-
if (key
|
|
107
|
+
if (!keepProviders.includes(key)) {
|
|
74
108
|
delete config.models.providers[key];
|
|
75
109
|
console.log(' ✓ 删除 provider: ' + key);
|
|
76
110
|
}
|
|
@@ -78,7 +112,7 @@ function run(cliArgs) {
|
|
|
78
112
|
}
|
|
79
113
|
if (config.auth?.profiles) {
|
|
80
114
|
for (const key of Object.keys(config.auth.profiles)) {
|
|
81
|
-
if (!key
|
|
115
|
+
if (!keepProfile(key)) {
|
|
82
116
|
delete config.auth.profiles[key];
|
|
83
117
|
console.log(' ✓ 删除 auth profile: ' + key);
|
|
84
118
|
}
|
|
@@ -86,7 +120,7 @@ function run(cliArgs) {
|
|
|
86
120
|
}
|
|
87
121
|
if (config.agents?.defaults?.models) {
|
|
88
122
|
for (const key of Object.keys(config.agents.defaults.models)) {
|
|
89
|
-
if (!key
|
|
123
|
+
if (!keepModel(key)) {
|
|
90
124
|
delete config.agents.defaults.models[key];
|
|
91
125
|
console.log(' ✓ 删除白名单: ' + key);
|
|
92
126
|
}
|
|
@@ -143,6 +177,19 @@ function run(cliArgs) {
|
|
|
143
177
|
config.agents.defaults.models["minimax/MiniMax-M3"] = {};
|
|
144
178
|
config.agents.defaults.models["minimax/MiniMax-M2.7-highspeed"] = {};
|
|
145
179
|
|
|
180
|
+
// ── --beta 附带注入 zai (glm-5.2 / glm-5-turbo) ──
|
|
181
|
+
if (betaMode) {
|
|
182
|
+
console.log('🔗 [--beta] 附带注入 zai: glm-5.2 / glm-5-turbo');
|
|
183
|
+
config.auth.profiles["zai:default"] = { provider: "zai", mode: "api_key" };
|
|
184
|
+
config.models.providers.zai = {
|
|
185
|
+
baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4",
|
|
186
|
+
api: "openai-completions",
|
|
187
|
+
models: ZAI_BETA_MODELS
|
|
188
|
+
};
|
|
189
|
+
config.agents.defaults.models["zai/glm-5.2"] = {};
|
|
190
|
+
config.agents.defaults.models["zai/glm-5-turbo"] = {};
|
|
191
|
+
}
|
|
192
|
+
|
|
146
193
|
// ── Step 3:--default 设默认模型 ──
|
|
147
194
|
if (setDefault) {
|
|
148
195
|
config.agents.defaults.model = { primary: DEFAULT_MODEL };
|
|
@@ -179,12 +226,18 @@ function run(cliArgs) {
|
|
|
179
226
|
if (agent.agentDir) agentDirs.set(agent.agentDir, agent.id);
|
|
180
227
|
}
|
|
181
228
|
|
|
182
|
-
//
|
|
183
|
-
//
|
|
229
|
+
// 写入目标说明:
|
|
230
|
+
// - auth-profiles.json:所有模式都写(5.X 鉴权源,6.X 仅作展示/审计,不参与运行时加载)
|
|
231
|
+
// - openclaw-agent.sqlite:仅 --beta 写(6.X 运行时唯一的鉴权源)
|
|
232
|
+
// 6.X 运行时只从 SQLite 的 auth_profile_store 读 key,完全不读 auth-profiles.json,
|
|
233
|
+
// 因此 6.X 必须靠 --beta 写 SQLite 才能让 minimax 鉴权成功。
|
|
234
|
+
// 非 --beta 模式不碰 SQLite,避免覆盖其他 provider 已有的凭据。
|
|
184
235
|
let DatabaseSync = null;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
236
|
+
if (betaMode) {
|
|
237
|
+
try {
|
|
238
|
+
({ DatabaseSync } = require('node:sqlite'));
|
|
239
|
+
} catch { /* Node < 22,无内置 sqlite */ }
|
|
240
|
+
}
|
|
188
241
|
|
|
189
242
|
const SQLITE_SCHEMA = `
|
|
190
243
|
CREATE TABLE IF NOT EXISTS auth_profile_store (
|
|
@@ -194,8 +247,13 @@ CREATE TABLE IF NOT EXISTS auth_profile_state (
|
|
|
194
247
|
state_key TEXT NOT NULL PRIMARY KEY, state_json TEXT NOT NULL, updated_at INTEGER NOT NULL
|
|
195
248
|
);`;
|
|
196
249
|
|
|
250
|
+
const zaiKey = DEFAULT_ZAI_KEY;
|
|
197
251
|
const sqliteStorePayload = { version: 1, profiles: { "minimax:cn": { type: "api_key", provider: "minimax", key: apiKey } } };
|
|
198
252
|
const sqliteStatePayload = { lastGood: { "minimax": "minimax:cn" } };
|
|
253
|
+
if (betaMode) {
|
|
254
|
+
sqliteStorePayload.profiles["zai:default"] = { type: "api_key", provider: "zai", key: zaiKey };
|
|
255
|
+
sqliteStatePayload.lastGood["zai"] = "zai:default";
|
|
256
|
+
}
|
|
199
257
|
|
|
200
258
|
let okCount = 0, skipCount = 0;
|
|
201
259
|
|
|
@@ -216,11 +274,15 @@ CREATE TABLE IF NOT EXISTS auth_profile_state (
|
|
|
216
274
|
}
|
|
217
275
|
profiles.profiles["minimax:cn"] = { type: "api_key", provider: "minimax", key: apiKey };
|
|
218
276
|
profiles.lastGood["minimax"] = "minimax:cn";
|
|
277
|
+
if (betaMode) {
|
|
278
|
+
profiles.profiles["zai:default"] = { type: "api_key", provider: "zai", key: zaiKey };
|
|
279
|
+
profiles.lastGood["zai"] = "zai:default";
|
|
280
|
+
}
|
|
219
281
|
try { fs.writeFileSync(profilesPath, JSON.stringify(profiles, null, 2) + '\n', 'utf8'); } catch { /* ignore */ }
|
|
220
282
|
|
|
221
|
-
// ── 6.X:写入 openclaw-agent.sqlite
|
|
283
|
+
// ── 6.X (--beta):写入 openclaw-agent.sqlite(运行时唯一鉴权源)──
|
|
222
284
|
let sqliteOk = false;
|
|
223
|
-
if (DatabaseSync) {
|
|
285
|
+
if (DatabaseSync) { // 仅 betaMode 下 DatabaseSync 才被赋值
|
|
224
286
|
const dbPath = path.join(agentDir, 'openclaw-agent.sqlite');
|
|
225
287
|
try {
|
|
226
288
|
const db = new DatabaseSync(dbPath);
|
|
@@ -284,9 +346,10 @@ CREATE TABLE IF NOT EXISTS auth_profile_state (
|
|
|
284
346
|
console.log('');
|
|
285
347
|
console.log('✅ MiniMax 注入完成');
|
|
286
348
|
console.log(' 默认模型: ' + (setDefault ? DEFAULT_MODEL : '(未修改)'));
|
|
287
|
-
console.log(' 备选模型: minimax/MiniMax-M2.7-highspeed');
|
|
349
|
+
console.log(' 备选模型: minimax/MiniMax-M2.7-highspeed' + (betaMode ? ' + zai/glm-5.2 + zai/glm-5-turbo' : ''));
|
|
288
350
|
console.log(' Agent: ' + okCount + ' 个写入,' + skipCount + ' 个跳过');
|
|
289
|
-
if (
|
|
351
|
+
if (betaMode) console.log(' 其他 provider 已清除 (保留 minimax + zai)');
|
|
352
|
+
else if (onlyMode) console.log(' 其他 provider 已清除');
|
|
290
353
|
console.log('');
|
|
291
354
|
}
|
|
292
355
|
|