@aiyiran/myclaw 1.0.52 → 1.0.54

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/index.js CHANGED
@@ -681,28 +681,35 @@ function runUpdate() {
681
681
  console.log('正在执行全量强制升级 (绕过缓存)...');
682
682
  console.log('');
683
683
 
684
- try {
685
- const { execSync } = require('child_process');
686
- // 第一步:清空缓存,防患于未然
687
- console.log('> ' + colors.yellow + 'npm cache clean --force' + colors.nc);
688
- execSync('npm cache clean --force', { stdio: 'inherit' });
689
- console.log('');
690
-
691
- // 第二步:强制拉最新版本
692
- console.log('> ' + colors.yellow + 'npm install -g @aiyiran/myclaw@latest --prefer-online' + colors.nc);
693
- execSync('npm install -g @aiyiran/myclaw@latest --prefer-online', { stdio: 'inherit' });
694
-
695
- console.log('');
696
- console.log('[' + colors.green + '成功' + colors.nc + '] MyClaw 升级完成!');
697
-
698
- if (detectPlatform() === 'wsl' || detectPlatform() === 'linux' || detectPlatform() === 'mac') {
684
+ const { execSync } = require('child_process');
685
+ const cmd = 'npm install -g @aiyiran/myclaw@latest --prefer-online';
686
+ const maxRetries = 3;
687
+
688
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
689
+ try {
690
+ console.log('> ' + colors.yellow + cmd + colors.nc);
691
+ if (attempt > 1) console.log(' (第 ' + attempt + ' 次尝试)');
692
+ execSync(cmd, { stdio: 'inherit' });
693
+
699
694
  console.log('');
700
- console.log('如果需要同时升级 OpenClaw 核心,请运行:');
701
- console.log(' ' + colors.yellow + 'myclaw install' + colors.nc);
695
+ console.log('[' + colors.green + '成功' + colors.nc + '] MyClaw 升级完成!');
696
+
697
+ if (detectPlatform() === 'wsl' || detectPlatform() === 'linux' || detectPlatform() === 'mac') {
698
+ console.log('');
699
+ console.log('如果需要同时升级 OpenClaw 核心,请运行:');
700
+ console.log(' ' + colors.yellow + 'myclaw install' + colors.nc);
701
+ }
702
+ break; // 成功就跳出
703
+ } catch (err) {
704
+ if (attempt < maxRetries) {
705
+ console.log('');
706
+ console.log('[' + colors.yellow + '重试' + colors.nc + '] 5 秒后重试 (' + attempt + '/' + maxRetries + ')...');
707
+ execSync('sleep 5', { stdio: 'ignore' });
708
+ } else {
709
+ console.log('');
710
+ console.log('[' + colors.red + '错误' + colors.nc + '] 升级失败: ' + err.message);
711
+ }
702
712
  }
703
- } catch (err) {
704
- console.log('');
705
- console.log('[' + colors.red + '错误' + colors.nc + '] 升级失败: ' + err.message);
706
713
  }
707
714
  console.log('');
708
715
  }
package/inject-minimax.js CHANGED
@@ -5,6 +5,7 @@
5
5
  *
6
6
  * 将 openclaw.json 中的模型配置清空,注入为唯一的 MiniMax 模型。
7
7
  * 自动查找 ~/.openclaw/openclaw.json
8
+ * API Key 通过 openclaw onboard 管理,不写环境变量。
8
9
  *
9
10
  * 入口: myclaw minimax [--key sk-xxx]
10
11
  */
@@ -49,7 +50,7 @@ function run(cliArgs) {
49
50
  }
50
51
  };
51
52
 
52
- // 2. models.providers → 只保留 minimax
53
+ // 2. models.providers → 只保留 minimax(key 由 onboard 管理)
53
54
  config.models = {
54
55
  mode: "merge",
55
56
  providers: {
@@ -57,9 +58,6 @@ function run(cliArgs) {
57
58
  baseUrl: "https://api.minimaxi.com/anthropic",
58
59
  api: "anthropic-messages",
59
60
  authHeader: true,
60
- headers: {
61
- "Authorization": "Bearer ${env:MINIMAX_API_KEY}"
62
- },
63
61
  models: [
64
62
  {
65
63
  id: "MiniMax-M2.7",
@@ -97,8 +95,7 @@ function run(cliArgs) {
97
95
  };
98
96
 
99
97
  // 写回文件
100
- const output = JSON.stringify(config, null, 2) + '\n';
101
- fs.writeFileSync(targetPath, output, 'utf8');
98
+ fs.writeFileSync(targetPath, JSON.stringify(config, null, 2) + '\n', 'utf8');
102
99
 
103
100
  console.log('✅ MiniMax 模型配置已注入');
104
101
  console.log('');
@@ -106,56 +103,28 @@ function run(cliArgs) {
106
103
  console.log(' models.providers → minimax (MiniMax-M2.7)');
107
104
  console.log(' agents.defaults → minimax/MiniMax-M2.7-highspeed');
108
105
 
109
- // 4. 如果传了 --key,写入环境变量
106
+ // 4. 通过 openclaw onboard 设置 API Key
110
107
  if (apiKey) {
111
108
  console.log('');
112
- console.log('🔑 设置 MINIMAX_API_KEY 环境变量...');
113
-
114
- const platform = os.platform();
115
-
116
- if (platform === 'win32') {
117
- try {
118
- const { execSync } = require('child_process');
119
- execSync('setx MINIMAX_API_KEY "' + apiKey + '"', { stdio: 'pipe' });
120
- console.log(' 已通过 setx 写入 Windows 用户环境变量');
121
- } catch (err) {
122
- console.log(' setx 写入失败: ' + err.message);
123
- }
124
- } else {
125
- const shell = process.env.SHELL || '/bin/bash';
126
- let rcFiles = [];
127
- if (shell.includes('zsh')) {
128
- rcFiles = [path.join(os.homedir(), '.zshrc')];
129
- } else {
130
- rcFiles = [path.join(os.homedir(), '.bashrc')];
131
- }
132
- const profilePath = path.join(os.homedir(), '.profile');
133
- if (fs.existsSync(profilePath) && !rcFiles.includes(profilePath)) {
134
- rcFiles.push(profilePath);
135
- }
136
-
137
- const exportLine = 'export MINIMAX_API_KEY="' + apiKey + '"';
138
-
139
- for (const rcFile of rcFiles) {
140
- let content = '';
141
- try { content = fs.readFileSync(rcFile, 'utf8'); } catch {}
142
-
143
- if (content.includes('MINIMAX_API_KEY')) {
144
- content = content.replace(/^export MINIMAX_API_KEY=.*$/m, exportLine);
145
- fs.writeFileSync(rcFile, content, 'utf8');
146
- console.log(' ✅ 已更新: ' + rcFile);
147
- } else {
148
- fs.appendFileSync(rcFile, '\n# MiniMax API Key (by myclaw minimax)\n' + exportLine + '\n');
149
- console.log(' ✅ 已追加: ' + rcFile);
150
- }
151
- }
152
-
153
- process.env.MINIMAX_API_KEY = apiKey;
154
- console.log(' ✅ 当前进程已设置 MINIMAX_API_KEY');
109
+ console.log('🔑 执行 openclaw onboard (设置 API Key)...');
110
+ try {
111
+ const { execSync } = require('child_process');
112
+ execSync([
113
+ 'openclaw onboard',
114
+ '--non-interactive',
115
+ '--accept-risk',
116
+ '--skip-health',
117
+ '--auth-choice minimax-cn-api',
118
+ '--token "' + apiKey + '"',
119
+ '--minimax-api-key "' + apiKey + '"',
120
+ ].join(' '), { stdio: 'inherit' });
121
+ console.log('✅ API Key 已通过 onboard 设置');
122
+ } catch (err) {
123
+ console.log('⚠️ onboard 失败: ' + err.message);
155
124
  }
156
125
  } else {
157
126
  console.log('');
158
- console.log('💡 未传入 --keyAPI Key 将使用环境变量 MINIMAX_API_KEY');
127
+ console.log('💡 未传入 --key,跳过 API Key 设置');
159
128
  console.log(' 设置方法: myclaw minimax --key sk-xxx');
160
129
  }
161
130
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.52",
3
+ "version": "1.0.54",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -7,8 +7,8 @@
7
7
  * OpenClaw agent 可直接调用此脚本。
8
8
  *
9
9
  * 用法:
10
- * node inject.js # 注入模型配置
11
- * node inject.js --key sk-xxx # 注入模型 + 设置 API Key
10
+ * node inject.js # 只注入模型配置(不设 key)
11
+ * node inject.js --key sk-xxx # 注入模型 + 通过 onboard 设置 key
12
12
  */
13
13
 
14
14
  const fs = require('fs');
@@ -65,9 +65,6 @@ config.models = {
65
65
  baseUrl: "https://api.minimaxi.com/anthropic",
66
66
  api: "anthropic-messages",
67
67
  authHeader: true,
68
- headers: {
69
- "Authorization": "Bearer ${env:MINIMAX_API_KEY}"
70
- },
71
68
  models: [
72
69
  {
73
70
  id: "MiniMax-M2.7",
@@ -111,50 +108,34 @@ console.log(' models.providers → minimax (MiniMax-M2.7)');
111
108
  console.log(' agents.defaults → minimax/MiniMax-M2.7-highspeed');
112
109
 
113
110
  // ============================================================================
114
- // 设置 API Key(如果传了 --key)
111
+ // 通过 openclaw onboard 设置 API Key
115
112
  // ============================================================================
116
113
 
117
114
  if (apiKey) {
118
115
  console.log('');
119
- console.log('🔑 设置 MINIMAX_API_KEY...');
120
-
121
- if (os.platform() === 'win32') {
122
- try {
123
- execSync('setx MINIMAX_API_KEY "' + apiKey + '"', { stdio: 'pipe' });
124
- console.log(' ✅ 已写入 Windows 用户环境变量');
125
- } catch (err) {
126
- console.log(' setx 失败: ' + err.message);
127
- }
128
- } else {
129
- const shell = process.env.SHELL || '/bin/bash';
130
- const rcFile = shell.includes('zsh')
131
- ? path.join(os.homedir(), '.zshrc')
132
- : path.join(os.homedir(), '.bashrc');
133
-
134
- const exportLine = 'export MINIMAX_API_KEY="' + apiKey + '"';
135
- let content = '';
136
- try { content = fs.readFileSync(rcFile, 'utf8'); } catch {}
137
-
138
- if (content.includes('MINIMAX_API_KEY')) {
139
- content = content.replace(/^export MINIMAX_API_KEY=.*$/m, exportLine);
140
- fs.writeFileSync(rcFile, content, 'utf8');
141
- console.log(' ✅ 已更新: ' + rcFile);
142
- } else {
143
- fs.appendFileSync(rcFile, '\n# MiniMax API Key\n' + exportLine + '\n');
144
- console.log(' ✅ 已追加: ' + rcFile);
145
- }
146
-
147
- // 同时设到当前进程,确保重启的 gateway 能继承
148
- process.env.MINIMAX_API_KEY = apiKey;
149
- console.log(' ✅ 当前进程已设置');
116
+ console.log('🔑 执行 openclaw onboard (设置 API Key)...');
117
+ try {
118
+ execSync([
119
+ 'openclaw onboard',
120
+ '--non-interactive',
121
+ '--accept-risk',
122
+ '--skip-health',
123
+ '--auth-choice minimax-cn-api',
124
+ '--token "' + apiKey + '"',
125
+ '--minimax-api-key "' + apiKey + '"',
126
+ ].join(' '), { stdio: 'inherit' });
127
+ console.log('✅ API Key 已通过 onboard 设置');
128
+ } catch (err) {
129
+ console.log('⚠️ onboard 失败: ' + err.message);
150
130
  }
151
131
  } else {
152
132
  console.log('');
153
- console.log('💡 未传入 --key,将使用环境变量 MINIMAX_API_KEY');
133
+ console.log('💡 未传入 --key,跳过 API Key 设置');
134
+ console.log(' 设置方法: node inject.js --key sk-xxx');
154
135
  }
155
136
 
156
137
  // ============================================================================
157
- // 重启 Gateway(不依赖 myclaw)
138
+ // 重启 Gateway
158
139
  // ============================================================================
159
140
 
160
141
  console.log('');