@badgerclaw/connect 1.4.1 → 1.4.3

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 CHANGED
@@ -26,14 +26,30 @@ const plugin = {
26
26
  try {
27
27
  const { redeemPairingCode } = await import("./src/connect.js");
28
28
  const result = await redeemPairingCode(code);
29
+
30
+ // Derive account key from localpart: @think_bot:... → "think"
31
+ const localpart = result.user_id.split(":")[0].replace("@", "").replace(/_bot$/, "");
32
+
33
+ // Write credentials directly to openclaw.json so hot-reload fires startAccount
34
+ const { readConfigFileSnapshotForWrite, writeConfigFile } = await import("openclaw/plugin-sdk/config-runtime");
35
+ const snapshot = await readConfigFileSnapshotForWrite();
36
+ const cfg = snapshot.config as any;
37
+ cfg.channels = cfg.channels ?? {};
38
+ cfg.channels.badgerclaw = cfg.channels.badgerclaw ?? {};
39
+ cfg.channels.badgerclaw.accounts = cfg.channels.badgerclaw.accounts ?? {};
40
+ cfg.channels.badgerclaw.accounts[localpart] = {
41
+ userId: result.user_id,
42
+ accessToken: result.access_token,
43
+ homeserver: result.homeserver,
44
+ encryption: true,
45
+ };
46
+ await writeConfigFile(snapshot.path, cfg);
47
+
29
48
  console.log("\n✅ Connected to BadgerClaw bot!");
30
49
  console.log(" Bot name: " + result.bot_name);
31
50
  console.log(" Bot user: " + result.user_id);
32
- console.log(" Homeserver: " + result.homeserver);
33
- console.log("\nSave these credentials in your OpenClaw config:");
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);
51
+ console.log(" Account: " + localpart);
52
+ console.log("\n⚡ Bot account written to OpenClaw config — hot-reloading...");
37
53
  } catch (err: any) {
38
54
  console.error("\n❌ Failed to connect: " + (err.message || err));
39
55
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@badgerclaw/connect",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "BadgerClaw channel plugin for OpenClaw",
5
5
  "type": "module",
6
6
  "dependencies": {
@@ -32,6 +32,6 @@
32
32
  }
33
33
  },
34
34
  "scripts": {
35
- "postinstall": "node scripts/postinstall.js"
35
+ "postinstall": "node scripts/postinstall.cjs"
36
36
  }
37
37
  }
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ const CANDIDATES = [
6
+ '/opt/homebrew/lib/node_modules/openclaw/package.json',
7
+ '/usr/local/lib/node_modules/openclaw/package.json',
8
+ path.join(process.env.HOME || '', '.npm-global/lib/node_modules/openclaw/package.json'),
9
+ ];
10
+
11
+ const MISSING_EXPORTS = {
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' },
15
+ };
16
+
17
+ const pkgPath = CANDIDATES.find(p => fs.existsSync(p));
18
+ if (!pkgPath) { console.log('[badgerclaw] postinstall: openclaw not found, skipping'); process.exit(0); }
19
+
20
+ try {
21
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
22
+ pkg.exports = pkg.exports || {};
23
+ let patched = false;
24
+ for (const [key, entry] of Object.entries(MISSING_EXPORTS)) {
25
+ if (!pkg.exports[key]) { pkg.exports[key] = entry; console.log(`[badgerclaw] patched: ${key}`); patched = true; }
26
+ }
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); }
@@ -1,44 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * postinstall.js — patches openclaw package.json exports map to expose
4
- * plugin-sdk/compat subpath, which was removed in openclaw >=2026.3.24.
5
- * This runs automatically after `npm install` in the plugin directory.
6
- */
7
- const fs = require('fs');
8
- const path = require('path');
9
-
10
- const OPENCLAW_PKG = path.join(
11
- path.dirname(require.resolve('openclaw/package.json')),
12
- 'package.json'
13
- );
14
-
15
- const MISSING_EXPORTS = {
16
- './plugin-sdk/compat': {
17
- types: './dist/plugin-sdk/compat.d.ts',
18
- default: './dist/plugin-sdk/compat.js',
19
- },
20
- './plugin-sdk/extension-shared': {
21
- types: './dist/plugin-sdk/extension-shared.d.ts',
22
- default: './dist/plugin-sdk/extension-shared.js',
23
- },
24
- };
25
-
26
- try {
27
- const pkg = JSON.parse(fs.readFileSync(OPENCLAW_PKG, 'utf-8'));
28
- if (!pkg.exports) pkg.exports = {};
29
- let patched = false;
30
- for (const [key, entry] of Object.entries(MISSING_EXPORTS)) {
31
- if (!pkg.exports[key]) {
32
- pkg.exports[key] = entry;
33
- console.log(`[badgerclaw] patched openclaw exports map: added ${key}`);
34
- patched = true;
35
- }
36
- }
37
- if (patched) {
38
- fs.writeFileSync(OPENCLAW_PKG, JSON.stringify(pkg, null, 2));
39
- } else {
40
- console.log('[badgerclaw] openclaw exports map already up to date');
41
- }
42
- } catch (e) {
43
- console.log('[badgerclaw] postinstall: could not patch openclaw exports map:', e.message);
44
- }