@clawchatsai/connector 0.0.4 → 0.0.5
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 +61 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -506,6 +506,64 @@ async function handleReset() {
|
|
|
506
506
|
console.error(`Reset failed: ${e.message}`);
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
|
+
async function handleImport(sourcePath, opts) {
|
|
510
|
+
const resolvedSource = path.resolve(sourcePath);
|
|
511
|
+
if (!fs.existsSync(resolvedSource)) {
|
|
512
|
+
console.error(`Source path not found: ${resolvedSource}`);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
const stat = fs.statSync(resolvedSource);
|
|
516
|
+
if (!stat.isDirectory()) {
|
|
517
|
+
console.error(`Source must be a directory: ${resolvedSource}`);
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
// Destination: ~/.openclaw/shellchats/data/
|
|
521
|
+
const destDataDir = path.join(CONFIG_DIR, 'data');
|
|
522
|
+
fs.mkdirSync(destDataDir, { recursive: true });
|
|
523
|
+
// Import .db files
|
|
524
|
+
const dbFiles = fs.readdirSync(resolvedSource).filter(f => f.endsWith('.db'));
|
|
525
|
+
if (dbFiles.length === 0) {
|
|
526
|
+
console.log('No .db files found in source directory.');
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
console.log(`Importing ${dbFiles.length} database(s) from ${resolvedSource}...`);
|
|
530
|
+
let imported = 0;
|
|
531
|
+
let skipped = 0;
|
|
532
|
+
for (const file of dbFiles) {
|
|
533
|
+
const src = path.join(resolvedSource, file);
|
|
534
|
+
const dst = path.join(destDataDir, file);
|
|
535
|
+
if (fs.existsSync(dst) && !opts.force) {
|
|
536
|
+
console.log(` Skipping ${file} (already exists — use --force to overwrite)`);
|
|
537
|
+
skipped++;
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
fs.copyFileSync(src, dst);
|
|
541
|
+
console.log(` ✓ ${file}`);
|
|
542
|
+
imported++;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
console.log(`Databases: ${imported} imported, ${skipped} skipped.`);
|
|
546
|
+
}
|
|
547
|
+
// Also try to migrate config.json from the parent directory
|
|
548
|
+
// e.g. if source is ~/.openclaw/shellchat/data/, config is at ~/.openclaw/shellchat/config.json
|
|
549
|
+
const parentConfigPath = path.join(path.dirname(resolvedSource), 'config.json');
|
|
550
|
+
if (fs.existsSync(parentConfigPath)) {
|
|
551
|
+
if (fs.existsSync(CONFIG_FILE) && !opts.force) {
|
|
552
|
+
console.log(' Skipping config.json (already exists — use --force to overwrite)');
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
try {
|
|
556
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
557
|
+
fs.copyFileSync(parentConfigPath, CONFIG_FILE);
|
|
558
|
+
console.log(' ✓ config.json (plugin credentials migrated)');
|
|
559
|
+
}
|
|
560
|
+
catch (e) {
|
|
561
|
+
console.error(` Failed to migrate config.json: ${e.message}`);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
console.log('Done.');
|
|
566
|
+
}
|
|
509
567
|
// ---------------------------------------------------------------------------
|
|
510
568
|
// Plugin definition
|
|
511
569
|
// ---------------------------------------------------------------------------
|
|
@@ -532,6 +590,9 @@ const plugin = {
|
|
|
532
590
|
cmd.command('reset')
|
|
533
591
|
.description('Disconnect and remove all ShellChats data')
|
|
534
592
|
.action(() => handleReset());
|
|
593
|
+
cmd.command('import <path>')
|
|
594
|
+
.description('Import databases from a folder (e.g. migrate from old data directory). Use --force to overwrite existing files.')
|
|
595
|
+
.action((srcPath) => handleImport(String(srcPath), { force: process.argv.includes('--force') }));
|
|
535
596
|
});
|
|
536
597
|
// Slash command for status from any channel
|
|
537
598
|
api.registerCommand({
|