@aiyiran/myclaw 1.1.5 → 1.1.6

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/gateway.js CHANGED
@@ -143,9 +143,8 @@ function start() {
143
143
  // 等待启动完成
144
144
  execSync(isWin ? 'timeout /t 3 /nobreak >nul' : 'sleep 3', { stdio: 'ignore' });
145
145
 
146
- // 注册守卫(仅非 Docker 环境)
147
- const isDocker = require('fs').existsSync('/.dockerenv');
148
- if (!isWin && !isDocker) {
146
+ // 注册守卫(崩溃自动重启、开机自启)
147
+ if (!isWin) {
149
148
  try {
150
149
  execSync('openclaw gateway install', { stdio: 'pipe', timeout: 10000 });
151
150
  console.log('[守卫] ' + colors.green + 'LaunchAgent 已注册,崩溃/重启会自动拉起' + colors.nc);
@@ -2,20 +2,23 @@
2
2
 
3
3
  /**
4
4
  * inject-minimax.js
5
- *
6
- * 注入 MiniMax 模型配置到 openclaw.json。
7
- *
8
- * 仅做以下事情:
9
- * 1. 设置 minimax auth profile
10
- * 2. 注册 minimax provider + 模型定义
11
- * 3. 设置默认聊天模型为 MiniMax
12
- * 4. 将 MiniMax 模型加入白名单
13
- *
5
+ *
6
+ * 注入 MiniMax 模型配置到 openclaw.json,并为所有 agent 写入 API Key
7
+ *
8
+ * 做以下事情:
9
+ * 1. 设置 minimax auth profile (openclaw.json)
10
+ * 2. 注册 minimax provider + 模型定义 (openclaw.json)
11
+ * 3. 设置默认聊天模型为 MiniMax (openclaw.json)
12
+ * 4. 将 MiniMax 模型加入白名单 (openclaw.json)
13
+ * 5. 为所有 agent 写入 API Key (~/.openclaw/agents/<id>/agent/auth-profiles.json)
14
+ *
14
15
  * 不触碰: 图片模型、其他 provider、onboard 流程
15
- *
16
- * 入口: myclaw minimax [--key sk-xxx]
16
+ *
17
+ * 入口: myclaw inject-minimax [--key sk-xxx]
17
18
  */
18
19
 
20
+ const fs = require('fs');
21
+ const path = require('path');
19
22
  const { readConfig, writeConfig } = require('../find-config');
20
23
 
21
24
  const DEFAULT_MINIMAX_KEY = "sk-cp-DC5lWd2Stt9CBFzLIT2awP4K-ZEn5AkYwjl3Cdj-mIBmgjxod518F2LaVF2L9c35Wv5-Eox0F1ctJD5vXtB9p3OmxoWLd9ge9zIUIMrCVuqBYdL_s6kb8Qs";
@@ -30,24 +33,23 @@ function run(cliArgs) {
30
33
  }
31
34
  }
32
35
 
33
- if (!apiKey && DEFAULT_MINIMAX_KEY) {
36
+ if (!apiKey) {
34
37
  apiKey = DEFAULT_MINIMAX_KEY;
35
38
  console.log('💡 未传入 --key 参数,使用默认 API Key');
36
39
  }
37
40
 
38
41
  // 读取配置
39
- let configPath;
42
+ let config, configPath;
40
43
  try {
41
- ({ configPath } = readConfig());
44
+ ({ config, configPath } = readConfig());
42
45
  } catch (err) {
43
46
  console.error('❌ ' + err.message);
44
47
  process.exit(1);
45
48
  }
46
49
 
47
50
  console.log('📍 找到配置: ' + configPath);
48
- const { config } = readConfig();
49
51
 
50
- // ─── 1. auth profile ───
52
+ // ─── 1. auth profile (openclaw.json) ───
51
53
  if (!config.auth) config.auth = {};
52
54
  if (!config.auth.profiles) config.auth.profiles = {};
53
55
  config.auth.profiles["minimax:cn"] = {
@@ -98,17 +100,64 @@ function run(cliArgs) {
98
100
  delete config.agents.defaults.models["minimax/MiniMax-M2.7"];
99
101
  }
100
102
 
101
- // ─── 写入 ───
103
+ // ─── 写入 openclaw.json ───
102
104
  writeConfig(config, configPath);
105
+ console.log('✅ openclaw.json 已更新');
106
+
107
+ // ─── 5. 为所有 agent 写入 auth-profiles.json ───
108
+ const agentList = (config.agents && config.agents.list) || [];
109
+ let okCount = 0;
110
+ let skipCount = 0;
111
+
112
+ for (const agent of agentList) {
113
+ const agentDir = agent.agentDir;
114
+ if (!agentDir) {
115
+ skipCount++;
116
+ continue;
117
+ }
118
+
119
+ const profilesPath = path.join(agentDir, 'auth-profiles.json');
120
+
121
+ // 读取现有文件(若存在),否则创建骨架
122
+ let profiles = { version: 1, profiles: {}, lastGood: {} };
123
+ if (fs.existsSync(profilesPath)) {
124
+ try {
125
+ profiles = JSON.parse(fs.readFileSync(profilesPath, 'utf8'));
126
+ if (!profiles.profiles) profiles.profiles = {};
127
+ if (!profiles.lastGood) profiles.lastGood = {};
128
+ } catch {
129
+ // 解析失败则重建
130
+ profiles = { version: 1, profiles: {}, lastGood: {} };
131
+ }
132
+ }
103
133
 
104
- // 验证
105
- const verify = readConfig();
106
- const writtenModelId = verify.config.models?.providers?.minimax?.models?.[0]?.id || '???';
107
- const writtenDefault = verify.config.agents?.defaults?.model?.primary || '???';
134
+ // 写入 minimax:cn,保留其他 profile 不动
135
+ profiles.profiles["minimax:cn"] = {
136
+ type: "api_key",
137
+ provider: "minimax",
138
+ key: apiKey
139
+ };
140
+ profiles.lastGood["minimax"] = "minimax:cn";
141
+
142
+ try {
143
+ // 确保目录存在
144
+ if (!fs.existsSync(agentDir)) {
145
+ fs.mkdirSync(agentDir, { recursive: true });
146
+ }
147
+ fs.writeFileSync(profilesPath, JSON.stringify(profiles, null, 2) + '\n', 'utf8');
148
+ console.log(' ✅ ' + agent.id);
149
+ okCount++;
150
+ } catch (err) {
151
+ console.log(' ⚠ ' + agent.id + ': ' + err.message);
152
+ skipCount++;
153
+ }
154
+ }
108
155
 
156
+ console.log('');
109
157
  console.log('✅ MiniMax 配置已注入');
110
- console.log(' 模型: ' + writtenModelId);
111
- console.log(' 默认: ' + writtenDefault);
158
+ console.log(' 模型: MiniMax-M2.7-highspeed');
159
+ console.log(' 默认: minimax/MiniMax-M2.7-highspeed');
160
+ console.log(' Agent: ' + okCount + ' 个写入成功,' + skipCount + ' 个跳过');
112
161
  console.log('');
113
162
  }
114
163
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {