owpenwork 0.1.4 → 0.1.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/cli.js CHANGED
@@ -11,7 +11,7 @@ import { loginWhatsApp, unpairWhatsApp } from "./whatsapp.js";
11
11
  const program = new Command();
12
12
  program
13
13
  .name("owpenbot")
14
- .version("0.1.3")
14
+ .version("0.1.7")
15
15
  .description("OpenCode WhatsApp + Telegram bridge")
16
16
  .argument("[path]")
17
17
  .option("--non-interactive", "Run setup defaults and exit", false)
@@ -279,15 +279,39 @@ program
279
279
  program
280
280
  .command("doctor")
281
281
  .description("Diagnose common issues")
282
- .action(async () => {
282
+ .option("--reset", "Reset owpenbot state", false)
283
+ .action(async (opts) => {
283
284
  const config = loadConfig(process.env, { requireOpencode: false });
284
285
  const authPath = `${config.whatsappAuthDir}/creds.json`;
285
286
  if (!fs.existsSync(authPath)) {
286
- console.log("WhatsApp not linked. Run: owpenbot whatsapp login");
287
+ console.log("WhatsApp not linked. Run: owpenwork whatsapp login");
287
288
  }
288
289
  else {
289
290
  console.log("WhatsApp linked.");
290
291
  }
291
- console.log("If replies fail, ensure OpenCode server is running at OPENCODE_URL.");
292
+ console.log(`OpenCode URL: ${config.opencodeUrl}`);
293
+ console.log("If replies fail, ensure the server is running.");
294
+ const resetRequested = Boolean(opts.reset);
295
+ if (!resetRequested && !process.stdin.isTTY)
296
+ return;
297
+ let confirmed = resetRequested;
298
+ if (!resetRequested) {
299
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
300
+ const answer = await rl.question("Reset owpenbot state (y/N)? ");
301
+ rl.close();
302
+ confirmed = answer.trim().toLowerCase() === "y";
303
+ }
304
+ if (!confirmed)
305
+ return;
306
+ const targets = [config.configPath, config.dbPath, config.whatsappAuthDir];
307
+ for (const target of targets) {
308
+ if (fs.existsSync(target)) {
309
+ fs.rmSync(target, { recursive: true, force: true });
310
+ }
311
+ }
312
+ console.log("Reset complete. Run: owpenwork setup");
313
+ });
314
+ program.parseAsync(process.argv).catch((error) => {
315
+ console.error(error);
316
+ process.exitCode = 1;
292
317
  });
293
- await program.parseAsync(process.argv);
package/dist/whatsapp.js CHANGED
@@ -50,6 +50,13 @@ export function createWhatsAppAdapter(config, logger, onMessage, opts = {}) {
50
50
  if (update.connection === "close") {
51
51
  const lastDisconnect = update.lastDisconnect;
52
52
  const statusCode = lastDisconnect?.error?.output?.statusCode;
53
+ if (statusCode === 515 && !stopped) {
54
+ log.warn("whatsapp stream error; restarting connection");
55
+ setTimeout(() => {
56
+ void connect();
57
+ }, 1000);
58
+ return;
59
+ }
53
60
  const shouldReconnect = statusCode !== DisconnectReason.loggedOut;
54
61
  if (shouldReconnect && !stopped) {
55
62
  log.warn("whatsapp connection closed, reconnecting");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owpenwork",
3
- "version": "0.1.4",
3
+ "version": "0.1.7",
4
4
  "description": "WhatsApp bridge for a running OpenCode server",
5
5
  "private": false,
6
6
  "type": "module",