@clawchatsai/connector 0.0.2 → 0.0.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/dist/index.js +24 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ let healthServer = null;
|
|
|
31
31
|
// ---------------------------------------------------------------------------
|
|
32
32
|
// Config helpers
|
|
33
33
|
// ---------------------------------------------------------------------------
|
|
34
|
-
const CONFIG_DIR = path.join(process.env.HOME || '/root', '.openclaw', '
|
|
34
|
+
const CONFIG_DIR = path.join(process.env.HOME || '/root', '.openclaw', 'shellchats');
|
|
35
35
|
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
36
36
|
const RUNTIME_FILE = path.join(CONFIG_DIR, 'runtime.json');
|
|
37
37
|
function loadConfig() {
|
|
@@ -53,7 +53,7 @@ function loadConfig() {
|
|
|
53
53
|
async function startShellChat(ctx, api) {
|
|
54
54
|
const config = loadConfig();
|
|
55
55
|
if (!config) {
|
|
56
|
-
ctx.logger.info('
|
|
56
|
+
ctx.logger.info('ShellChats not configured. Run: openclaw shellchats setup <token>');
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
// 1. Check for updates
|
|
@@ -64,7 +64,7 @@ async function startShellChat(ctx, api) {
|
|
|
64
64
|
try {
|
|
65
65
|
await performUpdate();
|
|
66
66
|
ctx.logger.info(`Updated to ${update.latest}. Requesting graceful restart...`);
|
|
67
|
-
api.runtime.requestRestart?.('
|
|
67
|
+
api.runtime.requestRestart?.('shellchats update');
|
|
68
68
|
return; // will restart with new version
|
|
69
69
|
}
|
|
70
70
|
catch (e) {
|
|
@@ -77,12 +77,12 @@ async function startShellChat(ctx, api) {
|
|
|
77
77
|
const gwAuth = gwCfg?.['gateway']?.['auth'];
|
|
78
78
|
const gatewayToken = gwAuth?.['token'] || config.gatewayToken || '';
|
|
79
79
|
if (!gatewayToken) {
|
|
80
|
-
ctx.logger.error('No gateway token available. Re-run: openclaw
|
|
80
|
+
ctx.logger.error('No gateway token available. Re-run: openclaw shellchats setup <token>');
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
// 3. Import server.js and create app instance with plugin paths
|
|
84
|
-
const dataDir = path.join(ctx.stateDir, '
|
|
85
|
-
const uploadsDir = path.join(ctx.stateDir, '
|
|
84
|
+
const dataDir = path.join(ctx.stateDir, 'shellchats', 'data');
|
|
85
|
+
const uploadsDir = path.join(ctx.stateDir, 'shellchats', 'uploads');
|
|
86
86
|
// Dynamic import of server.js (plain JS, no type declarations)
|
|
87
87
|
// @ts-expect-error — server.js is plain JS with no .d.ts
|
|
88
88
|
const serverModule = await import('../server.js');
|
|
@@ -375,10 +375,10 @@ async function handleSetup(token) {
|
|
|
375
375
|
return;
|
|
376
376
|
}
|
|
377
377
|
if (new Date(tokenData.expiresAt) < new Date()) {
|
|
378
|
-
console.error('Setup token has expired. Generate a new one from
|
|
378
|
+
console.error('Setup token has expired. Generate a new one from clawchats.ai.');
|
|
379
379
|
return;
|
|
380
380
|
}
|
|
381
|
-
console.log('Setting up
|
|
381
|
+
console.log('Setting up ShellChats...');
|
|
382
382
|
console.log(` Server: ${tokenData.serverUrl}`);
|
|
383
383
|
// Generate API key for signaling server auth
|
|
384
384
|
const { randomBytes } = await import('node:crypto');
|
|
@@ -435,8 +435,8 @@ async function handleSetup(token) {
|
|
|
435
435
|
const uploadsDir = path.join(CONFIG_DIR, 'uploads');
|
|
436
436
|
fs.mkdirSync(dataDir, { recursive: true });
|
|
437
437
|
fs.mkdirSync(uploadsDir, { recursive: true });
|
|
438
|
-
console.log('
|
|
439
|
-
console.log(' Open
|
|
438
|
+
console.log(' ShellChats is ready!');
|
|
439
|
+
console.log(' Open clawchats.ai in your browser to start chatting.');
|
|
440
440
|
ws.close();
|
|
441
441
|
resolve();
|
|
442
442
|
}
|
|
@@ -460,7 +460,7 @@ async function handleStatus() {
|
|
|
460
460
|
runtime = JSON.parse(fs.readFileSync(RUNTIME_FILE, 'utf8'));
|
|
461
461
|
}
|
|
462
462
|
catch {
|
|
463
|
-
console.log('
|
|
463
|
+
console.log('ShellChats: offline (service not running)');
|
|
464
464
|
return;
|
|
465
465
|
}
|
|
466
466
|
// Verify PID is alive
|
|
@@ -468,7 +468,7 @@ async function handleStatus() {
|
|
|
468
468
|
process.kill(runtime.pid, 0);
|
|
469
469
|
}
|
|
470
470
|
catch {
|
|
471
|
-
console.log('
|
|
471
|
+
console.log('ShellChats: offline (stale runtime file)');
|
|
472
472
|
try {
|
|
473
473
|
fs.unlinkSync(RUNTIME_FILE);
|
|
474
474
|
}
|
|
@@ -487,20 +487,20 @@ async function handleStatus() {
|
|
|
487
487
|
req.setTimeout(3000, () => { req.destroy(); reject(new Error('timeout')); });
|
|
488
488
|
});
|
|
489
489
|
const status = JSON.parse(body);
|
|
490
|
-
console.log(`
|
|
490
|
+
console.log(`ShellChats Plugin v${status.version}`);
|
|
491
491
|
console.log(`Uptime: ${Math.floor(status.uptime)}s`);
|
|
492
492
|
console.log(`Gateway: ${status.gateway.connected ? 'connected' : 'disconnected'}`);
|
|
493
493
|
console.log(`Signaling: ${status.signaling.connected ? 'connected' : 'disconnected'}`);
|
|
494
494
|
console.log(`Clients: ${status.clients.active}`);
|
|
495
495
|
}
|
|
496
496
|
catch {
|
|
497
|
-
console.log('
|
|
497
|
+
console.log('ShellChats: offline (could not reach service)');
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
500
|
async function handleReset() {
|
|
501
501
|
try {
|
|
502
502
|
fs.rmSync(CONFIG_DIR, { recursive: true, force: true });
|
|
503
|
-
console.log('
|
|
503
|
+
console.log('ShellChats data removed. Plugin disconnected.');
|
|
504
504
|
}
|
|
505
505
|
catch (e) {
|
|
506
506
|
console.error(`Reset failed: ${e.message}`);
|
|
@@ -511,32 +511,32 @@ async function handleReset() {
|
|
|
511
511
|
// ---------------------------------------------------------------------------
|
|
512
512
|
const plugin = {
|
|
513
513
|
id: PLUGIN_ID,
|
|
514
|
-
name: '
|
|
515
|
-
description: 'Connects your gateway to
|
|
514
|
+
name: 'ShellChats',
|
|
515
|
+
description: 'Connects your gateway to ShellChats via WebRTC P2P',
|
|
516
516
|
register(api) {
|
|
517
517
|
// Background service: signaling + gateway bridge + future WebRTC
|
|
518
518
|
api.registerService({
|
|
519
|
-
id: '
|
|
519
|
+
id: 'shellchats-service',
|
|
520
520
|
start: (ctx) => startShellChat(ctx, api),
|
|
521
521
|
stop: (ctx) => stopShellChat(ctx),
|
|
522
522
|
});
|
|
523
523
|
// CLI commands
|
|
524
524
|
api.registerCli((ctx) => {
|
|
525
|
-
const cmd = ctx.program.command('
|
|
525
|
+
const cmd = ctx.program.command('shellchats');
|
|
526
526
|
cmd.command('setup <token>')
|
|
527
|
-
.description('Set up
|
|
527
|
+
.description('Set up ShellChats with a setup token')
|
|
528
528
|
.action((token) => handleSetup(String(token)));
|
|
529
529
|
cmd.command('status')
|
|
530
|
-
.description('Show
|
|
530
|
+
.description('Show ShellChats connection status')
|
|
531
531
|
.action(() => handleStatus());
|
|
532
532
|
cmd.command('reset')
|
|
533
|
-
.description('Disconnect and remove all
|
|
533
|
+
.description('Disconnect and remove all ShellChats data')
|
|
534
534
|
.action(() => handleReset());
|
|
535
535
|
});
|
|
536
536
|
// Slash command for status from any channel
|
|
537
537
|
api.registerCommand({
|
|
538
|
-
name: '
|
|
539
|
-
description: 'Show
|
|
538
|
+
name: 'shellchats',
|
|
539
|
+
description: 'Show ShellChats tunnel status',
|
|
540
540
|
handler: () => ({ text: formatStatus() }),
|
|
541
541
|
});
|
|
542
542
|
},
|