@badgerclaw/connect 1.4.2 → 1.4.4
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.ts +43 -5
- package/package.json +1 -1
- package/scripts/postinstall.cjs +9 -27
package/index.ts
CHANGED
|
@@ -4,6 +4,27 @@ import { matrixPlugin } from "./src/channel.js";
|
|
|
4
4
|
import { ensureMatrixCryptoRuntime } from "./src/matrix/deps.js";
|
|
5
5
|
import { setMatrixRuntime } from "./src/runtime.js";
|
|
6
6
|
|
|
7
|
+
async function checkPluginUpdate(log: (msg: string) => void): Promise<void> {
|
|
8
|
+
try {
|
|
9
|
+
const CURRENT = "1.4.3";
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
setTimeout(() => controller.abort(), 3000);
|
|
12
|
+
const resp = await fetch("https://registry.npmjs.org/@badgerclaw/connect/latest", { signal: controller.signal });
|
|
13
|
+
if (!resp.ok) return;
|
|
14
|
+
const data = await resp.json() as { version: string };
|
|
15
|
+
const latest = data.version;
|
|
16
|
+
const toNum = (v: string) => v.split(".").map(Number);
|
|
17
|
+
const [cm, cmi, cp] = toNum(CURRENT);
|
|
18
|
+
const [lm, lmi, lp] = toNum(latest);
|
|
19
|
+
const isNewer = lm > cm || (lm === cm && lmi > cmi) || (lm === cm && lmi === cmi && lp > cp);
|
|
20
|
+
if (isNewer) {
|
|
21
|
+
log(`⚠️ BadgerClaw plugin update available: ${CURRENT} → ${latest}. Run: openclaw plugins install @badgerclaw/connect`);
|
|
22
|
+
}
|
|
23
|
+
} catch {
|
|
24
|
+
// non-fatal
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
7
28
|
const plugin = {
|
|
8
29
|
id: "badgerclaw",
|
|
9
30
|
name: "BadgerClaw",
|
|
@@ -11,6 +32,7 @@ const plugin = {
|
|
|
11
32
|
configSchema: emptyPluginConfigSchema(),
|
|
12
33
|
register(api: OpenClawPluginApi) {
|
|
13
34
|
setMatrixRuntime(api.runtime);
|
|
35
|
+
void checkPluginUpdate(api.logger.info ?? console.log);
|
|
14
36
|
void ensureMatrixCryptoRuntime({ log: api.logger.info }).catch((err) => {
|
|
15
37
|
const message = err instanceof Error ? err.message : String(err);
|
|
16
38
|
api.logger.warn?.(`badgerclaw: crypto runtime bootstrap failed: ${message}`);
|
|
@@ -26,14 +48,30 @@ const plugin = {
|
|
|
26
48
|
try {
|
|
27
49
|
const { redeemPairingCode } = await import("./src/connect.js");
|
|
28
50
|
const result = await redeemPairingCode(code);
|
|
51
|
+
|
|
52
|
+
// Derive account key from localpart: @think_bot:... → "think"
|
|
53
|
+
const localpart = result.user_id.split(":")[0].replace("@", "").replace(/_bot$/, "");
|
|
54
|
+
|
|
55
|
+
// Write credentials directly to openclaw.json so hot-reload fires startAccount
|
|
56
|
+
const { readConfigFileSnapshotForWrite, writeConfigFile } = await import("openclaw/plugin-sdk/config-runtime");
|
|
57
|
+
const snapshot = await readConfigFileSnapshotForWrite();
|
|
58
|
+
const cfg = snapshot.config as any;
|
|
59
|
+
cfg.channels = cfg.channels ?? {};
|
|
60
|
+
cfg.channels.badgerclaw = cfg.channels.badgerclaw ?? {};
|
|
61
|
+
cfg.channels.badgerclaw.accounts = cfg.channels.badgerclaw.accounts ?? {};
|
|
62
|
+
cfg.channels.badgerclaw.accounts[localpart] = {
|
|
63
|
+
userId: result.user_id,
|
|
64
|
+
accessToken: result.access_token,
|
|
65
|
+
homeserver: result.homeserver,
|
|
66
|
+
encryption: true,
|
|
67
|
+
};
|
|
68
|
+
await writeConfigFile(snapshot.path, cfg);
|
|
69
|
+
|
|
29
70
|
console.log("\n✅ Connected to BadgerClaw bot!");
|
|
30
71
|
console.log(" Bot name: " + result.bot_name);
|
|
31
72
|
console.log(" Bot user: " + result.user_id);
|
|
32
|
-
console.log("
|
|
33
|
-
console.log("\
|
|
34
|
-
console.log(" channels.badgerclaw.accounts.default.userId = " + result.user_id);
|
|
35
|
-
console.log(" channels.badgerclaw.accounts.default.accessToken = " + result.access_token);
|
|
36
|
-
console.log(" channels.badgerclaw.accounts.default.homeserver = " + result.homeserver);
|
|
73
|
+
console.log(" Account: " + localpart);
|
|
74
|
+
console.log("\n⚡ Bot account written to OpenClaw config — hot-reloading...");
|
|
37
75
|
} catch (err: any) {
|
|
38
76
|
console.error("\n❌ Failed to connect: " + (err.message || err));
|
|
39
77
|
process.exit(1);
|
package/package.json
CHANGED
package/scripts/postinstall.cjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
|
|
5
|
-
// Find openclaw package.json via common global install paths
|
|
6
5
|
const CANDIDATES = [
|
|
7
6
|
'/opt/homebrew/lib/node_modules/openclaw/package.json',
|
|
8
7
|
'/usr/local/lib/node_modules/openclaw/package.json',
|
|
@@ -10,38 +9,21 @@ const CANDIDATES = [
|
|
|
10
9
|
];
|
|
11
10
|
|
|
12
11
|
const MISSING_EXPORTS = {
|
|
13
|
-
'./plugin-sdk/compat': {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
'./plugin-sdk/extension-shared': {
|
|
18
|
-
types: './dist/plugin-sdk/extension-shared.d.ts',
|
|
19
|
-
default: './dist/plugin-sdk/extension-shared.js',
|
|
20
|
-
},
|
|
12
|
+
'./plugin-sdk/compat': { types: './dist/plugin-sdk/compat.d.ts', default: './dist/plugin-sdk/compat.js' },
|
|
13
|
+
'./plugin-sdk/extension-shared': { types: './dist/plugin-sdk/extension-shared.d.ts', default: './dist/plugin-sdk/extension-shared.js' },
|
|
14
|
+
'./plugin-sdk/config-runtime': { types: './dist/plugin-sdk/config-runtime.d.ts', default: './dist/plugin-sdk/config-runtime.js' },
|
|
21
15
|
};
|
|
22
16
|
|
|
23
17
|
const pkgPath = CANDIDATES.find(p => fs.existsSync(p));
|
|
24
|
-
if (!pkgPath) {
|
|
25
|
-
console.log('[badgerclaw] postinstall: openclaw not found, skipping exports patch');
|
|
26
|
-
process.exit(0);
|
|
27
|
-
}
|
|
18
|
+
if (!pkgPath) { console.log('[badgerclaw] postinstall: openclaw not found, skipping'); process.exit(0); }
|
|
28
19
|
|
|
29
20
|
try {
|
|
30
21
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
31
|
-
|
|
22
|
+
pkg.exports = pkg.exports || {};
|
|
32
23
|
let patched = false;
|
|
33
24
|
for (const [key, entry] of Object.entries(MISSING_EXPORTS)) {
|
|
34
|
-
if (!pkg.exports[key]) {
|
|
35
|
-
pkg.exports[key] = entry;
|
|
36
|
-
console.log(`[badgerclaw] patched openclaw exports map: added ${key}`);
|
|
37
|
-
patched = true;
|
|
38
|
-
}
|
|
25
|
+
if (!pkg.exports[key]) { pkg.exports[key] = entry; console.log(`[badgerclaw] patched: ${key}`); patched = true; }
|
|
39
26
|
}
|
|
40
|
-
if (patched)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
console.log('[badgerclaw] openclaw exports map already up to date');
|
|
44
|
-
}
|
|
45
|
-
} catch (e) {
|
|
46
|
-
console.log('[badgerclaw] postinstall warning:', e.message);
|
|
47
|
-
}
|
|
27
|
+
if (patched) fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
28
|
+
else console.log('[badgerclaw] openclaw exports map already up to date');
|
|
29
|
+
} catch (e) { console.log('[badgerclaw] postinstall warning:', e.message); }
|