@clawchatsai/connector 0.0.4 → 0.0.6
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 +74 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ let app = null;
|
|
|
28
28
|
let signaling = null;
|
|
29
29
|
let webrtcPeer = null;
|
|
30
30
|
let healthServer = null;
|
|
31
|
+
let _stopRequested = false;
|
|
31
32
|
// ---------------------------------------------------------------------------
|
|
32
33
|
// Config helpers
|
|
33
34
|
// ---------------------------------------------------------------------------
|
|
@@ -51,10 +52,18 @@ function loadConfig() {
|
|
|
51
52
|
// Service lifecycle
|
|
52
53
|
// ---------------------------------------------------------------------------
|
|
53
54
|
async function startShellChat(ctx, api) {
|
|
54
|
-
|
|
55
|
+
_stopRequested = false;
|
|
56
|
+
let config = loadConfig();
|
|
55
57
|
if (!config) {
|
|
56
|
-
ctx.logger.info('ShellChats not configured.
|
|
57
|
-
|
|
58
|
+
ctx.logger.info('ShellChats not configured. Waiting for setup...');
|
|
59
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
60
|
+
while (!config && !_stopRequested) {
|
|
61
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
62
|
+
config = loadConfig();
|
|
63
|
+
}
|
|
64
|
+
if (_stopRequested || !config)
|
|
65
|
+
return;
|
|
66
|
+
ctx.logger.info('Setup detected — connecting to ShellChats...');
|
|
58
67
|
}
|
|
59
68
|
// 1. Check for updates
|
|
60
69
|
const update = await checkForUpdates();
|
|
@@ -200,6 +209,7 @@ async function startShellChat(ctx, api) {
|
|
|
200
209
|
ctx.logger.info('ShellChat service started');
|
|
201
210
|
}
|
|
202
211
|
async function stopShellChat(ctx) {
|
|
212
|
+
_stopRequested = true;
|
|
203
213
|
ctx.logger.info('ShellChat service stopping...');
|
|
204
214
|
// 0. Tear down health endpoint
|
|
205
215
|
if (healthServer) {
|
|
@@ -506,6 +516,64 @@ async function handleReset() {
|
|
|
506
516
|
console.error(`Reset failed: ${e.message}`);
|
|
507
517
|
}
|
|
508
518
|
}
|
|
519
|
+
async function handleImport(sourcePath, opts) {
|
|
520
|
+
const resolvedSource = path.resolve(sourcePath);
|
|
521
|
+
if (!fs.existsSync(resolvedSource)) {
|
|
522
|
+
console.error(`Source path not found: ${resolvedSource}`);
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
const stat = fs.statSync(resolvedSource);
|
|
526
|
+
if (!stat.isDirectory()) {
|
|
527
|
+
console.error(`Source must be a directory: ${resolvedSource}`);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
// Destination: ~/.openclaw/shellchats/data/
|
|
531
|
+
const destDataDir = path.join(CONFIG_DIR, 'data');
|
|
532
|
+
fs.mkdirSync(destDataDir, { recursive: true });
|
|
533
|
+
// Import .db files
|
|
534
|
+
const dbFiles = fs.readdirSync(resolvedSource).filter(f => f.endsWith('.db'));
|
|
535
|
+
if (dbFiles.length === 0) {
|
|
536
|
+
console.log('No .db files found in source directory.');
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
console.log(`Importing ${dbFiles.length} database(s) from ${resolvedSource}...`);
|
|
540
|
+
let imported = 0;
|
|
541
|
+
let skipped = 0;
|
|
542
|
+
for (const file of dbFiles) {
|
|
543
|
+
const src = path.join(resolvedSource, file);
|
|
544
|
+
const dst = path.join(destDataDir, file);
|
|
545
|
+
if (fs.existsSync(dst) && !opts.force) {
|
|
546
|
+
console.log(` Skipping ${file} (already exists — use --force to overwrite)`);
|
|
547
|
+
skipped++;
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
fs.copyFileSync(src, dst);
|
|
551
|
+
console.log(` ✓ ${file}`);
|
|
552
|
+
imported++;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
console.log(`Databases: ${imported} imported, ${skipped} skipped.`);
|
|
556
|
+
}
|
|
557
|
+
// Also try to migrate config.json from the parent directory
|
|
558
|
+
// e.g. if source is ~/.openclaw/shellchat/data/, config is at ~/.openclaw/shellchat/config.json
|
|
559
|
+
const parentConfigPath = path.join(path.dirname(resolvedSource), 'config.json');
|
|
560
|
+
if (fs.existsSync(parentConfigPath)) {
|
|
561
|
+
if (fs.existsSync(CONFIG_FILE) && !opts.force) {
|
|
562
|
+
console.log(' Skipping config.json (already exists — use --force to overwrite)');
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
try {
|
|
566
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
567
|
+
fs.copyFileSync(parentConfigPath, CONFIG_FILE);
|
|
568
|
+
console.log(' ✓ config.json (plugin credentials migrated)');
|
|
569
|
+
}
|
|
570
|
+
catch (e) {
|
|
571
|
+
console.error(` Failed to migrate config.json: ${e.message}`);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
console.log('Done.');
|
|
576
|
+
}
|
|
509
577
|
// ---------------------------------------------------------------------------
|
|
510
578
|
// Plugin definition
|
|
511
579
|
// ---------------------------------------------------------------------------
|
|
@@ -532,6 +600,9 @@ const plugin = {
|
|
|
532
600
|
cmd.command('reset')
|
|
533
601
|
.description('Disconnect and remove all ShellChats data')
|
|
534
602
|
.action(() => handleReset());
|
|
603
|
+
cmd.command('import <path>')
|
|
604
|
+
.description('Import databases from a folder (e.g. migrate from old data directory). Use --force to overwrite existing files.')
|
|
605
|
+
.action((srcPath) => handleImport(String(srcPath), { force: process.argv.includes('--force') }));
|
|
535
606
|
});
|
|
536
607
|
// Slash command for status from any channel
|
|
537
608
|
api.registerCommand({
|