@badgerclaw/connect 1.4.5 → 1.4.7
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/package.json
CHANGED
package/scripts/postinstall.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
|
+
const os = require('os');
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
-
'/opt/homebrew/lib/node_modules/openclaw
|
|
7
|
-
'/usr/local/lib/node_modules/openclaw
|
|
8
|
-
path.join(
|
|
6
|
+
const OPENCLAW_PKG_CANDIDATES = [
|
|
7
|
+
'/opt/homebrew/lib/node_modules/openclaw',
|
|
8
|
+
'/usr/local/lib/node_modules/openclaw',
|
|
9
|
+
path.join(os.homedir(), '.npm-global/lib/node_modules/openclaw'),
|
|
9
10
|
];
|
|
10
11
|
|
|
11
12
|
const MISSING_EXPORTS = {
|
|
@@ -14,16 +15,65 @@ const MISSING_EXPORTS = {
|
|
|
14
15
|
'./plugin-sdk/config-runtime': { types: './dist/plugin-sdk/config-runtime.d.ts', default: './dist/plugin-sdk/config-runtime.js' },
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
const
|
|
18
|
-
if (!pkgPath) { console.log('[badgerclaw] postinstall: openclaw not found, skipping'); process.exit(0); }
|
|
18
|
+
const openclawDir = OPENCLAW_PKG_CANDIDATES.find(p => fs.existsSync(path.join(p, 'package.json')));
|
|
19
19
|
|
|
20
|
+
if (!openclawDir) {
|
|
21
|
+
console.log('[badgerclaw] openclaw not found — skipping setup');
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 1. Patch exports map
|
|
20
26
|
try {
|
|
27
|
+
const pkgPath = path.join(openclawDir, 'package.json');
|
|
21
28
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
22
29
|
pkg.exports = pkg.exports || {};
|
|
23
30
|
let patched = false;
|
|
24
31
|
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; }
|
|
32
|
+
if (!pkg.exports[key]) { pkg.exports[key] = entry; console.log(`[badgerclaw] patched exports: ${key}`); patched = true; }
|
|
26
33
|
}
|
|
27
34
|
if (patched) fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
28
|
-
else console.log('[badgerclaw]
|
|
29
|
-
} catch (e) { console.log('[badgerclaw]
|
|
35
|
+
else console.log('[badgerclaw] exports map already up to date');
|
|
36
|
+
} catch (e) { console.log('[badgerclaw] exports patch warning:', e.message); }
|
|
37
|
+
|
|
38
|
+
// 2. Symlink openclaw into plugin node_modules so imports resolve
|
|
39
|
+
try {
|
|
40
|
+
const pluginDir = path.join(os.homedir(), '.openclaw', 'extensions', 'badgerclaw');
|
|
41
|
+
const pluginNodeModules = path.join(pluginDir, 'node_modules');
|
|
42
|
+
const symlink = path.join(pluginNodeModules, 'openclaw');
|
|
43
|
+
if (!fs.existsSync(symlink)) {
|
|
44
|
+
fs.mkdirSync(pluginNodeModules, { recursive: true });
|
|
45
|
+
fs.symlinkSync(openclawDir, symlink);
|
|
46
|
+
console.log(`[badgerclaw] symlinked openclaw → ${openclawDir}`);
|
|
47
|
+
} else {
|
|
48
|
+
console.log('[badgerclaw] openclaw symlink already exists');
|
|
49
|
+
}
|
|
50
|
+
} catch (e) { console.log('[badgerclaw] symlink warning:', e.message); }
|
|
51
|
+
|
|
52
|
+
// 3. Config stash/restore for reinstalls
|
|
53
|
+
const configPath = path.join(os.homedir(), '.openclaw', 'openclaw.json');
|
|
54
|
+
const stashPath = configPath + '.badgerclaw-stash';
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(configPath)) { process.exit(0); }
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
60
|
+
const bcConfig = config.channels?.badgerclaw;
|
|
61
|
+
if (!bcConfig) { process.exit(0); }
|
|
62
|
+
|
|
63
|
+
delete config.channels.badgerclaw;
|
|
64
|
+
if (config.plugins?.entries?.badgerclaw) delete config.plugins.entries.badgerclaw;
|
|
65
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
66
|
+
fs.writeFileSync(stashPath, JSON.stringify(bcConfig, null, 2));
|
|
67
|
+
console.log('[badgerclaw] stashed channels.badgerclaw config');
|
|
68
|
+
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
try {
|
|
71
|
+
const cur = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
72
|
+
cur.channels = cur.channels || {};
|
|
73
|
+
cur.channels.badgerclaw = JSON.parse(fs.readFileSync(stashPath, 'utf-8'));
|
|
74
|
+
fs.writeFileSync(configPath, JSON.stringify(cur, null, 2));
|
|
75
|
+
fs.unlinkSync(stashPath);
|
|
76
|
+
console.log('[badgerclaw] restored channels.badgerclaw config');
|
|
77
|
+
} catch (e) { console.log('[badgerclaw] restore warning:', e.message); }
|
|
78
|
+
}, 500);
|
|
79
|
+
} catch (e) { console.log('[badgerclaw] config stash warning:', e.message); }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { LocationMessageEventContent, MatrixClient } from "@vector-im/matrix-bot-sdk";
|
|
2
2
|
import {
|
|
3
3
|
DEFAULT_ACCOUNT_ID,
|
|
4
|
-
|
|
4
|
+
createChannelPairingController,
|
|
5
5
|
createReplyPrefixOptions,
|
|
6
6
|
createTypingCallbacks,
|
|
7
7
|
dispatchReplyFromConfigWithSettledDispatcher,
|
|
@@ -154,7 +154,7 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
|
|
|
154
154
|
accountId,
|
|
155
155
|
} = params;
|
|
156
156
|
const resolvedAccountId = accountId?.trim() || DEFAULT_ACCOUNT_ID;
|
|
157
|
-
const pairing =
|
|
157
|
+
const pairing = createChannelPairingController({
|
|
158
158
|
core,
|
|
159
159
|
channel: "badgerclaw",
|
|
160
160
|
accountId: resolvedAccountId,
|