@openclawcity/become 1.0.0 → 1.0.2
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/README.md +25 -3
- package/dist/cli.cjs +46 -11
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +46 -11
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1226,18 +1226,24 @@ function patchOpenClaw(config) {
|
|
|
1226
1226
|
const raw = readFileSync4(OPENCLAW_CONFIG, "utf-8");
|
|
1227
1227
|
const clawConfig = JSON.parse(raw);
|
|
1228
1228
|
mkdirSync4(join4(homedir2(), ".become", "state"), { recursive: true });
|
|
1229
|
-
|
|
1229
|
+
if (!clawConfig.models?.providers?.become) {
|
|
1230
|
+
writeFileSync4(BACKUP_PATH, raw, "utf-8");
|
|
1231
|
+
}
|
|
1232
|
+
const originalModel = clawConfig.agents?.defaults?.model?.primary ?? "";
|
|
1233
|
+
const originalModelPath = join4(homedir2(), ".become", "state", "original_model.txt");
|
|
1234
|
+
writeFileSync4(originalModelPath, originalModel, "utf-8");
|
|
1235
|
+
const modelId = originalModel.includes("/") ? originalModel.split("/").slice(1).join("/") : originalModel;
|
|
1230
1236
|
if (!clawConfig.models) clawConfig.models = {};
|
|
1231
1237
|
if (!clawConfig.models.providers) clawConfig.models.providers = {};
|
|
1232
1238
|
clawConfig.models.providers.become = {
|
|
1233
|
-
api: "anthropic-messages",
|
|
1239
|
+
api: config.llm_provider === "openai" ? "openai-completions" : "anthropic-messages",
|
|
1234
1240
|
baseUrl: `http://127.0.0.1:${config.proxy_port}`,
|
|
1235
|
-
apiKey: config.llm_api_key
|
|
1241
|
+
apiKey: config.llm_api_key,
|
|
1242
|
+
models: [
|
|
1243
|
+
{ id: modelId, name: `${modelId} via become` }
|
|
1244
|
+
]
|
|
1236
1245
|
};
|
|
1237
|
-
if (
|
|
1238
|
-
const original = clawConfig.agents.defaults.model.primary;
|
|
1239
|
-
clawConfig.models.providers.become._originalModel = original;
|
|
1240
|
-
const modelId = original.includes("/") ? original.split("/").slice(1).join("/") : original;
|
|
1246
|
+
if (originalModel) {
|
|
1241
1247
|
clawConfig.agents.defaults.model.primary = `become/${modelId}`;
|
|
1242
1248
|
}
|
|
1243
1249
|
writeFileSync4(OPENCLAW_CONFIG, JSON.stringify(clawConfig, null, 2), "utf-8");
|
|
@@ -1248,17 +1254,46 @@ function patchOpenClaw(config) {
|
|
|
1248
1254
|
}
|
|
1249
1255
|
}
|
|
1250
1256
|
function restoreOpenClaw() {
|
|
1251
|
-
if (!existsSync4(
|
|
1252
|
-
throw new Error(
|
|
1257
|
+
if (!existsSync4(OPENCLAW_CONFIG)) {
|
|
1258
|
+
throw new Error(`OpenClaw config not found at ${OPENCLAW_CONFIG}`);
|
|
1259
|
+
}
|
|
1260
|
+
if (existsSync4(BACKUP_PATH)) {
|
|
1261
|
+
const backup = readFileSync4(BACKUP_PATH, "utf-8");
|
|
1262
|
+
const backupConfig = JSON.parse(backup);
|
|
1263
|
+
if (!backupConfig.models?.providers?.become) {
|
|
1264
|
+
writeFileSync4(OPENCLAW_CONFIG, backup, "utf-8");
|
|
1265
|
+
} else {
|
|
1266
|
+
manualRestore();
|
|
1267
|
+
}
|
|
1268
|
+
} else {
|
|
1269
|
+
manualRestore();
|
|
1253
1270
|
}
|
|
1254
|
-
const backup = readFileSync4(BACKUP_PATH, "utf-8");
|
|
1255
|
-
writeFileSync4(OPENCLAW_CONFIG, backup, "utf-8");
|
|
1256
1271
|
try {
|
|
1257
1272
|
execSync("openclaw gateway restart", { stdio: "pipe", timeout: 15e3 });
|
|
1258
1273
|
} catch {
|
|
1259
1274
|
console.log("Warning: Could not restart OpenClaw gateway. Restart it manually: openclaw gateway restart");
|
|
1260
1275
|
}
|
|
1261
1276
|
}
|
|
1277
|
+
function manualRestore() {
|
|
1278
|
+
const raw = readFileSync4(OPENCLAW_CONFIG, "utf-8");
|
|
1279
|
+
const config = JSON.parse(raw);
|
|
1280
|
+
const originalModelPath = join4(homedir2(), ".become", "state", "original_model.txt");
|
|
1281
|
+
if (existsSync4(originalModelPath)) {
|
|
1282
|
+
const originalModel = readFileSync4(originalModelPath, "utf-8").trim();
|
|
1283
|
+
if (originalModel && config.agents?.defaults?.model) {
|
|
1284
|
+
config.agents.defaults.model.primary = originalModel;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
if (config.models?.providers?.become) {
|
|
1288
|
+
delete config.models.providers.become;
|
|
1289
|
+
}
|
|
1290
|
+
for (const provider of Object.values(config.models?.providers ?? {})) {
|
|
1291
|
+
if (provider && typeof provider === "object" && "_originalModel" in provider) {
|
|
1292
|
+
delete provider._originalModel;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
writeFileSync4(OPENCLAW_CONFIG, JSON.stringify(config, null, 2), "utf-8");
|
|
1296
|
+
}
|
|
1262
1297
|
|
|
1263
1298
|
// src/cli/adapter/ironclaw.ts
|
|
1264
1299
|
import { readFileSync as readFileSync5, writeFileSync as writeFileSync5, existsSync as existsSync5, mkdirSync as mkdirSync5, copyFileSync } from "fs";
|