@aiyiran/myclaw 1.1.210 → 1.1.212

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.
Files changed (52) hide show
  1. package/assets/myclaw-inject.js +50 -17
  2. package/index.js +3 -3
  3. package/injects/inject-minimax.js +154 -134
  4. package/package.json +1 -1
  5. package/skills/minimax-inject/SKILL.md +5 -22
  6. package/skills/minimax-inject/scripts/inject.js +12 -243
  7. package/voice-input/voice-input.js +17 -6
  8. package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/1.html +0 -1756
  9. package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/__demo__.html +0 -1756
  10. package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/__student-view__.html +0 -77
  11. package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/__student__.json +0 -60
  12. package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/__teacher-view__.html +0 -52
  13. package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/__teacher__.json +0 -45
  14. package//345/234/260/344/270/213/345/237/216/345/244/247/345/206/222/351/231/251/index.html +0 -150
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  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/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
  28. 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
  29. 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
  30. 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
  31. 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
  32. 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
  33. 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
  34. 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
  35. 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
  36. 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
  37. 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
  38. 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
  39. 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
  40. 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
  41. package//350/264/246/345/215/225/345/210/206/346/236/220/345/212/251/346/211/213/__demo__.html +0 -411
  42. package//350/264/246/345/215/225/345/210/206/346/236/220/345/212/251/346/211/213/__student-view__.html +0 -77
  43. package//350/264/246/345/215/225/345/210/206/346/236/220/345/212/251/346/211/213/__student__.json +0 -54
  44. package//350/264/246/345/215/225/345/210/206/346/236/220/345/212/251/346/211/213/__teacher-view__.html +0 -52
  45. package//350/264/246/345/215/225/345/210/206/346/236/220/345/212/251/346/211/213/__teacher__.json +0 -50
  46. package//350/264/246/345/215/225/345/210/206/346/236/220/345/212/251/346/211/213/index.html +0 -148
  47. 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
  48. 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
  49. 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
  50. 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
  51. 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
  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/index.html +0 -150
@@ -955,6 +955,36 @@ btn.addEventListener("click", function () {
955
955
 
956
956
  // ═══ 4. 录音控制 ═══
957
957
 
958
+ // 连接失败重连:单通道 + 次数上限(参照 teacher-web XfIatRecorder 的 maxRetryCount)
959
+ var VOICE_MAX_RETRY = 3;
960
+ var voiceRetryCount = 0;
961
+ var voiceRetryTimer = null;
962
+
963
+ function clearVoiceRetry() {
964
+ if (voiceRetryTimer) {
965
+ clearTimeout(voiceRetryTimer);
966
+ voiceRetryTimer = null;
967
+ }
968
+ }
969
+
970
+ function scheduleVoiceRetry(delay) {
971
+ if (!recording || voiceRetryTimer) return;
972
+ if (voiceRetryCount >= VOICE_MAX_RETRY) {
973
+ console.error("[myclaw-voice] ⛔ 连续 " + VOICE_MAX_RETRY + " 次重连失败,停止录音");
974
+ recording = false;
975
+ updateButtonUI();
976
+ return;
977
+ }
978
+ voiceRetryCount++;
979
+ voiceRetryTimer = setTimeout(function () {
980
+ voiceRetryTimer = null;
981
+ if (recording && voice) {
982
+ console.log("[myclaw-voice] \u91cd\u8fde " + voiceRetryCount + "/" + VOICE_MAX_RETRY + "...");
983
+ voice.start();
984
+ }
985
+ }, delay);
986
+ }
987
+
958
988
  function initVoice() {
959
989
  if (typeof window.VoiceInput === "undefined") {
960
990
  console.error("[myclaw-inject] VoiceInput SDK \u672a\u52a0\u8f7d");
@@ -973,6 +1003,10 @@ btn.addEventListener("click", function () {
973
1003
  onStatusChange: function (oldStatus, newStatus) {
974
1004
  console.log("[myclaw-voice] \u72b6\u6001:", oldStatus, "->", newStatus);
975
1005
 
1006
+ if (newStatus === "recording") {
1007
+ voiceRetryCount = 0;
1008
+ }
1009
+
976
1010
  if (newStatus === "idle" && recording && !stopping) {
977
1011
  // 讯飞 60 秒断开,但用户没有点停止 → 自动重连
978
1012
  // 把当前识别的文字提交,并更新光标位置
@@ -981,32 +1015,27 @@ btn.addEventListener("click", function () {
981
1015
  pendingText = "";
982
1016
 
983
1017
  console.log("[myclaw-voice] \u81ea\u52a8\u91cd\u8fde...");
984
- setTimeout(function () {
985
- if (recording && voice) {
986
- voice.start();
987
- }
988
- }, 300);
1018
+ scheduleVoiceRetry(300);
989
1019
  }
990
1020
  },
991
1021
  onError: function (err) {
992
1022
  console.error("[myclaw-voice] \u9519\u8bef:", err);
993
- // 权限错误是永久性的,不重试,直接停止
1023
+ // 永久性错误重试只会刷屏,直接停止
994
1024
  var errStr = String(err).toLowerCase();
995
- if (errStr.indexOf("permission") !== -1 || errStr.indexOf("not allowed") !== -1) {
996
- console.error("[myclaw-voice] ⛔ 麦克风权限被拒绝,停止录音");
1025
+ if (
1026
+ errStr.indexOf("permission") !== -1 ||
1027
+ errStr.indexOf("not allowed") !== -1 ||
1028
+ errStr.indexOf("securityerror") !== -1 ||
1029
+ errStr.indexOf("insecure websocket") !== -1
1030
+ ) {
1031
+ console.error("[myclaw-voice] ⛔ 麦克风权限或页面安全策略阻止录音,停止录音");
1032
+ clearVoiceRetry();
997
1033
  recording = false;
998
1034
  updateButtonUI();
999
1035
  return;
1000
1036
  }
1001
- // 其他错误(如 WebSocket)尝试重连
1002
- if (recording) {
1003
- setTimeout(function () {
1004
- if (recording && voice) {
1005
- console.log("[myclaw-voice] \u9519\u8bef\u540e\u91cd\u8fde...");
1006
- voice.start();
1007
- }
1008
- }, 1000);
1009
- }
1037
+ // 其他错误(如 WebSocket)走带次数上限的重连
1038
+ scheduleVoiceRetry(1000);
1010
1039
  },
1011
1040
  });
1012
1041
 
@@ -1024,6 +1053,10 @@ btn.addEventListener("click", function () {
1024
1053
  cursorOffset = getCursorPosition();
1025
1054
  pendingText = "";
1026
1055
 
1056
+ // 手动开始是一次新的会话:清掉待执行的重连和上次的失败计数
1057
+ clearVoiceRetry();
1058
+ voiceRetryCount = 0;
1059
+
1027
1060
  recording = true;
1028
1061
  updateButtonUI();
1029
1062
  voice.start();
package/index.js CHANGED
@@ -1855,7 +1855,7 @@ const INJECT_MENU = [
1855
1855
 
1856
1856
  function runInjectCommand(cmd, extraArgs) {
1857
1857
  const modules = {
1858
- 'inject-minimax': './inject-minimax',
1858
+ 'inject-minimax': './injects/inject-minimax',
1859
1859
  'inject-zai': './inject-zai',
1860
1860
  'inject-claude': './inject-claude',
1861
1861
  'inject-image': './inject-image',
@@ -2629,7 +2629,7 @@ function showHelp() {
2629
2629
  console.log(' patch 注入 MyClaw UI + 技能 + 智能体 + 配置');
2630
2630
  console.log(' unpatch 回滚 UI 注入(恢复原版)');
2631
2631
  console.log(' inject 交互选择要执行的注入脚本');
2632
- console.log(' inject-minimax 注入 MiniMax 模型配置 (可选: --key sk-xxx, -f 强制清理其他模型)');
2632
+ console.log(' inject-minimax 注入 MiniMax M3.1 Flash(--default 替换为全局唯一聊天模型,思考深度 max)');
2633
2633
  console.log(' inject-claude 注入 B.AI 多模型配置 (Claude/GPT/Gemini,仅追加)');
2634
2634
  console.log(' inject-image 注入图像生成模型配置 (基于 vveai)');
2635
2635
  console.log(' inject-token 设置 Gateway Token 为 aiyiran');
@@ -2843,7 +2843,7 @@ if (!command) {
2843
2843
  console.log('[2/4] mc patch — 注入 UI + 技能');
2844
2844
  runPatchFresh();
2845
2845
  console.log('');
2846
- console.log('[2.5/4] inject-minimax --default — 注入 MiniMax 模型并设为默认');
2846
+ console.log('[2.5/4] inject-minimax --default — 将 MiniMax 设为唯一聊天模型');
2847
2847
  try {
2848
2848
  const minimax = require('./injects/inject-minimax');
2849
2849
  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
+ * 凭据按下面的逻辑优先使用。max 思考深度来自 MiniMax API 对 adaptive 请求的默认行为。
7
10
  *
8
11
  * 用法:
9
- * myclaw inject-minimax # 仅追加 minimax provider,不改默认,副作用最小
10
- * myclaw inject-minimax --default # 追加 + 设为默认 + 全部对话迁移到 MiniMax-M3
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
- * * - 独占清理时保留 minimax provider,默认模型仍为 minimax
21
+ * - 独占清理时保留 minimax provider,默认模型仍为 minimax
19
22
  */
20
23
 
21
24
  const fs = require('fs');
@@ -26,7 +29,31 @@ 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 DEFAULT_MODEL = "minimax/MiniMax-M2.7-highspeed";
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
+ }
30
57
 
31
58
  function run(cliArgs) {
32
59
  // ── 解析参数 ──
@@ -51,11 +78,6 @@ function run(cliArgs) {
51
78
  }
52
79
  }
53
80
 
54
- if (!apiKey) {
55
- apiKey = DEFAULT_MINIMAX_KEY;
56
- console.log('💡 未传入 --key,使用默认 API Key');
57
- }
58
-
59
81
  // ── 读取配置 ──
60
82
  let config, configPath;
61
83
  try {
@@ -65,6 +87,11 @@ function run(cliArgs) {
65
87
  process.exit(1);
66
88
  }
67
89
 
90
+ const configuredKey = config.models?.providers?.minimax?.apiKey;
91
+ const existingKey = typeof configuredKey === 'string' && !configuredKey.startsWith('$')
92
+ ? configuredKey : undefined;
93
+ apiKey ||= process.env.MINIMAX_API_KEY || existingKey;
94
+
68
95
  console.log('📍 找到配置: ' + configPath);
69
96
  console.log('📌 模式: ' + (betaMode ? '--beta (独占+6.X兼容)' : onlyMode ? '--only (独占)' : setDefault ? '--default (设默认)' : '追加'));
70
97
 
@@ -119,87 +146,82 @@ function run(cliArgs) {
119
146
  const minimaxProvider = {
120
147
  baseUrl: "https://api.minimaxi.com/anthropic",
121
148
  api: "anthropic-messages",
122
- models: [
123
- {
124
- id: "MiniMax-M3",
125
- name: "MiniMax M3",
126
- reasoning: true,
127
- input: ["text"],
128
- cost: { input: 0.3, output: 1.2, cacheRead: 0.06, cacheWrite: 0.375 },
129
- contextWindow: 204800,
130
- maxTokens: 131072
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
- ]
149
+ models: [{
150
+ id: MODEL_ID,
151
+ name: "MiniMax M3.1 Flash",
152
+ reasoning: true,
153
+ input: ["text", "image"],
154
+ cost: { input: 0.15, output: 0.60, cacheRead: 0.015, cacheWrite: 0 },
155
+ contextWindow: 1000000,
156
+ maxTokens: OUTPUT_BUDGET
157
+ }]
142
158
  };
143
- if (!betaMode) minimaxProvider.authHeader = true;
159
+ if (existingKey) minimaxProvider.apiKey = apiKey;
160
+ if (!setDefault) minimaxProvider.authHeader = true;
144
161
  config.models.providers.minimax = minimaxProvider;
145
162
 
146
163
  if (!config.agents) config.agents = {};
147
164
  if (!config.agents.defaults) config.agents.defaults = {};
148
165
  if (!config.agents.defaults.models) config.agents.defaults.models = {};
149
166
 
150
- // 清理 onboard 残留的无 -highspeed 版本
151
- delete config.agents.defaults.models["minimax/MiniMax-M2.7"];
152
- // 白名单:M3 + M2.7-highspeed
153
- config.agents.defaults.models["minimax/MiniMax-M3"] = {};
154
- config.agents.defaults.models["minimax/MiniMax-M2.7-highspeed"] = {};
167
+ const defaults = config.agents.defaults;
168
+ for (const model of Object.keys(defaults.models)) {
169
+ if (model !== DEFAULT_MODEL && (setDefault || isMiniMaxModel(model))) delete defaults.models[model];
170
+ }
171
+
172
+ // OpenClaw 2026.6.9 uses the MiniMax API's default max effort for adaptive thinking.
173
+ const modelConfig = defaults.models[DEFAULT_MODEL] || {};
174
+ defaults.models[DEFAULT_MODEL] = {
175
+ ...modelConfig,
176
+ params: { ...modelConfig.params, thinking: 'adaptive', maxTokens: OUTPUT_BUDGET }
177
+ };
155
178
 
156
- // ── Step 3:--default 设默认模型 ──
157
179
  if (setDefault) {
158
- config.agents.defaults.model = { primary: DEFAULT_MODEL };
180
+ defaults.model = { primary: DEFAULT_MODEL };
159
181
  console.log('⚡ 默认模型 → ' + DEFAULT_MODEL);
160
- } else {
161
- console.log('⊘ 未传 --default,保留现有默认模型');
182
+ } else if (defaults.model) {
183
+ defaults.model = migrateModelSelection(defaults.model);
162
184
  }
163
185
 
164
- // ── --only 额外清除 per-agent 覆盖 ──
165
- if (onlyMode) {
166
- let overrideCount = 0;
167
- for (const agent of (config.agents.list || [])) {
168
- if (agent.model && agent.model !== DEFAULT_MODEL) {
169
- delete agent.model;
170
- overrideCount++;
171
- }
186
+ for (const agent of config.agents.list || []) {
187
+ if (setDefault) {
188
+ delete agent.model;
189
+ if (agent.subagents) delete agent.subagents.model;
190
+ if (agent.heartbeat) delete agent.heartbeat.model;
191
+ } else if (agent.model) {
192
+ agent.model = migrateModelSelection(agent.model);
193
+ }
194
+ }
195
+ if (setDefault) {
196
+ for (const feature of [defaults.subagents, defaults.heartbeat, defaults.compaction]) {
197
+ if (feature) delete feature.model;
172
198
  }
173
- if (overrideCount > 0) console.log('🧹 --only: 已清除 ' + overrideCount + ' 个 agent 的独立 model 覆盖');
174
199
  }
175
-
176
- writeConfig(config, configPath);
177
- console.log('✅ openclaw.json 已更新');
178
200
 
179
201
  // ── Step 4:为所有 agent 写入 API Key ──
180
202
  console.log('');
181
203
  console.log('🔑 [Step 4] 写入 API Key 到所有 agent...');
182
204
 
183
- const DEFAULT_MAIN_DIR = path.join(os.homedir(), '.openclaw', 'agents', 'main', 'agent');
205
+ const stateDir = process.env.OPENCLAW_STATE_DIR || path.dirname(configPath);
206
+ const DEFAULT_MAIN_DIR = path.join(stateDir, 'agents', 'main', 'agent');
184
207
  const agentList = (config.agents && config.agents.list) || [];
185
208
 
186
209
  const agentDirs = new Map();
187
210
  agentDirs.set(DEFAULT_MAIN_DIR, 'main');
188
211
  for (const agent of agentList) {
189
- if (agent.agentDir) agentDirs.set(agent.agentDir, agent.id);
212
+ const directory = agent.agentDir?.replace(/^~\//, os.homedir() + '/') ||
213
+ path.join(stateDir, 'agents', agent.id, 'agent');
214
+ agentDirs.set(directory, agent.id);
190
215
  }
191
216
 
192
- // 写入目标说明:
193
- // - auth-profiles.json:所有模式都写(5.X 鉴权源,6.X 仅作展示/审计,不参与运行时加载)
194
- // - openclaw-agent.sqlite:仅 --beta 写(6.X 运行时唯一的鉴权源)
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) {
217
+ // 6.X loads agent credentials from SQLite. Legacy clients use auth-profiles.json.
218
+ let DatabaseSync;
219
+ if (setDefault) {
200
220
  try {
201
221
  ({ DatabaseSync } = require('node:sqlite'));
202
- } catch { /* Node < 22,无内置 sqlite */ }
222
+ } catch (err) {
223
+ if (err.code !== 'ERR_UNKNOWN_BUILTIN_MODULE') throw err;
224
+ }
203
225
  }
204
226
 
205
227
  const SQLITE_SCHEMA = `
@@ -210,102 +232,100 @@ CREATE TABLE IF NOT EXISTS auth_profile_state (
210
232
  state_key TEXT NOT NULL PRIMARY KEY, state_json TEXT NOT NULL, updated_at INTEGER NOT NULL
211
233
  );`;
212
234
 
213
- const sqliteStorePayload = { version: 1, profiles: { "minimax:cn": { type: "api_key", provider: "minimax", key: apiKey } } };
214
- const sqliteStatePayload = { lastGood: { "minimax": "minimax:cn" } };
215
-
216
- let okCount = 0, skipCount = 0;
235
+ let okCount = 0;
236
+ const profileId = 'minimax:cn';
217
237
 
218
238
  for (const [agentDir, agentId] of agentDirs) {
219
- if (!fs.existsSync(agentDir)) {
220
- try { fs.mkdirSync(agentDir, { recursive: true }); } catch { /* ignore */ }
221
- }
222
-
223
- // ── 5.X:始终写 auth-profiles.json(兼容旧版) ──
239
+ fs.mkdirSync(agentDir, { recursive: true });
224
240
  const profilesPath = path.join(agentDir, 'auth-profiles.json');
225
- let profiles = { version: 1, profiles: {}, lastGood: {} };
226
- if (fs.existsSync(profilesPath)) {
241
+ const profiles = fs.existsSync(profilesPath)
242
+ ? JSON.parse(fs.readFileSync(profilesPath, 'utf8'))
243
+ : { version: 1, profiles: {}, lastGood: {} };
244
+ profiles.profiles ||= {};
245
+ profiles.lastGood ||= {};
246
+ let key = apiKey || profiles.profiles[profileId]?.key;
247
+
248
+ if (DatabaseSync) {
249
+ const db = new DatabaseSync(path.join(agentDir, 'openclaw-agent.sqlite'));
227
250
  try {
228
- const parsed = JSON.parse(fs.readFileSync(profilesPath, 'utf8'));
229
- if (parsed.profiles) profiles = parsed;
230
- if (!profiles.lastGood) profiles.lastGood = {};
231
- } catch { /* 解析失败用空骨架 */ }
232
- }
233
- profiles.profiles["minimax:cn"] = { type: "api_key", provider: "minimax", key: apiKey };
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');
246
- try {
247
- const db = new DatabaseSync(dbPath);
248
- db.exec('PRAGMA journal_mode = WAL;');
251
+ db.exec('PRAGMA busy_timeout = 5000;');
249
252
  db.exec(SQLITE_SCHEMA);
253
+ db.exec('BEGIN IMMEDIATE');
254
+ const storeRow = db.prepare('SELECT store_json FROM auth_profile_store WHERE store_key = ?').get('primary');
255
+ const stateRow = db.prepare('SELECT state_json FROM auth_profile_state WHERE state_key = ?').get('primary');
256
+ const store = storeRow ? JSON.parse(storeRow.store_json) : { version: 1, profiles: {} };
257
+ const state = stateRow ? JSON.parse(stateRow.state_json) : {};
258
+ store.profiles ||= {};
259
+ state.lastGood ||= {};
260
+ const prior = store.profiles[state.lastGood.minimax] || store.profiles[profileId];
261
+ key = apiKey || prior?.key || key || DEFAULT_MINIMAX_KEY;
262
+ store.profiles[profileId] = { type: 'api_key', provider: PROVIDER_ID, key };
263
+ state.lastGood.minimax = profileId;
250
264
  const now = Date.now();
251
265
  db.prepare('INSERT OR REPLACE INTO auth_profile_store (store_key, store_json, updated_at) VALUES (?,?,?)')
252
- .run('primary', JSON.stringify(sqliteStorePayload), now);
266
+ .run('primary', JSON.stringify(store), now);
253
267
  db.prepare('INSERT OR REPLACE INTO auth_profile_state (state_key, state_json, updated_at) VALUES (?,?,?)')
254
- .run('primary', JSON.stringify(sqliteStatePayload), now);
268
+ .run('primary', JSON.stringify(state), now);
269
+ db.exec('COMMIT');
270
+ } finally {
255
271
  db.close();
256
- sqliteOk = true;
257
- } catch (err) {
258
- console.log(' ⚠ ' + agentId + ' (sqlite): ' + err.message);
259
272
  }
260
273
  }
261
274
 
262
- try {
263
- console.log(' ✅ ' + agentId + (sqliteOk ? ' (json+sqlite)' : ' (json)'));
264
- okCount++;
265
- } catch (err) {
266
- console.log(' ⚠ ' + agentId + ': ' + err.message);
267
- skipCount++;
268
- }
275
+ profiles.profiles[profileId] = { type: 'api_key', provider: PROVIDER_ID, key: key || DEFAULT_MINIMAX_KEY };
276
+ profiles.lastGood.minimax = profileId;
277
+ fs.writeFileSync(profilesPath, JSON.stringify(profiles, null, 2) + '\n', { mode: 0o600 });
278
+ console.log(' ✅ ' + agentId + (DatabaseSync ? ' (json+sqlite)' : ' (json)'));
279
+ okCount++;
269
280
  }
270
281
 
271
- // ── Step 5:--default / --only 迁移全部对话 ──
272
- if (setDefault) {
273
- console.log('');
274
- console.log('🔄 [Step 5] 迁移全部对话 → ' + DEFAULT_MODEL + ' ...');
275
- let sessionOk = 0, sessionSkip = 0, sessionChanged = 0;
282
+ writeConfig(config, configPath);
283
+ console.log('✅ openclaw.json 已更新');
276
284
 
277
- for (const [agentDir] of agentDirs) {
278
- const sessionsPath = path.join(agentDir, '..', 'sessions', 'sessions.json');
279
- if (!fs.existsSync(sessionsPath)) continue;
280
- try {
281
- const sessions = JSON.parse(fs.readFileSync(sessionsPath, 'utf8'));
282
- let changed = 0;
283
- for (const key of Object.keys(sessions)) {
284
- const m = sessions[key]?.model;
285
- if (!m) continue;
286
- // 修复无前缀的旧格式残留
287
- if (m === 'MiniMax-M2.7-highspeed') { sessions[key].model = 'minimax/MiniMax-M3'; changed++; continue; }
288
- // 统一迁移到新默认
289
- if (m !== DEFAULT_MODEL) { sessions[key].model = DEFAULT_MODEL; changed++; }
285
+ // ── Step 5:迁移旧 MiniMax 会话,设默认模式沿用全部会话迁移 ──
286
+ let sessionOk = 0, sessionSkip = 0, sessionChanged = 0;
287
+
288
+ for (const [agentDir] of agentDirs) {
289
+ const sessionsPath = path.join(agentDir, '..', 'sessions', 'sessions.json');
290
+ if (!fs.existsSync(sessionsPath)) continue;
291
+ try {
292
+ const sessions = JSON.parse(fs.readFileSync(sessionsPath, 'utf8'));
293
+ let changed = 0;
294
+ for (const session of Object.values(sessions)) {
295
+ if (!session) continue;
296
+ let updated = false;
297
+ if (session.model && (setDefault || isMiniMaxModel(session.model, session.modelProvider)) &&
298
+ (session.model !== MODEL_ID || session.modelProvider !== PROVIDER_ID)) {
299
+ session.model = MODEL_ID;
300
+ session.modelProvider = PROVIDER_ID;
301
+ updated = true;
290
302
  }
291
- if (changed > 0) {
292
- fs.writeFileSync(sessionsPath, JSON.stringify(sessions, null, 2) + '\n', 'utf8');
293
- sessionChanged += changed;
303
+ if (session.modelOverride &&
304
+ (setDefault || isMiniMaxModel(session.modelOverride, session.providerOverride)) &&
305
+ (session.modelOverride !== MODEL_ID || session.providerOverride !== PROVIDER_ID)) {
306
+ session.modelOverride = MODEL_ID;
307
+ session.providerOverride = PROVIDER_ID;
308
+ updated = true;
294
309
  }
295
- sessionOk++;
296
- } catch {
297
- sessionSkip++;
310
+ if (updated) changed++;
311
+ }
312
+ if (changed > 0) {
313
+ fs.writeFileSync(sessionsPath, JSON.stringify(sessions, null, 2) + '\n', 'utf8');
314
+ sessionChanged += changed;
298
315
  }
316
+ sessionOk++;
317
+ } catch {
318
+ sessionSkip++;
299
319
  }
300
- console.log(' 对话迁移: ' + sessionChanged + ' 条,文件: ' + sessionOk + ' 个,跳过: ' + sessionSkip + ' 个');
301
320
  }
321
+ console.log(' 对话迁移: ' + sessionChanged + ' 条,文件: ' + sessionOk + ' 个,跳过: ' + sessionSkip + ' 个');
302
322
 
303
323
  // ── 汇总 ──
304
324
  console.log('');
305
325
  console.log('✅ MiniMax 注入完成');
306
- console.log(' 默认模型: ' + (setDefault ? DEFAULT_MODEL : '(未修改)'));
307
- console.log(' 备选模型: minimax/MiniMax-M2.7-highspeed');
308
- console.log(' Agent: ' + okCount + ' 个写入,' + skipCount + ' 个跳过');
326
+ console.log(' MiniMax: ' + DEFAULT_MODEL + ' (adaptive / max)');
327
+ if (setDefault) console.log(' 全局唯一聊天模型: ' + DEFAULT_MODEL);
328
+ console.log(' Agent: ' + okCount + ' 个写入');
309
329
  if (betaMode) console.log(' 其他 provider 已清除 (保留 minimax)');
310
330
  else if (onlyMode) console.log(' 其他 provider 已清除');
311
331
  console.log('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.1.210",
3
+ "version": "1.1.212",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,33 +1,16 @@
1
1
  ---
2
2
  name: minimax-inject
3
- description: 将 OpenClaw 的模型配置替换为 MiniMax M2.7,并可选设置 API Key。执行后自动重启 Gateway。
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
- # 只注入模型配置(API Key 使用环境变量 MINIMAX_API_KEY)
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
- ## 注入内容
21
-
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 |
12
+ 该命令将 OpenClaw 的唯一可选聊天模型及全局默认设为 `minimax/MiniMax-M3.1-Flash`,生成预算为 131072 token。OpenClaw 2026.6.9 使用 adaptive thinking,思考深度由 MiniMax API 默认设为 max。命令在注入后重启 Gateway。
28
13
 
29
- ## 执行后
14
+ 模型、生成预算、API 地址和内置备用凭据由 myclaw 自己维护。插件运行不依赖开发者电脑的全局模型配置。可以在目标机器上复用已有凭据,也可以通过 `MINIMAX_API_KEY` 提供凭据。
30
15
 
31
- - 自动修改 `~/.openclaw/openclaw.json`
32
- - 自动重启 Gateway 使配置生效
33
- - 如果传了 `--key`,会将 MINIMAX_API_KEY 写入 shell 配置文件
16
+ 兼容入口 `node scripts/inject.js` 调用同一条命令。