@ysgao/web-cli 0.3.2 → 0.3.3

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.
Files changed (2) hide show
  1. package/dist/index.js +22 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -51494,6 +51494,8 @@ async function attemptSilentRefresh(opts, deps, credentials) {
51494
51494
  const connect = deps.connect ?? connectCdpSession;
51495
51495
  const now = deps.now ?? (() => Date.now());
51496
51496
  const sleep = deps.sleep ?? defaultSleep;
51497
+ const notify = deps.notify ?? ((message) => process.stderr.write(`${message}
51498
+ `));
51497
51499
  try {
51498
51500
  return await withChrome({ headless: true }, async (chrome) => {
51499
51501
  const session = await connect(chrome.port);
@@ -51502,24 +51504,40 @@ async function attemptSilentRefresh(opts, deps, credentials) {
51502
51504
  await session.navigate(opts.loginUrl);
51503
51505
  } catch {
51504
51506
  }
51505
- await attemptAutoFill(opts.site, session, deps, credentials);
51507
+ const firstAutoFillResult = await attemptAutoFill(opts.site, session, deps, credentials);
51506
51508
  const silentTimeoutMs = deps.silentRefreshTimeoutMs ?? (credentials ? SILENT_REFRESH_TIMEOUT_MS : SILENT_REFRESH_NO_CREDENTIAL_TIMEOUT_MS);
51507
- const deadline = now() + silentTimeoutMs;
51509
+ const startedAt = now();
51510
+ const deadline = startedAt + silentTimeoutMs;
51511
+ const retryAtMs = startedAt + Math.floor(silentTimeoutMs / 2);
51512
+ let retried = false;
51513
+ let retryAutoFillResult;
51514
+ let lastCookieCount = 0;
51508
51515
  for (; ; ) {
51509
51516
  const jar = await getLoginPageCookies(session, opts.loginUrl);
51510
- if (Object.keys(jar).length > 0 && await opts.isSessionReady(jar)) {
51517
+ lastCookieCount = Object.keys(jar).length;
51518
+ if (lastCookieCount > 0 && await opts.isSessionReady(jar)) {
51511
51519
  return jar;
51512
51520
  }
51513
51521
  if (now() >= deadline) {
51522
+ notify(
51523
+ `web-cli: silent session refresh for "${opts.site}" (${opts.intent}) did not establish a working session \u2014 credential stored: ${credentials ? "yes" : "no"}; auto-fill found a form to submit: ${firstAutoFillResult ? "yes" : "no"}` + (retried ? `; retried mid-wait, found a form that time: ${retryAutoFillResult ? "yes" : "no"}` : "") + `; cookies present when giving up: ${lastCookieCount}. If a credential is saved and this keeps happening, a CAPTCHA/2FA page or a changed login layout the auto-fill heuristic can't handle is the likely cause \u2014 try "web-cli login ${opts.site}" to sign in by hand and see what it actually shows.`
51524
+ );
51514
51525
  return null;
51515
51526
  }
51527
+ if (!retried && silentTimeoutMs > 0 && now() >= retryAtMs) {
51528
+ retried = true;
51529
+ retryAutoFillResult = await attemptAutoFill(opts.site, session, deps, credentials);
51530
+ }
51516
51531
  await sleep(SILENT_REFRESH_POLL_INTERVAL_MS);
51517
51532
  }
51518
51533
  } finally {
51519
51534
  await session.close();
51520
51535
  }
51521
51536
  });
51522
- } catch {
51537
+ } catch (err) {
51538
+ notify(
51539
+ `web-cli: silent session refresh for "${opts.site}" (${opts.intent}) did not run to completion (${err instanceof Error ? err.message : String(err)}).`
51540
+ );
51523
51541
  return null;
51524
51542
  }
51525
51543
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ysgao/web-cli",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Self-discovering REST API CLI for subscription medical-knowledge sites, driven by an AI agent",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {