@rubytech/create-realagent 1.0.444 → 1.0.445

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rubytech/create-realagent",
3
- "version": "1.0.444",
3
+ "version": "1.0.445",
4
4
  "description": "Install Real Agent — Built for agents. By agents.",
5
5
  "bin": {
6
6
  "create-realagent": "./dist/index.js"
@@ -9501,8 +9501,12 @@ function isLoginFresh(login) {
9501
9501
  }
9502
9502
  async function startLogin(opts) {
9503
9503
  const { accountId, authDir, force, timeoutMs = 3e4 } = opts;
9504
+ const existing0 = activeLogins.get(accountId);
9504
9505
  const hasAuth = await authExists(authDir);
9505
9506
  const selfId = readSelfId(authDir);
9507
+ console.error(
9508
+ `${TAG3} startLogin account=${accountId} force=${!!force} hasAuth=${hasAuth}` + (existing0 ? ` activeLogin={id=${existing0.id.slice(0, 8)},age=${Math.round((Date.now() - existing0.startedAt) / 1e3)}s,hasQr=${!!existing0.qr}}` : " activeLogin=none")
9509
+ );
9506
9510
  if (hasAuth && !force) {
9507
9511
  const who = selfId.e164 ?? selfId.jid ?? "unknown";
9508
9512
  return {
@@ -9512,12 +9516,17 @@ async function startLogin(opts) {
9512
9516
  }
9513
9517
  await clearAuth(authDir);
9514
9518
  const existing = activeLogins.get(accountId);
9515
- if (existing && isLoginFresh(existing) && existing.qrDataUrl) {
9519
+ if (existing && isLoginFresh(existing) && existing.qrDataUrl && !force) {
9520
+ console.error(`${TAG3} startLogin account=${accountId} guard: returning existing QR (age=${Math.round((Date.now() - existing.startedAt) / 1e3)}s)`);
9516
9521
  return {
9517
9522
  qrDataUrl: existing.qrDataUrl,
9523
+ qrRaw: existing.qr,
9518
9524
  message: "QR already active. Scan it in WhatsApp \u2192 Linked Devices."
9519
9525
  };
9520
9526
  }
9527
+ if (existing) {
9528
+ console.error(`${TAG3} startLogin account=${accountId} ${force ? "force override" : "stale/no-QR"}, resetting active login`);
9529
+ }
9521
9530
  resetActiveLogin(accountId);
9522
9531
  let resolveQr = null;
9523
9532
  let rejectQr = null;
@@ -9586,6 +9595,9 @@ async function startLogin(opts) {
9586
9595
  async function waitForLogin(opts) {
9587
9596
  const { accountId, timeoutMs = 6e4 } = opts;
9588
9597
  const login = activeLogins.get(accountId);
9598
+ console.error(
9599
+ `${TAG3} waitForLogin account=${accountId} timeout=${timeoutMs}ms` + (login ? ` login={id=${login.id.slice(0, 8)},age=${Math.round((Date.now() - login.startedAt) / 1e3)}s,connected=${login.connected},hasQr=${!!login.qr}}` : " login=none")
9600
+ );
9589
9601
  if (!login) {
9590
9602
  return { connected: false, message: "No active WhatsApp login in progress." };
9591
9603
  }
@@ -9616,6 +9628,9 @@ async function waitForLogin(opts) {
9616
9628
  }
9617
9629
  await new Promise((r) => setTimeout(r, 1e3));
9618
9630
  }
9631
+ const elapsed = Math.round((Date.now() - (deadline - timeoutMs)) / 1e3);
9632
+ console.error(`${TAG3} waitForLogin timeout account=${accountId} elapsed=${elapsed}s \u2014 cleaning up active login`);
9633
+ resetActiveLogin(accountId);
9619
9634
  return { connected: false, message: "Login timed out. Try generating a new QR." };
9620
9635
  }
9621
9636