@aiyiran/myclaw 1.1.132 → 1.1.134

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.
@@ -179,9 +179,38 @@ function run(cliArgs) {
179
179
  if (agent.agentDir) agentDirs.set(agent.agentDir, agent.id);
180
180
  }
181
181
 
182
+ // 写入目标说明:
183
+ // - auth-profiles.json:所有模式都写(5.X 鉴权源,6.X 仅作展示/审计,不参与运行时加载)
184
+ // - openclaw-agent.sqlite:仅 --beta 写(6.X 运行时唯一的鉴权源)
185
+ // 6.X 运行时只从 SQLite 的 auth_profile_store 读 key,完全不读 auth-profiles.json,
186
+ // 因此 6.X 必须靠 --beta 写 SQLite 才能让 minimax 鉴权成功。
187
+ // 非 --beta 模式不碰 SQLite,避免覆盖其他 provider 已有的凭据。
188
+ let DatabaseSync = null;
189
+ if (betaMode) {
190
+ try {
191
+ ({ DatabaseSync } = require('node:sqlite'));
192
+ } catch { /* Node < 22,无内置 sqlite */ }
193
+ }
194
+
195
+ const SQLITE_SCHEMA = `
196
+ CREATE TABLE IF NOT EXISTS auth_profile_store (
197
+ store_key TEXT NOT NULL PRIMARY KEY, store_json TEXT NOT NULL, updated_at INTEGER NOT NULL
198
+ );
199
+ CREATE TABLE IF NOT EXISTS auth_profile_state (
200
+ state_key TEXT NOT NULL PRIMARY KEY, state_json TEXT NOT NULL, updated_at INTEGER NOT NULL
201
+ );`;
202
+
203
+ const sqliteStorePayload = { version: 1, profiles: { "minimax:cn": { type: "api_key", provider: "minimax", key: apiKey } } };
204
+ const sqliteStatePayload = { lastGood: { "minimax": "minimax:cn" } };
205
+
182
206
  let okCount = 0, skipCount = 0;
183
207
 
184
208
  for (const [agentDir, agentId] of agentDirs) {
209
+ if (!fs.existsSync(agentDir)) {
210
+ try { fs.mkdirSync(agentDir, { recursive: true }); } catch { /* ignore */ }
211
+ }
212
+
213
+ // ── 5.X:始终写 auth-profiles.json(兼容旧版) ──
185
214
  const profilesPath = path.join(agentDir, 'auth-profiles.json');
186
215
  let profiles = { version: 1, profiles: {}, lastGood: {} };
187
216
  if (fs.existsSync(profilesPath)) {
@@ -191,14 +220,32 @@ function run(cliArgs) {
191
220
  if (!profiles.lastGood) profiles.lastGood = {};
192
221
  } catch { /* 解析失败用空骨架 */ }
193
222
  }
194
-
195
223
  profiles.profiles["minimax:cn"] = { type: "api_key", provider: "minimax", key: apiKey };
196
224
  profiles.lastGood["minimax"] = "minimax:cn";
225
+ try { fs.writeFileSync(profilesPath, JSON.stringify(profiles, null, 2) + '\n', 'utf8'); } catch { /* ignore */ }
226
+
227
+ // ── 6.X (--beta):写入 openclaw-agent.sqlite(运行时唯一鉴权源)──
228
+ let sqliteOk = false;
229
+ if (DatabaseSync) { // 仅 betaMode 下 DatabaseSync 才被赋值
230
+ const dbPath = path.join(agentDir, 'openclaw-agent.sqlite');
231
+ try {
232
+ const db = new DatabaseSync(dbPath);
233
+ db.exec('PRAGMA journal_mode = WAL;');
234
+ db.exec(SQLITE_SCHEMA);
235
+ const now = Date.now();
236
+ db.prepare('INSERT OR REPLACE INTO auth_profile_store (store_key, store_json, updated_at) VALUES (?,?,?)')
237
+ .run('primary', JSON.stringify(sqliteStorePayload), now);
238
+ db.prepare('INSERT OR REPLACE INTO auth_profile_state (state_key, state_json, updated_at) VALUES (?,?,?)')
239
+ .run('primary', JSON.stringify(sqliteStatePayload), now);
240
+ db.close();
241
+ sqliteOk = true;
242
+ } catch (err) {
243
+ console.log(' ⚠ ' + agentId + ' (sqlite): ' + err.message);
244
+ }
245
+ }
197
246
 
198
247
  try {
199
- if (!fs.existsSync(agentDir)) fs.mkdirSync(agentDir, { recursive: true });
200
- fs.writeFileSync(profilesPath, JSON.stringify(profiles, null, 2) + '\n', 'utf8');
201
- console.log(' ✅ ' + agentId);
248
+ console.log(' ✅ ' + agentId + (sqliteOk ? ' (json+sqlite)' : ' (json)'));
202
249
  okCount++;
203
250
  } catch (err) {
204
251
  console.log(' ⚠ ' + agentId + ': ' + err.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.1.132",
3
+ "version": "1.1.134",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {