beecork 1.4.3 → 1.4.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.
@@ -32,12 +32,16 @@ export class WhatsAppChannel {
32
32
  this.sttProvider = stt;
33
33
  this.ttsProvider = tts;
34
34
  try {
35
- const { default: makeWASocket, useMultiFileAuthState, DisconnectReason, downloadMediaMessage } = await import('@whiskeysockets/baileys');
35
+ const { default: makeWASocket, useMultiFileAuthState, DisconnectReason, downloadMediaMessage, fetchLatestBaileysVersion } = await import('@whiskeysockets/baileys');
36
36
  const sessionPath = this.ctx.config.whatsapp?.sessionPath ?? `${process.env.HOME}/.beecork/whatsapp-session`;
37
37
  fs.mkdirSync(sessionPath, { recursive: true, mode: 0o700 });
38
38
  const { state, saveCreds } = await useMultiFileAuthState(sessionPath);
39
+ const { version } = await fetchLatestBaileysVersion().catch(() => ({ version: undefined }));
40
+ const pino = (await import('pino')).default;
39
41
  this.sock = makeWASocket({
40
42
  auth: state,
43
+ version,
44
+ logger: pino({ level: 'silent' }),
41
45
  });
42
46
  const sock = this.sock;
43
47
  sock.ev.on('creds.update', saveCreds);
package/dist/index.js CHANGED
@@ -194,39 +194,72 @@ program
194
194
  rl.close();
195
195
  // Pair immediately — show QR code in this terminal
196
196
  try {
197
- const { default: makeWASocket, useMultiFileAuthState, DisconnectReason } = await import('@whiskeysockets/baileys');
197
+ const { default: makeWASocket, useMultiFileAuthState, DisconnectReason, fetchLatestBaileysVersion } = await import('@whiskeysockets/baileys');
198
+ const pino = (await import('pino')).default;
199
+ const silentLogger = pino({ level: 'silent' });
198
200
  fs.mkdirSync(sessionPath, { recursive: true, mode: 0o700 });
199
- const { state, saveCreds } = await useMultiFileAuthState(sessionPath);
200
- const sock = makeWASocket({
201
- auth: state,
202
- });
203
- sock.ev.on('creds.update', saveCreds);
204
- sock.ev.on('connection.update', async (update) => {
205
- if (update.qr) {
206
- try {
207
- const qrcodeTerminal = await import('qrcode-terminal');
208
- (qrcodeTerminal.default || qrcodeTerminal).generate(update.qr, { small: true });
201
+ let attempts = 0;
202
+ const maxAttempts = 5;
203
+ let paired = false;
204
+ const connect = async () => {
205
+ attempts++;
206
+ const { state, saveCreds } = await useMultiFileAuthState(sessionPath);
207
+ const { version } = await fetchLatestBaileysVersion().catch(() => ({ version: undefined }));
208
+ const sock = makeWASocket({ auth: state, version, logger: silentLogger });
209
+ sock.ev.on('creds.update', saveCreds);
210
+ sock.ev.on('connection.update', async (update) => {
211
+ if (update.qr) {
212
+ try {
213
+ const qrcodeTerminal = await import('qrcode-terminal');
214
+ (qrcodeTerminal.default || qrcodeTerminal).generate(update.qr, { small: true });
215
+ console.log('Scan the QR code above with your phone (WhatsApp → Linked Devices → Link a Device)\n');
216
+ }
217
+ catch {
218
+ console.log('QR data:', update.qr);
219
+ }
209
220
  }
210
- catch {
211
- console.log('QR data:', update.qr);
221
+ if (update.connection === 'open') {
222
+ paired = true;
223
+ console.log('✓ WhatsApp paired successfully!');
224
+ sock.end(undefined);
225
+ // Auto-restart daemon
226
+ const { getDaemonPid } = await import('./cli/helpers.js');
227
+ const pid = getDaemonPid();
228
+ if (pid) {
229
+ console.log(' Restarting daemon with WhatsApp enabled...');
230
+ const { execSync } = await import('node:child_process');
231
+ try {
232
+ execSync('beecork stop', { stdio: 'ignore' });
233
+ execSync('beecork start', { stdio: 'ignore' });
234
+ console.log(' ✓ Daemon restarted.\n');
235
+ }
236
+ catch {
237
+ console.log(' Could not restart daemon. Run: beecork stop && beecork start\n');
238
+ }
239
+ }
240
+ else {
241
+ console.log(' Start the daemon: beecork start\n');
242
+ }
243
+ process.exit(0);
212
244
  }
213
- }
214
- if (update.connection === 'open') {
215
- console.log('\n✓ WhatsApp paired successfully!');
216
- console.log(' You can now start the daemon: beecork start\n');
217
- sock.end(undefined);
218
- process.exit(0);
219
- }
220
- if (update.connection === 'close') {
221
- const reason = update.lastDisconnect?.error?.output?.statusCode;
222
- if (reason === DisconnectReason.loggedOut) {
223
- console.log('\n✗ WhatsApp logged out. Please try again.\n');
224
- process.exit(1);
245
+ if (update.connection === 'close') {
246
+ if (paired)
247
+ return; // Expected disconnect after pairing
248
+ const reason = update.lastDisconnect?.error?.output?.statusCode;
249
+ if (reason === DisconnectReason.loggedOut) {
250
+ console.log('\n✗ WhatsApp logged out. Please try again.\n');
251
+ process.exit(1);
252
+ }
253
+ if (attempts >= maxAttempts) {
254
+ console.log(`\n✗ Could not connect after ${maxAttempts} attempts. Please try again later.\n`);
255
+ process.exit(1);
256
+ }
257
+ setTimeout(connect, 3000);
225
258
  }
226
- }
227
- });
228
- console.log('Scan the QR code above with your phone (WhatsApp → Linked Devices → Link a Device)');
229
- console.log('Waiting for pairing... (Ctrl+C to cancel)\n');
259
+ });
260
+ };
261
+ await connect();
262
+ console.log('Waiting for QR code... (Ctrl+C to cancel)\n');
230
263
  }
231
264
  catch (err) {
232
265
  console.error('Failed to connect to WhatsApp:', err instanceof Error ? err.message : err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beecork",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "description": "Claude Code always-on infrastructure — a phone number, a memory, and an alarm clock",
5
5
  "type": "module",
6
6
  "bin": {