@aiyiran/myclaw 1.1.132 → 1.1.133
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/injects/inject-minimax.js +45 -4
- package/package.json +1 -1
|
@@ -179,9 +179,32 @@ function run(cliArgs) {
|
|
|
179
179
|
if (agent.agentDir) agentDirs.set(agent.agentDir, agent.id);
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
// 检测 openclaw 版本,决定写入目标
|
|
183
|
+
// 6.X 使用 node:sqlite (DatabaseSync),5.X 使用 auth-profiles.json
|
|
184
|
+
let DatabaseSync = null;
|
|
185
|
+
try {
|
|
186
|
+
({ DatabaseSync } = require('node:sqlite'));
|
|
187
|
+
} catch { /* Node < 22,无内置 sqlite,用 JSON 方式 */ }
|
|
188
|
+
|
|
189
|
+
const SQLITE_SCHEMA = `
|
|
190
|
+
CREATE TABLE IF NOT EXISTS auth_profile_store (
|
|
191
|
+
store_key TEXT NOT NULL PRIMARY KEY, store_json TEXT NOT NULL, updated_at INTEGER NOT NULL
|
|
192
|
+
);
|
|
193
|
+
CREATE TABLE IF NOT EXISTS auth_profile_state (
|
|
194
|
+
state_key TEXT NOT NULL PRIMARY KEY, state_json TEXT NOT NULL, updated_at INTEGER NOT NULL
|
|
195
|
+
);`;
|
|
196
|
+
|
|
197
|
+
const sqliteStorePayload = { version: 1, profiles: { "minimax:cn": { type: "api_key", provider: "minimax", key: apiKey } } };
|
|
198
|
+
const sqliteStatePayload = { lastGood: { "minimax": "minimax:cn" } };
|
|
199
|
+
|
|
182
200
|
let okCount = 0, skipCount = 0;
|
|
183
201
|
|
|
184
202
|
for (const [agentDir, agentId] of agentDirs) {
|
|
203
|
+
if (!fs.existsSync(agentDir)) {
|
|
204
|
+
try { fs.mkdirSync(agentDir, { recursive: true }); } catch { /* ignore */ }
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// ── 5.X:始终写 auth-profiles.json(兼容旧版) ──
|
|
185
208
|
const profilesPath = path.join(agentDir, 'auth-profiles.json');
|
|
186
209
|
let profiles = { version: 1, profiles: {}, lastGood: {} };
|
|
187
210
|
if (fs.existsSync(profilesPath)) {
|
|
@@ -191,14 +214,32 @@ function run(cliArgs) {
|
|
|
191
214
|
if (!profiles.lastGood) profiles.lastGood = {};
|
|
192
215
|
} catch { /* 解析失败用空骨架 */ }
|
|
193
216
|
}
|
|
194
|
-
|
|
195
217
|
profiles.profiles["minimax:cn"] = { type: "api_key", provider: "minimax", key: apiKey };
|
|
196
218
|
profiles.lastGood["minimax"] = "minimax:cn";
|
|
219
|
+
try { fs.writeFileSync(profilesPath, JSON.stringify(profiles, null, 2) + '\n', 'utf8'); } catch { /* ignore */ }
|
|
220
|
+
|
|
221
|
+
// ── 6.X:写入 openclaw-agent.sqlite ──
|
|
222
|
+
let sqliteOk = false;
|
|
223
|
+
if (DatabaseSync) {
|
|
224
|
+
const dbPath = path.join(agentDir, 'openclaw-agent.sqlite');
|
|
225
|
+
try {
|
|
226
|
+
const db = new DatabaseSync(dbPath);
|
|
227
|
+
db.exec('PRAGMA journal_mode = WAL;');
|
|
228
|
+
db.exec(SQLITE_SCHEMA);
|
|
229
|
+
const now = Date.now();
|
|
230
|
+
db.prepare('INSERT OR REPLACE INTO auth_profile_store (store_key, store_json, updated_at) VALUES (?,?,?)')
|
|
231
|
+
.run('primary', JSON.stringify(sqliteStorePayload), now);
|
|
232
|
+
db.prepare('INSERT OR REPLACE INTO auth_profile_state (state_key, state_json, updated_at) VALUES (?,?,?)')
|
|
233
|
+
.run('primary', JSON.stringify(sqliteStatePayload), now);
|
|
234
|
+
db.close();
|
|
235
|
+
sqliteOk = true;
|
|
236
|
+
} catch (err) {
|
|
237
|
+
console.log(' ⚠ ' + agentId + ' (sqlite): ' + err.message);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
197
240
|
|
|
198
241
|
try {
|
|
199
|
-
|
|
200
|
-
fs.writeFileSync(profilesPath, JSON.stringify(profiles, null, 2) + '\n', 'utf8');
|
|
201
|
-
console.log(' ✅ ' + agentId);
|
|
242
|
+
console.log(' ✅ ' + agentId + (sqliteOk ? ' (json+sqlite)' : ' (json)'));
|
|
202
243
|
okCount++;
|
|
203
244
|
} catch (err) {
|
|
204
245
|
console.log(' ⚠ ' + agentId + ': ' + err.message);
|