Split MAX bot loops and make chats cache-first

This commit is contained in:
sevenhill
2026-07-05 23:20:20 +03:00
parent 0106130744
commit 3bc6456ed7
7 changed files with 157 additions and 16 deletions
+14 -1
View File
@@ -674,7 +674,10 @@ app.listen(port, () => {
async function ensurePage(role = "default") {
const normalizedRole = String(role || "default");
const existing = pagesByRole.get(normalizedRole);
if (existing && !existing.isClosed()) return existing;
if (existing && !existing.isClosed()) {
await waitForRolePageReady(existing, normalizedRole);
return existing;
}
await ensureContext();
@@ -695,9 +698,19 @@ async function ensurePage(role = "default") {
pagesByRole.set(normalizedRole, rolePage);
attachNetworkCapture(rolePage);
await rolePage.goto(maxBaseUrl, { waitUntil: "domcontentloaded", timeout: 60000 });
await waitForRolePageReady(rolePage, normalizedRole);
return rolePage;
}
async function waitForRolePageReady(rolePage, role) {
if (role === "default") {
return;
}
await rolePage.waitForLoadState("domcontentloaded", { timeout: 15000 }).catch(() => {});
await waitForLoginStage(rolePage, "Authorized", 15000).catch(() => false);
}
async function ensureContext() {
if (context) return;
if (!contextInitialization) {