@clawchatsai/connector 0.0.5 → 0.0.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/dist/index.js +19 -4
- 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) {
|
|
@@ -443,7 +453,12 @@ async function handleSetup(token) {
|
|
|
443
453
|
else if (msg.type === 'setup-error') {
|
|
444
454
|
clearTimeout(timeout);
|
|
445
455
|
ws.close();
|
|
446
|
-
|
|
456
|
+
const reasons = {
|
|
457
|
+
'invalid_or_expired_token': 'Setup token is invalid or has expired. Generate a new one at clawchats.ai.',
|
|
458
|
+
'missing_fields': 'Setup failed: malformed token. Try copying the command again.',
|
|
459
|
+
};
|
|
460
|
+
const message = reasons[msg.reason] ?? `Setup failed: ${msg.reason}. Try again or visit clawchats.ai for support.`;
|
|
461
|
+
reject(new Error(message));
|
|
447
462
|
}
|
|
448
463
|
});
|
|
449
464
|
ws.on('error', (err) => {
|