@clawchatsai/connector 0.0.8 → 0.0.10
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/dist/index.js +40 -37
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -51,6 +51,28 @@ function loadConfig() {
|
|
|
51
51
|
// ---------------------------------------------------------------------------
|
|
52
52
|
// Service lifecycle
|
|
53
53
|
// ---------------------------------------------------------------------------
|
|
54
|
+
async function ensureNativeModules(ctx) {
|
|
55
|
+
// OpenClaw installs plugins with --ignore-scripts, which skips native module compilation.
|
|
56
|
+
// Check if better-sqlite3 is usable; if not, rebuild it automatically.
|
|
57
|
+
const pluginDir = path.resolve(__dirname, '..');
|
|
58
|
+
const bindingPath = path.join(pluginDir, 'node_modules', 'better-sqlite3', 'build', 'Release', 'better_sqlite3.node');
|
|
59
|
+
if (fs.existsSync(bindingPath))
|
|
60
|
+
return; // already built
|
|
61
|
+
ctx.logger.info('Building native modules (first run)...');
|
|
62
|
+
const { execFileSync } = await import('node:child_process');
|
|
63
|
+
try {
|
|
64
|
+
execFileSync('npm', ['rebuild', 'better-sqlite3'], {
|
|
65
|
+
cwd: pluginDir,
|
|
66
|
+
stdio: 'pipe',
|
|
67
|
+
timeout: 120_000,
|
|
68
|
+
});
|
|
69
|
+
ctx.logger.info('Native modules ready.');
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
ctx.logger.error(`Failed to build native modules: ${e.message}`);
|
|
73
|
+
ctx.logger.error('Try running manually: cd ~/.openclaw/extensions/connector && npm rebuild better-sqlite3');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
54
76
|
async function startShellChat(ctx, api) {
|
|
55
77
|
_stopRequested = false;
|
|
56
78
|
let config = loadConfig();
|
|
@@ -89,7 +111,9 @@ async function startShellChat(ctx, api) {
|
|
|
89
111
|
ctx.logger.error('No gateway token available. Re-run: openclaw shellchats setup <token>');
|
|
90
112
|
return;
|
|
91
113
|
}
|
|
92
|
-
// 3.
|
|
114
|
+
// 3. Ensure native modules are built (OpenClaw installs with --ignore-scripts)
|
|
115
|
+
await ensureNativeModules(ctx);
|
|
116
|
+
// 4. Import server.js and create app instance with plugin paths
|
|
93
117
|
const dataDir = path.join(ctx.stateDir, 'shellchats', 'data');
|
|
94
118
|
const uploadsDir = path.join(ctx.stateDir, 'shellchats', 'uploads');
|
|
95
119
|
// Dynamic import of server.js (plain JS, no type declarations)
|
|
@@ -521,7 +545,7 @@ async function handleReset() {
|
|
|
521
545
|
console.error(`Reset failed: ${e.message}`);
|
|
522
546
|
}
|
|
523
547
|
}
|
|
524
|
-
async function handleImport(sourcePath
|
|
548
|
+
async function handleImport(sourcePath) {
|
|
525
549
|
const resolvedSource = path.resolve(sourcePath);
|
|
526
550
|
if (!fs.existsSync(resolvedSource)) {
|
|
527
551
|
console.error(`Source path not found: ${resolvedSource}`);
|
|
@@ -547,54 +571,33 @@ async function handleImport(sourcePath, opts) {
|
|
|
547
571
|
for (const file of dbFiles) {
|
|
548
572
|
const src = path.join(resolvedSource, file);
|
|
549
573
|
const dst = path.join(destDataDir, file);
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
else {
|
|
555
|
-
fs.copyFileSync(src, dst);
|
|
556
|
-
console.log(` ✓ ${file}`);
|
|
557
|
-
imported++;
|
|
558
|
-
}
|
|
574
|
+
fs.copyFileSync(src, dst);
|
|
575
|
+
console.log(` ✓ ${file}`);
|
|
576
|
+
imported++;
|
|
559
577
|
}
|
|
560
|
-
console.log(`Databases: ${imported} imported
|
|
578
|
+
console.log(`Databases: ${imported} imported.`);
|
|
561
579
|
}
|
|
562
580
|
// Import .json config files (workspaces.json, settings.json, etc.)
|
|
563
581
|
const jsonFiles = fs.readdirSync(resolvedSource).filter(f => f.endsWith('.json'));
|
|
564
582
|
if (jsonFiles.length > 0) {
|
|
565
|
-
let jsonImported = 0;
|
|
566
|
-
let jsonSkipped = 0;
|
|
567
583
|
for (const file of jsonFiles) {
|
|
568
584
|
const src = path.join(resolvedSource, file);
|
|
569
585
|
const dst = path.join(destDataDir, file);
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
jsonSkipped++;
|
|
573
|
-
}
|
|
574
|
-
else {
|
|
575
|
-
fs.copyFileSync(src, dst);
|
|
576
|
-
console.log(` ✓ ${file}`);
|
|
577
|
-
jsonImported++;
|
|
578
|
-
}
|
|
586
|
+
fs.copyFileSync(src, dst);
|
|
587
|
+
console.log(` ✓ ${file}`);
|
|
579
588
|
}
|
|
580
|
-
console.log(`Config files: ${jsonImported} imported, ${jsonSkipped} skipped.`);
|
|
581
589
|
}
|
|
582
590
|
// Also try to migrate config.json from the parent directory
|
|
583
591
|
// e.g. if source is ~/.openclaw/shellchat/data/, config is at ~/.openclaw/shellchat/config.json
|
|
584
592
|
const parentConfigPath = path.join(path.dirname(resolvedSource), 'config.json');
|
|
585
593
|
if (fs.existsSync(parentConfigPath)) {
|
|
586
|
-
|
|
587
|
-
|
|
594
|
+
try {
|
|
595
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
596
|
+
fs.copyFileSync(parentConfigPath, CONFIG_FILE);
|
|
597
|
+
console.log(' ✓ config.json (plugin credentials migrated)');
|
|
588
598
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
592
|
-
fs.copyFileSync(parentConfigPath, CONFIG_FILE);
|
|
593
|
-
console.log(' ✓ config.json (plugin credentials migrated)');
|
|
594
|
-
}
|
|
595
|
-
catch (e) {
|
|
596
|
-
console.error(` Failed to migrate config.json: ${e.message}`);
|
|
597
|
-
}
|
|
599
|
+
catch (e) {
|
|
600
|
+
console.error(` Failed to migrate config.json: ${e.message}`);
|
|
598
601
|
}
|
|
599
602
|
}
|
|
600
603
|
console.log('Done.');
|
|
@@ -626,8 +629,8 @@ const plugin = {
|
|
|
626
629
|
.description('Disconnect and remove all ShellChats data')
|
|
627
630
|
.action(() => handleReset());
|
|
628
631
|
cmd.command('import <path>')
|
|
629
|
-
.description('Import databases from a folder (e.g. migrate from old data directory)
|
|
630
|
-
.action((srcPath) => handleImport(String(srcPath)
|
|
632
|
+
.description('Import databases and config from a folder (e.g. migrate from old data directory)')
|
|
633
|
+
.action((srcPath) => handleImport(String(srcPath)));
|
|
631
634
|
});
|
|
632
635
|
// Slash command for status from any channel
|
|
633
636
|
api.registerCommand({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clawchatsai/connector",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "ShellChat OpenClaw plugin — P2P tunnel + local API bridge",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"prebuild": "cp ../server.js ./server.js",
|
|
21
21
|
"build": "tsc",
|
|
22
22
|
"dev": "tsc --watch",
|
|
23
|
-
"prepublishOnly": "npm run build"
|
|
23
|
+
"prepublishOnly": "npm run build",
|
|
24
|
+
"postinstall": "npm rebuild better-sqlite3 2>/dev/null || true"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"better-sqlite3": ">=9.0.0",
|