// Check the cache, get the action, and run it // If selfHeal is true, we'll attempt to self-heal if the action fails async function actWithCache(page: Page, key: string, prompt: string, selfHeal = false) { try { const cacheExists = await getCache(key); let action: ObserveResult; if (cacheExists) { // Get the cached action action = await getCache(prompt); } else { // Get the observe result (the action) [action] = await page.observe(prompt); // Cache the action await setCache(prompt, action); } // Run the action (no LLM inference) await page.act(action); } catch (e) { console.error(e); // in selfHeal mode, we'll retry the action if (selfHeal) { console.log("Attempting to self-heal..."); await page.act(prompt); } else { throw e; } } }