beecork 1.4.3 → 1.4.4

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,14 @@ 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 }));
39
40
  this.sock = makeWASocket({
40
41
  auth: state,
42
+ version,
41
43
  });
42
44
  const sock = this.sock;
43
45
  sock.ev.on('creds.update', saveCreds);
package/dist/index.js CHANGED
@@ -194,37 +194,48 @@ 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
198
  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 });
199
+ let attempts = 0;
200
+ const maxAttempts = 5;
201
+ const connect = async () => {
202
+ attempts++;
203
+ const { state, saveCreds } = await useMultiFileAuthState(sessionPath);
204
+ const { version } = await fetchLatestBaileysVersion().catch(() => ({ version: undefined }));
205
+ const sock = makeWASocket({ auth: state, version });
206
+ sock.ev.on('creds.update', saveCreds);
207
+ sock.ev.on('connection.update', async (update) => {
208
+ if (update.qr) {
209
+ try {
210
+ const qrcodeTerminal = await import('qrcode-terminal');
211
+ (qrcodeTerminal.default || qrcodeTerminal).generate(update.qr, { small: true });
212
+ }
213
+ catch {
214
+ console.log('QR data:', update.qr);
215
+ }
209
216
  }
210
- catch {
211
- console.log('QR data:', update.qr);
217
+ if (update.connection === 'open') {
218
+ console.log('\n✓ WhatsApp paired successfully!');
219
+ console.log(' You can now start the daemon: beecork start\n');
220
+ sock.end(undefined);
221
+ process.exit(0);
212
222
  }
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);
223
+ if (update.connection === 'close') {
224
+ const reason = update.lastDisconnect?.error?.output?.statusCode;
225
+ if (reason === DisconnectReason.loggedOut) {
226
+ console.log('\n✗ WhatsApp logged out. Please try again.\n');
227
+ process.exit(1);
228
+ }
229
+ if (attempts >= maxAttempts) {
230
+ console.log(`\n✗ Could not connect after ${maxAttempts} attempts. Please try again later.\n`);
231
+ process.exit(1);
232
+ }
233
+ console.log(`Connection dropped, retrying (${attempts}/${maxAttempts})...`);
234
+ setTimeout(connect, 3000);
225
235
  }
226
- }
227
- });
236
+ });
237
+ };
238
+ await connect();
228
239
  console.log('Scan the QR code above with your phone (WhatsApp → Linked Devices → Link a Device)');
229
240
  console.log('Waiting for pairing... (Ctrl+C to cancel)\n');
230
241
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beecork",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "Claude Code always-on infrastructure — a phone number, a memory, and an alarm clock",
5
5
  "type": "module",
6
6
  "bin": {