@aiyiran/myclaw 1.1.211 → 1.1.213
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/find-config.js +13 -4
- package/index.js +5 -3
- package/injects/inject-minimax.js +213 -137
- package/package.json +1 -1
- package/skills/minimax-inject/SKILL.md +6 -21
- package/skills/minimax-inject/scripts/inject.js +12 -243
- package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/1.html +0 -1756
- package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/__demo__.html +0 -1756
- package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/__student-view__.html +0 -77
- package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/__student__.json +0 -60
- package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/__teacher-view__.html +0 -52
- package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/__teacher__.json +0 -45
- package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/index.html +0 -150
- package//346/210/221/347/232/204/345/217/254/345/224/244/345/233/276/351/211/264/357/274/232/346/215/242/344/270/273/351/242/230/346/215/242/345/215/241/346/261/240/__demo__.html +0 -1531
- package//346/210/221/347/232/204/345/217/254/345/224/244/345/233/276/351/211/264/357/274/232/346/215/242/344/270/273/351/242/230/346/215/242/345/215/241/346/261/240/__student-view__.html +0 -77
- package//346/210/221/347/232/204/345/217/254/345/224/244/345/233/276/351/211/264/357/274/232/346/215/242/344/270/273/351/242/230/346/215/242/345/215/241/346/261/240/__student__.json +0 -60
- package//346/210/221/347/232/204/345/217/254/345/224/244/345/233/276/351/211/264/357/274/232/346/215/242/344/270/273/351/242/230/346/215/242/345/215/241/346/261/240/__teacher-view__.html +0 -52
- package//346/210/221/347/232/204/345/217/254/345/224/244/345/233/276/351/211/264/357/274/232/346/215/242/344/270/273/351/242/230/346/215/242/345/215/241/346/261/240/__teacher__.json +0 -45
- package//346/210/221/347/232/204/345/217/254/345/224/244/345/233/276/351/211/264/357/274/232/346/215/242/344/270/273/351/242/230/346/215/242/345/215/241/346/261/240/index.html +0 -150
- package//347/264/257/345/220/220/350/241/200/345/220/216/347/232/204/346/200/273/347/273/223.md +0 -196
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/1.jpg +0 -0
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/2.jpg +0 -0
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/3.jpg +0 -0
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/4.jpg +0 -0
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/AI/344/270/215/347/224/250/347/234/213/347/232/204/345/216/237/345/247/213/346/217/220/347/244/272/350/257/215/344/272/272/347/261/273/347/234/213/__/351/200/211/351/242/230/345/274/225/346/223/216__.html +0 -589
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/AI/344/270/215/347/224/250/347/234/213/347/232/204/345/216/237/345/247/213/346/217/220/347/244/272/350/257/215/344/272/272/347/261/273/347/234/213//345/216/237/345/247/213/346/217/220/347/244/272/350/257/215.md +0 -125
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/AI/344/270/215/347/224/250/347/234/213/347/232/204/345/216/237/345/247/213/346/217/220/347/244/272/350/257/215/344/272/272/347/261/273/347/234/213//350/200/201/350/202/226/347/210/206/346/254/276/351/200/211/351/242/230/345/274/225/346/223/216.md +0 -179
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/AI/344/270/215/347/224/250/347/234/213/347/232/204/345/216/237/345/247/213/346/217/220/347/244/272/350/257/215/344/272/272/347/261/273/347/234/213//350/200/201/350/202/226/351/207/221/345/217/245/345/272/223v1.md +0 -594
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/__demo__.html +0 -588
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/__student-view__.html +0 -77
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/__student__.json +0 -54
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/__teacher-view__.html +0 -52
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/__teacher__.json +0 -46
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220/index.html +0 -148
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220//344/270/211/344/270/252/350/247/206/351/242/221/345/216/237/345/247/213/345/206/205/345/256/271/1-/344/273/200/344/271/210/346/230/257/344/274/230/347/247/200/347/232/204/345/255/251/345/255/220+/350/223/235/346/230/237/344/277/261/344/271/220/351/203/250/345/210/233/345/212/236+/347/210/266/346/257/215/345/244/251/350/201/214/357/274/210/351/200/220/345/255/227/347/250/277/357/274/211.md +0 -48
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220//344/270/211/344/270/252/350/247/206/351/242/221/345/216/237/345/247/213/345/206/205/345/256/271/2-/350/277/207/347/250/213/345/206/231/344/275/234/350/257/276/347/250/213/345/210/206/344/272/253/357/274/210/351/200/220/345/255/227/347/250/277/357/274/211.md +0 -27
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220//344/270/211/344/270/252/350/247/206/351/242/221/345/216/237/345/247/213/345/206/205/345/256/271/3-/350/202/262/345/204/277/345/273/272/350/256/256/357/274/232/345/242/236/351/207/217/344/277/241/346/201/257+/346/214/207/345/274/225vs/345/216/237/345/210/231+/345/210/206/344/272/253/347/224/237/346/264/273/347/273/206/350/212/202/357/274/210/351/200/220/345/255/227/347/250/277/357/274/211.md +0 -204
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220//344/270/211/344/270/252/350/247/206/351/242/221/345/216/237/345/247/213/345/206/205/345/256/271//346/213/206/345/210/206/345/211/215/345/275/225/351/237/263/346/226/207/346/234/254.md +0 -267
- package//350/223/235/346/230/237/345/276/256/344/277/241/347/237/255/350/247/206/351/242/221/345/210/206/346/236/220//350/264/242/345/212/241/345/210/206/346/236/220.html +0 -411
- package//350/264/246/345/215/225/345/210/206/346/236/220/345/212/251/346/211/213/__demo__.html +0 -411
- package//350/264/246/345/215/225/345/210/206/346/236/220/345/212/251/346/211/213/__student-view__.html +0 -77
- package//350/264/246/345/215/225/345/210/206/346/236/220/345/212/251/346/211/213/__student__.json +0 -54
- package//350/264/246/345/215/225/345/210/206/346/236/220/345/212/251/346/211/213/__teacher-view__.html +0 -52
- package//350/264/246/345/215/225/345/210/206/346/236/220/345/212/251/346/211/213/__teacher__.json +0 -50
- package//350/264/246/345/215/225/345/210/206/346/236/220/345/212/251/346/211/213/index.html +0 -148
- package//351/200/203/345/207/272/350/277/267/345/256/253/357/274/232/346/210/221/346/235/245/345/256/232/350/247/204/345/210/231/__demo__.html +0 -842
- package//351/200/203/345/207/272/350/277/267/345/256/253/357/274/232/346/210/221/346/235/245/345/256/232/350/247/204/345/210/231/__student-view__.html +0 -77
- package//351/200/203/345/207/272/350/277/267/345/256/253/357/274/232/346/210/221/346/235/245/345/256/232/350/247/204/345/210/231/__student__.json +0 -60
- package//351/200/203/345/207/272/350/277/267/345/256/253/357/274/232/346/210/221/346/235/245/345/256/232/350/247/204/345/210/231/__teacher-view__.html +0 -52
- package//351/200/203/345/207/272/350/277/267/345/256/253/357/274/232/346/210/221/346/235/245/345/256/232/350/247/204/345/210/231/__teacher__.json +0 -45
- package//351/200/203/345/207/272/350/277/267/345/256/253/357/274/232/346/210/221/346/235/245/345/256/232/350/247/204/345/210/231/index.html +0 -150
package/find-config.js
CHANGED
|
@@ -22,15 +22,24 @@ const CONFIG_FILENAME = 'openclaw.json';
|
|
|
22
22
|
/**
|
|
23
23
|
* 查找 openclaw.json 的路径
|
|
24
24
|
* 按优先级尝试:
|
|
25
|
-
* 1.
|
|
26
|
-
* 2.
|
|
25
|
+
* 1. OPENCLAW_CONFIG_PATH 指定的配置文件
|
|
26
|
+
* 2. OPENCLAW_STATE_DIR 或 OPENCLAW_HOME 指定的目录
|
|
27
|
+
* 3. ~/.openclaw/openclaw.json(标准路径)
|
|
27
28
|
*
|
|
28
29
|
* @returns {string|null} 配置文件路径,未找到返回 null
|
|
29
30
|
*/
|
|
30
31
|
function findConfig() {
|
|
31
32
|
const candidates = [];
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
const configOverride = process.env.OPENCLAW_CONFIG_PATH?.trim();
|
|
35
|
+
const stateOverride = process.env.OPENCLAW_STATE_DIR?.trim();
|
|
36
|
+
if (configOverride || stateOverride) {
|
|
37
|
+
const configuredPath = configOverride || path.join(stateOverride, CONFIG_FILENAME);
|
|
38
|
+
const resolvedPath = path.resolve(configuredPath.replace(/^~(?=[/\\]|$)/, os.homedir()));
|
|
39
|
+
return fs.existsSync(resolvedPath) ? resolvedPath : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 保留 myclaw 旧版 OPENCLAW_HOME 路径约定。
|
|
34
43
|
if (process.env.OPENCLAW_HOME) {
|
|
35
44
|
candidates.push(path.join(process.env.OPENCLAW_HOME, CONFIG_FILENAME));
|
|
36
45
|
}
|
|
@@ -62,7 +71,7 @@ function findConfig() {
|
|
|
62
71
|
function readConfig() {
|
|
63
72
|
const configPath = findConfig();
|
|
64
73
|
if (!configPath) {
|
|
65
|
-
throw new Error('未找到 openclaw
|
|
74
|
+
throw new Error('未找到 OpenClaw 配置,请用 openclaw config file 核对当前用户的配置路径');
|
|
66
75
|
}
|
|
67
76
|
|
|
68
77
|
const raw = fs.readFileSync(configPath, 'utf8');
|
package/index.js
CHANGED
|
@@ -1178,6 +1178,8 @@ function runPatch() {
|
|
|
1178
1178
|
// manifest 加载失败,跳过
|
|
1179
1179
|
}
|
|
1180
1180
|
|
|
1181
|
+
require('./injects/inject-minimax').reapplyManaged();
|
|
1182
|
+
|
|
1181
1183
|
if (uiResult.success || skillResult.success || (agentResult && agentResult.success)) {
|
|
1182
1184
|
console.log('');
|
|
1183
1185
|
console.log(bar);
|
|
@@ -1855,7 +1857,7 @@ const INJECT_MENU = [
|
|
|
1855
1857
|
|
|
1856
1858
|
function runInjectCommand(cmd, extraArgs) {
|
|
1857
1859
|
const modules = {
|
|
1858
|
-
'inject-minimax': './inject-minimax',
|
|
1860
|
+
'inject-minimax': './injects/inject-minimax',
|
|
1859
1861
|
'inject-zai': './inject-zai',
|
|
1860
1862
|
'inject-claude': './inject-claude',
|
|
1861
1863
|
'inject-image': './inject-image',
|
|
@@ -2629,7 +2631,7 @@ function showHelp() {
|
|
|
2629
2631
|
console.log(' patch 注入 MyClaw UI + 技能 + 智能体 + 配置');
|
|
2630
2632
|
console.log(' unpatch 回滚 UI 注入(恢复原版)');
|
|
2631
2633
|
console.log(' inject 交互选择要执行的注入脚本');
|
|
2632
|
-
console.log(' inject-minimax 注入 MiniMax
|
|
2634
|
+
console.log(' inject-minimax 注入 MiniMax M3.1 Flash(--default 替换为全局唯一聊天模型,思考深度 max)');
|
|
2633
2635
|
console.log(' inject-claude 注入 B.AI 多模型配置 (Claude/GPT/Gemini,仅追加)');
|
|
2634
2636
|
console.log(' inject-image 注入图像生成模型配置 (基于 vveai)');
|
|
2635
2637
|
console.log(' inject-token 设置 Gateway Token 为 aiyiran');
|
|
@@ -2843,7 +2845,7 @@ if (!command) {
|
|
|
2843
2845
|
console.log('[2/4] mc patch — 注入 UI + 技能');
|
|
2844
2846
|
runPatchFresh();
|
|
2845
2847
|
console.log('');
|
|
2846
|
-
console.log('[2.5/4] inject-minimax --default —
|
|
2848
|
+
console.log('[2.5/4] inject-minimax --default — 将 MiniMax 设为唯一聊天模型');
|
|
2847
2849
|
try {
|
|
2848
2850
|
const minimax = require('./injects/inject-minimax');
|
|
2849
2851
|
minimax.run(['--default']);
|
|
@@ -4,10 +4,13 @@
|
|
|
4
4
|
* inject-minimax.js
|
|
5
5
|
*
|
|
6
6
|
* 注入 MiniMax 模型配置到 openclaw.json,并为所有 agent 写入 API Key。
|
|
7
|
+
* 这是 myclaw 自己的部署配置。默认型号、生成预算、API 地址和内置凭据随插件版本维护,
|
|
8
|
+
* 运行时不读取开发者电脑的全局 MiniMax 接入标准。替换模式使用插件内置凭据,
|
|
9
|
+
* 可通过 --key 或 --key-from-env 显式覆盖。max 思考深度来自 MiniMax API 的默认行为。
|
|
7
10
|
*
|
|
8
11
|
* 用法:
|
|
9
|
-
* myclaw inject-minimax #
|
|
10
|
-
* myclaw inject-minimax --default #
|
|
12
|
+
* myclaw inject-minimax # 更新 minimax provider,迁移旧 MiniMax 引用
|
|
13
|
+
* myclaw inject-minimax --default # 将 MiniMax-M3.1-Flash 设为唯一可选的聊天模型
|
|
11
14
|
* myclaw inject-minimax --only # 追加 + 设为默认 + 全部对话迁移 + 清掉所有其他 provider
|
|
12
15
|
* myclaw inject-minimax --beta # 6.X 模式: 仅 minimax,写 SQLite 鉴权,默认 minimax
|
|
13
16
|
* myclaw inject-minimax --key sk-xxx # 使用指定 API Key (仅 minimax)
|
|
@@ -15,7 +18,7 @@
|
|
|
15
18
|
* --beta 说明:
|
|
16
19
|
* - 适配 openclaw 6.X: 直接写 openclaw-agent.sqlite (6.X 运行时唯一鉴权源)
|
|
17
20
|
* - 去掉 minimax 的 authHeader
|
|
18
|
-
*
|
|
21
|
+
* - 独占清理时保留 minimax provider,默认模型仍为 minimax
|
|
19
22
|
*/
|
|
20
23
|
|
|
21
24
|
const fs = require('fs');
|
|
@@ -26,9 +29,59 @@ const { readConfig, writeConfig } = require('../find-config');
|
|
|
26
29
|
const DEFAULT_MINIMAX_KEY = "sk-cp-dZnzWB-ScLfjo8bO7DKTqSutkBXQsLWUmjhNDBRkgJd5e42qcE7z8J9i5m27V28eX-dYfo5Q7JNVG4XVsDi1zRxkIFZ4fT0DPGPJY7cHbqY5aBzJO1c6QVA";
|
|
27
30
|
|
|
28
31
|
const PROVIDER_ID = "minimax";
|
|
29
|
-
const
|
|
32
|
+
const MODEL_ID = "MiniMax-M3.1-Flash";
|
|
33
|
+
const DEFAULT_MODEL = PROVIDER_ID + '/' + MODEL_ID;
|
|
34
|
+
const OUTPUT_BUDGET = 131072;
|
|
35
|
+
|
|
36
|
+
function isMiniMaxModel(model, provider) {
|
|
37
|
+
return typeof model === 'string' && (
|
|
38
|
+
model.startsWith(PROVIDER_ID + '/') ||
|
|
39
|
+
(!model.includes('/') && (provider === PROVIDER_ID || model.startsWith('MiniMax-')))
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function migrateModelSelection(selection) {
|
|
44
|
+
if (typeof selection === 'string') {
|
|
45
|
+
return isMiniMaxModel(selection) ? DEFAULT_MODEL : selection;
|
|
46
|
+
}
|
|
47
|
+
if (!selection) return selection;
|
|
48
|
+
|
|
49
|
+
const primary = migrateModelSelection(selection.primary);
|
|
50
|
+
const updated = { ...selection, primary };
|
|
51
|
+
if (Array.isArray(selection.fallbacks)) {
|
|
52
|
+
updated.fallbacks = [...new Set(selection.fallbacks.map(migrateModelSelection))]
|
|
53
|
+
.filter((model) => model !== primary);
|
|
54
|
+
}
|
|
55
|
+
return updated;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function readPolicy(configPath) {
|
|
59
|
+
try {
|
|
60
|
+
const policy = JSON.parse(fs.readFileSync(configPath + '.myclaw-minimax.json', 'utf8'));
|
|
61
|
+
if (policy.version !== 1 || (policy.apiKey !== undefined &&
|
|
62
|
+
(typeof policy.apiKey !== 'string' || !policy.apiKey.trim()))) {
|
|
63
|
+
throw new Error('无法识别 myclaw 的 MiniMax 持久配置');
|
|
64
|
+
}
|
|
65
|
+
return policy;
|
|
66
|
+
} catch (err) {
|
|
67
|
+
if (err.code === 'ENOENT') return null;
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
30
71
|
|
|
31
|
-
function
|
|
72
|
+
function writePolicy(configPath, apiKey) {
|
|
73
|
+
const policyPath = configPath + '.myclaw-minimax.json';
|
|
74
|
+
const staging = fs.mkdtempSync(path.join(path.dirname(configPath), '.myclaw-minimax-'));
|
|
75
|
+
try {
|
|
76
|
+
const file = path.join(staging, 'policy.json');
|
|
77
|
+
fs.writeFileSync(file, JSON.stringify({ version: 1, apiKey }) + '\n', { mode: 0o600 });
|
|
78
|
+
fs.renameSync(file, policyPath);
|
|
79
|
+
} finally {
|
|
80
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function run(cliArgs, { reapply = false } = {}) {
|
|
32
85
|
// ── 解析参数 ──
|
|
33
86
|
let apiKey = null;
|
|
34
87
|
let setDefault = false;
|
|
@@ -36,9 +89,13 @@ function run(cliArgs) {
|
|
|
36
89
|
let betaMode = false;
|
|
37
90
|
|
|
38
91
|
for (let i = 0; i < cliArgs.length; i++) {
|
|
39
|
-
if (cliArgs[i] === '--key'
|
|
40
|
-
apiKey = cliArgs[i + 1];
|
|
92
|
+
if (cliArgs[i] === '--key') {
|
|
93
|
+
apiKey = cliArgs[i + 1]?.trim();
|
|
94
|
+
if (!apiKey || apiKey.startsWith('--')) throw new Error('--key 需要提供 MiniMax API Key');
|
|
41
95
|
i++;
|
|
96
|
+
} else if (cliArgs[i] === '--key-from-env') {
|
|
97
|
+
apiKey = process.env.MINIMAX_API_KEY?.trim();
|
|
98
|
+
if (!apiKey) throw new Error('--key-from-env 需要设置 MINIMAX_API_KEY');
|
|
42
99
|
} else if (cliArgs[i] === '--default') {
|
|
43
100
|
setDefault = true;
|
|
44
101
|
} else if (cliArgs[i] === '--only') {
|
|
@@ -51,11 +108,6 @@ function run(cliArgs) {
|
|
|
51
108
|
}
|
|
52
109
|
}
|
|
53
110
|
|
|
54
|
-
if (!apiKey) {
|
|
55
|
-
apiKey = DEFAULT_MINIMAX_KEY;
|
|
56
|
-
console.log('💡 未传入 --key,使用默认 API Key');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
111
|
// ── 读取配置 ──
|
|
60
112
|
let config, configPath;
|
|
61
113
|
try {
|
|
@@ -65,6 +117,16 @@ function run(cliArgs) {
|
|
|
65
117
|
process.exit(1);
|
|
66
118
|
}
|
|
67
119
|
|
|
120
|
+
const policy = readPolicy(configPath);
|
|
121
|
+
if (reapply && !policy) return;
|
|
122
|
+
const managedKey = apiKey || policy?.apiKey;
|
|
123
|
+
const configuredKey = config.models?.providers?.minimax?.apiKey;
|
|
124
|
+
const existingKey = typeof configuredKey === 'string' && !configuredKey.startsWith('$')
|
|
125
|
+
? configuredKey : undefined;
|
|
126
|
+
apiKey = setDefault || policy
|
|
127
|
+
? managedKey || DEFAULT_MINIMAX_KEY
|
|
128
|
+
: apiKey || process.env.MINIMAX_API_KEY || existingKey;
|
|
129
|
+
|
|
68
130
|
console.log('📍 找到配置: ' + configPath);
|
|
69
131
|
console.log('📌 模式: ' + (betaMode ? '--beta (独占+6.X兼容)' : onlyMode ? '--only (独占)' : setDefault ? '--default (设默认)' : '追加'));
|
|
70
132
|
|
|
@@ -111,6 +173,10 @@ function run(cliArgs) {
|
|
|
111
173
|
if (!config.auth) config.auth = {};
|
|
112
174
|
if (!config.auth.profiles) config.auth.profiles = {};
|
|
113
175
|
config.auth.profiles["minimax:cn"] = { provider: "minimax", mode: "api_key" };
|
|
176
|
+
if (setDefault || policy) {
|
|
177
|
+
config.auth.order ||= {};
|
|
178
|
+
config.auth.order.minimax = ['minimax:cn'];
|
|
179
|
+
}
|
|
114
180
|
|
|
115
181
|
if (!config.models) config.models = {};
|
|
116
182
|
if (!config.models.mode) config.models.mode = "merge";
|
|
@@ -119,87 +185,87 @@ function run(cliArgs) {
|
|
|
119
185
|
const minimaxProvider = {
|
|
120
186
|
baseUrl: "https://api.minimaxi.com/anthropic",
|
|
121
187
|
api: "anthropic-messages",
|
|
122
|
-
models: [
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
id: "MiniMax-M2.7-highspeed",
|
|
134
|
-
name: "MiniMax M2.7 Highspeed",
|
|
135
|
-
reasoning: true,
|
|
136
|
-
input: ["text"],
|
|
137
|
-
cost: { input: 0.3, output: 1.2, cacheRead: 0.06, cacheWrite: 0.375 },
|
|
138
|
-
contextWindow: 204800,
|
|
139
|
-
maxTokens: 131072
|
|
140
|
-
}
|
|
141
|
-
]
|
|
188
|
+
models: [{
|
|
189
|
+
id: MODEL_ID,
|
|
190
|
+
name: "MiniMax M3.1 Flash",
|
|
191
|
+
reasoning: true,
|
|
192
|
+
input: ["text", "image"],
|
|
193
|
+
cost: { input: 0.15, output: 0.60, cacheRead: 0.015, cacheWrite: 0 },
|
|
194
|
+
contextWindow: 1000000,
|
|
195
|
+
maxTokens: OUTPUT_BUDGET
|
|
196
|
+
}]
|
|
142
197
|
};
|
|
143
|
-
if (
|
|
198
|
+
if (setDefault || policy || existingKey) minimaxProvider.apiKey = apiKey;
|
|
199
|
+
if (!setDefault && !policy) minimaxProvider.authHeader = true;
|
|
144
200
|
config.models.providers.minimax = minimaxProvider;
|
|
145
201
|
|
|
146
202
|
if (!config.agents) config.agents = {};
|
|
147
203
|
if (!config.agents.defaults) config.agents.defaults = {};
|
|
148
204
|
if (!config.agents.defaults.models) config.agents.defaults.models = {};
|
|
149
205
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
206
|
+
const defaults = config.agents.defaults;
|
|
207
|
+
for (const model of Object.keys(defaults.models)) {
|
|
208
|
+
if (model !== DEFAULT_MODEL && (setDefault || isMiniMaxModel(model))) delete defaults.models[model];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// OpenClaw 2026.6.9 uses the MiniMax API's default max effort for adaptive thinking.
|
|
212
|
+
const modelConfig = defaults.models[DEFAULT_MODEL] || {};
|
|
213
|
+
defaults.models[DEFAULT_MODEL] = {
|
|
214
|
+
...modelConfig,
|
|
215
|
+
params: { ...modelConfig.params, thinking: 'adaptive', maxTokens: OUTPUT_BUDGET }
|
|
216
|
+
};
|
|
155
217
|
|
|
156
|
-
// ── Step 3:--default 设默认模型 ──
|
|
157
218
|
if (setDefault) {
|
|
158
|
-
|
|
219
|
+
defaults.model = { primary: DEFAULT_MODEL };
|
|
159
220
|
console.log('⚡ 默认模型 → ' + DEFAULT_MODEL);
|
|
160
|
-
} else {
|
|
161
|
-
|
|
221
|
+
} else if (defaults.model) {
|
|
222
|
+
defaults.model = migrateModelSelection(defaults.model);
|
|
162
223
|
}
|
|
163
224
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (agent.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
225
|
+
for (const agent of config.agents.list || []) {
|
|
226
|
+
if (setDefault) {
|
|
227
|
+
delete agent.model;
|
|
228
|
+
if (agent.subagents) delete agent.subagents.model;
|
|
229
|
+
if (agent.heartbeat) delete agent.heartbeat.model;
|
|
230
|
+
} else if (agent.model) {
|
|
231
|
+
agent.model = migrateModelSelection(agent.model);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (setDefault) {
|
|
235
|
+
for (const feature of [defaults.subagents, defaults.heartbeat, defaults.compaction]) {
|
|
236
|
+
if (feature) delete feature.model;
|
|
172
237
|
}
|
|
173
|
-
if (overrideCount > 0) console.log('🧹 --only: 已清除 ' + overrideCount + ' 个 agent 的独立 model 覆盖');
|
|
174
238
|
}
|
|
175
|
-
|
|
176
|
-
writeConfig(config, configPath);
|
|
177
|
-
console.log('✅ openclaw.json 已更新');
|
|
178
239
|
|
|
179
240
|
// ── Step 4:为所有 agent 写入 API Key ──
|
|
180
241
|
console.log('');
|
|
181
242
|
console.log('🔑 [Step 4] 写入 API Key 到所有 agent...');
|
|
182
243
|
|
|
183
|
-
const
|
|
244
|
+
const stateDirOverride = process.env.OPENCLAW_STATE_DIR?.trim();
|
|
245
|
+
const stateDir = stateDirOverride
|
|
246
|
+
? path.resolve(stateDirOverride.replace(/^~(?=[/\\]|$)/, os.homedir()))
|
|
247
|
+
: process.env.OPENCLAW_CONFIG_PATH?.trim()
|
|
248
|
+
? path.join(os.homedir(), '.openclaw')
|
|
249
|
+
: path.dirname(configPath);
|
|
250
|
+
const DEFAULT_MAIN_DIR = path.join(stateDir, 'agents', 'main', 'agent');
|
|
184
251
|
const agentList = (config.agents && config.agents.list) || [];
|
|
185
252
|
|
|
186
253
|
const agentDirs = new Map();
|
|
187
254
|
agentDirs.set(DEFAULT_MAIN_DIR, 'main');
|
|
188
255
|
for (const agent of agentList) {
|
|
189
|
-
|
|
256
|
+
const directory = agent.agentDir?.replace(/^~\//, os.homedir() + '/') ||
|
|
257
|
+
path.join(stateDir, 'agents', agent.id, 'agent');
|
|
258
|
+
agentDirs.set(directory, agent.id);
|
|
190
259
|
}
|
|
191
260
|
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
// 6.X 运行时只从 SQLite 的 auth_profile_store 读 key,完全不读 auth-profiles.json,
|
|
196
|
-
// 因此 6.X 必须靠 --beta 写 SQLite 才能让 minimax 鉴权成功。
|
|
197
|
-
// 非 --beta 模式不碰 SQLite,避免覆盖其他 provider 已有的凭据。
|
|
198
|
-
let DatabaseSync = null;
|
|
199
|
-
if (betaMode) {
|
|
261
|
+
// 6.X loads agent credentials from SQLite. Legacy clients use auth-profiles.json.
|
|
262
|
+
let DatabaseSync;
|
|
263
|
+
if (setDefault || policy) {
|
|
200
264
|
try {
|
|
201
265
|
({ DatabaseSync } = require('node:sqlite'));
|
|
202
|
-
} catch {
|
|
266
|
+
} catch (err) {
|
|
267
|
+
if (err.code !== 'ERR_UNKNOWN_BUILTIN_MODULE') throw err;
|
|
268
|
+
}
|
|
203
269
|
}
|
|
204
270
|
|
|
205
271
|
const SQLITE_SCHEMA = `
|
|
@@ -210,105 +276,115 @@ CREATE TABLE IF NOT EXISTS auth_profile_state (
|
|
|
210
276
|
state_key TEXT NOT NULL PRIMARY KEY, state_json TEXT NOT NULL, updated_at INTEGER NOT NULL
|
|
211
277
|
);`;
|
|
212
278
|
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
let okCount = 0, skipCount = 0;
|
|
279
|
+
let okCount = 0;
|
|
280
|
+
const profileId = 'minimax:cn';
|
|
217
281
|
|
|
218
282
|
for (const [agentDir, agentId] of agentDirs) {
|
|
219
|
-
|
|
220
|
-
try { fs.mkdirSync(agentDir, { recursive: true }); } catch { /* ignore */ }
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// ── 5.X:始终写 auth-profiles.json(兼容旧版) ──
|
|
283
|
+
fs.mkdirSync(agentDir, { recursive: true });
|
|
224
284
|
const profilesPath = path.join(agentDir, 'auth-profiles.json');
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
profiles.lastGood["minimax"] = "minimax:cn";
|
|
235
|
-
// 智谱已停用,移除旧版写入的鉴权。
|
|
236
|
-
for (const id of Object.keys(profiles.profiles)) {
|
|
237
|
-
if (profiles.profiles[id]?.provider === 'zai' || id.startsWith('zai:')) delete profiles.profiles[id];
|
|
238
|
-
}
|
|
239
|
-
delete profiles.lastGood.zai;
|
|
240
|
-
try { fs.writeFileSync(profilesPath, JSON.stringify(profiles, null, 2) + '\n', 'utf8'); } catch { /* ignore */ }
|
|
241
|
-
|
|
242
|
-
// ── 6.X (--beta):写入 openclaw-agent.sqlite(运行时唯一鉴权源)──
|
|
243
|
-
let sqliteOk = false;
|
|
244
|
-
if (DatabaseSync) { // 仅 betaMode 下 DatabaseSync 才被赋值
|
|
245
|
-
const dbPath = path.join(agentDir, 'openclaw-agent.sqlite');
|
|
285
|
+
const profiles = fs.existsSync(profilesPath)
|
|
286
|
+
? JSON.parse(fs.readFileSync(profilesPath, 'utf8'))
|
|
287
|
+
: { version: 1, profiles: {}, lastGood: {} };
|
|
288
|
+
profiles.profiles ||= {};
|
|
289
|
+
profiles.lastGood ||= {};
|
|
290
|
+
let key = apiKey || profiles.profiles[profileId]?.key;
|
|
291
|
+
|
|
292
|
+
if (DatabaseSync) {
|
|
293
|
+
const db = new DatabaseSync(path.join(agentDir, 'openclaw-agent.sqlite'));
|
|
246
294
|
try {
|
|
247
|
-
|
|
248
|
-
db.exec('PRAGMA journal_mode = WAL;');
|
|
295
|
+
db.exec('PRAGMA busy_timeout = 5000;');
|
|
249
296
|
db.exec(SQLITE_SCHEMA);
|
|
297
|
+
db.exec('BEGIN IMMEDIATE');
|
|
298
|
+
const storeRow = db.prepare('SELECT store_json FROM auth_profile_store WHERE store_key = ?').get('primary');
|
|
299
|
+
const stateRow = db.prepare('SELECT state_json FROM auth_profile_state WHERE state_key = ?').get('primary');
|
|
300
|
+
const store = storeRow ? JSON.parse(storeRow.store_json) : { version: 1, profiles: {} };
|
|
301
|
+
const state = stateRow ? JSON.parse(stateRow.state_json) : {};
|
|
302
|
+
store.profiles ||= {};
|
|
303
|
+
state.lastGood ||= {};
|
|
304
|
+
const prior = store.profiles[state.lastGood.minimax] || store.profiles[profileId];
|
|
305
|
+
key = apiKey || prior?.key || key || DEFAULT_MINIMAX_KEY;
|
|
306
|
+
if (store.profiles[profileId]?.key !== key && state.usageStats) {
|
|
307
|
+
delete state.usageStats[profileId];
|
|
308
|
+
}
|
|
309
|
+
store.profiles[profileId] = { type: 'api_key', provider: PROVIDER_ID, key };
|
|
310
|
+
state.lastGood.minimax = profileId;
|
|
250
311
|
const now = Date.now();
|
|
251
312
|
db.prepare('INSERT OR REPLACE INTO auth_profile_store (store_key, store_json, updated_at) VALUES (?,?,?)')
|
|
252
|
-
.run('primary', JSON.stringify(
|
|
313
|
+
.run('primary', JSON.stringify(store), now);
|
|
253
314
|
db.prepare('INSERT OR REPLACE INTO auth_profile_state (state_key, state_json, updated_at) VALUES (?,?,?)')
|
|
254
|
-
.run('primary', JSON.stringify(
|
|
315
|
+
.run('primary', JSON.stringify(state), now);
|
|
316
|
+
db.exec('COMMIT');
|
|
317
|
+
} finally {
|
|
255
318
|
db.close();
|
|
256
|
-
sqliteOk = true;
|
|
257
|
-
} catch (err) {
|
|
258
|
-
console.log(' ⚠ ' + agentId + ' (sqlite): ' + err.message);
|
|
259
319
|
}
|
|
260
320
|
}
|
|
261
321
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
} catch (err) {
|
|
266
|
-
console.log(' ⚠ ' + agentId + ': ' + err.message);
|
|
267
|
-
skipCount++;
|
|
322
|
+
key ||= DEFAULT_MINIMAX_KEY;
|
|
323
|
+
if (profiles.profiles[profileId]?.key !== key && profiles.usageStats) {
|
|
324
|
+
delete profiles.usageStats[profileId];
|
|
268
325
|
}
|
|
326
|
+
profiles.profiles[profileId] = { type: 'api_key', provider: PROVIDER_ID, key };
|
|
327
|
+
profiles.lastGood.minimax = profileId;
|
|
328
|
+
fs.writeFileSync(profilesPath, JSON.stringify(profiles, null, 2) + '\n', { mode: 0o600 });
|
|
329
|
+
console.log(' ✅ ' + agentId + (DatabaseSync ? ' (json+sqlite)' : ' (json)'));
|
|
330
|
+
okCount++;
|
|
269
331
|
}
|
|
270
332
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
console.log('🔄 [Step 5] 迁移全部对话 → ' + DEFAULT_MODEL + ' ...');
|
|
275
|
-
let sessionOk = 0, sessionSkip = 0, sessionChanged = 0;
|
|
333
|
+
if (setDefault && !reapply) writePolicy(configPath, managedKey);
|
|
334
|
+
writeConfig(config, configPath);
|
|
335
|
+
console.log('✅ openclaw.json 已更新');
|
|
276
336
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
337
|
+
// ── Step 5:迁移旧 MiniMax 会话,设默认模式沿用全部会话迁移 ──
|
|
338
|
+
let sessionOk = 0, sessionSkip = 0, sessionChanged = 0;
|
|
339
|
+
|
|
340
|
+
for (const [agentDir] of reapply ? [] : agentDirs) {
|
|
341
|
+
const sessionsPath = path.join(agentDir, '..', 'sessions', 'sessions.json');
|
|
342
|
+
if (!fs.existsSync(sessionsPath)) continue;
|
|
343
|
+
try {
|
|
344
|
+
const sessions = JSON.parse(fs.readFileSync(sessionsPath, 'utf8'));
|
|
345
|
+
let changed = 0;
|
|
346
|
+
for (const session of Object.values(sessions)) {
|
|
347
|
+
if (!session) continue;
|
|
348
|
+
let updated = false;
|
|
349
|
+
if (session.model && (setDefault || isMiniMaxModel(session.model, session.modelProvider)) &&
|
|
350
|
+
(session.model !== MODEL_ID || session.modelProvider !== PROVIDER_ID)) {
|
|
351
|
+
session.model = MODEL_ID;
|
|
352
|
+
session.modelProvider = PROVIDER_ID;
|
|
353
|
+
updated = true;
|
|
290
354
|
}
|
|
291
|
-
if (
|
|
292
|
-
|
|
293
|
-
|
|
355
|
+
if (session.modelOverride &&
|
|
356
|
+
(setDefault || isMiniMaxModel(session.modelOverride, session.providerOverride)) &&
|
|
357
|
+
(session.modelOverride !== MODEL_ID || session.providerOverride !== PROVIDER_ID)) {
|
|
358
|
+
session.modelOverride = MODEL_ID;
|
|
359
|
+
session.providerOverride = PROVIDER_ID;
|
|
360
|
+
updated = true;
|
|
294
361
|
}
|
|
295
|
-
|
|
296
|
-
} catch {
|
|
297
|
-
sessionSkip++;
|
|
362
|
+
if (updated) changed++;
|
|
298
363
|
}
|
|
364
|
+
if (changed > 0) {
|
|
365
|
+
fs.writeFileSync(sessionsPath, JSON.stringify(sessions, null, 2) + '\n', 'utf8');
|
|
366
|
+
sessionChanged += changed;
|
|
367
|
+
}
|
|
368
|
+
sessionOk++;
|
|
369
|
+
} catch {
|
|
370
|
+
sessionSkip++;
|
|
299
371
|
}
|
|
300
|
-
console.log(' 对话迁移: ' + sessionChanged + ' 条,文件: ' + sessionOk + ' 个,跳过: ' + sessionSkip + ' 个');
|
|
301
372
|
}
|
|
373
|
+
console.log(' 对话迁移: ' + sessionChanged + ' 条,文件: ' + sessionOk + ' 个,跳过: ' + sessionSkip + ' 个');
|
|
302
374
|
|
|
303
375
|
// ── 汇总 ──
|
|
304
376
|
console.log('');
|
|
305
377
|
console.log('✅ MiniMax 注入完成');
|
|
306
|
-
console.log('
|
|
307
|
-
console.log('
|
|
308
|
-
console.log(' Agent: ' + okCount + '
|
|
378
|
+
console.log(' MiniMax: ' + DEFAULT_MODEL + ' (adaptive / max)');
|
|
379
|
+
if (setDefault) console.log(' 全局唯一聊天模型: ' + DEFAULT_MODEL);
|
|
380
|
+
console.log(' Agent: ' + okCount + ' 个写入');
|
|
309
381
|
if (betaMode) console.log(' 其他 provider 已清除 (保留 minimax)');
|
|
310
382
|
else if (onlyMode) console.log(' 其他 provider 已清除');
|
|
311
383
|
console.log('');
|
|
312
384
|
}
|
|
313
385
|
|
|
314
|
-
|
|
386
|
+
function reapplyManaged() {
|
|
387
|
+
if (require('../find-config').findConfig()) run(['--default'], { reapply: true });
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
module.exports = { run, reapplyManaged };
|
package/package.json
CHANGED
|
@@ -1,33 +1,18 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: minimax-inject
|
|
3
|
-
description:
|
|
3
|
+
description: 通过 myclaw 注入 MiniMax M3.1 Flash。将 M3.1 Flash 设为全局唯一聊天模型,默认使用 max 思考深度。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# MiniMax 模型注入
|
|
7
7
|
|
|
8
|
-
将 OpenClaw 的模型配置清空,替换为唯一的 MiniMax M2.7 模型。
|
|
9
|
-
|
|
10
|
-
## 使用方法
|
|
11
|
-
|
|
12
8
|
```bash
|
|
13
|
-
|
|
14
|
-
node scripts/inject.js
|
|
15
|
-
|
|
16
|
-
# 注入模型 + 设置 API Key
|
|
17
|
-
node scripts/inject.js --key sk-你的key
|
|
9
|
+
myclaw inject-minimax --default
|
|
18
10
|
```
|
|
19
11
|
|
|
20
|
-
|
|
12
|
+
该命令将 OpenClaw 的唯一可选聊天模型及全局默认设为 `minimax/MiniMax-M3.1-Flash`,生成预算为 131072 token。OpenClaw 2026.6.9 使用 adaptive thinking,思考深度由 MiniMax API 默认设为 max。命令在注入后重启 Gateway。
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
|------|-----|
|
|
24
|
-
| auth.profiles | minimax:cn |
|
|
25
|
-
| models.providers | minimax (MiniMax-M2.7) |
|
|
26
|
-
| agents.defaults.model | minimax/MiniMax-M2.7-highspeed |
|
|
27
|
-
| imageGenerationModel | minimax/image-01 |
|
|
14
|
+
模型、生成预算、API 地址和内置凭据由 myclaw 自己维护。插件运行不依赖开发者电脑的全局模型配置。`--default` 会为当前 OpenClaw 配置启用 myclaw 管理,默认使用内置凭据。容器中的 `MINIMAX_API_KEY` 仅在指定 `--key-from-env` 时用于此模式,也可通过 `--key` 显式指定。显式凭据保存在配置文件旁的受限权限文件中。
|
|
28
15
|
|
|
29
|
-
|
|
16
|
+
启用后,`mc patch` 会在其他补丁完成后重新应用此设置。`mc up` 使用新版的 `mc patch`,同样会读回此设置。容器部署请让 OpenClaw 配置及其旁边的 `.myclaw-minimax.json` 配置文件后缀一起留在持久卷中。
|
|
30
17
|
|
|
31
|
-
|
|
32
|
-
- 自动重启 Gateway 使配置生效
|
|
33
|
-
- 如果传了 `--key`,会将 MINIMAX_API_KEY 写入 shell 配置文件
|
|
18
|
+
兼容入口 `node scripts/inject.js` 调用同一条命令。
|